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