Source

dotfiles / xmonad / xmonad.hs

Full commit
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, unsafeSpawn)
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
                , workspaces = ["1:dev","2:web","3:twt","4:im"] ++ map show [5..9]
                , 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 60
                            }
                , borderWidth = myBorderWidth
                } `additionalKeys`
                [ ((mod4Mask, xK_r), spawn "exe=`dmenu_path | dmenu -b` && eval \"exec $exe\"")
                , ((mod4Mask .|. shiftMask, xK_l), spawn "xscreensaver-command -lock")
                , ((mod4Mask .|. shiftMask, xK_s), spawn "pavucontrol")
                , ((mod4Mask, xK_q), spawn "xmonad.start --recompile; xmonad.start --restart")
                , ((mod4Mask, xK_F11), spawn "sudo shutdown -r now")
                , ((mod4Mask, xK_F12), spawn "sudo shutdown -h now")


              -- Media Keys
              --, ((0, 0x1008ff12), spawn "amixer -q sset PCM toggle") -- XF86AudioMute
              --, ((0, 0x1008ff11), spawn "amixer -q sset PCM 655- unmute") -- XF86AudioLowerVolume
              --, ((0, 0x1008ff13), spawn "amixer -q sset PCM 655+ unmute") -- XF86AudioRaiseVolume
              , ((0, 0x1008ff12), spawn "amixer -q sset Master toggle") -- XF86AudioMute
              , ((0, 0x1008ff11), spawn "amixer -q sset Master 3- unmute") -- XF86AudioLowerVolume
              , ((0, 0x1008ff13), spawn "amixer -q sset Master 3+ unmute") -- XF86AudioRaiseVolume

                --, ((mod4Mask .|. shiftMask, xK_p), spawn "scrot $HOME/Pictures/Screen-%Y%m%d-%H%M%S.png -d 1")
                --, ((mod4Mask .|. shiftMask, xK_p), spawn "scrot")
                --
                --
                --
                --
                --

-- <function/media keys>
    --, ((0 .|. controlMask,         0x1008ff02   ), unsafeSpawn "moodlight -m") -- maximum screen brightness ((XF86MonBrightnessUp [max]))
                --, ((0, 0x1008ff02), unsafeSpawn "moodlight -u") -- increase screen brightness ((XF86MonBrightnessUp))
                --, ((0, 0x1008ff02), unsafeSpawn "moodlight -d") -- increase screen brightness ((XF86MonBrightnessUp))
    --, ((0,                         0x1008ff12   ), unsafeSpawn "mossrat -m")   -- mute volume, via "mossrat" ((XF86AudioMute))
    --, ((0,                         0x1008ff11   ), unsafeSpawn "mossrat -d 1") -- decrease volume, via "mossrat" ((XF86AudioLowerVolume))
    --, ((0,                         0x1008ff13   ), unsafeSpawn "mossrat -i 1") -- increase volume, via "mossrat" ((XF86AudioRaiseVolume))

                --, ((0, xK_Print), unsafeSpawn "import -window root $HOME/Pictures/$(date '+%Y%m%d-%H%M%S').png")

                --, ((0, xK_Print), unsafeSpawn "now=`date '+%Y%m%d-%H%M%S'` && eval \"import -window root $HOME/Pictures/Screenshot-$now.png\"")

                --, ((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