-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmonad.hs
340 lines (271 loc) · 15.2 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
332
333
334
335
336
337
338
339
340
---------------------------------------------------------
-- XMonad Config by Anapal --
-- My personal config for my (or your) needs. --
-- --
-- > https://github.com/AnapalOne/xmonad-packed --
---------------------------------------------------------
import XMonad
import Data.Monoid
import Data.Char (isSpace)
import System.Exit
import System.IO
import Graphics.X11.ExtraTypes.XF86
import XMonad.Prompt
import XMonad.Prompt.Input
import XMonad.Prompt.ConfirmPrompt
import XMonad.Config.Desktop
import XMonad.Actions.GridSelect
import XMonad.Actions.CycleWS
import XMonad.Actions.FloatKeys
import XMonad.Actions.FloatSnap
import XMonad.Layout.NoBorders
import XMonad.Layout.Grid
import XMonad.Layout.Spiral
import XMonad.Layout.ThreeColumns
import XMonad.Layout.Spacing
import XMonad.Layout.Renamed
import XMonad.ManageHook
import XMonad.Hooks.StatusBar
import XMonad.Hooks.StatusBar.PP
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers (doCenterFloat)
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.DynamicProperty (dynamicPropertyChange)
import XMonad.Util.Run
import XMonad.Util.SpawnOnce
import XMonad.Util.NamedScratchpad
import XMonad.Util.Cursor
import qualified XMonad.StackSet as W
import qualified Data.Map as M
---------------------------------------------------------
-- Configs
---------------------------------------------------------
myTerminal = "alacritty"
myModMask = mod4Mask -- win key
myCursor = xC_left_ptr
myBorderWidth = 3
myNormalBorderColor = "#849DAB"
myFocusedBorderColor = "#24788F"
-- grid applications (menu key)
myGridSpawn = [ "subl","firefox","github-desktop",
"libreoffice", "discord","spotify",
"gimp","krita"]
---------------------------------------------------------
-- Workspaces
---------------------------------------------------------
myWorkspaces :: [String]
myWorkspaces = clickable . (map xmobarEscape)
-- $ ["ter","doc","www","dev","vid","img","chat","mus","art"] -- text
$ ["\xf120", "\xf718", "\xe743", "\xf121", "\xf008", "\xf03e", "\xf1d7", "\xf886", "\xf1fc"] -- icons
where
clickable l = [ "<action=xdotool key super+" ++ show (n) ++ ">" ++ ws ++ "</action>" |
(i,ws) <- zip [1..9] l,
let n = i ]
---------------------------------------------------------
-- Key Binds
-- > modm = myModMask
--
-- Do xev | sed -ne '/^KeyPress/,/^$/p' for key maps.
---------------------------------------------------------
altMask = mod1Mask
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
-- // windows
[ ((modm, xK_BackSpace), kill) -- close focused window
, ((modm, xK_space ), sendMessage NextLayout) -- rotate layout
, ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) -- reset layout order
, ((mod1Mask, xK_Tab ), windows W.focusUp ) -- rotate focus between windows
, ((modm, xK_Return), windows W.swapMaster ) -- swap focus master and window
, ((modm .|. shiftMask, xK_comma ), sendMessage Shrink ) -- decreases master window size
, ((modm .|. shiftMask, xK_period), sendMessage Expand ) -- increases master window size
, ((modm, xK_comma ), windows W.swapUp ) -- move tiled window
, ((modm, xK_period), windows W.swapDown ) --
-- // floating windows
, ((modm .|. shiftMask, xK_Tab ), withFocused toggleFloat) -- toggle between tiled and floating window
, ((modm, xK_Up ), withFocused (keysMoveWindow (0,-10))) -- move floating window
, ((modm, xK_Down ), withFocused (keysMoveWindow (0,10))) --
, ((modm, xK_Left ), withFocused (keysMoveWindow (-10,0))) --
, ((modm, xK_Right ), withFocused (keysMoveWindow (10,0))) --
, ((modm .|. shiftMask, xK_Up ), withFocused (keysResizeWindow (0,-10) (0,0))) -- resize floating window
, ((modm .|. shiftMask, xK_Down ), withFocused (keysResizeWindow (0,10) (0,0))) --
, ((modm .|. shiftMask, xK_Left ), withFocused (keysResizeWindow (-10,0) (0,0))) --
, ((modm .|. shiftMask, xK_Right ), withFocused (keysResizeWindow (10,0) (0,0))) --
, ((modm .|. controlMask, xK_Left ), withFocused $ snapMove L Nothing) -- snap window relative to window or desktop
, ((modm .|. controlMask, xK_Right), withFocused $ snapMove R Nothing) --
, ((modm .|. controlMask, xK_Up ), withFocused $ snapMove U Nothing) --
, ((modm .|. controlMask, xK_Down ), withFocused $ snapMove D Nothing) --
, ((modm .|. altMask, xK_Left ), withFocused $ snapGrow L Nothing) -- snap window size to relative to other windows or desktop
, ((modm .|. altMask, xK_Right ), withFocused $ snapGrow R Nothing) --
, ((modm .|. altMask, xK_Up ), withFocused $ snapGrow U Nothing) --
, ((modm .|. altMask, xK_Down ), withFocused $ snapGrow D Nothing) --
-- // system commands
, ((modm, xK_b ), sendMessage ToggleStruts) -- toggle xmobar to front of screen
, ((modm, xK_q ), confirmPrompt logoutPrompt "recompile?" $ spawn "xmonad --recompile; xmonad --restart") -- recompiles xmonad
, ((modm, xK_Escape ), confirmPrompt logoutPrompt "logout?" $ io (exitWith ExitSuccess)) -- logout from xmonad
, ((modm .|. shiftMask, xK_Escape ), confirmPrompt logoutPrompt "reboot?" $ spawn "systemctl reboot") -- reboot computer
, ((0, xF86XK_Sleep ), spawn "systemctl hibernate") -- sleep mode
, ((0, xF86XK_MonBrightnessUp), spawn "lux -a 5% -M 936") -- change brightness
, ((0, xF86XK_MonBrightnessDown), spawn "lux -s 5% -m 50") --
, ((0, xF86XK_AudioRaiseVolume), spawn "pamixer -i 10") -- change volume
, ((0, xF86XK_AudioLowerVolume), spawn "pamixer -d 10") --
, ((0, xF86XK_AudioMute), spawn "pamixer -t") --
, ((0, xF86XK_ScreenSaver), spawn "xset dpms force suspend") -- suspend screen
-- // programs
, ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) -- open terminal
, ((modm .|. shiftMask, xK_s ), spawn "flameshot gui") -- equivelent to prntscr
, ((modm, xK_r ), spawn "dmenu_run") -- run program
, ((modm .|. shiftMask, xK_v ), spawn "alacritty -t alsamixer -e alsamixer") -- sound system
-- // scratchpad
, ((modm .|. controlMask, xK_Return), namedScratchpadAction myScratchpads "ScrP_alacritty")
, ((modm .|. shiftMask, xK_slash ), namedScratchpadAction myScratchpads "help")
, ((modm, xK_grave ), namedScratchpadAction myScratchpads "ScrP_htop")
, ((modm .|. shiftMask, xK_grave ), namedScratchpadAction myScratchpads "ScrP_ncdu")
, ((modm, xK_v ), namedScratchpadAction myScratchpads "ScrP_vim")
, ((modm, xK_m ), namedScratchpadAction myScratchpads "ScrP_cmus")
-- // grid
, ((modm, xK_Tab ), goToSelected def)
, ((0, xK_Menu ), spawnSelected def myGridSpawn)
]
++
-- mod-[1..9] = Switch to workspace
-- mod-shift-[1..9] = Move window to workspace
[((m .|. modm, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
---------------------------------------------------------
-- Layouts
---------------------------------------------------------
myLayout = avoidStruts
(smartBorders Full ||| renamed [CutWordsLeft 1] $ spacingWithEdge 7 (Full ||| tiled ||| Mirror tiled ||| threecol ||| Mirror threecol ||| Grid ||| spiral (6/7)))
where
tiled = Tall nmaster delta ratio
nmaster = 1
delta = 3/100
ratio = 1/2
threecol = ThreeCol cnmaster cdelta cratio
cnmaster = 1
cdelta = 3/100
cratio = 1/2
---------------------------------------------------------
-- Scratchpads
---------------------------------------------------------
myScratchpads =
[ NS "ScrP_alacritty" "alacritty -t scratchpad" (title =? "scratchpad") floatScratchpad
, NS "ScrP_htop" "alacritty -t htop -e htop" (title =? "htop") floatScratchpad
, NS "ScrP_vim" "alacritty -t vim -e vim" (title =? "vim") floatScratchpad
, NS "ScrP_ncdu" "alacritty -t ncdu -e ncdu" (title =? "ncdu") floatScratchpad
, NS "help" "alacritty -t \"list of programs\" -e bash -c \'less ~/.config/xmonad/help\'" (title =? "list of programs") floatScratchpad
, NS "ScrP_cmus" "alacritty -t cmus -e cmus" (title =? "cmus") floatScratchpad
]
where
floatScratchpad = customFloating $ W.RationalRect l t w h
where
h = 0.9
w = 0.9
l = 0.95 -h
t = 0.95 -w
---------------------------------------------------------
-- Prompts
---------------------------------------------------------
logoutPrompt :: XPConfig
logoutPrompt = def
{ font = "xft: Bitstream Vera Sans Mono:size=8:bold:antialias=true:hinting=true"
, bgColor = "black"
, fgColor = "white"
, bgHLight = "white"
, fgHLight = "black"
, borderColor = "white"
, height = 50
, position = CenteredAt (0.5) (0.5)
}
---------------------------------------------------------
-- Hooks
---------------------------------------------------------
--Parameters for certain programs
-- > doFloat to open in floating mode
-- > doShift to open only in a specific workspace
myManageHook :: Query (Data.Monoid.Endo WindowSet)
myManageHook = composeAll
-- Opens the program only on a specific workspace.
-- NOTE: It will not work when the workspaces in myWorkspace does not match the doShift command here.
-- Instead, replace the workspace inside doShift with your renamed workspace.
-- ter
[ title =? "alacritty" --> doShift "<action=xdotool key super+1>\xf120</action>"
-- doc
, className =? "libreoffice-startcenter" --> doShift "<action=xdotool key super+2>\xf718</action>"
-- www
, className =? "firefox" --> doShift "<action=xdotool key super+3>\xe743</action>"
-- dev
, className =? "Subl" --> doShift "<action=xdotool key super+4>\xf121</action>"
, className =? "Audacity" --> doShift "<action=xdotool key super+4>\xf121</action>"
, className =? "GitHub Desktop" --> doShift "<action=xdotool key super+4>\xf121</action>"
-- vid
, className =? "vlc" --> doShift "<action=xdotool key super+5>\xf008</action>"
, className =? "mpv" --> doShift "<action=xdotool key super+5>\xf008</action>"
-- img
, className =? "Gimp" --> doShift "<action=xdotool key super+6>\xf03e</action>"
, className =? "Mirage" --> doShift "<action=xdotool key super+6>\xf03e</action>"
-- chat
, className =? "discord" --> doShift "<action=xdotool key super+7>\xf1d7</action>"
-- art
, className =? "krita" --> doShift "<action=xdotool key super+9>\xf1fc</action>"
-- Places the window in floating mode.
, title =? "welcome" --> doCenterFloat
, title =? "alsamixer" --> doCenterFloat
]
-- Spotify's WM_CLASS name is not set when first opening the window, so this is a workaround.
spotifyWindowNameFix = dynamicPropertyChange "WM_NAME" (title =? "Spotify" --> doShift "<action=xdotool key super+8>\xf886</action>") --mus
--event handling
myEventHook = fullscreenEventHook <+> spotifyWindowNameFix
--Executes whenever xmonad starts
myStartupHook = do
spawnOnce "nitrogen --restore &"
spawnOnce "picom &"
spawnOnce "~/.config/xmonad/scripts/startup_window.sh"
spawnOnce "libinput-gestures &"
setDefaultCursor myCursor
myLogHook xmproc = dynamicLogWithPP . filterOutWsPP [scratchpadWorkspaceTag] $ def
{ ppOutput = hPutStrLn xmproc
, ppCurrent = xmobarColor "#4381fb" "" . wrap "[" "]"
, ppVisible = xmobarColor "#4381fb" ""
, ppHidden = xmobarColor "#d1426e" "" . wrap "*" ""
, ppHiddenNoWindows = xmobarColor "#061d8e" ""
, ppTitle = xmobarColor "#ffffff" "" . shorten 60
, ppSep = "<fc=#666666> | </fc>"
, ppWsSep = "<fc=#666666> . </fc>"
, ppExtras = [windowCount]
, ppOrder = \(ws:l:t:ex) -> [ws,l]++ex++[t]
}
---------------------------------------------------------
-- XMonad Main
---------------------------------------------------------
main = do
xmproc <- spawnPipe "xmobar -x 0 ~/.xmobarrc/xmobar.hs"
xmonad $ docks $ ewmhFullscreen . ewmh $ desktopConfig
{ terminal = myTerminal
, modMask = myModMask
, workspaces = myWorkspaces
, borderWidth = myBorderWidth
, normalBorderColor = myNormalBorderColor
, focusedBorderColor = myFocusedBorderColor
, keys = myKeys
, layoutHook = myLayout
, manageHook = myManageHook <+> namedScratchpadManageHook myScratchpads
, handleEventHook = myEventHook
, logHook = myLogHook xmproc
, startupHook = myStartupHook
}
---------------------------------------------------------
-- Functions
---------------------------------------------------------
windowCount :: X (Maybe String)
windowCount = gets $ Just . show . length . W.integrate' . W.stack . W.workspace . W.current . windowset
toggleFloat :: Window -> X ()
toggleFloat w = windows
( \s -> if M.member w (W.floating s)
then W.sink w s
else (W.float w (W.RationalRect (0.01) (0.04) (0.55) (0.55)) s) )
xmobarEscape :: String -> String
xmobarEscape = concatMap doubleLts
where
doubleLts '<' = "<<"
doubleLts x = [x]