forked from Lykathia/.dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmonad.hs
331 lines (271 loc) · 11.5 KB
/
xmonad.hs
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
import System.FilePath ((</>))
import System.IO
import System.IO.Unsafe
import System.Exit
import Data.Char (chr)
import qualified Data.Map as M
import qualified XMonad.StackSet as W
import XMonad
import XMonad.Hooks.DynamicHooks
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.FadeInactive (fadeInactiveLogHook)
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.SetWMName
import XMonad.Hooks.UrgencyHook
import XMonad.Layout.Fullscreen
import XMonad.Layout.Gaps
import XMonad.Layout.Grid
import XMonad.Layout.IndependentScreens (countScreens)
import XMonad.Layout.IM
import XMonad.Layout.LayoutHints (layoutHints)
import XMonad.Layout.NoBorders (noBorders, smartBorders, withBorder)
import XMonad.Layout.PerWorkspace
import XMonad.Layout.Renamed
import XMonad.Layout.ResizableTile
import XMonad.Layout.Spacing
import XMonad.Layout.Tabbed
import XMonad.Util.Cursor
import XMonad.Util.Run (hPutStrLn, spawnPipe)
---------------------------------------------------------------------
-- Bar Setup
---------------------------------------------------------------------
-- Helper Functoin for Icons
dzenIcon :: String -> String
dzenIcon icon = "^i(" ++ unsafePerformIO getXMonadDir </> "icons" </> icon ++ ") "
-- Workspace Names
allWorkspaces, staticWorkspaces :: [WorkspaceId]
allWorkspaces =
[ workspace "" "TERM"
, workspace "arch.xbm" "WEB"
, workspace "mail.xbm" "CHAT"
, workspace "mem.xbm" "CODE"
, workspace "mem.xbm" "CODE 2"
, workspace "" "TEMP"
, workspace "" "STEAM"
, workspace "mail.xbm" "MAIL"
, workspace "" "VM"
]
where
workspace image text = dzenIcon image ++ text
staticWorkspaces = []
-- Dzen
workspaceDzenCmd :: String
workspaceDzenCmd = "dzen2 -dock -y -1 -ta l -p -e ''"
tempDzen1 = "dzen2 -xs 0 -dock -ta l -p -e ''"
tempDzen2 = "conky -qc /home/freyr/.dotfiles/conky/dzen_tr.rc | dzen2 -dock -ta r -p -e ''"
-- Formatting for dzen
myDzenPP :: Handle -> PP
myDzenPP h = dzenPP
{ ppCurrent = dzenColor colourRed colourBlack . pad
, ppVisible = dzenColor colourBlue colourBlack . pad
, ppHidden = dzenColor colourWhiteAlt colourBlack . pad
, ppHiddenNoWindows = dzenColor colourGray colourBlack . pad
, ppUrgent = dzenColor colourGreen colourBlack . pad
, ppTitle = dzenColor colourWhiteAlt colourBlack . pad . titleText . dzenEscape
, ppLayout = dzenColor colourBlue colourBlack . pad . clickableLayout .
(\x -> dzenIcon $ case x of
"A" -> "fox.xbm"
"G" -> "pacman.xbm"
"F" -> "full.xbm"
"C" -> "play.xbm"
"S" -> "cpu.xbm"
)
, ppOrder = \(ws:l:t:_) -> [l,ws,t]
, ppSep = "^fg(" ++ colourGray ++ ")|"
, ppWsSep = ""
, ppOutput = hPutStrLn h
}
where
titleText [] = "Desktop"
titleText x = (shorten 82 x)
clickableLayout x = "^ca(1,xdotool key alt+space)" ++ x ++ "^ca()"
clickableWorkspace x y = ""
---------------------------------------------------------------------
-- Colours / Fonts / Appearance
---------------------------------------------------------------------
-- Fonts
barFont :: String
barFont = "inconsolata"
delimChar :: Char
delimChar = chr 127
-- Color Definitions
colourBlack = "#020202"
colourBlackAlt = "#1c1c1c"
colourGray = "#444444"
colourGrayAlt = "#161616"
colourWhite = "#a9a6af"
colourWhiteAlt = "#9d9d9d"
colourMagenta = "#8e82a2"
colourBlue = "#3475aa"
colourRed = "#d74b73"
colourGreen = "#99cc66"
myFocusedBorder = colourBlackAlt
myUnfocusedBorder = colourGray
myTabTheme :: Theme
myTabTheme = defaultTheme
{ fontName = barFont
, activeColor = colourBlackAlt
, activeTextColor = colourWhiteAlt
, activeBorderColor = colourGray
, inactiveColor = colourBlack
, inactiveTextColor = colourGray
, inactiveBorderColor = colourBlackAlt
, urgentBorderColor = colourGray
, urgentTextColor = colourGreen
}
---------------------------------------------------------------------
-- Hooks
---------------------------------------------------------------------
myManageHook :: ManageHook
myManageHook = composeAll . concat $
[ [ className =? "Xfce4-notifyd" --> doIgnore ]
, [ isFullscreen --> doFullFloat ]
, [ (className =? x <||> title =? x <||> resource =? x) --> doShift "1:main" | x <- my1Shifts ]
, [ (className =? x <||> title =? x <||> resource =? x) --> doShift "8:steam" | x <- my1Shifts ]
]
where
my1Shifts = []
my8Shifts = ["Steam", "Friends"]
---------------------------------------------------------------------
-- Layouts
---------------------------------------------------------------------
-- General Layouts
tiledLayout = renamed [Replace "A"] $ spacing 5 $ smartBorders $ ResizableTall 1 0.03 0.5 []
gridLayout = renamed [Replace "G"] $ smartBorders $ spacing 5 $ Grid
fullLayout = renamed [Replace "F"] $ smartBorders $ tabbedAlways shrinkText myTabTheme
-- Special Layouts
chatLayout = renamed [Replace "C"] $ withIM (0.15) (Title "Buddy List") $ Grid
steamLayout = renamed [Replace "S"] $ withIM (0.15) (Title "Friends") $ Mirror $ ResizableTall 1 0.03 0.5 []
-- Hook
myLayout = avoidStruts
$ onWorkspace (allWorkspaces !! 2) chatLayout
$ onWorkspace (allWorkspaces !! 6) steamLayout
$ allLayouts
where
allLayouts = tiledLayout ||| gridLayout ||| fullLayout
--------------------------------------------------------------------
-- Keybindings
---------------------------------------------------------------------
-- Keyboard Bindings
myKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
-----------------------------------------------------------------
-- Programs
-----------------------------------------------------------------
-- terminal / tmux
[ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
, ((modm .|. shiftMask, xK_backslash), spawn "urxvtc -e tmux")
-- dmenu
, ((modm, xK_p ), spawn "dmenu_run")
-- slock
, ((mod4Mask, xK_l ), spawn "slock")
-- uzbl
, ((modm, xK_b ), spawn "uzbl-tabbed")
-----------------------------------------------------------------
-- Global Controls
-----------------------------------------------------------------
{-
-- ncmpcpp
-}
-----------------------------------------------------------------
-- Window Control
-----------------------------------------------------------------
-- close focused window
, ((modm .|. shiftMask, xK_c ), kill)
-- Rotate through the available layout algorithms
, ((modm, xK_space ), sendMessage NextLayout)
-- Reset the layouts on the current workspace to default
, ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
-- Resize viewed windows to the correct size
, ((modm, xK_n ), refresh)
-- Move focus to the next window
, ((modm, xK_Tab ), windows W.focusDown)
, ((modm, xK_j ), windows W.focusDown)
-- Move focus to the previous window
, ((modm, xK_k ), windows W.focusUp)
, ((modm .|. shiftMask, xK_Tab ), windows W.focusUp)
-- Move focus to the master window
, ((modm, xK_m ), windows W.focusMaster)
-- Swap the focused window and the master window
, ((modm, xK_Return), windows W.swapMaster)
-- Swap the focused window with the next window
, ((modm .|. shiftMask, xK_j ), windows W.swapDown)
-- Swap the focused window with the previous window
, ((modm .|. shiftMask, xK_k ), windows W.swapUp)
-- Shrink the master area
, ((modm, xK_h ), sendMessage Shrink)
-- Expand the master area
, ((modm, xK_l ), sendMessage Expand)
-- Push window back into tiling
, ((modm, xK_t ), withFocused $ windows . W.sink)
-- Increment the number of windows in the master area
, ((modm , xK_comma ), sendMessage (IncMasterN 1))
-- Deincrement the number of windows in the master area
, ((modm , xK_period), sendMessage (IncMasterN (-1)))
-----------------------------------------------------------------
-- Misc
-----------------------------------------------------------------
-- Colemak
, ((modm, xK_a ), spawn "setxkbmap us -variant colemak")
-- Qwerty
, ((modm, xK_z ), spawn "setxkbmap us")
-- Quit xmonad
, ((modm .|. shiftMask, xK_q ), io (exitWith ExitSuccess))
-- Restart xmonad
, ((modm , xK_q ), spawn "killall dzen2 trayer; xmonad --recompile && xmonad --restart")
]
++
-- mod-[1..9], Switch to workspace N
-- mod-shift-[1..9], Move client to workspace N
[((m .|. modm, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
++
-- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
-- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
[((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
---------------------------------------------------------------------
-- Startup Commands
---------------------------------------------------------------------
spawnTrayer :: Int -> String
spawnTrayer n
| n == 1 = "trayer --edge bottom --align right --height 16 --width 10 --expand true --SetDockType true --SetPartialStrut false --transparent true --alpha 0 --tint 0x0c0c0b"
| n == 2 = "trayer --edge bottom --align right --height 16 --width 10 --expand true --SetDockType true --SetPartialStrut false --transparent true --alpha 0 --tint 0x0c0c0b"
myStartupHook :: Int -> X ()
myStartupHook n = do
spawn $ spawnTrayer n
--spawn tempDzen1
spawn tempDzen2
setWMName "LG3D"
setDefaultCursor xC_left_ptr
---------------------------------------------------------------------
-- XMonad Main
---------------------------------------------------------------------
main :: IO ()
main = do
-- Get number of physical screens
screens <- countScreens
workspaceBar <- spawnPipe workspaceDzenCmd
xmonad $ withUrgencyHook NoUrgencyHook $ defaultConfig
{ terminal = "urxvtc"
, workspaces = allWorkspaces
-- Hooks / Layouts
, layoutHook = myLayout
, manageHook = myManageHook <+> manageDocks <+> (doF W.swapDown)
, handleEventHook = fullscreenEventHook
, startupHook = myStartupHook screens
, logHook = do
dynamicLogWithPP $ myDzenPP workspaceBar
fadeInactiveLogHook 1.0
-- Graphical stuff
, focusFollowsMouse = True
, borderWidth = 1
, normalBorderColor = myUnfocusedBorder
, focusedBorderColor = myFocusedBorder
-- Bindings
, keys = myKeys
, modMask = mod1Mask
}