blob: 197f28c8bb018401e90c25e515304f9edf8429bb [file] [log] [blame]
Skyler Greyb43ac6b2022-10-31 00:48:34 +00001-- spell-checker:words xmonad
Skyler Grey37e2a402023-02-25 10:11:07 +00002{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
3{-# HLINT ignore "Move brackets to avoid $" #-}
Skyler Greyf2c55ae2022-11-05 17:48:02 +00004import XMonad
Skyler Greyb43ac6b2022-10-31 00:48:34 +00005
Skyler Greyf2c55ae2022-11-05 17:48:02 +00006import System.Exit
7import XMonad.Util.EZConfig
Skyler Greyb43ac6b2022-10-31 00:48:34 +00008
Skyler Greyf2c55ae2022-11-05 17:48:02 +00009import XMonad.Config.Desktop
10import XMonad.Hooks.EwmhDesktops
11import XMonad.Hooks.ManageDocks
Skyler Grey51a0c612022-11-05 09:59:04 +000012
Skyler Grey08082762023-01-26 00:35:19 +000013import qualified DBus.Client as D
Skyler Greyf2c55ae2022-11-05 17:48:02 +000014import XMonad.Hooks.DynamicLog
15import XMonadLog
Skyler Grey51a0c612022-11-05 09:59:04 +000016
Skyler Grey08082762023-01-26 00:35:19 +000017import Blaze.ByteString.Builder (toByteString)
18import Foreign.C
Skyler Grey3a9a2b12023-02-13 08:04:05 +000019import Graphics.X11.ExtraTypes (xF86XK_AudioLowerVolume,
20 xF86XK_AudioMute,
21 xF86XK_AudioRaiseVolume,
22 xF86XK_MonBrightnessDown,
23 xF86XK_MonBrightnessUp,
24 xF86XK_Xfer)
25import qualified XMonad as W
Skyler Grey08082762023-01-26 00:35:19 +000026import XMonad.Hooks.DynamicProperty (dynamicPropertyChange)
27import XMonad.Hooks.ManageHelpers (doFullFloat, doLower,
Skyler Grey3a9a2b12023-02-13 08:04:05 +000028 doRectFloat, isInProperty)
Skyler Grey08082762023-01-26 00:35:19 +000029import XMonad.Hooks.UrgencyHook
Skyler Grey37e2a402023-02-25 10:11:07 +000030import XMonad.Layout (Tall)
Skyler Grey08082762023-01-26 00:35:19 +000031import XMonad.Layout.Drawer (propertyToQuery)
Skyler Greyf2c55ae2022-11-05 17:48:02 +000032import XMonad.Layout.Gaps
Skyler Grey37e2a402023-02-25 10:11:07 +000033import XMonad.Layout.Grid
34import XMonad.Layout.MultiToggle (mkToggle)
35import XMonad.Layout.NoBorders (smartBorders, SetsAmbiguous, hiddens, Ambiguity (OnlyScreenFloat, Combine), lessBorders, With (Union), hasBorder)
36import XMonad.Layout.ResizableTile (ResizableTall (ResizableTall), MirrorResize (MirrorShrink, MirrorExpand))
Skyler Greyf2c55ae2022-11-05 17:48:02 +000037import XMonad.Layout.Spacing
Skyler Grey08082762023-01-26 00:35:19 +000038import qualified XMonad.StackSet as W
39import XMonad.Util.Hacks
Skyler Grey3a9a2b12023-02-13 08:04:05 +000040import XMonad.Util.PureX (curScreen, curScreenId)
41import XMonad.Util.Run (safeSpawn, safeSpawnProg)
Skyler Grey37e2a402023-02-25 10:11:07 +000042import qualified Data.Map as M
43import XMonad.StackSet (allWindows)
44import Data.Containers
45import Data.List ((\\))
Skyler Grey51a0c612022-11-05 09:59:04 +000046
Skyler Grey3a9a2b12023-02-13 08:04:05 +000047volumeChangeCmd = "${{./vol_change.py}}"
48
49terminal = "/usr/bin/env SHLVL=0 kitty" -- Kitty, my beloved <3
Skyler Greye2ec0de2022-11-02 08:07:25 +000050launcher = "pkill rofi; rofi -show combi"
Skyler Grey08082762023-01-26 00:35:19 +000051networkManager = "wpa_cli select_network $(wpa_cli list_networks | tail -n +3 | awk '!seen[$2]++' | rofi -dmenu -window-title 'Select Network' | awk '{print $1;}')"
52
53screenshot = "mkdir -p ~/Screenshots && maim | tee ~/Screenshots/\"$(date --rfc-3339=seconds)\".png | xclip -select clipboard -t image/png"
Skyler Greye631f4c2023-02-14 17:20:18 +000054selectScreenshot = "mkdir -p ~/Screenshots && maim -us | tee ~/Screenshots/\"$(date --rfc-3339=seconds)\".png | xclip -select clipboard -t image/png"
Skyler Grey08082762023-01-26 00:35:19 +000055
Skyler Greye2ec0de2022-11-02 08:07:25 +000056modifierKey = mod4Mask -- Use Super as our mod key
57
Skyler Grey3a9a2b12023-02-13 08:04:05 +000058statusBar = "pkill polybar; polybar main; polybar dp1; polybar dp2; polybar dp3; polybar dp4"
Skyler Grey51a0c612022-11-05 09:59:04 +000059compositor = "pkill picom; picom"
Skyler Grey08082762023-01-26 00:35:19 +000060background = "pkill show; show ~/.xmonad/wallpaper.glsl > /dev/null"
Skyler Grey9db914a2023-02-19 23:50:59 +000061colorSelection = "xcolor | xclip -sel clip"
Skyler Grey08082762023-01-26 00:35:19 +000062keybindings = "setxkbmap -option caps:none && xmodmap ~/.Xmodmap"
Skyler Grey34021e32022-11-04 09:28:03 +000063
Skyler Greye2ec0de2022-11-02 08:07:25 +000064shift = shiftMask
65
Skyler Grey3a9a2b12023-02-13 08:04:05 +000066-- spell-checker:words xobsock
67xobsock = "$XDG_RUNTIME_DIR/xob.sock"
68
Skyler Grey70301492023-02-24 09:04:51 +000069workspaces = ["7", "5", "3", "1", "9", "0", "2", "4", "6", "8"];
70
Skyler Grey37e2a402023-02-25 10:11:07 +000071data NonFloats = NonFloats deriving (Read, Show)
72
73instance SetsAmbiguous NonFloats where
74 hiddens _ wset _ _ _ = allWindows wset \\ M.keys (W.floating wset)
75
Skyler Grey34021e32022-11-04 09:28:03 +000076startupHook = do
Skyler Grey51a0c612022-11-05 09:59:04 +000077 spawn Main.statusBar
78 spawn Main.compositor
79 spawn background
Skyler Grey08082762023-01-26 00:35:19 +000080 spawn keybindings
Skyler Greya23445b2023-02-25 07:01:35 +000081 windows $ W.view "0"
Skyler Grey3a9a2b12023-02-13 08:04:05 +000082 spawn "pgrep keepass || run_keepass"
83 spawn $ "pkill xob; rm -f " ++ xobsock ++ " && mkfifo " ++ xobsock ++ " && tail -f " ++ xobsock ++ " | xob"
Skyler Greyf2c55ae2022-11-05 17:48:02 +000084
Skyler Grey70301492023-02-24 09:04:51 +000085numRowKeys = [xK_bracketleft
86 , xK_braceleft
87 , xK_braceright
88 , xK_parenleft
89 , xK_equal
90 , xK_asterisk
91 , xK_parenright
92 , xK_plus
93 , xK_bracketright
94 , xK_exclam
95 ]
Skyler Grey34021e32022-11-04 09:28:03 +000096
Skyler Greyb43ac6b2022-10-31 00:48:34 +000097main :: IO ()
Skyler Grey51a0c612022-11-05 09:59:04 +000098main = XMonadLog.xmonadLog >>= main'
99
100main' :: D.Client -> IO ()
Skyler Grey08082762023-01-26 00:35:19 +0000101main' dbus = xmonad
102 $ javaHack
103 $ ewmh . setEwmhActivateHook doAskUrgent
104 $ docks
105 $ def
Skyler Greye2ec0de2022-11-02 08:07:25 +0000106 { modMask = modifierKey -- Use Super as our mod key
Skyler Grey37e2a402023-02-25 10:11:07 +0000107 , borderWidth = 2
Skyler Greye2ec0de2022-11-02 08:07:25 +0000108 , XMonad.terminal = Main.terminal
Skyler Grey70301492023-02-24 09:04:51 +0000109 , XMonad.workspaces = Main.workspaces
Skyler Grey51a0c612022-11-05 09:59:04 +0000110 , XMonad.startupHook = Main.startupHook
111 , XMonad.logHook = dynamicLogWithPP (polybarHook dbus)
Skyler Grey37e2a402023-02-25 10:11:07 +0000112 , XMonad.layoutHook = lessBorders NonFloats
113 $ (smartSpacing 5
114
115 $ avoidStruts
Skyler Grey08082762023-01-26 00:35:19 +0000116 $ gaps [(U, 5), (D, 5), (L, 5), (R, 5)]
Skyler Grey37e2a402023-02-25 10:11:07 +0000117 $ ResizableTall 1 (3/100) (1/2) []
118 ||| Mirror (ResizableTall 1 (3/100) (1/2) [])
119 ||| Grid
120 ||| Full)
121 ||| gaps [(U, 0), (D, 0), (L, 0), (R, 0)] Full
Skyler Greyf2c55ae2022-11-05 17:48:02 +0000122 , XMonad.manageHook = composeAll
Skyler Grey08082762023-01-26 00:35:19 +0000123 [ isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP"
Skyler Grey37e2a402023-02-25 10:11:07 +0000124 --> hasBorder False <+> doIgnore <+> doLower <+> doLower
125 , checkDock --> doLower <+> doLower
Skyler Greyf2c55ae2022-11-05 17:48:02 +0000126 ] <+> manageHook def
Skyler Grey08082762023-01-26 00:35:19 +0000127 , XMonad.handleEventHook = composeAll
128 [ windowedFullscreenFixEventHook
129 , dynamicPropertyChange "_NET_WM_WINDOW_TYPE"
130 (isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP"
Skyler Grey37e2a402023-02-25 10:11:07 +0000131 --> hasBorder False <+> doLower
Skyler Grey08082762023-01-26 00:35:19 +0000132 <+> (ask >>= \w -> liftX (modifyWindowSet (W.delete w))
133 >> mempty)
134 <+> (ask >>= \w -> liftX (withDisplay $ \dpy -> io (moveResizeWindow dpy w 0 0 (fromIntegral $ displayWidth dpy $ defaultScreen dpy) (fromIntegral $ displayHeight dpy $ defaultScreen dpy))) >> mempty))
135 ]
136 <+> handleEventHook def
Skyler Grey70301492023-02-24 09:04:51 +0000137 } `additionalKeys` (
Skyler Greye2ec0de2022-11-02 08:07:25 +0000138 [ ((modifierKey, xK_d), spawn launcher)
139 , ((modifierKey, xK_n), spawn networkManager)
Skyler Grey08082762023-01-26 00:35:19 +0000140 , ((modifierKey .|. Main.shift, xK_q), kill)
Skyler Grey37e2a402023-02-25 10:11:07 +0000141 , ((modifierKey, xK_o), sendMessage MirrorShrink)
142 , ((modifierKey, xK_e), sendMessage MirrorExpand)
Skyler Greye2ec0de2022-11-02 08:07:25 +0000143 , ((modifierKey, xK_q), spawn "xmonad --restart")
Skyler Grey08082762023-01-26 00:35:19 +0000144 , ((modifierKey .|. Main.shift, xK_c), io exitSuccess)
145 , ((modifierKey .|. Main.shift, xK_s), spawn selectScreenshot)
Skyler Grey9db914a2023-02-19 23:50:59 +0000146 , ((modifierKey .|. Main.shift, xK_h), spawn colorSelection)
Skyler Grey08082762023-01-26 00:35:19 +0000147 , ((0, xK_Print), spawn screenshot)
Skyler Grey3a9a2b12023-02-13 08:04:05 +0000148 , ((modifierKey .|. Main.shift, xK_Return), spawn Main.terminal)
149 , ((0, xF86XK_AudioLowerVolume), spawn $ volumeChangeCmd ++ " -d")
150 , ((0, xF86XK_AudioRaiseVolume), spawn $ volumeChangeCmd ++ " -u")
151 , ((0, xF86XK_AudioMute), spawn $ volumeChangeCmd ++ " -m")
152 , ((modifierKey, xF86XK_AudioLowerVolume), spawn $ volumeChangeCmd ++ " -d -i")
153 , ((modifierKey, xF86XK_AudioRaiseVolume), spawn $ volumeChangeCmd ++ " -u -i")
154 , ((modifierKey, xF86XK_AudioMute), spawn $ volumeChangeCmd ++ " -m -i")
155 , ((0, xF86XK_MonBrightnessDown), spawn $ "light -U 6 && light -G | cut -d'.' -f1 > " ++ xobsock)
156 , ((0, xF86XK_MonBrightnessUp), spawn $ "light -A 6 && light -G | cut -d'.' -f1 > " ++ xobsock)
157 , ((modifierKey, xF86XK_MonBrightnessDown), spawn $ "light -U 3 && light -G | cut -d'.' -f1 > " ++ xobsock)
158 , ((modifierKey, xF86XK_MonBrightnessUp), spawn $ "light -A 3 && light -G | cut -d'.' -f1 > " ++ xobsock)
Skyler Grey70301492023-02-24 09:04:51 +0000159 ] ++ (zip numRowKeys Main.workspaces >>= (\(key, workspace) -> [((modifierKey, key), windows $ W.view workspace)
160 , ((modifierKey .|. Main.shift, key), windows $ W.shift workspace)
161 ])))