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