]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - xmonad.hs
d4c323a162c12236484828adb40b75316c4ece51
[config/dotfiles.git] / xmonad.hs
1 -- xmonad configuration file.
2 --
3 -- Tested with xmonad 0.9, most settings should work fine with xmonad 0.7.
4
5
6 -- "hiding" necessary for LayoutCombinators.
7 import XMonad hiding ( (|||) )
8 -- Necessary for reflectVert.
9 import XMonad.Layout.Reflect
10 -- Necessary for avoidMaster.
11 import qualified XMonad.StackSet as W
12 -- Necessary for toggleLayouts.
13 import XMonad.Layout.ToggleLayouts
14 -- Necessary for smartBorders.
15 import XMonad.Layout.NoBorders
16 -- Necessary for composeOne and -?>.
17 import XMonad.Hooks.ManageHelpers
18 -- Necessary for `additionalKeys`.
19 import XMonad.Util.EZConfig
20 -- Necessary for setWMName.
21 import XMonad.Hooks.SetWMName
22 -- Necessary for toggleWS.
23 import XMonad.Actions.CycleWS
24 -- Necessary for named.
25 import XMonad.Layout.Named
26 -- Necessary for JumpToLayout.
27 import XMonad.Layout.LayoutCombinators
28 -- Necessary for Limit layout.
29 import XMonad.Layout.TwoPane
30
31
32 -- Prevent new windows from spawning in the master pane. Taken from
33 -- http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions on
34 -- 2009-06-30. Thanks. Modified to not steal focus from the master pane when a
35 -- new window is created, thanks to vav in #xmonad on Freenode (2010-04-15
36 -- 21:59 CEST).
37 avoidMaster :: W.StackSet i l a s sd -> W.StackSet i l a s sd
38 avoidMaster = W.modify' $ \c -> case c of
39     W.Stack t [] (r:rs) -> W.Stack r [] (t:rs)
40     otherwise           -> c
41
42 -- Create my custom layout.
43 --
44 -- Only use horizontal (Mirror tiled) and fullscreen layouts, but allow
45 -- switching to other layouts with bindings.
46 --
47 -- The master pane is at the top of the screen. To make sure new windows don't
48 -- spawn in the master pane avoidMaster (see below) is used. Borders are only
49 -- drawn when the screen has more then one window (smartBorders).
50 --
51 -- Thanks to jrick in #xmonad on Freenode (2009-06-29 22:19 CEST) for telling
52 -- me how to remove the vertical tiled layout.
53 --
54 -- JumpToLayout (from LayoutCombinators) is used to jump to specific layouts,
55 -- thanks to aavogt in #xmonad on Freenode (2011-06-12 22:13 CEST).
56 --
57 -- named is used to name layouts which allows switching to a specific layout
58 -- (see below), thanks to vav in #xmonad on Freenode (2011-06-12 22:28 CEST).
59 --
60 -- The limit layout displays only one window in the lower pane, thanks to to
61 -- Qantourisc (2010-06-12 15:15 CEST) for the hint to use TwoPane.
62 myLayoutHook = named "Default" (smartBorders $ Mirror tiled)
63            ||| named "Full" (smartBorders Full)
64            ||| named "Vertical" (smartBorders tiled)
65            ||| named "Limit" (smartBorders $ Mirror $ TwoPane delta ratio)
66     where
67     -- Default tiling algorithm partitions the screen into two panes.
68     tiled   = Tall nmaster delta ratio
69     -- The default number of windows in the master pane.
70     nmaster = 1
71     -- Percent of screen to increment by when resizing panes.
72     delta   = 3/100
73     -- Default proportion of screen occupied by master pane.
74     ratio   = 1/2
75
76 -- Don't spawn new windows in the master pane (which is at the top of the
77 -- screen). Thanks to dschoepe, aavogt and especially vav in #xmonad on
78 -- Freenode (2009-06-30 02:10f CEST).
79 --
80 -- Also some applications are spawned on specific workspaces. Thanks to
81 -- dschoepe and ivanm in #xmonad on Freenode (2009-07-12 14:50 CEST).
82 myManageHook = composeOne
83     -- Browser on "2".
84     [ className =? "Iceweasel"          -?> doF (W.shift "2")
85     -- Miscellaneous on "3".
86     , className =? "Wireshark"          -?> doF (W.shift "3")
87     , title     =? "OpenOffice.org"     -?> doF (W.shift "3") -- splash screen
88     , className =? "OpenOffice.org 2.4" -?> doF (W.shift "3")
89     , className =? "Vncviewer"          -?> doF (W.shift "3")
90     -- Wine on "4".
91     , className =? "Wine"               -?> doF (W.shift "4")
92
93     -- Don't spawn new windows in the master pane.
94     , return True -?> doF avoidMaster
95     -- Prevent windows which get moved to other workspaces from removing the
96     -- focus of the currently selected window. Thanks to vav in #xmonad on
97     -- Freenode (2010-04-15 21:04 CEST).
98     , return True -?> doF W.focusDown
99     ]
100
101 -- Switch to next layout, but skip all layouts not in layouts argument. This
102 -- allows switching to some layouts with mappings but excluding them from
103 -- meta-space (which gets mapped to this function). Thanks to aavogt in
104 -- #xmonad on Freenode for this function (2011-06-13 12:45 CEST) and
105 -- rootzlevel in #xmonad on Freenode for fixes (2011-06-13 15:20 CEST),
106 -- modified to take list of layouts to switch to, not layouts to exclude.
107 nextLayoutIncluding :: [String] -> X ()
108 nextLayoutIncluding layouts = do
109     cws <- gets (W.workspace . W.current . windowset)
110     sendMessageWithNoRefresh NextLayout cws
111     nextLayoutIncluding' layouts 1000 -- nobody has more than 1000 layouts
112
113 nextLayoutIncluding' :: [String] -> Int -> X ()
114 nextLayoutIncluding' layouts iterations = do
115     cws <- gets (W.workspace . W.current . windowset)
116     -- iterations prevents an endless loop if no valid layout can be found.
117     if not ((description $ W.layout cws) `elem` layouts) && iterations > 0
118         -- Skip over excluded layouts.
119         then do
120             sendMessageWithNoRefresh NextLayout cws
121             nextLayoutIncluding' layouts (iterations - 1)
122         -- Found allowed layout, show it.
123         else refresh
124
125 myKeys = [
126         -- Switch to next layout, but only use the listed layouts.
127         ((mod4Mask, xK_space), nextLayoutIncluding ["Default", "Full"])
128         -- Switch to vertical tiled layout.
129       , ((mod4Mask, xK_v), sendMessage $ JumpToLayout "Vertical")
130         -- Switch to limit layout which displays only one window in the lower
131         -- pane.
132       , ((mod4Mask, xK_b), sendMessage $ JumpToLayout "Limit")
133
134         -- Switch to last active workspace, thanks to moljac024 in #xmonad on
135         -- Freenode (2010-12-18 14:45 CET).
136       , ((mod4Mask, xK_f), toggleWS)
137     ]
138     ++
139     -- When using multiple screens, switching to another workspace causes
140     -- xmonad to pull the workspace to the current screen if it was also
141     -- displayed on another one. This is confusing for me so the following
142     -- code changes it to just switch to the screen where the workspace is
143     -- already displayed.
144     --
145     -- Thanks to the xmonad FAQ, read on 2010-06-16 13:42 CEST
146     -- (http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions).
147     -- Thanks to MrElendig in #xmonad on Freenode (2010-06-17 17:16 CEST) to
148     -- use the default XMonad workspaces.
149     [((m .|. mod4Mask, k), windows $ f i)
150         | (i, k) <- zip (XMonad.workspaces defaultConfig) [xK_1 .. xK_9]
151         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
152
153 main = xmonad $ defaultConfig
154     -- Use Windows key as main key as it doesn't conflict with any other key
155     -- bindings.
156     { modMask = mod4Mask
157     -- Inactive borders are black - invisible on my black screen.
158     , normalBorderColor = "#000000"
159     -- Active borders are dark red.
160     , focusedBorderColor = "#990000"
161     -- Use my layout and manage hooks (see above).
162     , layoutHook = myLayoutHook
163     , manageHook = myManageHook
164     -- Use unicode rxvt as my terminal.
165     , terminal = "urxvt"
166     -- Necessary for Java so it recognizes xmonad as tiling window manager.
167     , startupHook = setWMName "LG3D"
168     }
169     `additionalKeys` myKeys
170
171 -- vim: nospell