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