]> code.delx.au - dotfiles/blob - .xmonad/xmonad.hs
xmonad: key binding for cycling workspaces
[dotfiles] / .xmonad / xmonad.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 import System.IO
3 import XMonad
4 import XMonad.Actions.CycleRecentWS
5 import XMonad.Actions.PhysicalScreens
6 import XMonad.Hooks.DynamicLog
7 import XMonad.Hooks.EwmhDesktops
8 import XMonad.Hooks.ICCCMFocus
9 import XMonad.Hooks.ManageDocks
10 import XMonad.Hooks.ManageHelpers
11 import XMonad.Hooks.SetWMName
12 import XMonad.Layout.IM
13 import XMonad.Layout.LayoutHints
14 import qualified XMonad.Layout.Magnifier as Mag
15 import XMonad.Layout.Master
16 import XMonad.Layout.NoBorders
17 import XMonad.Layout.NoFrillsDecoration
18 import XMonad.Layout.PerWorkspace
19 import XMonad.Layout.Renamed
20 import XMonad.Layout.Reflect
21 import XMonad.Layout.Tabbed
22 import XMonad.Layout.ThreeColumns
23 import XMonad.Util.Run(spawnPipe)
24 import qualified Data.Map as M
25 import qualified XMonad.StackSet as W
26
27
28 myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
29 [
30 ((modm .|. shiftMask, xK_h), spawn "xfce4-session-logout"),
31 ((modm .|. shiftMask, xK_l), spawn "xscreensaver-command --lock"),
32 ((modm .|. shiftMask, xK_r), spawn "xmonad --restart"),
33
34 ((modm, xK_n), spawn "xfce4-terminal"),
35 ((modm, xK_i), spawn "firefox"),
36 ((modm, xK_c), spawn "emacsclient --create-frame --no-wait"),
37 ((modm, xK_p), spawn "kupfer"),
38
39 ((modm .|. shiftMask, xK_c ), kill),
40 ((modm, xK_space ), sendMessage NextLayout),
41 ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf),
42 ((modm, xK_j ), windows W.focusDown),
43 ((modm, xK_k ), windows W.focusUp ),
44 ((modm, xK_m ), windows W.focusMaster ),
45 ((modm, xK_Return), windows W.swapMaster),
46 ((modm .|. shiftMask, xK_j ), windows W.swapDown ),
47 ((modm .|. shiftMask, xK_k ), windows W.swapUp ),
48 ((modm, xK_h ), sendMessage Shrink),
49 ((modm, xK_l ), sendMessage Expand),
50 ((modm, xK_t ), withFocused $ windows . W.sink),
51 ((modm , xK_comma ), sendMessage (IncMasterN 1)),
52 ((modm , xK_period), sendMessage (IncMasterN (-1))),
53 ((modm , xK_b ), sendMessage ToggleStruts),
54 ((modm , xK_z ), sendMessage Mag.Toggle),
55 ((modm , xK_a), cycleRecentWS [xK_Super_L] xK_a xK_a)
56 ]
57 ++
58
59 -- mod-{o,e,u}, Switch to physical/Xinerama screens 1, 2, or 3
60 -- mod-shift-{o,e,u}, Move client to screen 1, 2, or 3
61 [((m .|. modm, key), f sc)
62 | (key, sc) <- zip [xK_o, xK_e, xK_u] [0..]
63 , (f, m) <- [(viewScreen, 0), (sendToScreen, shiftMask)]
64 ]
65 ++
66
67 -- mod-[1..9], Switch to workspace N
68 -- mod-shift-[1..9], Move client to workspace N
69 [((m .|. modm, k), windows $ f i)
70 | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
71 , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]
72 ]
73
74
75 avoidMaster = W.modify' $ \c -> case c of
76 W.Stack t [] (r:rs) -> W.Stack t [r] rs
77 otherwise -> c
78
79 isSkipTaskBar = isInProperty "_NET_WM_STATE" "_NET_WM_STATE_SKIP_TASKBAR"
80
81 myManageHook =
82 manageDocks <+>
83 composeOne [
84 transience,
85 (isSkipTaskBar -?> doFloat),
86 (isDialog -?> doFloatAt 0.1 0.1),
87 (isFullscreen -?> doFullFloat),
88 (fmap Just $ doF avoidMaster)
89 ]
90
91
92 myWorkspaces = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
93
94 myPP = xmobarPP
95 {
96 ppCurrent = xmobarColor "#A01010" "" . wrap "[" "]",
97 ppTitle = xmobarColor "#10A010" ""
98 }
99
100 myLogHook hooks = do
101 mapM (\h -> dynamicLogWithPP myPP { ppOutput = hPutStrLn h }) hooks
102 takeTopFocus -- fix for Java Swing apps
103
104 myStartupHook = do
105 setWMName "LG3D" -- fix for Java Swing apps
106 spawn "xfce4-panel --restart" -- ensure it appears on top of xmobar
107
108 goldenRatio = (toRational (2/(1+sqrt(5)::Double)))
109
110 myTitleTheme = defaultTheme {
111 fontName = "xft:sans-serif:size=10",
112 decoHeight = 24
113 }
114
115 createLayout name layout =
116 renamed [Replace name] $
117 layoutHints $
118 smartBorders $
119 layout
120
121 myFullLayout = createLayout "Full" $
122 noBorders $
123 Full
124
125 myTiledLayout = createLayout "Tall" $
126 avoidStruts $
127 Mag.magnifierOff $
128 Tall nMaster ratioIncrement masterRatio
129 where
130 nMaster = 1
131 ratioIncrement = 3/100
132 masterRatio = goldenRatio
133
134 myTabbedLayout = createLayout "Tab" $
135 avoidStruts $
136 tabbed shrinkText myTitleTheme
137
138 myThreeColLayout = createLayout "ThreeCol" $
139 avoidStruts $
140 Mag.magnifierOff $
141 ThreeCol numMaster resizeDelta masterRatio
142 where
143 resizeDelta = 3/100
144 masterRatio = 4/10
145 numMaster = 1
146
147 myMasterTabbedLayout = createLayout "MTab" $
148 avoidStruts $
149 Mag.magnifierOff $
150 mastered resizeDelta masterRatio $
151 tabbed shrinkText myTitleTheme
152 where
153 resizeDelta = 3/100
154 masterRatio = goldenRatio
155
156 myGimpLayout = createLayout "Gimp" $
157 avoidStruts $
158 withIM (1/6) (Role "gimp-toolbox") $
159 reflectHoriz $
160 withIM (1/6) (Role "gimp-dock") $
161 reflectHoriz $
162 tabbed shrinkText myTitleTheme
163
164
165 -- This was the easiest way I found to avoid a compile error when I have
166 -- an unused layout
167 referenceAllLayoutsToAvoidErrors =
168 myFullLayout |||
169 myTiledLayout |||
170 myTabbedLayout |||
171 myThreeColLayout |||
172 myMasterTabbedLayout |||
173 myGimpLayout
174
175
176 myLayout =
177 (
178 onWorkspace "1" (myTabbedLayout ||| myMasterTabbedLayout) $
179 onWorkspace "2" (myTabbedLayout ||| myMasterTabbedLayout) $
180 onWorkspace "9" (myFullLayout ||| myMasterTabbedLayout ||| myTabbedLayout ||| myTiledLayout ||| myGimpLayout) $
181 (myMasterTabbedLayout ||| myTabbedLayout ||| myTiledLayout)
182 )
183
184 main = do
185 xmonadDir <- getXMonadDir
186 xmobars <- mapM (\x -> spawnPipe ("xmobar -x " ++ (show x) ++ " " ++ xmonadDir ++ "/xmobar.hs")) [1, 2]
187 xmonad $ ewmh defaultConfig {
188 manageHook = myManageHook,
189 layoutHook = myLayout,
190 workspaces = myWorkspaces,
191 logHook = myLogHook xmobars,
192 startupHook = myStartupHook,
193 keys = myKeys,
194 modMask = mod4Mask,
195 handleEventHook = handleEventHook defaultConfig <+> fullscreenEventHook,
196 focusFollowsMouse = False
197 }
198