Source

dotfiles / xmonad / xmonad.hs

import Data.Monoid (All (All))
import Monad
import System.IO
import XMonad
--import XMonad.Actions.Volume
import XMonad.Config.Desktop
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Layout.Maximize
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Util.Run (spawnPipe)
import qualified Data.Map as M
import qualified XMonad.StackSet as W

myTerminal = "exo-open --launch TerminalEmulator"

myManageHook = composeAll
    [ className =? "MPlayer" --> doFloat
    , className =? "Gimp" --> doFloat
    ]

myFocusedBorderColour = "#FF6600"
myBorderWidth = 3

main = do
      xmproc <- spawnPipe "xmobar"
      xmonad $ defaultConfig
                { modMask = mod4Mask
                , terminal = myTerminal
                , focusedBorderColor = myFocusedBorderColour
                --, manageHook = manageDocks <+> myManageHook
                , manageHook = manageDocks <+> myManageHook <+> manageHook defaultConfig
                --, layoutHook = ewmhDesktopsLayout $ avoidStruts $ myLayout
                , handleEventHook = fullscreenEventHook
                , layoutHook = avoidStruts $ layoutHook defaultConfig
                , logHook = dynamicLogWithPP xmobarPP
                            { ppOutput = hPutStrLn xmproc
                            , ppHiddenNoWindows = xmobarColor "grey" ""
                            , ppTitle = xmobarColor "green" "" . shorten 85
                            }
                , borderWidth = myBorderWidth
                } `additionalKeys`
                [ ((mod4Mask, xK_r), spawn "exe=`dmenu_path | dmenu -b` && eval \"exec $exe\"")
                , ((mod4Mask .|. shiftMask, xK_l), spawn "xscreensaver-command -lock")
                , ((mod4Mask, xK_F11), spawn "sudo shutdown -r now")
                , ((mod4Mask, xK_F12), spawn "sudo shutdown -h now")

                --, ((mod4Mask, xK_Down), setMute False >> lowerVolume 4 >> return ())
                --, ((mod4Mask, xK_Up), setMute False >> raiseVolume 4 >> return ())
                --, ((mod4Mask, xK_m), toggleMute >> return ())


                --, ((0, 0x1008ff11), spawn "amixer -q set Master unmute & amixer -q set LFE unmute & amixer -q set PCM 7%-")
                --, ((0, 0x1008ff13), spawn "amixer -q set Master unmute & amixer -q set LFE unmute & amixer -q set PCM 7%+")
                --, ((0, 0x1008ff12), spawn "amixer -q set Master toggle & amixer -q set LFE toggle")

                -- ncmpcpp (mpd) controls
                --, ((mod4Mask .|. controlMask, xK_o), spawn "ncmpcpp toggle")
                --, ((mod4Mask .|. controlMask, xK_h), spawn "ncmpcpp stop; ncmpcpp play") -- "reset" current song to beginning
                --, ((mod4Mask .|. controlMask, xK_j), spawn "ncmpcpp next")
                --, ((mod4Mask .|. controlMask, xK_k), spawn "ncmpcpp prev")
                --, ((mod4Mask .|. controlMask, xK_l), spawn "ncmpcpp stop")
                --, ((mod4Mask .|. controlMask, xK_semicolon), spawn "ncmpcpp play")
                -- volume controls
                --, ((modm, xK_backslash), spawn "amixer -q set Master toggle")
                --, ((modm, xK_minus), spawn "amixer -q set Master 3- unmute")
                --, ((modm, xK_equal), spawn "amixer -q set Master 3+ unmute")
                -- screen brightness (call the script “~/syscfg/shellscripts/sys/brightness.sh”, which is symlinked to /usr/bin/brightness to toggle screen brightness — entry for this in “sudo visudo” allows us to do it as sudo w/o password prompt)
                --, ((modm     .|. shiftMask, xK_backslash ), spawn “sudo brightness”) — toggle brightness (100 or 0)

                ]

-- Helper functions to fullscreen the window
fullFloat, tileWin :: Window -> X ()
fullFloat w = windows $ W.float w r
    where r = W.RationalRect 0 0 1 1

tileWin w = windows $ W.sink w

fullscreenEventHook :: Event -> X All
fullscreenEventHook (ClientMessageEvent _ _ _ dpy win typ dat) = do
  state <- getAtom "_NET_WM_STATE"
  fullsc <- getAtom "_NET_WM_STATE_FULLSCREEN"
  isFull <- runQuery isFullscreen win

  -- Constants for the _NET_WM_STATE protocol
  let remove = 0
      add = 1
      toggle = 2

      -- The ATOM property type for changeProperty
      ptype = 4 

      action = head dat

  when (typ == state && (fromIntegral fullsc) `elem` tail dat) $ do
    when (action == add || (action == toggle && not isFull)) $ do
         io $ changeProperty32 dpy win state ptype propModeReplace [fromIntegral fullsc]
         fullFloat win
    when (head dat == remove || (action == toggle && isFull)) $ do
         io $ changeProperty32 dpy win state ptype propModeReplace []
         tileWin win

  -- It shouldn't be necessary for xmonad to do anything more with this event
  return $ All False

fullscreenEventHook _ = return $ All True