aboutsummaryrefslogtreecommitdiff
path: root/.xmonad/xmonad.hs
blob: a20b04d2d6dde1e380bcf1925fff06881a5921e1 (plain)
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
import XMonad
import XMonad.Hooks.ManageDocks (avoidStruts)
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Config.Xfce
import XMonad.Config.Desktop
import XMonad.Hooks.EwmhDesktops
import XMonad.Actions.CycleWS
import XMonad.Actions.PhysicalScreens
import XMonad.Layout.NoBorders
import XMonad.Layout.SimpleDecoration
import XMonad.Layout.NoFrillsDecoration
import XMonad.Layout.Grid
import XMonad.Layout.FixedColumn
import XMonad.Layout.IM
import XMonad.Layout.Reflect
import XMonad.Layout.PerWorkspace
import XMonad.Layout.ResizableTile
import XMonad.Layout.Dishes
import XMonad.Layout.PerWorkspace
import XMonad.Layout.ThreeColumns
import XMonad.Layout.ToggleLayouts
import XMonad.Layout.LimitWindows
import XMonad.Layout.Spiral
import XMonad.Layout.Tabbed
import XMonad.Actions.UpdateFocus
import XMonad.Actions.CopyWindow
import XMonad.Util.Themes
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Actions.RotSlaves
import XMonad.Actions.PerWorkspaceKeys
import qualified XMonad.Actions.FlexibleResize as Flex
import XMonad.Hooks.ManageHelpers
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import Control.Monad
import Data.Ratio ((%))
import Data.Maybe
import Data.List
import Graphics.X11.ExtraTypes.XF86

myMod = mod4Mask -- windows key
myTerminal = "xfce4-terminal"

myTheme = defaultTheme
        { activeColor         = blue
        , inactiveColor       = grey
        , activeBorderColor   = red
        , inactiveBorderColor = grey
        , activeTextColor     = "white"
        , inactiveTextColor   = "black"
        , decoHeight          = 12
        }
        where
                blue = "#4a708b" -- same color used by pager
                grey = "#cccccc"
                red  = "#ff0000"

myXPConfig = defaultXPConfig
        { fgColor  = "white"
        , bgColor  = "black"
        , promptBorderWidth = 1
        , position = Bottom
        , height   = 25
        }

myWorkSpaces = ["emacs", "web", "chat", "4", "email", "6", "web-2", "8", "logs"]

myLayout = toggleLayouts Full perWS
        where
                -- Per workspace layout selection.
                perWS = onWorkspace "emacs" (noTitles   $ (myWide  ||| myCode)) $
                        onWorkspace "web"   (noTitles   $ (mySplit ||| myWide)) $
                        onWorkspace "chat"  (noTitles   $ (myChat gridFirst ||| simpleTabbed)) $
                        onWorkspace "irc"   (noTitles   $ (myChat gridFirst ||| simpleTabbed)) $
                        onWorkspace "email" (noTitles   $ myWide) $
                        onWorkspace "book"  (noTitles   $ myBook) $
                        onWorkspace "web-2" (noTitles   $ (mySplit ||| myWide)) $
                        onWorkspace "logs"  (withTitles $ myLogs dishFirst) $
                                            (simpleTabbed ||| (withTitles $ (myGrid ||| myCode ||| myWide)))

                -- Modifies a layout to be desktop friendly with title bars
                -- and avoid the panel.
                withTitles l = noFrillsDeco shrinkText myTheme $ l
                --withTitles l = desktopLayoutModifiers l

                -- Modifies a layout to be desktop friendly, but with no title bars
                -- and avoid the panel.
                noTitles l = desktopLayoutModifiers l

                -- Each of these allows toggling through a set of layouts
                -- in the same logical order, but from a different starting
                -- point.
               -- codeFirst = myCode ||| myWide ||| mySpiral ||| myGrid ||| myDish
                dishFirst = myDish ||| myCode ||| myWide ||| mySpiral ||| myGrid
                gridFirst = myGrid ||| myDish ||| myCode ||| myWide ||| mySpiral

                -- This is a tall-like layout.
                -- The master window is fixed at 80 columns wide, making
                -- this good for coding. Limited to 4 visible windows at
                -- a time to ensure all are a good size.
                myCode = limitWindows 4 $
                        FixedColumn 1 1 80 10

                -- Stack with one large master window.
                -- It's easy to overflow a stack to the point that windows
                -- are too small, so only show first 5.
                myDish = limitWindows 5 $ Dishes nmaster ratio
                        where
                                -- default number of windows in the master pane
                                nmaster = 1
                                -- proportion of screen occupied by other panes
                                ratio = 1/5

                -- Wide layout with subwindows at the bottom.
                myWide = Mirror $ Tall nmaster delta ratio
                        where
                                -- default number of windows in the master pane
                                nmaster = 1
                                -- Percent of screen to increment by when resizing panes
                                delta   = 3/100
                                -- proportion of screen occupied by master pane
                                ratio   = 80/100

                -- Split screen, optimized for web browsing.
                mySplit = Tall nmaster delta ratio
                        where
                                -- default number of windows in the master pane
                                nmaster = 1
                                -- Percent of screen to increment by when resizing panes
                                delta   = 3/100
                                -- proportion of screen occupied by master pane
                                ratio   = 60/100

                -- Standard grid.
                myGrid = Grid

                -- Determined experimentally
                mySpiral = spiral (6/7)

                -- The chat workspace has a roster on the right.
                myChat base = mirror base $ withIM size roster
                        where
                                -- Ratio of screen roster will occupy
                                size = 1%5
                                -- Match roster window
                                roster = Title "Buddy List"

                -- The logs workspace has space for procmeter.
                myLogs base = mirror base $ withIM procmeterSize procmeter
                        where
                                -- Ratio of screen procmeter will occupy
                                procmeterSize = 1%7
                                -- Match procmeter
                                procmeter = ClassName "ProcMeter3"

                -- For reading books, I typically want borders on
                -- the margin of the screen.
                myBook = ThreeColMid nmaster delta ratio
                        where
                                -- default number of windows in the master pane
                                nmaster = 1
                                -- Percent of screen to increment by when resizing panes
                                delta   = 3/100
                                -- proportion of screen occupied by master pane
                                ratio   = 2/3
                -- Applies a layout mirrored.
                mirror base a = reflectHoriz $ a $ reflectHoriz base

myKeys =
        [ ((myMod, xK_x), spawn myTerminal)
        , ((myMod, xK_c), kill)
        , ((myMod, xK_a), toggleWS)
        , ((myMod, xK_z), shellPrompt myXPConfig)
        , ((myMod, xK_p), spawn "assword gui")
        , ((altMask .|. controlMask, xK_l), spawn "xflock4")
        , ((0, xF86XK_AudioLowerVolume   ), spawn "amixer set Master 5%-")
        , ((0, xF86XK_AudioRaiseVolume   ), spawn "amixer set Master 5%+")
        , ((0, xF86XK_AudioMute          ), spawn "amixer set Master toggle")
        ] ++ [((myMod .|. mask, key), f sc)
             | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
             , (f, mask) <- [(viewScreen, 0), (sendToScreen, shiftMask)]]
        where
          altMask = mod1Mask

myManageHook = composeAll
        -- comes first to partially override default gimp floating behavior
        [ gimp "toolbox" --> nofloat
        , gimp "image-window" --> nofloat
        , manageHook xfceConfig
        , doF avoidMaster
        , resource =? "floatterm" --> doFloat
        , resource =? "xeyes" --> doFloat
        , className =? "mplayer2" --> doFloat
        , className =? "Xfce4-panel" --> doIgnore
        , className =? "Xfce4-notifyd" -->  doIgnore
        , className =? "Evolution-alarm-notify" -->  doIgnore
        -- workaround for <http://code.google.com/p/xmonad/issues/detail?id=228>
        , composeOne [ isFullscreen -?> doFullFloat ]
        -- display notifications on all workspaces,
        -- and avoid focus stealing
        --, className =? "Xfce4-notifyd" --> doF W.focusDown <+> doF copyToAll
        ]
        where
                gimp win = className =? "Gimp" <&&> fmap (win `isSuffixOf`) role
                role = stringProperty "WM_WINDOW_ROLE"
                nofloat = ask >>= doF . W.sink

-- Modified to only operate on floating windows, since I seem to do this by
-- accident to non-floating.
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList
        -- mod-button1, Move by dragging
        [ ((modMask, button1), (\w -> focus w >> ifFloating w mouseMoveWindow))
        -- mod-button2, Raise the window to the top of the stack
        --, ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
        -- mod-button3, Resize by dragging
        , ((modMask, button3), (\w -> focus w >> ifFloating w mouseResizeWindow))
        ]
        where
                ifFloating w f = withWindowSet $ \ws ->
                        when (M.member w $ W.floating ws) (f w)

myConfig = xfceConfig
        { manageHook = myManageHook
        , layoutHook = smartBorders (avoidStruts myLayout)
        , modMask = myMod
        , workspaces = myWorkSpaces
        , mouseBindings = myMouseBindings
        , terminal = myTerminal
        , borderWidth = 1
        , normalBorderColor  = inactiveBorderColor myTheme
        , focusedBorderColor = activeBorderColor myTheme
        --, startupHook = adjustEventInput
        --, handleEventHook = focusOnMouseMove
        , handleEventHook = handleEventHook xfceConfig <+> fullscreenEventHook
        } `additionalKeys` myKeys

main = xmonad myConfig

-- Avoid the master window, but otherwise manage new windows normally.
avoidMaster :: W.StackSet i l a s sd -> W.StackSet i l a s sd
avoidMaster = W.modify' $ \c ->
        case c of
                W.Stack t [] (r:rs) -> W.Stack t [r] rs
                _ -> c
nihil fit ex nihilo