aboutsummaryrefslogtreecommitdiff
path: root/.config/XMonad/xmonad.hs
blob: 3b83b1bdf80d27cccac268aef59a57fc555d6ce1 (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
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
import XMonad
import qualified XMonad.StackSet as W
import XMonad.ManageHook

-- data
import Data.Tree
import qualified Data.Map as M

-- actions
import XMonad.Actions.CopyWindow
import XMonad.Actions.CycleWS
import XMonad.Actions.GridSelect
import XMonad.Actions.SwapWorkspaces
import qualified XMonad.Actions.TreeSelect as TS

-- layout modifiers
import XMonad.Layout.Spacing
import XMonad.Layout.WindowNavigation as WN
import XMonad.Layout.Maximize
import XMonad.Layout.Fullscreen
import XMonad.Layout.NoBorders

-- Layouts
import XMonad.Layout.BinarySpacePartition as BSP
import XMonad.Layout.Grid
import XMonad.Layout.Tabbed

-- hooks
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops (ewmh)

-- utilities
import XMonad.Util.SpawnOnce
import XMonad.Util.EZConfig
import XMonad.Util.Cursor
import XMonad.Util.NamedScratchpad

-- defaults
myModMask = mod4Mask 
altMask = mod1Mask
myLockscreen = "notify-send 'to be set up!' 'to be set up!'"
myColorPicker = "colorpicker --short --one-shot --preview | xsel -b"
myFont = "xft:Hack:style=Regular:size=14"

myExtraWorkspaces = [(xK_0, "十")] -- , (xK_comma, "  十一  "), (xK_period, "  十二  "), (xK_slash, "  十三  ")]
myWorkspaces = ["一", "二", "三", "四", "五", "六", "七", "八", "九"] ++ (map snd myExtraWorkspaces)

myScratchpads = 
  [ NS "Term 0" "alacritty -t 'Term 0'"     (title     =? "Term 0") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
	, NS "Term 1" "alacritty -t 'Term 1'"     (title     =? "Term 1") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
	, NS "Term 2" "alacritty -t 'Term 2'"     (title     =? "Term 2") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
  , NS "OBS"    "obs"                       (className =? "obs")    (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
	, NS "lf"     "alacritty -t 'lf' -e 'lf'" (title     =? "lf")     (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
	, NS "calc"   "kcalc"                     (className =? "kcalc")  defaultFloating
	, NS "arandr" "arandr"                    (className =? "Arandr") defaultFloating
	, NS "pavucontrol" "pavucontrol"          (className =? "Pavucontrol") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
	, NS "BPYTOP" "alacritty -t 'BPYTOP' -e 'bpytop'"  (title =? "BPYTOP") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8))
  ]

myTabTheme = def { fontName            = myFont
                 , activeColor         = "#755999"
                 , inactiveColor       = "#282c35"
                 , activeBorderColor   = "#755999"
                 , inactiveBorderColor = "#313846"
                 , activeTextColor     = "#FFFFFF"
                 , inactiveTextColor   = "#d0d0d0"
                 , decoHeight          = 20
                 }

myTSConfig = TS.TSConfig { TS.ts_hidechildren = False
                           , TS.ts_background   = 0xdd282c34
                           , TS.ts_font         = myFont
                           , TS.ts_node         = (0xffd0d0d0, 0xff1c1f24)
                           , TS.ts_nodealt      = (0xffd0d0d0, 0xff282c34)
                           , TS.ts_highlight    = (0xffffffff, 0xff755999)
                           , TS.ts_extra        = 0xffd0d0d0
                           , TS.ts_node_width   = 220
                           , TS.ts_node_height  = 34
                           , TS.ts_originX      = 10000
                           , TS.ts_originY      = 100
                           , TS.ts_indent       = 80
                           , TS.ts_navigate     = TS.defaultNavigation
                           }

networkingTS =
  [ Node (TS.TSNode "KTorrent"  "" (spawn "ktorrent")) []
  , Node (TS.TSNode "TOR"       "" (spawn "torbrowser-launcher")) []
  , Node (TS.TSNode "Discord"   "" (spawn "discord")) []
  , Node (TS.TSNode "Icecat"    "" (spawn "icecat")) []
  , Node (TS.TSNode "Librewolf" "" (spawn "librewolf")) []
  , Node (TS.TSNode "Brave"     "" (spawn "brave")) []
  , Node (TS.TSNode "Firefox"   "" (spawn "firefox")) []
  ]
myNetworkingTS a = TS.treeselectAction a networkingTS

powerTS =
  [ Node (TS.TSNode "Shutdown" "" (return())) 
    [ Node (TS.TSNode "Confirm" "" (spawn "shutdown now")) [] ]
  , Node (TS.TSNode "Restart"  "" (return()))
    [ Node (TS.TSNode "Confirm" "" (spawn "reboot")) [] ]
  ]
myPowerTS a = TS.treeselectAction a powerTS

mediaTS =
  [ Node (TS.TSNode "VLC"      "" (spawn "vlc")) []
  , Node (TS.TSNode "GIMP"     "" (spawn "gimp")) []
  , Node (TS.TSNode "Kdenlive" "" (spawn "kdenlive")) []
  , Node (TS.TSNode "OBS"      "" (spawn "OBS")) []
  ]
myMediaTS a = TS.treeselectAction a mediaTS

gamingTS =
  [ Node (TS.TSNode "Minecraft" "" (spawn "minecraft-launcher")) []
  , Node (TS.TSNode "osu!lazer" "" (spawn "env LUTRIS_SKIP_INIT=1 lutris lutris:rungameid/3")) []
  , Node (TS.TSNode "Steam"     "" (spawn "steam")) []
  , Node (TS.TSNode "Lutris"    "" (spawn "lutris")) []
  ]
myGamingTS a = TS.treeselectAction a gamingTS

scratchpadTS =
  [ Node (TS.TSNode "Term 0"      "" (namedScratchpadAction myScratchpads "Term 0")) []
  , Node (TS.TSNode "Term 1"      "" (namedScratchpadAction myScratchpads "Term 1")) []
  , Node (TS.TSNode "Term 2"      "" (namedScratchpadAction myScratchpads "Term 2")) []
  , Node (TS.TSNode "OBS"         "" (namedScratchpadAction myScratchpads "OBS"))    []
  , Node (TS.TSNode "lf"          "" (namedScratchpadAction myScratchpads "lf"))     []
  , Node (TS.TSNode "BPYTOP"      "" (namedScratchpadAction myScratchpads "BPYTOP")) []
  , Node (TS.TSNode "Calculator"  "" (namedScratchpadAction myScratchpads "calc"))   []
  , Node (TS.TSNode "Arandr"      "" (namedScratchpadAction myScratchpads "arandr")) []
  , Node (TS.TSNode "Pavucontrol" "" (namedScratchpadAction myScratchpads "pavucontrol")) []
  ]
myScratchpadTS a = TS.treeselectAction a scratchpadTS

xmonadTS = 
  [ Node (TS.TSNode   "Go To Window"     "" (goToSelected defaultGSConfig)) []
  , Node (TS.TSNode   "Bring Window"     "" (bringSelected defaultGSConfig)) []
  , Node (TS.TSNode   "Rotate Windows"   "" (sendMessage Rotate)) []
  , Node (TS.TSNode   "Swap Windows"     "" (sendMessage BSP.Swap)) []
  , Node (TS.TSNode   "Un/Maximize"      "" (withFocused (sendMessage . maximizeRestore))) []
  , Node (TS.TSNode   "Sink Window"      "" (withFocused $ windows . W.sink)) []
  , Node (TS.TSNode   "Sticky Window"    "" (windows copyToAll)) []
  , Node (TS.TSNode   "Un-sticky Window" "" (killAllOtherCopies)) []
  ]
myXmonadTS a = TS.treeselectAction a xmonadTS

devTS = 
  [ Node (TS.TSNode "Android Studio" "" (spawn "android-studio")) []
  , Node (TS.TSNode "VSCodium"       "" (spawn "code")) []
  ]
myDevTS a = TS.treeselectAction a (devTS ++ vmTS)

vmTS = 
  [ Node (TS.TSNode "Virt Manager" "" (spawn "virt-manager")) []
  , Node (TS.TSNode "VirtualBox"   "" (spawn "virtualbox"))   []
  ]
myVmTS a = TS.treeselectAction a vmTS

utilTS = 
  [ Node (TS.TSNode "Pavucontrol"    "" (spawn "pavucontrol")) []
  , Node (TS.TSNode "OBS"            "" (spawn "obs")) []
  , Node (TS.TSNode "Arandr"         "" (spawn "arandr")) []
  , Node (TS.TSNode "System Monitor" "" (spawn "alacritty -e bpytop")) []
  , Node (TS.TSNode "File Manager"   "" (spawn "dolphin")) []
  , Node (TS.TSNode "Calculator"     "" (spawn "kcalc")) []
  ]
myUtilTS a = TS.treeselectAction a utilTS

myTreeMenu a = TS.treeselectAction a
  ([Node (TS.TSNode "Utilities"         "" (return()))          utilTS
  , Node (TS.TSNode "Networking"        "" (return()))          networkingTS
  , Node (TS.TSNode "Development"       "" (return()))          devTS
  , Node (TS.TSNode "Virtual Machines"  "" (return()))          vmTS
  , Node (TS.TSNode "XMonad"            "" (return()))
    [ Node (TS.TSNode "Window/Layout"   "" (return()))          xmonadTS
    , Node (TS.TSNode "Scratchpads"     "" (return()))          scratchpadTS 
    ]
  , Node (TS.TSNode "Gaming"            "" (return()))          gamingTS
  , Node (TS.TSNode "Media"             "" (return()))          mediaTS
  , Node (TS.TSNode "Power"             "" (return()))          powerTS
  , Node (TS.TSNode "Screenshot"        "" (spawn "spectacle")) []
  ])

sGap = 4 -- screen gap
wGap = 10 -- window gap

myGap = spacingRaw True (Border sGap sGap sGap sGap) True (Border wGap wGap wGap wGap) True
myGap' = spacingRaw False (Border sGap sGap sGap sGap) True (Border wGap wGap wGap wGap) True

main :: IO ()
main = do
  xmonad $ ewmh $ docks $ fullscreenSupport def {
    focusFollowsMouse  = True
    , borderWidth        = 2
    , modMask            = myModMask
    , workspaces         = myWorkspaces
    , normalBorderColor  = "#130F23"
    , focusedBorderColor = "#BF00FF"
    , layoutHook         = avoidStruts $ maximize $ windowNavigation $ smartBorders $ myGap $ (
        emptyBSP ||| tabbed shrinkText myTabTheme ||| emptyBSP ||| Grid)
    , manageHook         = namedScratchpadManageHook myScratchpads <+> manageDocks <+> composeAll [ className =? "plasmashell"    --> doIgnore , className =? "ksmserver"      --> doIgnore 
      , className =? "kcalc"          --> doFloat 
      , className =? "systemsettings" --> doFloat 
      , className =? "confirm"        --> doFloat 
      , className =? "file_progress"  --> doFloat 
      , className =? "dialog"         --> doFloat 
      , className =? "download"       --> doFloat 
      , className =? "error"          --> doFloat 
      , className =? "notification"   --> doFloat 
      , className =? "splash"         --> doFloat 
      , className =? "toolbar"        --> doFloat 
      ]
} `additionalMouseBindings` [ 
      ((myModMask, 4), \w -> prevWS), ((myModMask, 5), \w -> nextWS)
    ] `additionalKeys` ([
    ((myModMask, xK_Return), spawn ("open_terminal"))
    , ((myModMask .|. shiftMask, xK_q), kill1)
    
    -- modify gaps on runtime
    , ((myModMask, xK_equal), incWindowSpacing 1)
    , ((myModMask, xK_minus), decWindowSpacing 1)
    , ((myModMask .|. shiftMask, xK_equal), incScreenSpacing 1)  
    , ((myModMask .|. shiftMask, xK_minus), decScreenSpacing 1)         

    -- view prev/next workspaces
    , ((altMask, xK_h), prevWS)
    , ((altMask, xK_l), nextWS)
    -- do the same without the evil alt key 
    , ((myModMask, xK_comma),  prevWS)
    , ((myModMask, xK_period), nextWS)
    
    -- move to prev/next workspaces
    , ((altMask .|. shiftMask, xK_h), shiftToPrev >> prevWS)
    , ((altMask .|. shiftMask, xK_l), shiftToNext >> nextWS)
    -- do the same without the evil alt key (might remove either pair later)
    , ((myModMask .|. shiftMask, xK_comma),  shiftToPrev >> prevWS)
    , ((myModMask .|. shiftMask, xK_period), shiftToNext >> nextWS)

    -- focus previous.next monitor
    , ((myModMask,               xK_bracketleft),   prevScreen)
    , ((myModMask,               xK_bracketright),  nextScreen)

    -- move window to previous/next monitor
    , ((myModMask .|. shiftMask, xK_bracketleft),   shiftPrevScreen >> prevScreen)
    , ((myModMask .|. shiftMask, xK_bracketright),  shiftNextScreen >> nextScreen)

    -- swap different screens
    , ((myModMask .|. controlMask, xK_bracketleft),  swapPrevScreen)
    , ((myModMask .|. controlMask, xK_bracketright), swapNextScreen)

    , ((myModMask, xK_backslash), sendMessage ToggleStruts) -- toggle both bars
    , ((myModMask, xK_f), withFocused (sendMessage . maximizeRestore)) -- toggle maximize
    , ((myModMask .|. shiftMask, xK_f), withFocused $ windows . W.sink) -- unfloat windows

    -- cycle through windows 
    , ((altMask, xK_j), windows W.focusDown)
    , ((altMask, xK_k), windows W.focusUp)
    
    -- 2D navigation
    , ((myModMask,                 xK_l), sendMessage $ Go R)
    , ((myModMask,                 xK_h), sendMessage $ Go L)
    , ((myModMask,                 xK_k), sendMessage $ Go U)
    , ((myModMask,                 xK_j), sendMessage $ Go D)
    
    -- swap windows
    , ((myModMask .|. shiftMask, xK_l), sendMessage $ WN.Swap R)
    , ((myModMask .|. shiftMask, xK_h), sendMessage $ WN.Swap L)
    , ((myModMask .|. shiftMask, xK_k), sendMessage $ WN.Swap U)
    , ((myModMask .|. shiftMask, xK_j), sendMessage $ WN.Swap D)

    -- resize
    , ((myModMask .|. mod1Mask,                  xK_l  ), sendMessage $ ExpandTowards R)
    , ((myModMask .|. mod1Mask,                  xK_h  ), sendMessage $ ExpandTowards L)
    , ((myModMask .|. mod1Mask,                  xK_j  ), sendMessage $ ExpandTowards D)
    , ((myModMask .|. mod1Mask,                  xK_k  ), sendMessage $ ExpandTowards U)
    , ((myModMask .|. mod1Mask .|. shiftMask ,   xK_l  ), sendMessage $ ShrinkFrom R)
    , ((myModMask .|. mod1Mask .|. shiftMask ,   xK_h  ), sendMessage $ ShrinkFrom L)
    , ((myModMask .|. mod1Mask .|. shiftMask ,   xK_j  ), sendMessage $ ShrinkFrom D)
    , ((myModMask .|. mod1Mask .|. shiftMask ,   xK_k  ), sendMessage $ ShrinkFrom U)

    ] ++ [ -- for extra workspace(s)
        ((myModMask, key), (windows $ W.greedyView ws))
        | (key,ws) <- myExtraWorkspaces
    ] ++ [ -- also for extra workspaces
        ((myModMask .|. shiftMask, key), (windows $ W.shift ws))
        | (key,ws) <- myExtraWorkspaces
    ] ++ [ -- to swap workspace
        ((mod1Mask .|. shiftMask, k), windows $ swapWithCurrent i)
        | (i, k) <- zip myWorkspaces [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0]
    ] ++ [ -- copy
        ((m .|. myModMask, k), windows $ f i)
        | (i, k) <- zip (myWorkspaces) [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0]
        , (f, m) <- [(copy, shiftMask .|. altMask)]
    ] ++ [ -- for not swapping tags while using multihead
        ((m .|. myModMask, k), windows $ f i) 
        | (i, k) <- zip myWorkspaces [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0]
        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]
    ] -- ++ [ -- focus different monitors
--         ((m .|. myModMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
--         | (key, sc) <- zip [xK_bracketleft, xK_bracketright] [1,0] -- was [0..] *** change to match your screen order ***
--         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]
--     ]
    ) `additionalKeysP` [
        ("M-c", spawn myColorPicker)
        -- Launchers
        , ("M-S-w",   myDevTS          myTSConfig)
        , ("M-x",   myXmonadTS       myTSConfig)
        , ("M-e",   myMediaTS        myTSConfig)
        , ("M-S-e", myGamingTS       myTSConfig)
        , ("M-w",   myScratchpadTS   myTSConfig)
        , ("M-o",   myUtilTS         myTSConfig)
        , ("M-i",   myNetworkingTS   myTSConfig)
        , ("M-S-<Return>", myPowerTS myTSConfig)
        , ("M-p",   myTreeMenu       myTSConfig)
        , ("M-S-p", spawn "dmenu_run")
        -- scratchpads
        , ("M-r",   namedScratchpadAction myScratchpads "Term 0")
        , ("M-t",   namedScratchpadAction myScratchpads "Term 1")
        , ("M-y",   namedScratchpadAction myScratchpads "Term 2")
        , ("M-S-o", namedScratchpadAction myScratchpads "OBS")
        , ("M-m",   namedScratchpadAction myScratchpads "BPYTOP")
        , ("M-S-m", namedScratchpadAction myScratchpads "calc")
        , ("M-n",   namedScratchpadAction myScratchpads "pavucontrol")
        , ("M-S-n", namedScratchpadAction myScratchpads "arandr")
        , ("M-b", namedScratchpadAction myScratchpads "lf")
        -- other apps
        , ("M-S-b", spawn "dolphin")
    ]
    -- used keys: x e w o i p r t y q n b