Skyler Grey | b43ac6b | 2022-10-31 00:48:34 +0000 | [diff] [blame] | 1 | -- spell-checker:words xmonad |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 2 | {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} |
| 3 | {-# HLINT ignore "Move brackets to avoid $" #-} |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 4 | import XMonad |
Skyler Grey | b43ac6b | 2022-10-31 00:48:34 +0000 | [diff] [blame] | 5 | |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 6 | import System.Exit |
| 7 | import XMonad.Util.EZConfig |
Skyler Grey | b43ac6b | 2022-10-31 00:48:34 +0000 | [diff] [blame] | 8 | |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 9 | import XMonad.Config.Desktop |
| 10 | import XMonad.Hooks.EwmhDesktops |
| 11 | import XMonad.Hooks.ManageDocks |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 12 | |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 13 | import qualified DBus.Client as D |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 14 | import XMonad.Hooks.DynamicLog |
| 15 | import XMonadLog |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 16 | |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 17 | import Blaze.ByteString.Builder (toByteString) |
Skyler Grey | 424a0a4 | 2023-02-26 23:05:45 +0000 | [diff] [blame] | 18 | import Data.Containers |
| 19 | import Data.List ((\\)) |
| 20 | import qualified Data.Map as M |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 21 | import Foreign.C |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 22 | import Graphics.X11.ExtraTypes (xF86XK_AudioLowerVolume, |
| 23 | xF86XK_AudioMute, |
| 24 | xF86XK_AudioRaiseVolume, |
| 25 | xF86XK_MonBrightnessDown, |
| 26 | xF86XK_MonBrightnessUp, |
| 27 | xF86XK_Xfer) |
| 28 | import qualified XMonad as W |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 29 | import XMonad.Hooks.DynamicProperty (dynamicPropertyChange) |
| 30 | import XMonad.Hooks.ManageHelpers (doFullFloat, doLower, |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 31 | doRectFloat, isInProperty) |
Skyler Grey | 62f4fa3 | 2023-03-07 13:16:06 +0000 | [diff] [blame] | 32 | import XMonad.Hooks.Place (fixed, placeHook, underMouse, withGaps) |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 33 | import XMonad.Hooks.UrgencyHook |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 34 | import XMonad.Layout (Tall) |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 35 | import XMonad.Layout.Drawer (propertyToQuery) |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 36 | import XMonad.Layout.Gaps |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 37 | import XMonad.Layout.Grid |
| 38 | import XMonad.Layout.MultiToggle (mkToggle) |
Skyler Grey | 424a0a4 | 2023-02-26 23:05:45 +0000 | [diff] [blame] | 39 | import XMonad.Layout.NoBorders (Ambiguity (Combine, OnlyScreenFloat), |
| 40 | SetsAmbiguous, With (Union), |
| 41 | hasBorder, hiddens, lessBorders, |
| 42 | smartBorders) |
| 43 | import XMonad.Layout.ResizableTile (MirrorResize (MirrorExpand, MirrorShrink), |
| 44 | ResizableTall (ResizableTall)) |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 45 | import XMonad.Layout.Spacing |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 46 | import qualified XMonad.StackSet as W |
Skyler Grey | 424a0a4 | 2023-02-26 23:05:45 +0000 | [diff] [blame] | 47 | import XMonad.StackSet (allWindows) |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 48 | import XMonad.Util.Hacks |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 49 | import XMonad.Util.PureX (curScreen, curScreenId) |
| 50 | import XMonad.Util.Run (safeSpawn, safeSpawnProg) |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 51 | |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 52 | volumeChangeCmd = "${{./vol_change.py}}" |
| 53 | |
Skyler Grey | 8964db5 | 2023-03-19 19:46:44 +0000 | [diff] [blame] | 54 | terminal = "/usr/bin/env SHLVL=0 wezterm" |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 55 | launcher = "pkill rofi; rofi -show combi" |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 56 | networkManager = "wpa_cli select_network $(wpa_cli list_networks | tail -n +3 | awk '!seen[$2]++' | rofi -dmenu -window-title 'Select Network' | awk '{print $1;}')" |
| 57 | |
| 58 | screenshot = "mkdir -p ~/Screenshots && maim | tee ~/Screenshots/\"$(date --rfc-3339=seconds)\".png | xclip -select clipboard -t image/png" |
Skyler Grey | e631f4c | 2023-02-14 17:20:18 +0000 | [diff] [blame] | 59 | selectScreenshot = "mkdir -p ~/Screenshots && maim -us | tee ~/Screenshots/\"$(date --rfc-3339=seconds)\".png | xclip -select clipboard -t image/png" |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 60 | |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 61 | modifierKey = mod4Mask -- Use Super as our mod key |
| 62 | |
Skyler Grey | a16cb70 | 2023-03-11 19:20:06 +0000 | [diff] [blame] | 63 | statusBar = "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 Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 64 | compositor = "pkill picom; picom" |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 65 | background = "pkill show; show ~/.xmonad/wallpaper.glsl > /dev/null" |
Skyler Grey | 9db914a | 2023-02-19 23:50:59 +0000 | [diff] [blame] | 66 | colorSelection = "xcolor | xclip -sel clip" |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 67 | keybindings = "setxkbmap -option caps:none && xmodmap ~/.Xmodmap" |
Skyler Grey | 34021e3 | 2022-11-04 09:28:03 +0000 | [diff] [blame] | 68 | |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 69 | shift = shiftMask |
| 70 | |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 71 | -- spell-checker:words xobsock |
| 72 | xobsock = "$XDG_RUNTIME_DIR/xob.sock" |
| 73 | |
Skyler Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 74 | workspaces = ["7", "5", "3", "1", "9", "0", "2", "4", "6", "8"]; |
| 75 | |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 76 | data NonFloats = NonFloats deriving (Read, Show) |
| 77 | |
| 78 | instance SetsAmbiguous NonFloats where |
| 79 | hiddens _ wset _ _ _ = allWindows wset \\ M.keys (W.floating wset) |
| 80 | |
Skyler Grey | 34021e3 | 2022-11-04 09:28:03 +0000 | [diff] [blame] | 81 | startupHook = do |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 82 | spawn Main.statusBar |
| 83 | spawn Main.compositor |
| 84 | spawn background |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 85 | spawn keybindings |
Skyler Grey | a23445b | 2023-02-25 07:01:35 +0000 | [diff] [blame] | 86 | windows $ W.view "0" |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 87 | spawn "pgrep keepass || run_keepass" |
| 88 | spawn $ "pkill xob; rm -f " ++ xobsock ++ " && mkfifo " ++ xobsock ++ " && tail -f " ++ xobsock ++ " | xob" |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 89 | |
Skyler Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 90 | numRowKeys = [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 Grey | 34021e3 | 2022-11-04 09:28:03 +0000 | [diff] [blame] | 101 | |
Skyler Grey | b43ac6b | 2022-10-31 00:48:34 +0000 | [diff] [blame] | 102 | main :: IO () |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 103 | main = XMonadLog.xmonadLog >>= main' |
| 104 | |
| 105 | main' :: D.Client -> IO () |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 106 | main' dbus = xmonad |
| 107 | $ javaHack |
| 108 | $ ewmh . setEwmhActivateHook doAskUrgent |
| 109 | $ docks |
| 110 | $ def |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 111 | { modMask = modifierKey -- Use Super as our mod key |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 112 | , borderWidth = 2 |
Skyler Grey | 3e434b6 | 2023-02-26 20:38:25 +0000 | [diff] [blame] | 113 | , normalBorderColor = "#61afef" |
Skyler Grey | f1fbcc1 | 2023-02-26 20:40:04 +0000 | [diff] [blame] | 114 | , focusedBorderColor = "#61afef" |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 115 | , XMonad.terminal = Main.terminal |
Skyler Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 116 | , XMonad.workspaces = Main.workspaces |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 117 | , XMonad.startupHook = Main.startupHook |
| 118 | , XMonad.logHook = dynamicLogWithPP (polybarHook dbus) |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 119 | , XMonad.layoutHook = lessBorders NonFloats |
| 120 | $ (smartSpacing 5 |
| 121 | |
| 122 | $ avoidStruts |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 123 | $ gaps [(U, 5), (D, 5), (L, 5), (R, 5)] |
Skyler Grey | 9c260ff | 2023-02-26 23:06:59 +0000 | [diff] [blame] | 124 | $ Grid |
| 125 | ||| ResizableTall 1 (3/100) (1/2) [] |
Skyler Grey | 424a0a4 | 2023-02-26 23:05:45 +0000 | [diff] [blame] | 126 | ||| Full |
| 127 | ||| Mirror (ResizableTall 1 (3/100) (1/2) [])) |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 128 | ||| gaps [(U, 0), (D, 0), (L, 0), (R, 0)] Full |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 129 | , XMonad.manageHook = composeAll |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 130 | [ isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP" |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 131 | --> hasBorder False <+> doIgnore <+> doLower <+> doLower |
| 132 | , checkDock --> doLower <+> doLower |
Skyler Grey | 424a0a4 | 2023-02-26 23:05:45 +0000 | [diff] [blame] | 133 | , isInProperty "_NET_WM_STATE" "_NET_WM_STATE_MODAL" |
Skyler Grey | 62f4fa3 | 2023-03-07 13:16:06 +0000 | [diff] [blame] | 134 | --> placeHook (withGaps (30, 30, 30, 30) (underMouse (0.5, 0.5))) <+> doFloat |
Skyler Grey | f2c55ae | 2022-11-05 17:48:02 +0000 | [diff] [blame] | 135 | ] <+> manageHook def |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 136 | , XMonad.handleEventHook = composeAll |
| 137 | [ windowedFullscreenFixEventHook |
| 138 | , dynamicPropertyChange "_NET_WM_WINDOW_TYPE" |
| 139 | (isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DESKTOP" |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 140 | --> hasBorder False <+> doLower |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 141 | <+> (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 Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 146 | } `additionalKeys` ( |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 147 | [ ((modifierKey, xK_d), spawn launcher) |
| 148 | , ((modifierKey, xK_n), spawn networkManager) |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 149 | , ((modifierKey .|. Main.shift, xK_q), kill) |
Skyler Grey | 37e2a40 | 2023-02-25 10:11:07 +0000 | [diff] [blame] | 150 | , ((modifierKey, xK_o), sendMessage MirrorShrink) |
| 151 | , ((modifierKey, xK_e), sendMessage MirrorExpand) |
Skyler Grey | e2ec0de | 2022-11-02 08:07:25 +0000 | [diff] [blame] | 152 | , ((modifierKey, xK_q), spawn "xmonad --restart") |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 153 | , ((modifierKey .|. Main.shift, xK_c), io exitSuccess) |
| 154 | , ((modifierKey .|. Main.shift, xK_s), spawn selectScreenshot) |
Skyler Grey | 9db914a | 2023-02-19 23:50:59 +0000 | [diff] [blame] | 155 | , ((modifierKey .|. Main.shift, xK_h), spawn colorSelection) |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 156 | , ((0, xK_Print), spawn screenshot) |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 157 | , ((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 Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 168 | ] ++ (zip numRowKeys Main.workspaces >>= (\(key, workspace) -> [((modifierKey, key), windows $ W.view workspace) |
| 169 | , ((modifierKey .|. Main.shift, key), windows $ W.shift workspace) |
| 170 | ]))) |