1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
-----------------------------------------------------------------------------
-- |
-- Module : Documentation
-- Copyright : (C) 2007 Andrea Rossato
-- License : BSD3
--
-- Maintainer : andrea.rossato@unibz.it
-- Stability : unstable
-- Portability : unportable
--
-- This is a module for documenting the xmonad-contrib library
--
-----------------------------------------------------------------------------
module Documentation
(
-- * Configuring XMonad
-- $configure
-- ** A simple example
-- $example
-- ** Checking your xmonad.hs is correct
-- $check
-- ** Loading your configuration
-- $load
-- ** Where are the defaults?
-- $where
-- * The XmonadContrib Library
-- $library
-- * Extending XMonad
-- $extending
-- ** Editing Key Bindings
-- $keys
-- *** Adding Key Bindings
-- $keyAdding
-- *** Removing Key Bindings
-- $keyDel
-- *** Adding and Removing Key Bindings
-- $keyAddDel
-- ** Adding\/Removing Layouts
-- $layout
-- ** Hooks Management
-- $hooks
-- * Writing Other Extensions
-- $writing
) where
--------------------------------------------------------------------------------
--
-- Configuring Xmonad
--
--------------------------------------------------------------------------------
{- $configure
xmonad is configured by creating and editing the Haskell file:
> ~/.xmonad/xmonad.hs
xmonad then uses default settings from this file as arguments to the
window manager.
-}
{- $example
Here is a basic example, which takes defaults from xmonad, and
overrides the border width, default terminal, and some colours:
> --
> -- An example, simple ~/.xmonad/xmonad.hs file.
> -- It overrides a few basic settings, reusing all the other defaults,
> --
>
> import XMonad
>
> main = xmonad $ defaultConfig
> { borderWidth = 2
> , terminal = "urxvt"
> , normalBorderColor = "#cccccc"
> , focusedBorderColor = "#cd8b00" }
This will run \'xmonad\', the window manager, with your settings
passed as arguments.
Overriding default settings like this (using \"record update
syntax\"), will yield the shortest config file, as you only have to
describe values that differ from the defaults.
An alternative is to inline the entire default config file from
xmonad, and edit values you wish to change. This is requires more
work, but some users may find this easier. You can find the defaults
in the file:
> XMonad/Config.hs
-}
{- $check
Place this text in @~\/.xmonad\/xmonad.hs@, and then check that it is
syntactically and type correct, by loading it in the Haskell
interpreter:
> $ ghci ~/.xmonad/xmonad.hs
> GHCi, version 6.8.1: http://www.haskell.org/ghc/ :? for help
> Loading package base ... linking ... done.
> Ok, modules loaded: Main.
>
> Prelude Main> :t main
> main :: IO ()
Ok, looks good.
-}
{- $load
To have xmonad start using your settings, try @mod-q@. xmonad will
attempt to compile this file, and run it. If it is unable to, the
defaults are used. This requires GHC and xmonad are in your @$PATH@
settings. If GHC isn't in your path, you can still compile the
@xmonad.hs@ file yourself:
> $ cd ~/.xmonad
> $ ghc --make xmonad.hs
> $ ls
> xmonad xmonad.hi xmonad.hs xmonad.o
When you hit @mod-q@, this newly compiled xmonad will be used.
-}
{- $where
The default configuration values are defined in the source file:
> XMonad/Config.hs
the 'XMonad.Core.XConfig' data structure itself is defined in:
> XMonad/Core.hs
See "XMonad.Core".
-}
--------------------------------------------------------------------------------
--
-- The XmonadContrib Library
--
--------------------------------------------------------------------------------
{- $library
The xmonad-contrib (xmc) library is a set of modules contributed by
xmonad hackers and users. Examples include an ion3-like tabbed layout,
a prompt\/program launcher, and various other useful modules.
Some of these modules provide libraries and other useful functions to
write other modules and extensions.
Here is a short overview of the xmc content:
[@Actions@] The content of Action
[@Config@] The content of Config
[@Hooks@] The content of Hooks
[@Layout@] The content of Layout
[@Prompt@] The content of Prompt
[@Util@] The content of Util
-}
--------------------------------------------------------------------------------
--
-- Extending Xmonad
--
--------------------------------------------------------------------------------
{- $extending
Since the @xmonad.hs@ file is just another Haskell module, you may
import and use any Haskell code or libraries you wish, such as
extensions from the xmonad-contrib library, or other code you write
yourself.
-}
{- $keys
Editing key bindings means changing the 'XMonad.Core.XConfig.keys'
record of the 'XMonad.Core.XConfig' data type, like:
> main = xmonad defaultConfig { keys = myKeys }
and providing a proper definition of @myKeys@ such as:
> myKeys x =
> [ ((modMask x, xK_F12), xmonadPrompt defaultXPConfig)
> , ((modMask x, xK_F3 ), shellPrompt defaultXPConfig)
> ]
Remember that this definition requires importing "Graphics.X11.Xlib",
"XMonad.Prompt", "XMonad.Prompt.Shell", and "XMonad.Prompt.XMonad"
-}
{- $keyAdding
Adding key bindings can be done in different ways. The type signature
of "XMonad.Core.XConfig.keys" is:
> keys :: XConfig Layout -> M.Map (ButtonMask,KeySym) (X ())
which means thatm in order to add new bindings you need to create a
'Data.Map.Map' from the list of your new key bindings, you can do that
with 'Data.Map.fromList', and then join this newly created map with
the one of the existing bindings. This can be done with
'Data.Map.union'.
For instance, if you have defined some additional key bindings like
these:
> myKeys x =
> [ ((modMask x, xK_F12), xmonadPrompt defaultXPConfig)
> , ((modMask x, xK_F3 ), shellPrompt defaultXPConfig)
> ]
then you create a new key bindings map by joining the default one with
yours:
> newKeys x = M.union (keys defaultConfig x) (M.fromList (myKeys x))
Finally you need to update accordingly the default configuration
'XMonad.Core.XConfig.keys' record:
> main = xmonad defaultConfig { keys = newKeys }
And that's it.
At the end your @~\/.xmonad\/xmonad.hs@ would look like this:
> module Main (main) where
>
> import XMonad
>
> import qualified Data.Map as M
> import Graphics.X11.Xlib
> import XMonad.Prompt
> import XMonad.Prompt.Shell
> import XMonad.Prompt.XMonad
>
> main :: IO ()
> main = xmonad defaultConfig { keys = newKeys }
>
> newKeys x = M.union (keys defaultConfig x) (M.fromList (myKeys x))
>
> myKeys x =
> [ ((modMask x, xK_F12), xmonadPrompt defaultXPConfig)
> , ((modMask x, xK_F3 ), shellPrompt defaultXPConfig)
> ]
Obviously there are other ways of defining @newKeys@. For instance,
you could define it like this:
> newKeys x = foldr (uncurry M.insert) (keys defaultConfig x) (myKeys x)
An even simpler way to add new key bindings is the use of some of the
utilities provided by the xmonad-contrib library. For instance,
"XMonad.Util.EZConfig" and "XMonad.Util.CustomKeys" both provide
useful functions for editing your key bindings. Look, for instance, at
'XMonad.Util.EZConfig.additionalKeys'.
-}
{- $keyDel
Removing key bindings requires modifying the binding 'Data.Map.Map'.
This can be done with 'Data.Map.difference' or with 'Data.Map.delete'.
Suppose you wan to get rid of @mod-q@ and @mod-shift-q@. To do this
you just need to define a @newKeys@ as a 'Data.Map.difference' between
the default map and the map of the key bindings you want to remove.
> newKeys x = M.difference (keys defaultConfig x) (M.fromList $ keysToRemove x)
>
> keysToRemove :: XConfig Layout -> [((KeyMask, KeySym),X ())]
> keysToRemove x =
> [ ((modMask x , xK_q ), return ())
> , ((modMask x .|. shiftMask, xK_q ), return ())
> ]
As you may see we do not need to define an action for the key bindings
we want to get rid of. We just build a map of keys to remove.
It is also possible to define a list of key bindings and then use
'Data.Map.delete' to remove them from the default key bindings, in
which case we should write something like:
> newKeys x = foldr M.delete (keys defaultConfig x) (keysToRemove x)
>
> keysToRemove :: XConfig Layout -> [(KeyMask, KeySym)]
> keysToRemove x =
> [ (modMask x , xK_q )
> , (modMask x .|. shiftMask, xK_q )
> ]
Another even simpler possibility is the use of some of the utilities
provided by the xmonad-contrib library. Look, for instance, at
'XMonad.Util.EZConfig.removeKeys'.
-}
{- $keyAddDel
Adding and removing key bindings requires to compose the action of
removing and, after that, the action of adding.
This is an example you may find in "XMonad.Config.Arossato":
> defKeys = keys defaultConfig
> delKeys x = foldr M.delete (defKeys x) (toRemove x)
> newKeys x = foldr (uncurry M.insert) (delKeys x) (toAdd x)
> -- remove some of the default key bindings
> toRemove x =
> [ (modMask x , xK_j )
> , (modMask x , xK_k )
> , (modMask x , xK_p )
> , (modMask x .|. shiftMask, xK_p )
> , (modMask x .|. shiftMask, xK_q )
> , (modMask x , xK_q )
> ] ++
> -- I want modMask .|. shiftMask 1-9 to be free!
> [(shiftMask .|. modMask x, k) | k <- [xK_1 .. xK_9]]
> -- These are my personal key bindings
> toAdd x =
> [ ((modMask x , xK_F12 ), xmonadPrompt defaultXPConfig )
> , ((modMask x , xK_F3 ), shellPrompt defaultXPConfig )
> ] ++
> -- Use modMask .|. shiftMask .|. controlMask 1-9 instead
> [( (m .|. modMask x, k), windows $ f i)
> | (i, k) <- zip (workspaces x) [xK_1 .. xK_9]
> , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask .|. controlMask)]
> ]
You can achieve the same result by using "XMonad.Util.CustomKeys" and,
specifically, 'XMonad.Util.CustomKeys.customKeys'.
-}
{- $layout
Layouts
-}
{- $hooks
Hooks
-}
--------------------------------------------------------------------------------
--
-- Writing Extensions
--
--------------------------------------------------------------------------------
{- $writing
Writing Other Extensions
-}
|