]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - xmonad/xmonad.hs
xmonad/xmonad.hs: Fix typo.
[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 -- Copyright (C) 2011-2012  Simon Ruderich
6 --
7 -- This file is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as published by
9 -- the Free Software Foundation, either version 3 of the License, or
10 -- (at your option) any later version.
11 --
12 -- This file is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with this file.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 -- "hiding" necessary for LayoutCombinators.
22 import XMonad hiding ( (|||) )
23 -- Necessary for reflectVert.
24 import XMonad.Layout.Reflect
25 -- Necessary for avoidMaster.
26 import qualified XMonad.StackSet as W
27 -- Necessary for toggleLayouts.
28 import XMonad.Layout.ToggleLayouts
29 -- Necessary for smartBorders.
30 import XMonad.Layout.NoBorders
31 -- Necessary for composeOne and -?>.
32 import XMonad.Hooks.ManageHelpers
33 -- Necessary for `additionalKeys`.
34 import XMonad.Util.EZConfig
35 -- Necessary for setWMName.
36 import XMonad.Hooks.SetWMName
37 -- Necessary for toggleWS.
38 import XMonad.Actions.CycleWS
39 -- Necessary for named.
40 import XMonad.Layout.Named
41 -- Necessary for JumpToLayout.
42 import XMonad.Layout.LayoutCombinators
43 -- Necessary for Limit layout.
44 import XMonad.Layout.TwoPane
45 -- Necessary for the Gimp layout.
46 import XMonad.Layout.PerWorkspace
47 import XMonad.Layout.IM
48
49
50 -- Prevent new windows from spawning in the master pane. Taken from
51 -- http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions on
52 -- 2009-06-30. Thanks. Modified to not steal focus from the master pane when a
53 -- new window is created, thanks to vav in #xmonad on Freenode (2010-04-15
54 -- 21:59 CEST).
55 avoidMaster :: W.StackSet i l a s sd -> W.StackSet i l a s sd
56 avoidMaster = W.modify' $ \c -> case c of
57     W.Stack t [] (r:rs) -> W.Stack r [] (t:rs)
58     otherwise           -> c
59
60 -- Create my custom layout.
61 --
62 -- Only use horizontal (Mirror tiled) and fullscreen layouts, but allow
63 -- switching to other layouts with bindings.
64 --
65 -- The master pane is at the top of the screen. To make sure new windows don't
66 -- spawn in the master pane avoidMaster (see below) is used. Borders are only
67 -- drawn when the screen has more then one window (smartBorders).
68 --
69 -- Thanks to jrick in #xmonad on Freenode (2009-06-29 22:19 CEST) for telling
70 -- me how to remove the vertical tiled layout.
71 --
72 -- JumpToLayout (from LayoutCombinators) is used to jump to specific layouts,
73 -- thanks to aavogt in #xmonad on Freenode (2011-06-12 22:13 CEST).
74 --
75 -- named is used to name layouts which allows switching to a specific layout
76 -- (see below), thanks to vav in #xmonad on Freenode (2011-06-12 22:28 CEST).
77 --
78 -- The limit layout displays only one window in the lower pane, thanks to to
79 -- Qantourisc (2010-06-12 15:15 CEST) for the hint to use TwoPane.
80 --
81 -- onWorkspace is used for a special layout for Gimp, thanks to Nathan Howell
82 -- (http://nathanhowell.net/2009/03/08/xmonad-and-the-gimp/) for this layout
83 -- (read on 2011-06-19).
84 myLayoutHook =
85     onWorkspace "5" gimp
86     $ (
87         named "Default" (smartBorders $ Mirror tiled)
88         ||| named "Full" (smartBorders Full)
89         ||| named "Vertical" (smartBorders tiled)
90         ||| named "Limit" (smartBorders $ Mirror $ TwoPane delta ratio)
91     ) where
92     -- Default tiling algorithm partitions the screen into two panes.
93     tiled   = Tall nmaster delta ratio
94     -- The default number of windows in the master pane.
95     nmaster = 1
96     -- Percent of screen to increment by when resizing panes.
97     delta   = 3/100
98     -- Default proportion of screen occupied by master pane.
99     ratio   = 1/2
100     -- Special layout for Gimp: toolbox left, dock right, main window in the
101     -- center.
102     gimp    = withIM (0.11) (Role "gimp-toolbox") $
103               reflectHoriz $
104               withIM (0.15) (Role "gimp-dock")
105               -- Layouts for the centered window.
106               (Mirror tiled ||| Full)
107
108 -- Don't spawn new windows in the master pane (which is at the top of the
109 -- screen). Thanks to dschoepe, aavogt and especially vav in #xmonad on
110 -- Freenode (2009-06-30 02:10f CEST).
111 --
112 -- Also some applications are spawned on specific workspaces. Thanks to
113 -- dschoepe and ivanm in #xmonad on Freenode (2009-07-12 14:50 CEST).
114 myManageHook = composeOne
115     -- Browser on "2".
116     [ className =? "Iceweasel"          -?> doF (W.shift "2")
117     -- Miscellaneous on "3".
118     , className =? "Wireshark"          -?> doF (W.shift "3")
119     , title     =? "OpenOffice.org"     -?> doF (W.shift "3") -- splash screen
120     , className =? "OpenOffice.org 2.4" -?> doF (W.shift "3")
121     , className =? "Vncviewer"          -?> doF (W.shift "3")
122     -- Wine on "4".
123     , className =? "Wine"               -?> doF (W.shift "4")
124     -- Gimp on "5".
125     , className =? "Gimp"               -?> doF (W.shift "5")
126
127     -- Don't spawn new windows in the master pane.
128     , return True -?> doF avoidMaster
129     -- Prevent windows which get moved to other workspaces from removing the
130     -- focus of the currently selected window. Thanks to vav in #xmonad on
131     -- Freenode (2010-04-15 21:04 CEST).
132     , return True -?> doF W.focusDown
133     ]
134
135 -- Switch to next layout, but skip all layouts not in layouts argument. This
136 -- allows switching to some layouts with mappings but excluding them from
137 -- meta-space (which gets mapped to this function). Thanks to aavogt in
138 -- #xmonad on Freenode for this function (2011-06-13 12:45 CEST) and
139 -- rootzlevel in #xmonad on Freenode for fixes (2011-06-13 15:20 CEST),
140 -- modified to take list of layouts to switch to, not layouts to exclude.
141 nextLayoutIncluding :: [String] -> X ()
142 nextLayoutIncluding layouts = do
143     cws <- gets (W.workspace . W.current . windowset)
144     sendMessageWithNoRefresh NextLayout cws
145     nextLayoutIncluding' layouts 1000 -- nobody has more than 1000 layouts
146
147 nextLayoutIncluding' :: [String] -> Int -> X ()
148 nextLayoutIncluding' layouts iterations = do
149     cws <- gets (W.workspace . W.current . windowset)
150     -- iterations prevents an endless loop if no valid layout can be found.
151     if not ((description $ W.layout cws) `elem` layouts) && iterations > 0
152         -- Skip over excluded layouts.
153         then do
154             sendMessageWithNoRefresh NextLayout cws
155             nextLayoutIncluding' layouts (iterations - 1)
156         -- Found allowed layout, show it.
157         else refresh
158
159 -- Use additional workspaces. Access with meta 1,2,..,9,0 for the first ten,
160 -- meta f1,f2,..,f10 for the second ten workspaces (see mappings below).
161 myWorkspaces = map show [1 .. 20 :: Int]
162
163 -- Use Windows (= Super) key as main key as it doesn't conflict with any other
164 -- key bindings.
165 myModMask = mod4Mask
166
167 myKeys = [
168         -- Switch to next layout, but only use the listed layouts.
169         ((myModMask, xK_space), nextLayoutIncluding ["Default", "Full"])
170         -- Switch to vertical tiled layout.
171       , ((myModMask, xK_v), sendMessage $ JumpToLayout "Vertical")
172         -- Switch to limit layout which displays only one window in the lower
173         -- pane.
174       , ((myModMask, xK_b), sendMessage $ JumpToLayout "Limit")
175
176         -- Switch to last active workspace, thanks to moljac024 in #xmonad on
177         -- Freenode (2010-12-18 14:45 CET).
178       , ((myModMask, xK_f), toggleWS)
179
180       -- Lock the screen. The sleep is necessary to allow xtrlock to grab the
181       -- keyboard input.
182       , ((myModMask, xK_z), spawn "sleep 1 && xtrlock")
183     ]
184     ++
185     -- When using multiple screens, switching to another workspace causes
186     -- xmonad to pull the workspace to the current screen if it was also
187     -- displayed on another one. This is confusing for me so the following
188     -- code changes it to just switch to the screen where the workspace is
189     -- already displayed.
190     --
191     -- Thanks to the xmonad FAQ, read on 2010-06-16 13:42 CEST
192     -- (http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions).
193     -- Thanks to MrElendig in #xmonad on Freenode (2010-06-17 17:16 CEST) how
194     -- to use the default xmonad workspaces. Thanks to geekosaur and OODavo in
195     -- #xmonad on Freenode (2012-12-23 01:14 CET) how to use more workspaces.
196     [((m .|. myModMask, k), windows $ f i)
197         | (i, k) <- zip myWorkspaces ([xK_1 .. xK_9] ++ [xK_0] -- 1..9,0
198                                       ++ [xK_F1 .. xK_F10])    -- f1..f10
199         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
200
201 main = xmonad $ defaultConfig
202     -- Change main key.
203     { modMask = myModMask
204     -- Inactive borders are black - invisible on my black screen.
205     , normalBorderColor = "#000000"
206     -- Active borders are dark red.
207     , focusedBorderColor = "#990000"
208     -- Use my layout and manage hooks (see above).
209     , layoutHook = myLayoutHook
210     , manageHook = myManageHook
211     -- Use unicode rxvt as my terminal.
212     , terminal = "urxvt"
213     -- Necessary for Java so it recognizes xmonad as tiling window manager.
214     , startupHook = setWMName "LG3D"
215     -- Use more workspaces than the default.
216     , workspaces = myWorkspaces
217     }
218     `additionalKeys` myKeys
219
220 -- vim: nospell