blob: 553522ccdea5c24896d06baf1dab07e6eb67b394 [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)
Skyler Grey424a0a42023-02-26 23:05:45 +000018import Data.Containers
19import Data.List ((\\))
20import qualified Data.Map as M
Skyler Grey08082762023-01-26 00:35:19 +000021import Foreign.C
Skyler Grey3a9a2b12023-02-13 08:04:05 +000022import Graphics.X11.ExtraTypes (xF86XK_AudioLowerVolume,
23 xF86XK_AudioMute,
24 xF86XK_AudioRaiseVolume,
25 xF86XK_MonBrightnessDown,
26 xF86XK_MonBrightnessUp,
27 xF86XK_Xfer)
28import qualified XMonad as W
Skyler Grey08082762023-01-26 00:35:19 +000029import XMonad.Hooks.DynamicProperty (dynamicPropertyChange)
30import XMonad.Hooks.ManageHelpers (doFullFloat, doLower,
Skyler Grey3a9a2b12023-02-13 08:04:05 +000031 doRectFloat, isInProperty)
Skyler Grey62f4fa32023-03-07 13:16:06 +000032import XMonad.Hooks.Place (fixed, placeHook, underMouse, withGaps)
Skyler Grey08082762023-01-26 00:35:19 +000033import XMonad.Hooks.UrgencyHook
Skyler Grey37e2a402023-02-25 10:11:07 +000034import XMonad.Layout (Tall)
Skyler Grey08082762023-01-26 00:35:19 +000035import XMonad.Layout.Drawer (propertyToQuery)
Skyler Greyf2c55ae2022-11-05 17:48:02 +000036import XMonad.Layout.Gaps
Skyler Grey37e2a402023-02-25 10:11:07 +000037import XMonad.Layout.Grid
38import XMonad.Layout.MultiToggle (mkToggle)
Skyler Grey424a0a42023-02-26 23:05:45 +000039import XMonad.Layout.NoBorders (Ambiguity (Combine, OnlyScreenFloat),
40 SetsAmbiguous, With (Union),
41 hasBorder, hiddens, lessBorders,
42 smartBorders)
43import XMonad.Layout.ResizableTile (MirrorResize (MirrorExpand, MirrorShrink),
44 ResizableTall (ResizableTall))
Skyler Greyf2c55ae2022-11-05 17:48:02 +000045import XMonad.Layout.Spacing
Skyler Grey08082762023-01-26 00:35:19 +000046import qualified XMonad.StackSet as W
Skyler Grey424a0a42023-02-26 23:05:45 +000047import XMonad.StackSet (allWindows)
Skyler Grey08082762023-01-26 00:35:19 +000048import XMonad.Util.Hacks
Skyler Grey3a9a2b12023-02-13 08:04:05 +000049import XMonad.Util.PureX (curScreen, curScreenId)
50import XMonad.Util.Run (safeSpawn, safeSpawnProg)
Skyler Grey51a0c612022-11-05 09:59:04 +000051
Skyler Grey3a9a2b12023-02-13 08:04:05 +000052volumeChangeCmd = "${{./vol_change.py}}"
53
Skyler Grey29c15f12023-03-26 11:22:41 +000054terminal = "/usr/bin/env SHLVL=0 kitty" -- Kitty, my beloved <3
Skyler Greye2ec0de2022-11-02 08:07:25 +000055launcher = "pkill rofi; rofi -show combi"
Skyler Grey08082762023-01-26 00:35:19 +000056networkManager = "wpa_cli select_network $(wpa_cli list_networks | tail -n +3 | awk '!seen[$2]++' | rofi -dmenu -window-title 'Select Network' | awk '{print $1;}')"
57
58screenshot = "mkdir -p ~/Screenshots && maim | tee ~/Screenshots/\"$(date --rfc-3339=seconds)\".png | xclip -select clipboard -t image/png"
Skyler Greye631f4c2023-02-14 17:20:18 +000059selectScreenshot = "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 +000060
Skyler Greye2ec0de2022-11-02 08:07:25 +000061modifierKey = mod4Mask -- Use Super as our mod key
62
Skyler Greya16cb702023-03-11 19:20:06 +000063statusBar = "pkill polybar; polybar main; ${{builtins.concatStringsSep '' '' (map (num: ''polybar DP-'' + toString num + ''; '')(lib.range 1 8))}} polybar HDMI-A-1-0; polybar HDMI-A-1"
Skyler Grey51a0c612022-11-05 09:59:04 +000064compositor = "pkill picom; picom"
Skyler Grey08082762023-01-26 00:35:19 +000065background = "pkill show; show ~/.xmonad/wallpaper.glsl > /dev/null"
Skyler Grey9db914a2023-02-19 23:50:59 +000066colorSelection = "xcolor | xclip -sel clip"
Skyler Grey08082762023-01-26 00:35:19 +000067keybindings = "setxkbmap -option caps:none && xmodmap ~/.Xmodmap"
Skyler Grey34021e32022-11-04 09:28:03 +000068
Skyler Greye2ec0de2022-11-02 08:07:25 +000069shift = shiftMask
70
Skyler Grey3a9a2b12023-02-13 08:04:05 +000071-- spell-checker:words xobsock
72xobsock = "$XDG_RUNTIME_DIR/xob.sock"
73
Skyler Grey70301492023-02-24 09:04:51 +000074workspaces = ["7", "5", "3", "1", "9", "0", "2", "4", "6", "8"];
75
Skyler Grey37e2a402023-02-25 10:11:07 +000076data NonFloats = NonFloats deriving (Read, Show)
77
78instance SetsAmbiguous NonFloats where
79 hiddens _ wset _ _ _ = allWindows wset \\ M.keys (W.floating wset)
80
Skyler Grey34021e32022-11-04 09:28:03 +000081startupHook = do
Skyler Grey51a0c612022-11-05 09:59:04 +000082 spawn Main.statusBar
83 spawn Main.compositor
84 spawn background
Skyler Grey08082762023-01-26 00:35:19 +000085 spawn keybindings
Skyler Greya23445b2023-02-25 07:01:35 +000086 windows $ W.view "0"
Skyler Grey3a9a2b12023-02-13 08:04:05 +000087 spawn "pgrep keepass || run_keepass"
88 spawn $ "pkill xob; rm -f " ++ xobsock ++ " && mkfifo " ++ xobsock ++ " && tail -f " ++ xobsock ++ " | xob"
Skyler Greyf2c55ae2022-11-05 17:48:02 +000089
Skyler Grey70301492023-02-24 09:04:51 +000090numRowKeys = [xK_bracketleft
91 , xK_braceleft
92 , xK_braceright
93 , xK_parenleft
94 , xK_equal
95 , xK_asterisk
96 , xK_parenright
97 , xK_plus
98 , xK_bracketright
99 , xK_exclam
100 ]
Skyler Grey34021e32022-11-04 09:28:03 +0000101
Skyler Greyb43ac6b2022-10-31 00:48:34 +0000102main :: IO ()
Skyler Grey51a0c612022-11-05 09:59:04 +0000103main = XMonadLog.xmonadLog >>= main'
104
105main' :: D.Client -> IO ()
Skyler Grey08082762023-01-26 00:35:19 +0000106main' dbus = xmonad
107 $ javaHack
108 $ ewmh . setEwmhActivateHook doAskUrgent
109 $ docks
110 $ def
Skyler Greye2ec0de2022-11-02 08:07:25 +0000111 { modMask = modifierKey -- Use Super as our mod key
Skyler Grey37e2a402023-02-25 10:11:07 +0000112 , borderWidth = 2
Skyler Grey3e434b62023-02-26 20:38:25 +0000113 , normalBorderColor = "#61afef"
Skyler Greyf1fbcc12023-02-26 20:40:04 +0000114 , focusedBorderColor = "#61afef"
Skyler Greye2ec0de2022-11-02 08:07:25 +0000115 , XMonad.terminal = Main.terminal
Skyler Grey70301492023-02-24 09:04:51 +0000116 , XMonad.workspaces = Main.workspaces
Skyler Grey51a0c612022-11-05 09:59:04 +0000117 , XMonad.startupHook = Main.startupHook
118 , XMonad.logHook = dynamicLogWithPP (polybarHook dbus)
Skyler Grey37e2a402023-02-25 10:11:07 +0000119 , XMonad.layoutHook = lessBorders NonFloats
120 $ (smartSpacing 5
121
122 $ avoidStruts
Skyler Grey08082762023-01-26 00:35:19 +0000123 $ gaps [(U, 5), (D, 5), (L, 5), (R, 5)]
Skyler Grey9c260ff2023-02-26 23:06:59 +0000124 $ Grid
125 ||| ResizableTall 1 (3/100) (1/2) []
Skyler Grey424a0a42023-02-26 23:05:45 +0000126 ||| Full
127 ||| Mirror (ResizableTall 1 (3/100) (1/2) []))
Skyler Grey37e2a402023-02-25 10:11:07 +0000128 ||| gaps [(U, 0), (D, 0), (L, 0), (R, 0)] Full
Skyler Greyf2c55ae2022-11-05 17:48:02 +0000129 , XMonad.manageHook = composeAll
Skyler Grey08082762023-01-26 00:35:19 +0000130 [ isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP"
Skyler Grey37e2a402023-02-25 10:11:07 +0000131 --> hasBorder False <+> doIgnore <+> doLower <+> doLower
132 , checkDock --> doLower <+> doLower
Skyler Grey424a0a42023-02-26 23:05:45 +0000133 , isInProperty "_NET_WM_STATE" "_NET_WM_STATE_MODAL"
Skyler Grey62f4fa32023-03-07 13:16:06 +0000134 --> placeHook (withGaps (30, 30, 30, 30) (underMouse (0.5, 0.5))) <+> doFloat
Skyler Greyf2c55ae2022-11-05 17:48:02 +0000135 ] <+> manageHook def
Skyler Grey08082762023-01-26 00:35:19 +0000136 , XMonad.handleEventHook = composeAll
137 [ windowedFullscreenFixEventHook
138 , dynamicPropertyChange "_NET_WM_WINDOW_TYPE"
139 (isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP"
Skyler Grey37e2a402023-02-25 10:11:07 +0000140 --> hasBorder False <+> doLower
Skyler Grey08082762023-01-26 00:35:19 +0000141 <+> (ask >>= \w -> liftX (modifyWindowSet (W.delete w))
142 >> mempty)
143 <+> (ask >>= \w -> liftX (withDisplay $ \dpy -> io (moveResizeWindow dpy w 0 0 (fromIntegral $ displayWidth dpy $ defaultScreen dpy) (fromIntegral $ displayHeight dpy $ defaultScreen dpy))) >> mempty))
144 ]
145 <+> handleEventHook def
Skyler Grey70301492023-02-24 09:04:51 +0000146 } `additionalKeys` (
Skyler Greye2ec0de2022-11-02 08:07:25 +0000147 [ ((modifierKey, xK_d), spawn launcher)
148 , ((modifierKey, xK_n), spawn networkManager)
Skyler Grey08082762023-01-26 00:35:19 +0000149 , ((modifierKey .|. Main.shift, xK_q), kill)
Skyler Grey37e2a402023-02-25 10:11:07 +0000150 , ((modifierKey, xK_o), sendMessage MirrorShrink)
151 , ((modifierKey, xK_e), sendMessage MirrorExpand)
Skyler Greye2ec0de2022-11-02 08:07:25 +0000152 , ((modifierKey, xK_q), spawn "xmonad --restart")
Skyler Grey08082762023-01-26 00:35:19 +0000153 , ((modifierKey .|. Main.shift, xK_c), io exitSuccess)
154 , ((modifierKey .|. Main.shift, xK_s), spawn selectScreenshot)
Skyler Grey9db914a2023-02-19 23:50:59 +0000155 , ((modifierKey .|. Main.shift, xK_h), spawn colorSelection)
Skyler Grey08082762023-01-26 00:35:19 +0000156 , ((0, xK_Print), spawn screenshot)
Skyler Grey3a9a2b12023-02-13 08:04:05 +0000157 , ((modifierKey .|. Main.shift, xK_Return), spawn Main.terminal)
158 , ((0, xF86XK_AudioLowerVolume), spawn $ volumeChangeCmd ++ " -d")
159 , ((0, xF86XK_AudioRaiseVolume), spawn $ volumeChangeCmd ++ " -u")
160 , ((0, xF86XK_AudioMute), spawn $ volumeChangeCmd ++ " -m")
161 , ((modifierKey, xF86XK_AudioLowerVolume), spawn $ volumeChangeCmd ++ " -d -i")
162 , ((modifierKey, xF86XK_AudioRaiseVolume), spawn $ volumeChangeCmd ++ " -u -i")
163 , ((modifierKey, xF86XK_AudioMute), spawn $ volumeChangeCmd ++ " -m -i")
164 , ((0, xF86XK_MonBrightnessDown), spawn $ "light -U 6 && light -G | cut -d'.' -f1 > " ++ xobsock)
165 , ((0, xF86XK_MonBrightnessUp), spawn $ "light -A 6 && light -G | cut -d'.' -f1 > " ++ xobsock)
166 , ((modifierKey, xF86XK_MonBrightnessDown), spawn $ "light -U 3 && light -G | cut -d'.' -f1 > " ++ xobsock)
167 , ((modifierKey, xF86XK_MonBrightnessUp), spawn $ "light -A 3 && light -G | cut -d'.' -f1 > " ++ xobsock)
Skyler Grey70301492023-02-24 09:04:51 +0000168 ] ++ (zip numRowKeys Main.workspaces >>= (\(key, workspace) -> [((modifierKey, key), windows $ W.view workspace)
169 , ((modifierKey .|. Main.shift, key), windows $ W.shift workspace)
170 ])))