-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmonad.hs
280 lines (237 loc) · 7.87 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
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BlockArguments #-}
module Main where
import qualified Data.Map as M
import Data.List (sortBy)
import Data.Function (on)
import Control.Monad (forM_, join)
import XMonad
import qualified XMonad.StackSet as W
import XMonad.Operations (windows)
import XMonad.Util.EZConfig (mkKeymap)
import XMonad.Util.Ungrab (unGrab)
import XMonad.Util.SpawnOnce (spawnOnce, spawnOnOnce)
import XMonad.Util.Loggers
import XMonad.Util.Run (safeSpawn)
import XMonad.Util.NamedWindows (getName)
import XMonad.Util.PureX (toX)
import XMonad.Hooks.EwmhDesktops (ewmh, ewmhFullscreen)
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.DynamicLog
import XMonad.Layout
import XMonad.Layout.ThreeColumns
import XMonad.Layout.Grid
import XMonad.Layout.IfMax
import XMonad.Layout.Maximize
import XMonad.Layout.Minimize
import XMonad.Layout.NoBorders
import XMonad.Layout.Gaps
import XMonad.Actions.Minimize
import XMonad.Actions.Navigation2D
import XMonad.Actions.Search
import XMonad.Actions.Submap
import XMonad.Actions.DynamicWorkspaces
import XMonad.Prompt
import XMonad.Prompt.FuzzyMatch (fuzzyMatch, fuzzySort)
import XMonad.Prompt.Input
import XMonad.Prompt.Shell
main :: IO ()
main =
xmonad
$ withNavigation2DConfig def
$ ewmhFullscreen
$ ewmh
$ docks
$ myXConfig
myXConfig = def
{ terminal = "alacritty"
, modMask = mod4Mask
, workspaces = myWorkspaces
, borderWidth = 2
, normalBorderColor = "#928374"
, focusedBorderColor = "#b16286"
, keys = \c -> mkKeymap c (myKeymap c)
, startupHook = myStartupHook
, layoutHook = myLayoutHook
, manageHook = manageHook def <+> myManageHook
}
myXPConfig = def
{ bgColor = "#282828"
, fgColor = "#ebdbb2"
, bgHLight = "#ebdbb2"
, fgHLight = "#282828"
, borderColor = "#928374"
, promptBorderWidth = 2
, height = 30
, searchPredicate = fuzzyMatch
, sorter = fuzzySort
}
myWorkspaces = digitKeys
myKeymap = \c
-> appKeys c
++ webpageKeys c
++ windowsFocus
++ windowsSwap
++ layoutKeys
++ workspaceSwitchKeys
++ workspaceKeys c
++ screenshotKeys
++ promptKeys
++ popupKeys
++ audioKeys
windowsFocus =
[ ("M1-<Tab>" , windows W.focusDown)
, ("M1-S-<Tab>" , windows W.focusUp )
, ("M1-C-<Left>" , windowGo L True )
, ("M1-C-<Down>" , windowGo D True )
, ("M1-C-<Up>" , windowGo U True )
, ("M1-C-<Right>" , windowGo R True )
]
windowsSwap =
[ ("M-<Tab>" , windows W.swapDown)
, ("M-S-<Tab>" , windows W.swapUp )
, ("M1-S-<Left>" , windowSwap L True )
, ("M1-S-<Down>" , windowSwap D True )
, ("M1-S-<Up>" , windowSwap U True )
, ("M1-S-<Right>" , windowSwap R True )
]
layoutKeys =
[ ("M-<Up>" , withFocused (sendMessage . maximizeRestore))
, ("M-<Down>" , withFocused minimizeWindow )
, ("M-S-<Down>", withLastMinimized maximizeWindowAndFocus )
, ("M-S-t" , withFocused $ windows . W.sink )
, ("M-l" , sendMessage NextLayout )
] ++
[("M-C-" ++ k, sendMessage $ JumpToLayout l)
| (k, l) <- zip digitKeys [ "Tall", "ThreeCol", "Grid", "Full"]
]
workspaceSwitchKeys =
[ ("M-" ++ m ++ k, windows $ f i)
| (i, k) <- zip myWorkspaces digitKeys
, (f, m) <- [(W.greedyView, ""), (W.shift, "S-")]
]
workspaceKeys = \c ->
[ ("M-S-w", submap $ mkKeymap c keymap)
]
where
keymap =
[ ("g", gamingWorkspace)
, ("S-g", removeWorkspaceByTag "Game")
, ("q", selectWorkspace myXPConfig)
]
gamingWorkspace = addWorkspace "Game" >> spawn "steam" >> spawn "discord"
appKeys = \c ->
[ ("M-S-c" , kill )
, ("M-S-<Return>", spawn $ terminal c )
, ("M-e" , spawn "nautilus" )
, ("M-f" , spawn "firefox" )
, ("M-w" , spawn "codium" )
, ("M-t" , spawn "telegram-desktop")
, ("M-d" , spawn "discord" )
, ("M-a" , spawn "annotator" )
]
webpageKeys = \c ->
[ ("M-p", submap $ mkKeymap c keymap)
]
where
keymap =
[ ("a", openPage aur )
, ("h", openPage hoogle )
, ("y", openPage youtube )
, ("v", openPage vkMessages)
, ("m", openPage gMail )
, ("c", openPage gCalendar )
]
openPage p = spawn $ "firefox " ++ p
aur = "https://aur.archlinux.org/"
hoogle = "https://hoogle.haskell.org/"
youtube = "https://www.youtube.com/"
vkMessages = "https://vk.com/im"
gMail = "https://mail.google.com/"
gCalendar = "https://calendar.google.com"
screenshotKeys =
[ ("<Print>" , spawn $ select ++ toClipImg)
, ("S-<Print>" , spawn $ fullscreen ++ toClipImg)
, ("M-<Print>" , spawn $ select ++ toClipImg ++ toEdit)
, ("M-S-<Print>", spawn $ fullscreen ++ toClipImg ++ toEdit)
, ("C-<Print>" , spawn $ select ++ toFile)
, ("C-S-<Print>", spawn $ fullscreen ++ toFile)
]
where
fullscreen = "maim -u"
select = "maim -su"
active = "maim -u -i $(xdotool getactivewindow)"
toClip = "| xclip -selection clipboard"
toClipImg = toClip ++ " -t image/png"
toFile = " ~/Pictures/Screenshots/$(date +%Y-%m-%d_%H-%M-%S).png"
toEdit = " && com.github.phase1geo.annotator --use-clipboard"
popupKeys =
[ ("M-o" , spawn launcher )
, ("M-s" , spawn leftPopup)
, ("M-S-s", spawn ewwclose )
, ("M-v" , spawn clipboard)
, ("M-b" , sendMessage ToggleStruts)
]
where
launcher = "rofi -no-lazy-grab -show drun -modi run,drun,window -theme ~/.xmonad/rofi/style.rasi"
ewwclose = "exec ~/bin/eww close-all"
leftPopup = "exec ~/bin/eww open-many weather_side time_side smol_calendar player_side sys_side sliders_side"
clipboard = "rofi -modi \"clipboard:greenclip print\" -show clipboard -run-command '{cmd}' -theme ~/.xmonad/rofi/style.rasi"
audioKeys =
[ ("<XF86AudioPlay>", spawn "playerctl play-pause" )
, ("<XF86AudioPrev>", spawn "playerctl previous" )
, ("<XF86AudioNext>", spawn "playerctl next" )
]
promptKeys =
[ ("M-x" , shellPrompt myXPConfig)
]
myStartupHook = do
spawnOnce "polybar -r -c ~/.xmonad/polybar/polybar top"
spawnOnce "exec ~/bin/eww daemon"
spawnOnce "xsetroot -cursor_name left_ptr"
spawnOnce "feh --bg-scale ~/.xmonad/assets/images/bg-gruvbox.png"
spawnOnce "picom"
spawnOnce "greenclip daemon"
spawnOnce "python ~/bin/jakowlew/getweather.py"
spawnOnce "sleep 3 && setxkbmap -model pc105 -layout us,ru -option grp:win_space_toggle"
spawnOnce "/etc/X11/xinit/xinitrc.d/50-systemd-user.sh ~/.xinitrc"
spawnOnce "exec redshift -l 54.790311:32.050366"
myLayoutHook = avoidStruts
$ smartBorders
$ minimize
$ maximizeWithPadding 0
$ layout
where
layout = tiled
||| threeColMid
||| Grid
||| Full
tiled = Tall nmaster delta ratio
threeColMid = ThreeColMid nmaster delta ratio
nmaster = 1
ratio = 1 / 2
delta = 5 / 100
myManageHook = composeAll
[ isDialog --> doFloat
, isPolybar --> doLower
, isPicInPic --> doPicInPic
]
isPolybar = className =? "Polybar"
isPicInPic = title =? "Picture-in-Picture"
doPicInPic = hasBorder False >> doSideFloat SE
moveTo i = doF $ W.shift (myWorkspaces !! i)
digitKeys :: [String]
digitKeys = map (:[]) ['1'..'9']
class MyPrompt a where
name :: String
compl :: [String]
handler :: String -> X ()
buildPrompt :: forall a. MyPrompt a => X ()
buildPrompt = inputPromptWithCompl myXPConfig (name @a) promptCompl ?+ (handler @a)
where
promptCompl = mkComplFunFromList' myXPConfig (compl @a)