summaryrefslogtreecommitdiff
path: root/desktop/xmonad/xmonad.hs
blob: 25127f8e8f720b49f91b0d4f806d25ac936bc0a8 (plain)
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
{-# LANGUAGE DeriveDataTypeable #-}

import XMonad
import qualified XMonad.Config
import XMonad.Config.Gnome
import XMonad.Actions.DynamicWorkspaces
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.XMonad
import XMonad.Util.Run
import qualified XMonad.Layout
import qualified XMonad.Util.EZConfig as EZ
import qualified XMonad.StackSet as W
import XMonad.Actions.CycleWS
import qualified XMonad.Actions.DynamicWorkspaceOrder as DO
import XMonad.Hooks.EwmhDesktops
import System.Taffybar.Hooks.PagerHints (pagerHints)
import XMonad.Layout.Grid
import XMonad.Layout.Minimize
import XMonad.Layout.NoBorders
import XMonad.Layout.PerWorkspace
import XMonad.Layout.MultiToggle
import XMonad.Layout.MultiToggle.Instances
import XMonad.Actions.WindowGo
import Control.Monad (liftM2)
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.ManageDocks (avoidStruts)
import XMonad.Util.ExtensibleState as XS
import XMonad.Layout.IndependentScreens (countScreens)
import XMonad.Hooks.SetWMName

launchInSpeshulTerminal :: String -> String -> X ()
launchInSpeshulTerminal roleTitle cmd = do
  safeSpawn "mate-terminal" [ "--role"
                             , roleTitle
                             , "--title"
                             , roleTitle
                             , "-e"
                             , cmd ]

launchSpeshulUnlessPresent :: String -> String -> X ()
launchSpeshulUnlessPresent roleTitle cmd = do
  raiseMaybe (launchInSpeshulTerminal roleTitle cmd) (title =? roleTitle)

launchOrRaiseEmail :: X ()
launchOrRaiseEmail = do
  launchSpeshulUnlessPresent "OfflineIMAP" "offlineimap"
  launchSpeshulUnlessPresent "Mutt" "mutt"



myManageHook =
  composeAll [ title =? "OfflineIMAP" --> doShift "mail"
             , title =? "Mutt" --> viewShift "mail"
             , className =? "Steam" --> doFloat
             , className =? "steam" --> doFullFloat
             , isFullscreen --> doFullFloat
             ]
  where 
    viewShift = doF . liftM2 (.) W.greedyView W.shift


data ScreenTracker = ScreenTracker { stScreenCount :: Int }
                     deriving (Typeable, Read, Show)

instance ExtensionClass ScreenTracker where
  initialValue = ScreenTracker { stScreenCount = 0 }
  extensionType = PersistentExtension

myScreenChangeHook :: X ()
myScreenChangeHook = do
  liftIO $ putStrLn "Examining screen count..."
  st <- XS.get
  let count = stScreenCount st
  nowCount <- countScreens
  if count == nowCount
    then liftIO $ putStrLn "No change"
    else do
         XS.put $ st { stScreenCount = nowCount }
         liftIO $ putStrLn $ "Changed from " ++ (show count) ++ " to " ++ (show nowCount)
         if (nowCount > 1)
           then safeSpawn "mate-display-properties" []
           else liftIO $ putStrLn "Not doing anything, nowCount < 2"
  
  liftIO $ putStrLn "Screen count examined."

myEventHandler :: (Event -> X a) -> Event -> X a
myEventHandler h e@(ConfigureEvent {ev_window = w}) =
  (whenX (isRoot w) myScreenChangeHook) >> h e
myEventHandler h e = h e

myPromptConfig :: XPConfig
myPromptConfig = def { font = "xft:Inconsolata Medium-8"
                     , height = 40
                     }

mainLayout = layoutHook XMonad.Config.def

myLayoutHook = smartBorders . minimize . mkToggle (single FULL) $ perWS
  where
    perWS = onWorkspace "mail" (avoidStruts XMonad.Layout.Full) $
            onWorkspace "vms" (avoidStruts griddy) $
             (layoutHook gnomeConfig)
    griddy = Grid ||| mainLayout

main :: IO ()
main = do
  xmonad $ ewmh $ pagerHints $ gnomeConfig
              { modMask = mod4Mask
              , manageHook = myManageHook <+> manageHook gnomeConfig
              , workspaces = defaultWorkSpaces
              , handleEventHook = myEventHandler fullscreenEventHook
              , layoutHook = myLayoutHook
              , startupHook = startupHook gnomeConfig >> setWMName "LG3D"
              , focusedBorderColor = "#FFA500"
              } `EZ.additionalKeysP`
              [ -- General keys
                ("M-x", spawn "mate-terminal")
              , ("M-M1-C-m", launchOrRaiseEmail)
              , ("M-M1-C-d", safeSpawn "mate-control-center" ["display"])
              , ("M1-<F2>", shellPrompt myPromptConfig)
                -- Screens, Workspaces and Windows
              , ("M1-C-<Left>", DO.moveTo Prev HiddenWS)
              , ("M1-C-<Right>", DO.moveTo Next HiddenWS)
              , ("<XF86Back>", DO.moveTo Prev HiddenWS)
              , ("<XF86Forward>", DO.moveTo Next HiddenWS)
              , ("M1-C-S-<Left>", DO.shiftTo Prev HiddenWS >> DO.moveTo Prev HiddenWS)
              , ("M1-C-S-<Right>", DO.shiftTo Next HiddenWS >> DO.moveTo Next HiddenWS)
              , ("M1-C-<Up>", prevScreen)
              , ("M1-C-<Down>", nextScreen)
              , ("M1-C-S-<Up>", shiftPrevScreen >> prevScreen)
              , ("M1-C-S-<Down>", shiftNextScreen >> nextScreen)
              , ("M-<Tab>", windows W.focusDown)
              , ("M-S-<Tab>", windows W.focusUp)
              , ("M1-<F4>", kill)
              , ("M-<F11>", sendMessage $ Toggle FULL)
              , ("M-S-t", withFocused $ windows . W.sink)
              , ("M-z", withFocused minimizeWindow)
              , ("M-S-z", sendMessage RestoreNextMinimizedWin)
                -- Workspace management
              , ("M-t", addWorkspacePrompt myPromptConfig)
              , ("M-r", renameWorkspace myPromptConfig)
              , ("M-w", removeEmptyWorkspace)
              , ("M-C-M1-<Left>", DO.swapWith Prev HiddenWS)
              , ("M-C-M1-<Right>", DO.swapWith Next HiddenWS)
                -- Management keys
              , ("M-<F12>", xmonadPrompt myPromptConfig)
              , ("M-S-r", spawn "if type xmonad; then xmonad --recompile && xmonad --restart; else xmessage xmonad not in \\$PATH: \"$PATH\"; fi")
              , ("M-C-M1-s", spawn "/home/dsilvers/bin/dmenu_shutdown")
              , ("M1-C-l", spawn "mate-screensaver-command --lock")
              ]
              `EZ.additionalKeys` extraKeyMappings mod4Mask

defaultWorkSpaces :: [String]
defaultWorkSpaces = ["mail", "irc", "www", "emacs", "term"]

extraKeyMappings :: ButtonMask -> [((ButtonMask, KeySym), X ())]
extraKeyMappings modm =
  [ ((modm, xK_Menu), spawn "/home/danielsilverstone/bin/dmenu_shutdown")
  ]