public
Last active

xmonad with urgency hooks

  • Download Gist
xmonad.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
import System.IO
 
import Data.Ratio
import Control.Monad (liftM2)
 
import XMonad
-- import XMonad.Config.Gnome
import Data.Monoid
import System.Exit
 
import XMonad.Actions.CycleWS
import XMonad.Actions.FloatKeys
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.InsertPosition
import XMonad.Hooks.ManageDocks
-- import XMonad.Hooks.EwmhDesktops
-- import XMonad.Hooks.ManageHelpers
-- import XMonad.Hooks.SetWMName
import XMonad.Hooks.UrgencyHook
 
-- import XMonad.Layout
import XMonad.Layout.Grid
import XMonad.Layout.Reflect
-- import XMonad.Layout.CenteredMaster
import XMonad.Layout.Accordion
-- import XMonad.Layout.Circle
import XMonad.Layout.Tabbed
-- import XMonad.Layout.Spiral
-- import XMonad.Layout.IM
-- import XMonad.Layout.NoBorders
import XMonad.Layout.PerWorkspace
-- import XMonad.Layout.ResizableTile
-- import XMonad.Layout.StackTile
 
-- import XMonad.Config.Desktop
 
import qualified XMonad.StackSet as W
 
import XMonad.Util.Run(spawnPipe)
-- import XMonad.Util.EZConfig(additionalKeys)
 
import qualified Data.Map as M
 
-- The preferred terminal program, which is used in a binding below and by
-- certain contrib modules.
--
myTerminal :: String
myTerminal = "terminator"
 
-- Whether focus follows the mouse pointer.
myFocusFollowsMouse :: Bool
myFocusFollowsMouse = False
 
-- Width of the window border in pixels.
myBorderWidth :: Dimension
myBorderWidth = 3
 
-- modMask lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt"). You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
--
-- myModMask = mod4Mask
myModMask :: KeyMask
myModMask = mod1Mask
 
-- The default number of workspaces (virtual screens) and their names.
-- By default we use numeric strings, but any string may be used as a
-- workspace name. The number of workspaces is determined by the length
-- of this list.
--
-- A tagging example:
--
-- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
--
myWorkspaces :: [String]
myWorkspaces = [ "^ vim"
, "1 /"
, "2 pdf"
, "3 web"
, "4 twit"
, "5 radio"
, "6 mail"
, "7 irc"
, "8 grphx"
, "9 misc"
, "0 emacs"
]
 
-- Border colors for unfocused and focused windows, respectively.
myNormalBorderColor :: String
myNormalBorderColor = "#000000"
 
myFocusedBorderColor :: String
myFocusedBorderColor = "#ffa71a" -- Day[9]'s yellow :-)
 
------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
--
myKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
 
-- launch a terminal/dmenu/gmrun
[ ((modm, xK_F1 ), spawn $ XMonad.terminal conf)
, ((mod4Mask, xK_F1 ), spawn "gvim")
, ((modm, xK_F2 ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"")
, ((mod4Mask, xK_F2 ), spawn "emacs")
, ((modm, xK_F3 ), spawn "gmrun")
 
-- close focused window
, ((modm, xK_F4 ), kill)
, ((modm .|. shiftMask, xK_c ), kill)
 
-- Rotate through the available layout algorithms
, ((modm, xK_space ), sendMessage NextLayout)
 
-- Reset the layouts on the current workspace to default
, ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
-- on laptop disabling the touchpad is quite handy
, ((mod4Mask , xK_space ), spawn "synclient TouchpadOff=$(synclient -l | grep -c 'TouchpadOff.*=.*0')")
 
-- -- Resize viewed windows to the correct size
-- , ((modm, xK_n ), refresh)
 
-- Move focus to the next/previous window
, ((modm, xK_Tab ), windows W.focusDown)
, ((modm .|. shiftMask, xK_Tab ), windows W.focusUp)
 
-- Move window to the next/previous position
, ((mod4Mask, xK_Tab ), windows W.swapDown)
, ((mod4Mask .|. shiftMask, xK_Tab ), windows W.swapUp)
 
-- Move focus to the master window
, ((modm, xK_m ), windows W.focusMaster )
 
-- Swap the focused window and the master window
-- , ((modm, xK_u ), windows W.swapMaster)
 
-- Swap the focused window and the master window
, ((modm, xK_Return ), windows W.swapMaster)
, ((modm, xK_Escape ), windows W.swapMaster)
 
-- -- Swap the focused window with the next window
-- , ((modm .|. shiftMask, xK_i ), windows W.swapDown )
--
-- -- Swap the focused window with the previous window
-- , ((modm .|. shiftMask, xK_a ), windows W.swapUp )
 
-- Shrink/Expand the master area
, ((modm, xK_comma ), sendMessage Shrink)
, ((modm, xK_period ), sendMessage Expand)
 
-- Push window back into tiling
, ((modm, xK_j ), withFocused $ windows . W.sink)
, ((modm .|. shiftMask, xK_Left ), withFocused $ keysMoveWindow (-10,0))
, ((modm .|. shiftMask, xK_Up ), withFocused $ keysMoveWindow (0,-10))
, ((modm .|. shiftMask, xK_Right ), withFocused $ keysMoveWindow (10,0))
, ((modm .|. shiftMask, xK_Down ), withFocused $ keysMoveWindow (0,10))
, ((mod4Mask.|. shiftMask, xK_Left ), withFocused $ keysResizeWindow (-10,0) (1%2,1%2))
, ((mod4Mask.|. shiftMask, xK_Up ), withFocused $ keysResizeWindow (0 ,-10) (1%2,1%2))
, ((mod4Mask.|. shiftMask, xK_Right ), withFocused $ keysResizeWindow (10 ,0) (1%2,1%2))
, ((mod4Mask.|. shiftMask, xK_Down ), withFocused $ keysResizeWindow (0 ,20) (1%2,1%2))
 
-- , ((modm, xK_J ), withFocused $ \w -> focus w >> mouseResizeWindow w
-- >> windows W.shiftMaster)
, ((mod4Mask , xK_x ), focusUrgent)
-- De/Increment the number of windows in the master area
, ((modm .|. shiftMask, xK_comma ), sendMessage (IncMasterN 1))
, ((modm .|. shiftMask, xK_period ), sendMessage (IncMasterN (-1)))
 
-- Toggle the status bar gap
-- Use this binding with avoidStruts from Hooks.ManageDocks.
-- See also the statusBar function from Hooks.DynamicLog.
--
-- , ((modm , xK_b ), sendMessage ToggleStruts)
 
-- Quit xmonad
, ((modm .|. shiftMask , xK_F5 ), io exitSuccess)
 
-- , ((modm .|. shiftMask , xK_F5 ), spawn "gnome-session-save --gui --kill")
 
-- Restart xmonad
, ((modm , xK_F5 ), spawn "xmonad --recompile; xmonad --restart")
 
-- Screensaver
, ((mod4Mask , xK_l ), spawn "xscreensaver-command -lock")
 
-- VolumeControl
-- , ((mod4Mask , xK_v ), spawn "xfce4-mixer")
 
-- FileManager
, ((mod4Mask , xK_f ), spawn "pcmanfm")
, ((mod4Mask .|. shiftMask, xK_p ), spawn "evince")
, ((mod4Mask , xK_p ), spawn "okular")
 
-- Opera
, ((mod4Mask , xK_w ), spawn "opera")
, ((mod4Mask .|. shiftMask, xK_w ), spawn "opera-next")
 
-- make ScreenPicture in .2 seconds
, ((controlMask , xK_Print), spawn "sleep 0.2; scrot -s")
 
-- make ScreenPicture NOW
, ((0 , xK_Print), spawn "scrot")
 
-- Special Keys
--
-- XF68XK_AudioMute
, ((0 , 0x1008FF12), spawn "amixer -q set Master toggle")
, ((shiftMask , 0x1008FF12), spawn "amixer -q set Front toggle; amixer -q set Side toggle; amixer -q set Surround toggle")
--
-- -- playpause/previous/next Track
, ((mod4Mask , 0x1008FF14), spawn "banshee --toggle-playing")
, ((mod4Mask , 0x1008FF11), spawn "banshee --restart-or-previous")
, ((mod4Mask , 0x1008FF13), spawn "banshee --next")
, ((0 , 0x1008FF14), spawn "rhythmbox-client --play-pause")
, ((shiftMask , 0x1008FF11), spawn "rhythmbox-client --previous")
, ((shiftMask , 0x1008FF13), spawn "rhythmbox-client --next")
--
-- -- XF68XK_Audio[Lower/Raise]Volume
, ((0 , 0x1008FF11), spawn "amixer -q set Master 5%- unmute")
, ((0 , 0x1008FF13), spawn "amixer -q set Master 5%+ unmute")
 
-- XF68XK_Calculator
, ((0 , 0x1008ff1d), spawn "gvim")
 
-- XF68XK_Calculator
, ((shiftMask , 0x1008ff1d), spawn "gcalctool")
 
]
++
 
-- mod-[1..9], Switch to workspace N
-- mod4-[1..9], Move client to workspace N
--
[((0 .|. m, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) ([0xFE52]++[xK_1 .. xK_9]++[xK_0])
, (f, m) <- [(W.greedyView, modm), (W.shift, mod4Mask)]]
 
++
 
-- mod-{1,2,3}, Switch to physical/Xinerama screens 1, 2, or 3
-- mod-shift-{1,2,3}, Move client to screen 1, 2, or 3
--
[((shiftMask .|. m, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_1, xK_2, xK_3] [0..]
, (f, m) <- [(W.view, modm), (W.shift, mod4Mask)]]
 
------------------------------------------------------------------------
-- Mouse bindings: default actions bound to mouse events
--
myMouseBindings :: XConfig t -> M.Map (KeyMask, Button) (Window -> X ())
myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList
 
-- mod-button1, Set the window to floating mode and move by dragging
[ ((modm, button1), \w -> focus w >> mouseMoveWindow w
>> windows W.shiftMaster)
 
-- mod-button2, Raise the window to the top of the stack
, ((modm, button2), \w -> focus w >> windows W.shiftMaster)
 
-- mod-button3, Set the window to floating mode and resize by dragging
, ((modm, button3), \w -> focus w >> mouseResizeWindow w
>> windows W.shiftMaster)
 
, ((modm, button4), \w -> focus w >> prevWS)
, ((modm, button5), \w -> focus w >> nextWS)
 
, ((shiftMask.|. modm , button4), \w -> focus w >> shiftToNext)
, ((shiftMask.|. modm , button5), \w -> focus w >> shiftToPrev)
 
, ((mod4Mask, button4), \w -> focus w >> windows W.focusUp)
, ((mod4Mask, button5), \w -> focus w >> windows W.focusDown)
-- 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 = onWorkspaces ["2 pdf", "5 radio"] (
avoidStruts ( reflectHoriz tiled
||| reflectHoriz Grid
||| simpleTabbed )) $
avoidStruts ( reflectHoriz tiled
||| reflectHoriz Grid
||| reflectHoriz (Mirror Accordion)
||| Accordion
||| simpleTabbed)
 
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 = 1/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 :: Query (Endo WindowSet)
myManageHook = composeAll
[ className =? "Ardour2" --> doFloat
, className =? "Banshee" --> doShift "5 radio"
, className =? "banshee" --> doShift "5 radio"
, className =? "Chromium-browser" --> doShift "3 web"
, resource =? "desktop_window" --> doIgnore
, className =? "Emacs" --> doShift "0 emacs"
, className =? "Evince" --> doShift "2 pdf"
, className =? "Exe" --> doFloat
, className =? "Gimp-2.6" --> doShift "8 grphx" <+> doFloat
, className =? "Gimp" --> doShift "8 grphx" <+> doFloat
, className =? "Gpodder" --> doFloat
, className =? "Guake" --> doFloat
, className =? "Gvim" --> viewShift "^ vim"
, className =? "Hotot" --> doShift "4 twit"
, className =? "Icedove" --> doShift "6 mail"
, className =? "Inkscape" --> doShift "8 grphx"
, resource =? "kdesktop" --> doIgnore
, className =? "Okular" --> doShift "2 pdf"
, className =? "Opera" --> doShift "3 web"
, className =? "OperaNext" --> doShift "3 web"
, className =? "Operapluginwrapper" --> doFloat
, className =? "operapluginwrapper-native" --> doFloat
, className =? "Operapluginwrapper-native" --> doFloat
, className =? "Pidgin" --> doShift "7 irc" <+> doFloat
, className =? "Plugin-container" --> doFloat
, className =? "Qjackctl.real" --> doFloat
, className =? "Qt Jambi application" --> doFloat
, className =? "Rhythmbox" --> doShift "5 radio"
, className =? "Skype" --> doFloat
, className =? "Transmission-gtk" --> doFloat
, className =? "Volumeicon" --> doFloat
, className =? "W" --> doFloat
, className =? "Xfce4-mixer" --> doFloat
, className =? "Xpdf" --> doShift "2 pdf"
 
, title =? "Copying Files" --> doFloat ]
where viewShift = doF . liftM2 (.) W.greedyView W.shift
 
------------------------------------------------------------------------
-- Event handling
 
-- * EwmhDesktops users should change this to ewmhDesktopsEventHook
--
-- Defines a custom handler function for X Events. The function should
-- return (All True) if the default handler is to be run afterwards. To
-- combine event hooks use mappend or mconcat from Data.Monoid.
--
myEventHook :: Event -> X All
myEventHook = mempty
 
------------------------------------------------------------------------
-- Status bars and logging
 
-- Perform an arbitrary action on each internal state change or X event.
-- See the 'XMonad.Hooks.DynamicLog' extension for examples.
-- rmalBorderColor :: [Char]
--
-- myLogHook = dynamicLogWithPP dzenPP
myLogHook :: Handle -> X ()
myLogHook dest = dynamicLogWithPP defaultPP { ppOutput = hPutStrLn dest,
ppVisible = wrap "(" ")"
}
 
------------------------------------------------------------------------
-- Startup hook
 
-- Perform an arbitrary action each time xmonad starts or is restarted
-- with mod-q. Used by, e.g., XMonad.Layout.PerWorkspace to initialize
-- per-workspace layout choices.
--
-- By default, do nothing.
myStartupHook :: X ()
myStartupHook = return ()
 
------------------------------------------------------------------------
-- Now run xmonad with all the defaults we set up.
 
-- Run xmonad with the settings you specify. No need to modify this.
--
 
main :: IO ()
main = do
xmproc <- spawnPipe "/usr/bin/xmobar"
xmonad $ withUrgencyHook NoUrgencyHook $ defaultConfig {
-- simple stuff
terminal = myTerminal,
focusFollowsMouse = myFocusFollowsMouse,
borderWidth = myBorderWidth,
modMask = myModMask,
workspaces = myWorkspaces,
normalBorderColor = myNormalBorderColor,
focusedBorderColor = myFocusedBorderColor,
 
-- key and mouse bindings
keys = myKeys,
mouseBindings = myMouseBindings,
 
-- hooks, layouts
manageHook = manageDocks <+> insertPosition Above Newer
<+> myManageHook,
layoutHook = myLayout,
logHook = myLogHook xmproc,
handleEventHook = myEventHook,
startupHook = myStartupHook
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.