blob: c2db7c9d7bdfb5ec4472f973e1105b5509f90b6a [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 Greyd4d57e22023-05-01 08:07:48 +000065background = "pkill show; show -d HDMI-1-1 ~/.xmonad/wallpaper.glsl > /dev/null && show -d eDP-1 ~/.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 Greyd4d57e22023-05-01 08:07:48 +000074-- workspaces = ["7", "5", "3", "1", "9", "0", "2", "4", "6", "8"];
75workspaces = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
Skyler Grey70301492023-02-24 09:04:51 +000076
Skyler Grey37e2a402023-02-25 10:11:07 +000077data NonFloats = NonFloats deriving (Read, Show)
78
79instance SetsAmbiguous NonFloats where
80 hiddens _ wset _ _ _ = allWindows wset \\ M.keys (W.floating wset)
81
Skyler Grey34021e32022-11-04 09:28:03 +000082startupHook = do
Skyler Grey51a0c612022-11-05 09:59:04 +000083 spawn Main.statusBar
84 spawn Main.compositor
85 spawn background
Skyler Grey08082762023-01-26 00:35:19 +000086 spawn keybindings
Skyler Greyd4d57e22023-05-01 08:07:48 +000087 -- windows $ W.view "0"
Skyler Grey3a9a2b12023-02-13 08:04:05 +000088 spawn "pgrep keepass || run_keepass"
89 spawn $ "pkill xob; rm -f " ++ xobsock ++ " && mkfifo " ++ xobsock ++ " && tail -f " ++ xobsock ++ " | xob"
Skyler Greyf2c55ae2022-11-05 17:48:02 +000090
Skyler Grey70301492023-02-24 09:04:51 +000091numRowKeys = [xK_bracketleft
92 , xK_braceleft
93 , xK_braceright
94 , xK_parenleft
95 , xK_equal
96 , xK_asterisk
97 , xK_parenright
98 , xK_plus
99 , xK_bracketright
100 , xK_exclam
101 ]
Skyler Grey34021e32022-11-04 09:28:03 +0000102
Skyler Greyb43ac6b2022-10-31 00:48:34 +0000103main :: IO ()
Skyler Grey51a0c612022-11-05 09:59:04 +0000104main = XMonadLog.xmonadLog >>= main'
105
106main' :: D.Client -> IO ()
Skyler Grey08082762023-01-26 00:35:19 +0000107main' dbus = xmonad
108 $ javaHack
109 $ ewmh . setEwmhActivateHook doAskUrgent
110 $ docks
111 $ def
Skyler Greye2ec0de2022-11-02 08:07:25 +0000112 { modMask = modifierKey -- Use Super as our mod key
Skyler Grey37e2a402023-02-25 10:11:07 +0000113 , borderWidth = 2
Skyler Grey3e434b62023-02-26 20:38:25 +0000114 , normalBorderColor = "#61afef"
Skyler Greyf1fbcc12023-02-26 20:40:04 +0000115 , focusedBorderColor = "#61afef"
Skyler Greye2ec0de2022-11-02 08:07:25 +0000116 , XMonad.terminal = Main.terminal
Skyler Grey70301492023-02-24 09:04:51 +0000117 , XMonad.workspaces = Main.workspaces
Skyler Grey51a0c612022-11-05 09:59:04 +0000118 , XMonad.startupHook = Main.startupHook
119 , XMonad.logHook = dynamicLogWithPP (polybarHook dbus)
Skyler Grey37e2a402023-02-25 10:11:07 +0000120 , XMonad.layoutHook = lessBorders NonFloats
121 $ (smartSpacing 5
122
123 $ avoidStruts
Skyler Grey08082762023-01-26 00:35:19 +0000124 $ gaps [(U, 5), (D, 5), (L, 5), (R, 5)]
Skyler Grey9c260ff2023-02-26 23:06:59 +0000125 $ Grid
126 ||| ResizableTall 1 (3/100) (1/2) []
Skyler Grey424a0a42023-02-26 23:05:45 +0000127 ||| Full
128 ||| Mirror (ResizableTall 1 (3/100) (1/2) []))
Skyler Grey37e2a402023-02-25 10:11:07 +0000129 ||| gaps [(U, 0), (D, 0), (L, 0), (R, 0)] Full
Skyler Greyf2c55ae2022-11-05 17:48:02 +0000130 , XMonad.manageHook = composeAll
Skyler Grey08082762023-01-26 00:35:19 +0000131 [ isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP"
Skyler Grey37e2a402023-02-25 10:11:07 +0000132 --> hasBorder False <+> doIgnore <+> doLower <+> doLower
133 , checkDock --> doLower <+> doLower
Skyler Grey424a0a42023-02-26 23:05:45 +0000134 , isInProperty "_NET_WM_STATE" "_NET_WM_STATE_MODAL"
Skyler Grey62f4fa32023-03-07 13:16:06 +0000135 --> placeHook (withGaps (30, 30, 30, 30) (underMouse (0.5, 0.5))) <+> doFloat
Skyler Greyf2c55ae2022-11-05 17:48:02 +0000136 ] <+> manageHook def
Skyler Grey08082762023-01-26 00:35:19 +0000137 , XMonad.handleEventHook = composeAll
138 [ windowedFullscreenFixEventHook
139 , dynamicPropertyChange "_NET_WM_WINDOW_TYPE"
140 (isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP"
Skyler Grey37e2a402023-02-25 10:11:07 +0000141 --> hasBorder False <+> doLower
Skyler Grey08082762023-01-26 00:35:19 +0000142 <+> (ask >>= \w -> liftX (modifyWindowSet (W.delete w))
143 >> mempty)
144 <+> (ask >>= \w -> liftX (withDisplay $ \dpy -> io (moveResizeWindow dpy w 0 0 (fromIntegral $ displayWidth dpy $ defaultScreen dpy) (fromIntegral $ displayHeight dpy $ defaultScreen dpy))) >> mempty))
145 ]
146 <+> handleEventHook def
Skyler Grey70301492023-02-24 09:04:51 +0000147 } `additionalKeys` (
Skyler Greye2ec0de2022-11-02 08:07:25 +0000148 [ ((modifierKey, xK_d), spawn launcher)
149 , ((modifierKey, xK_n), spawn networkManager)
Skyler Grey08082762023-01-26 00:35:19 +0000150 , ((modifierKey .|. Main.shift, xK_q), kill)
Skyler Grey37e2a402023-02-25 10:11:07 +0000151 , ((modifierKey, xK_o), sendMessage MirrorShrink)
152 , ((modifierKey, xK_e), sendMessage MirrorExpand)
Skyler Greye2ec0de2022-11-02 08:07:25 +0000153 , ((modifierKey, xK_q), spawn "xmonad --restart")
Skyler Grey08082762023-01-26 00:35:19 +0000154 , ((modifierKey .|. Main.shift, xK_c), io exitSuccess)
155 , ((modifierKey .|. Main.shift, xK_s), spawn selectScreenshot)
Skyler Grey9db914a2023-02-19 23:50:59 +0000156 , ((modifierKey .|. Main.shift, xK_h), spawn colorSelection)
Skyler Grey08082762023-01-26 00:35:19 +0000157 , ((0, xK_Print), spawn screenshot)
Skyler Grey3a9a2b12023-02-13 08:04:05 +0000158 , ((modifierKey .|. Main.shift, xK_Return), spawn Main.terminal)
159 , ((0, xF86XK_AudioLowerVolume), spawn $ volumeChangeCmd ++ " -d")
160 , ((0, xF86XK_AudioRaiseVolume), spawn $ volumeChangeCmd ++ " -u")
161 , ((0, xF86XK_AudioMute), spawn $ volumeChangeCmd ++ " -m")
162 , ((modifierKey, xF86XK_AudioLowerVolume), spawn $ volumeChangeCmd ++ " -d -i")
163 , ((modifierKey, xF86XK_AudioRaiseVolume), spawn $ volumeChangeCmd ++ " -u -i")
164 , ((modifierKey, xF86XK_AudioMute), spawn $ volumeChangeCmd ++ " -m -i")
165 , ((0, xF86XK_MonBrightnessDown), spawn $ "light -U 6 && light -G | cut -d'.' -f1 > " ++ xobsock)
166 , ((0, xF86XK_MonBrightnessUp), spawn $ "light -A 6 && light -G | cut -d'.' -f1 > " ++ xobsock)
167 , ((modifierKey, xF86XK_MonBrightnessDown), spawn $ "light -U 3 && light -G | cut -d'.' -f1 > " ++ xobsock)
168 , ((modifierKey, xF86XK_MonBrightnessUp), spawn $ "light -A 3 && light -G | cut -d'.' -f1 > " ++ xobsock)
Skyler Grey70301492023-02-24 09:04:51 +0000169 ] ++ (zip numRowKeys Main.workspaces >>= (\(key, workspace) -> [((modifierKey, key), windows $ W.view workspace)
170 , ((modifierKey .|. Main.shift, key), windows $ W.shift workspace)
171 ])))