Skip to content

Instantly share code, notes, and snippets.

@mxey
Created March 8, 2010 03:19
Show Gist options
  • Save mxey/324806 to your computer and use it in GitHub Desktop.
Save mxey/324806 to your computer and use it in GitHub Desktop.
import XMonad
import System.Exit
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import Data.Ratio ((%))
import XMonad.Actions.CopyWindow
import XMonad.Actions.FocusNth
import XMonad.Actions.SpawnOn
import XMonad.Actions.SwapWorkspaces
import XMonad.Actions.UpdatePointer
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.UrgencyHook
import XMonad.Layout.Grid
import XMonad.Layout.LayoutScreens
import XMonad.Layout.Magnifier
import XMonad.Layout.NoBorders
import XMonad.Layout.Tabbed
import XMonad.Layout.ToggleLayouts
import XMonad.Prompt
import XMonad.Prompt.AppendFile
import XMonad.Prompt.Input
import XMonad.Prompt.Man
import XMonad.Prompt.Shell
import XMonad.Prompt.Ssh
import XMonad.Util.Run
import System.IO
import Graphics.X11.Types
-- Keysyms missing in XMonad
xK_XF86AudioLowerVolume = 0x1008ff11
xK_XF86AudioRaiseVolume = 0x1008ff13
xK_XF86Launch1 = 0x1008ff41
-- Prompt configuration
myXPConfig = defaultXPConfig
-- My extra prompts
screenshotPrompt :: XPConfig -> X ()
screenshotPrompt c =
inputPrompt c "Screenshot name" ?+ \name ->
io $ spawn ("screenshot " ++ name)
twitterPrompt :: XPConfig -> X ()
twitterPrompt c =
inputPrompt c "Tweet" ?+ \tweet ->
io $ runProcessWithInput "bti" [] (tweet ++ "\n")
>> return ()
myWorkspaceKeys = [xK_F1 .. xK_F9]
------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
myKeys sp amixer conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
-- launch a terminal
[ ((modMask, xK_space ), spawnHere sp $ XMonad.terminal conf)
-- launch terminals on common SSH targets
, ((modMask, xK_u), spawnHere sp "exec urxvtc -e ssh donik.lan.secute.org")
, ((modMask, xK_i), spawnHere sp "exec urxvtc -e ssh shells.chaosdorf.de")
-- launch start prompt
, ((modMask, xK_p), shellPromptHere sp myXPConfig)
-- open chat windows
, ((modMask, xK_c), spawnHere sp "exec /home/mxey/bin/open-chats")
-- launch GUI browser
, ((modMask, xK_w ), spawnHere sp "exec x-www-browser")
-- launch screen locker
, ((0, xK_XF86Launch1 ), spawnHere sp "exec i3lock")
-- pause MPD
, ((0, xK_Pause), spawnHere sp "exec envify mpc toggle")
-- next track in MPD
, ((modMask, xK_Pause), spawnHere sp "exec envify mpc next")
-- open ncmpc
, ((0, xK_Scroll_Lock), spawnHere sp "exec urxvtc -e envify ncmpc")
-- launch xkill
, ((modMask, xK_k), spawn "exec xkill")
-- make screenshot
, ((0, xK_Print), screenshotPrompt myXPConfig)
-- tweet
, ((modMask, xK_F12), twitterPrompt myXPConfig)
-- add a quick note to GTD inbox
, ((modMask, xK_g), appendFilePrompt myXPConfig "/home/mxey/leben/inbox")
-- add current selection to GTD inbox
, ((modMask .|. controlMask, xK_g), spawnHere sp "exec xclip -o >> ~/leben/inbox")
-- raise audio volume
, ((0, xK_XF86AudioRaiseVolume), io $ hPutStrLn amixer "set Master 5%+")
, ((shiftMask, xK_XF86AudioRaiseVolume), io $ hPutStrLn amixer "set PCM 5%+")
, ((controlMask, xK_XF86AudioRaiseVolume), spawn "envify mpc volume +5")
-- lower audio volume
, ((0, xK_XF86AudioLowerVolume), io $ hPutStrLn amixer "set Master 5%-")
, ((shiftMask, xK_XF86AudioLowerVolume), io $ hPutStrLn amixer "set PCM 5%-")
, ((controlMask, xK_XF86AudioLowerVolume), spawn "envify mpc volume -5")
-- close focused window
, ((modMask, xK_q), kill)
-- toggle fullscreen
, ((modMask, xK_f), sendMessage (XMonad.Layout.ToggleLayouts.Toggle "Full"))
-- Rotate through the available layout algorithms
, ((modMask .|. shiftMask, xK_Return), sendMessage NextLayout)
-- Move focus to the next window
, ((modMask, xK_n), windows W.focusDown)
-- Move focus to the previous window
, ((modMask, xK_r), windows W.focusUp)
-- Move focus to the master window
, ((modMask, xK_m), windows W.focusMaster)
-- Swap the focused window and the master window
, ((modMask, xK_Return), windows W.swapMaster)
-- Swap the focused window with the next window
, ((modMask .|. shiftMask, xK_n), windows W.swapDown)
-- Swap the focused window with the previous window
, ((modMask .|. shiftMask, xK_r), windows W.swapUp)
-- Shrink the master area
, ((modMask, xK_s), sendMessage Shrink)
-- Expand the master area
, ((modMask, xK_t), sendMessage Expand)
-- Push window back into tiling
, ((modMask .|. shiftMask, xK_space), withFocused $ windows . W.sink)
-- Increment the number of windows in the master area
, ((modMask .|. shiftMask, xK_s ), sendMessage (IncMasterN 1))
-- Deincrement the number of windows in the master area
, ((modMask .|. shiftMask, xK_t), sendMessage (IncMasterN (-1)))
-- toggle the status bar gap
, ((modMask, xK_b), sendMessage ToggleStruts)
-- Quit xmonad
, ((modMask .|. shiftMask, xK_x), io (exitWith ExitSuccess))
-- Make window sticky
, ((modMask, xK_l ), windows copyToAll)
-- Unstick window
, ((modMask .|. shiftMask, xK_l), killAllOtherCopies)
-- Restart xmonad
, ((modMask , xK_x), restart "xmonad" True)
]
++
-- mod-F[k..c], Switch to workspace N
-- mod-shift-F[k..c], Move client to workspace N
[((m .|. modMask, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) myWorkspaceKeys
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
++
-- mod-ctrl-F[k..c] Exchange workspaces
[((modMask .|. controlMask, k), windows $ swapWithCurrent i)
| (i, k) <- zip (XMonad.workspaces conf) myWorkspaceKeys]
++
-- mod4-[1..9] Switch to window N
[((modMask, k), focusNth i)
| (i, k) <- zip [0 .. 8] [xK_1 ..]]
------------------------------------------------------------------------
-- Mouse bindings: default actions bound to mouse events
--
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
-- mod-button1, Set the window to floating mode and move by dragging
[ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
-- mod-button2, Raise the window to the top of the stack
, ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
-- mod-button3, Set the window to floating mode and resize by dragging
, ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
-- you may also bind events to the mouse scroll wheel (button4 and button5)
]
------------------------------------------------------------------------
-- Layouts:
-- You can specify and transform your layouts by modifying these values.
-- If you change layout bindings be sure to use 'mod-shift-space' after
-- restarting (with 'mod-q') to reset your layout state to the new
-- defaults, as xmonad preserves your old layout settings by default.
--
-- The available layouts. Note that each layout is separated by |||,
-- which denotes layout choice.
--
myLayout = smartBorders (avoidStruts (toggleLayouts Full (GridRatio 1.2 ||| tiled ||| tabbed shrinkText defaultTheme)))
where
-- default tiling algorithm partitions the screen into two panes
tiled = Tall nmaster delta ratio
-- The default number of windows in the master pane
nmaster = 1
-- Default proportion of screen occupied by master pane
ratio = 1/2
-- Percent of screen to increment by when resizing panes
delta = 3/100
------------------------------------------------------------------------
-- Window rules:
-- Execute arbitrary actions and WindowSet manipulations when managing
-- a new window. You can use this to, for example, always float a
-- particular program, or have a client always appear on a particular
-- workspace.
--
-- To find the property name associated with a program, use
-- > xprop | grep WM_CLASS
-- and click on the client you're interested in.
--
-- To match on the WM_NAME, you can use 'title' in the same way that
-- 'className' and 'resource' are used below.
--
myManageHook = composeAll
[ className =? "MPlayer" --> doFloat
, className =? "Gimp" --> doFloat
, className =? "feh" --> doFloat
, className =? "Wine" --> doFloat
, className =? "Vncviewer" --> doFloat
, className =? "VLC" --> doFloat
, className =? "Xmessage" --> doFloat
, title =? "Irssi" --> doF W.shiftMaster
, doF avoidMaster
, manageDocks
]
-- Don't replace master window with new window
avoidMaster :: W.StackSet i l a s sd -> W.StackSet i l a s sd
avoidMaster = W.modify' $ \c -> case c of
W.Stack t [] (r:rs) -> W.Stack t [r] rs
otherwise -> c
myPP h = dzenPP { ppOutput = hPutStrLn h
, ppCurrent = dzenColor "green" "" . pad
, ppVisible = dzenColor "blue" "" . pad
, ppHidden = dzenColor "" "" . pad
, ppHiddenNoWindows = const ""
, ppUrgent = dzenColor "red" ""
, ppWsSep = ""
, ppSep = ""
, ppLayout = dzenColor "grey" "" . pad
, ppTitle = dzenEscape
}
main = do
sp <- mkSpawner
amixer <- spawnPipe "exec amixer -s"
din <- spawnPipe "exec dzen2 -bg black -fg grey -fn fixed -ta l -w 800"
xmonad $
withUrgencyHookC dzenUrgencyHook {
args = ["-fn", "fixed", "-bg", "black", "-fg", "lightgrey", "-xs", "1"],
duration = seconds 1
} urgencyConfig {
remindWhen = Every 120
}
$ ewmh $ defaultConfig {
-- simple stuff
terminal = "urxvtc",
focusFollowsMouse = True,
borderWidth = 1,
modMask = mod4Mask,
numlockMask = mod2Mask,
workspaces = map show [1..9],
normalBorderColor = "darkblue",
focusedBorderColor = "red",
-- key bindings
keys = myKeys sp amixer,
mouseBindings = myMouseBindings,
-- hooks, layouts
layoutHook = myLayout,
manageHook = manageSpawn sp <+> myManageHook,
logHook = dynamicLogWithPP (myPP din)
>> updatePointer (Relative 0.5 0.5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment