xmonad: fix urgency marker and ws 3 focus, simplify hooks

Enable withUrgencyHook so ppUrgent works, focus ws 3 when it opens on HDMI, and
make ppOrder total. Track discover-overlay windows instead of scanning the tree
on every log hook. Group manage rules with classIn, deduplicate the layouts and
scratchpads, and use wpctl for all volume keys.
This commit is contained in:
Daniele Fucini committed 2026-11-17 21:47:48 +01:00
1 parent 7e8328bf60
commit 108f71e711
1 file changed
+90 -74
+90 -74
View File
@@ -3,11 +3,11 @@
import Data.Monoid import Data.Monoid
import Data.Bits (complement, (.&.)) import Data.Bits (complement, (.&.))
import Data.Char (toLower) import Data.Char (toLower)
import Control.Monad (forM_, join, liftM2, when) import Control.Monad (filterM, forM_, join, unless, when)
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Data.Maybe (isJust) import Data.Maybe (isJust)
import XMonad import XMonad
import XMonad.Actions.OnScreen (greedyViewOnScreen) import XMonad.Actions.OnScreen (Focus (FocusNew), onScreen)
import XMonad.Actions.PhysicalScreens import XMonad.Actions.PhysicalScreens
import XMonad.Hooks.EwmhDesktops import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageDocks import XMonad.Hooks.ManageDocks
@@ -15,6 +15,7 @@ import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.Rescreen import XMonad.Hooks.Rescreen
import XMonad.Hooks.StatusBar import XMonad.Hooks.StatusBar
import XMonad.Hooks.StatusBar.PP import XMonad.Hooks.StatusBar.PP
import XMonad.Hooks.UrgencyHook (NoUrgencyHook (..), withUrgencyHook)
import XMonad.Layout.Grid import XMonad.Layout.Grid
import XMonad.Layout.Magnifier import XMonad.Layout.Magnifier
import XMonad.Layout.NoBorders import XMonad.Layout.NoBorders
@@ -45,6 +46,7 @@ main =
. setEwmhSwitchDesktopHook safeView . setEwmhSwitchDesktopHook safeView
. ewmh . ewmh
. docks . docks
. withUrgencyHook NoUrgencyHook
. rescreenHook def {afterRescreenHook = restartStatusBars, rescreenWorkspacesHook = Last (Just safeRescreen)} . rescreenHook def {afterRescreenHook = restartStatusBars, rescreenWorkspacesHook = Last (Just safeRescreen)}
. addRandrChangeHook (spawn myScreenHotplug) . addRandrChangeHook (spawn myScreenHotplug)
$ myConfig $ myConfig
@@ -65,17 +67,12 @@ myNormBorderColor = "#1f2335"
myFocusBorderColor :: String myFocusBorderColor :: String
myFocusBorderColor = "#41a6b5" myFocusBorderColor = "#41a6b5"
myKeyboardLayoutIT :: String myEarbuds :: String
myKeyboardLayoutIT = " -layout it" myEarbuds = "F4:9D:8A:B9:8C:EE"
myKeyboardLayoutUS :: String
myKeyboardLayoutUS = " -layout us"
myKeyboardLayoutSK :: String
myKeyboardLayoutSK = " -layout sk -variant qwerty"
-- Expanded by sh, as spawn runs it
myScreenshotDir :: String myScreenshotDir :: String
myScreenshotDir = "/home/fuxino/Pictures/Screenshots/" myScreenshotDir = "~/Pictures/Screenshots/"
myScreenshotName :: String myScreenshotName :: String
myScreenshotName = "Screenshot-%Y-%m-%d-%H%M%S.png" myScreenshotName = "Screenshot-%Y-%m-%d-%H%M%S.png"
@@ -96,18 +93,17 @@ myScreenHotplug = myScreenLayout ++ " --keep-wallpaper"
myScratchpads :: [NamedScratchpad] myScratchpads :: [NamedScratchpad]
myScratchpads = myScratchpads =
[ NS "Windscribe" "windscribe" (className =? "Windscribe2") (customFloating $ W.RationalRect 0.15 0.4 0.15 0.4), [ NS "Windscribe" "windscribe" (className =? "Windscribe2") (customFloating $ W.RationalRect 0.15 0.4 0.15 0.4),
NS "Terminal" spawnTerminal (className =? "scratch-terminal") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), termPad "Terminal" "kitty-float" "",
NS "Music" spawnMusic (className =? "scratch-music") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), termPad "Music" "ncmpcpp" "ncmpcpp",
NS "Mail" spawnMail (className =? "scratch-mail") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), termPad "Mail" "mutt" "bash -c 'pushd ~/Downloads > /dev/null; mutt; popd > /dev/null'",
NS "Cal" spawnCal (className =? "scratch-cal") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), termPad "Cal" "calcurse" "calcurse",
NS "Btop" spawnBtop (className =? "scratch-btop") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6) termPad "Btop" "btop" "btop"
] ]
where where
spawnTerminal = myTerminal ++ " --class scratch-terminal -T kitty-float" -- Centred kitty with class scratch-<name>, window title t, running cmd
spawnMusic = myTerminal ++ " --class scratch-music -T ncmpcpp ncmpcpp" termPad name t cmd =
spawnMail = myTerminal ++ " --class scratch-mail -T mutt bash -c 'pushd ~/Downloads > /dev/null; mutt; popd > /dev/null'" let cls = "scratch-" ++ map toLower name
spawnCal = myTerminal ++ " --class scratch-cal -T calcurse calcurse" in NS name (unwords [myTerminal, "--class", cls, "-T", t, cmd]) (className =? cls) (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6)
spawnBtop = myTerminal ++ " --class scratch-btop -T btop btop"
-- Config -- Config
myConfig = myConfig =
@@ -164,11 +160,11 @@ myCustomKeys c =
("M-C-n", addName "Close all notifications" $ spawn "dunstctl close-all"), ("M-C-n", addName "Close all notifications" $ spawn "dunstctl close-all"),
("M-b", addName "Toggle the status bar gap" $ sendMessage ToggleStruts), ("M-b", addName "Toggle the status bar gap" $ sendMessage ToggleStruts),
("M-f", addName "Tabbed layout" $ sendMessage $ JumpToLayout "Tabbed"), ("M-f", addName "Tabbed layout" $ sendMessage $ JumpToLayout "Tabbed"),
("M-i", addName "Keyboard: Italian" $ spawn $ "setxkbmap" ++ myKeyboardLayoutIT), ("M-i", addName "Keyboard: Italian" $ spawn "setxkbmap -layout it"),
("M-u", addName "Keyboard: US" $ spawn $ "setxkbmap" ++ myKeyboardLayoutUS), ("M-u", addName "Keyboard: US" $ spawn "setxkbmap -layout us"),
("M-s", addName "Keyboard: Slovak" $ spawn $ "setxkbmap" ++ myKeyboardLayoutSK), ("M-s", addName "Keyboard: Slovak" $ spawn "setxkbmap -layout sk -variant qwerty"),
("M-x", addName "Connect earbuds" $ spawn "bluetoothctl connect F4:9D:8A:B9:8C:EE"), ("M-x", addName "Connect earbuds" $ spawn $ "bluetoothctl connect " ++ myEarbuds),
("M-S-x", addName "Disconnect earbuds" $ spawn "bluetoothctl disconnect F4:9D:8A:B9:8C:EE") ("M-S-x", addName "Disconnect earbuds" $ spawn $ "bluetoothctl disconnect " ++ myEarbuds)
] ]
), ),
( "screenshots", ( "screenshots",
@@ -178,8 +174,8 @@ myCustomKeys c =
] ]
), ),
( "media keys", ( "media keys",
[ ("<XF86AudioMute>", addName "Mute" $ spawn "pactl set-sink-mute $(pactl get-default-sink) toggle"), [ ("<XF86AudioMute>", addName "Mute" $ spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"),
("<XF86AudioLowerVolume>", addName "Volume down" $ spawn "pactl set-sink-volume $(pactl get-default-sink) -10%"), ("<XF86AudioLowerVolume>", addName "Volume down" $ spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%-"),
("<XF86AudioRaiseVolume>", addName "Volume up" $ spawn "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 10%+"), ("<XF86AudioRaiseVolume>", addName "Volume up" $ spawn "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 10%+"),
("<XF86AudioPlay>", addName "Play/pause" $ spawn "playerctl play-pause"), ("<XF86AudioPlay>", addName "Play/pause" $ spawn "playerctl play-pause"),
("<XF86AudioPause>", addName "Pause" $ spawn "playerctl pause"), ("<XF86AudioPause>", addName "Pause" $ spawn "playerctl pause"),
@@ -214,10 +210,10 @@ showKeys ks = addName "Show keybindings" $ do
fixMod (x : r) = x : fixMod r fixMod (x : r) = x : fixMod r
fixMod [] = [] fixMod [] = []
-- greedyView that keeps wsGames on screen 0 (HDMI): Wine games lose the mouse when moved between screens -- greedyView that keeps wsGames on screen 0 (HDMI), and focuses it: Wine games lose the mouse when moved between screens
safeView :: WorkspaceId -> WindowSet -> WindowSet safeView :: WorkspaceId -> WindowSet -> WindowSet
safeView i ws safeView i ws
| i == wsGames = greedyViewOnScreen 0 i ws | i == wsGames = onScreen (W.greedyView i) FocusNew 0 ws
| W.currentTag ws == wsGames && i `elem` map (W.tag . W.workspace) (W.visible ws) = W.view i ws | W.currentTag ws == wsGames && i `elem` map (W.tag . W.workspace) (W.visible ws) = W.view i ws
| otherwise = W.greedyView i ws | otherwise = W.greedyView i ws
@@ -241,7 +237,7 @@ safeRescreen = do
-- Workspaces -- Workspaces
myWorkspaces :: [String] myWorkspaces :: [String]
myWorkspaces = [wsTerm, wsWeb, wsGames, wsChat, wsMedia, wsDocs, wsVM] ++ map show [8, 9] myWorkspaces = [wsTerm, wsWeb, wsGames, wsChat, wsMedia, wsDocs, wsVM] ++ map show [8, 9 :: Int]
-- Icons spill past their advance in the non-Mono Nerd Font: keep them ~1000-1160 units wide or gaps look uneven -- Icons spill past their advance in the non-Mono Nerd Font: keep them ~1000-1160 units wide or gaps look uneven
wsTerm, wsWeb, wsGames, wsChat, wsMedia, wsDocs, wsVM :: String wsTerm, wsWeb, wsGames, wsChat, wsMedia, wsDocs, wsVM :: String
@@ -254,12 +250,15 @@ wsDocs = "6:\xede2 "
wsVM = "7:\xf108 " wsVM = "7:\xf108 "
-- Layout -- Layout
myLayoutHook = onWorkspace wsWeb myWebLayout $ onWorkspace wsGames myGamesLayout $ onWorkspace wsMedia myVideoLayout myDefaultLayout myLayoutHook =
avoidStruts $
onWorkspaces [wsGames, wsMedia] (smartBorders Full) $
onWorkspace wsWeb (spaced $ myTabbed ||| tiled ||| Mirror tiled ||| others) $
spaced (tiled ||| Mirror tiled ||| myTabbed ||| others)
where where
myWebLayout = avoidStruts $ renamed [CutWordsLeft 1] $ spacingWithEdge 3 $ myTabbed ||| tiled ||| Mirror tiled ||| threeCol ||| Grid ||| spiral 0.856 -- CutWordsLeft drops the "Spacing" prefix from the layout names
myGamesLayout = avoidStruts $ smartBorders Full spaced l = renamed [CutWordsLeft 1] $ spacingWithEdge 3 l
myVideoLayout = avoidStruts $ smartBorders Full others = threeCol ||| Grid ||| spiral 0.856
myDefaultLayout = avoidStruts $ renamed [CutWordsLeft 1] $ spacingWithEdge 3 $ tiled ||| Mirror tiled ||| myTabbed ||| threeCol ||| Grid ||| spiral 0.856
threeCol = threeCol =
renamed [Replace "ThreeCol"] $ renamed [Replace "ThreeCol"] $
magnifiercz' 1.3 $ magnifiercz' 1.3 $
@@ -309,11 +308,16 @@ myXmobarPP =
_ -> tag, _ -> tag,
-- NamedScratchpad never removes NSP once created; hide it while it's empty -- NamedScratchpad never removes NSP once created; hide it while it's empty
ppSort = (. filter (\w -> W.tag w /= scratchpadWorkspaceTag || isJust (W.stack w))) <$> ppSort def, ppSort = (. filter (\w -> W.tag w /= scratchpadWorkspaceTag || isJust (W.stack w))) <$> ppSort def,
ppOrder = \[ws, l, _, wins] -> [ws, l, wins], ppOrder = dropTitle,
ppLayout = layoutIcon, ppLayout = layoutIcon,
ppExtras = [budgetTitles] ppExtras = [budgetTitles]
} }
where where
-- The focused title is replaced by budgetTitles
dropTitle :: [String] -> [String]
dropTitle (ws : l : _ : rest) = ws : l : rest
dropTitle xs = xs
layoutIcon :: String -> String layoutIcon :: String -> String
layoutIcon l = case l of layoutIcon l = case l of
"Tall" -> "\xf0bcc" "Tall" -> "\xf0bcc"
@@ -330,11 +334,12 @@ myXmobarPP =
budgetTitles = do budgetTitles = do
n <- gets $ length . W.integrate' . W.stack . W.workspace . W.current . windowset n <- gets $ length . W.integrate' . W.stack . W.workspace . W.current . windowset
let width = max 8 . min 30 $ 60 `div` max 1 n let width = max 8 . min 30 $ 60 `div` max 1 n
logTitles (formatFocused width) (formatUnfocused width) logTitles' (TitlesFormat (formatFocused width) (formatUnfocused width) (formatUrgent width))
formatFocused, formatUnfocused :: Int -> String -> String formatFocused, formatUnfocused, formatUrgent :: Int -> String -> String
formatFocused w = wrap (cultured "[") (cultured "]") . pink . ppWindow w formatFocused w = wrap (cultured "[") (cultured "]") . pink . ppWindow w
formatUnfocused w = wrap (outerspace "[") (outerspace "]") . cultured . ppWindow w formatUnfocused w = wrap (outerspace "[") (outerspace "]") . cultured . ppWindow w
formatUrgent w = wrap (keylime "!") (keylime "!") . sunsetorange . ppWindow w
ppWindow :: Int -> String -> String ppWindow :: Int -> String -> String
ppWindow w = xmobarRaw . (\t -> if null t then "untitled" else t) . shorten' "…" w ppWindow w = xmobarRaw . (\t -> if null t then "untitled" else t) . shorten' "…" w
@@ -350,6 +355,7 @@ myXmobarPP =
myStartupHook :: X () myStartupHook :: X ()
myStartupHook = do myStartupHook = do
restartStatusBars restartStatusBars
scanDiscoverOverlay
spawnOnce myScreenSetup spawnOnce myScreenSetup
spawnOnce "systemctl --user start fehbg.timer" spawnOnce "systemctl --user start fehbg.timer"
spawnOnce "xsetroot -cursor_name left_ptr" spawnOnce "xsetroot -cursor_name left_ptr"
@@ -378,44 +384,30 @@ myManageHook =
[ -- Proton games are steam_app_<id>; Wine windows are named after their .exe [ -- Proton games are steam_app_<id>; Wine windows are named after their .exe
className ^? "steam_app_" --> doShift wsGames, className ^? "steam_app_" --> doShift wsGames,
className $? ".exe" --> doShift wsGames, className $? ".exe" --> doShift wsGames,
className =? "Gpodder" --> doShift wsMedia, classIn ["steam", "an anime game launcher"] --> doShift wsGames,
className =? "An Anime Game Launcher" --> doShift wsGames,
className =? "Qalculate-gtk" --> doFloat,
title =? "Genshin Impact" --> doShift wsGames, title =? "Genshin Impact" --> doShift wsGames,
classIn ["gimp", "audacity"] --> doShift wsMedia, classIn ["steam_app_109600", "steam_app_289070"] --> doFloat,
classIn ["pavucontrol", "org.pulseaudio.pavucontrol", "zenity", "org.gnome.zenity", "lxappearance", "qt5ct", "qt6ct"] --> doFloat, classIn ["zen", "vivaldi-stable", "transmission-gtk"] --> doShift wsWeb,
classIn ["signal", "discord"] --> doShift wsChat, classIn ["signal", "discord"] --> doShift wsChat,
className =? "Spotify" --> doShift wsMedia, classIn ["gpodder", "spotify", "freetube", "scrcpy", "gimp", "audacity"] --> doShift wsMedia,
className =? "Transmission-gtk" --> doShift wsWeb, classIn ["xreader", "calibre", "library_manager", "libreoffice-calc", "libreoffice-writer"] --> doShift wsDocs,
className =? "Viewnior" --> doFloat, classIn ["virtualbox manager"] --> doShift wsVM,
className =? "Vivaldi-stable" --> doShift wsWeb, className =? "VirtualBox Machine" --> doFullFloat <+> doShift wsVM,
className =? "Xmessage" --> doFloat, className =? "mpv" --> doFullFloat <+> viewShift wsMedia,
className =? "Xreader" --> doShift wsDocs,
className =? "calibre" --> doShift wsDocs,
className =? "feh" --> doFloat,
title =? "glxgears" --> doFloat,
className =? "library_manager" --> doShift wsDocs,
className =? "libreoffice-calc" --> doShift wsDocs,
className =? "libreoffice-writer" --> doShift wsDocs,
className =? "mpv" --> doFullFloat,
className =? "mpv" --> viewShift wsMedia,
className =? "freetube" --> doShift wsMedia,
className =? myTerminal --> doShift wsTerm, className =? myTerminal --> doShift wsTerm,
className =? "scrcpy" --> doShift wsMedia, classIn
className =? "steam" --> doShift wsGames, [ "qalculate-gtk", "viewnior", "xmessage", "feh", "lxappearance", "qt5ct", "qt6ct",
className =? "steam_app_109600" --> doFloat, "pavucontrol", "org.pulseaudio.pavucontrol", "zenity", "org.gnome.zenity"
className =? "steam_app_289070" --> doFloat, ]
className =? "VirtualBox Machine" --> doShift wsVM, --> doFloat,
className =? "VirtualBox Machine" --> doFullFloat, title =? "glxgears" --> doFloat,
className =? "VirtualBox Manager" --> doShift wsVM,
className =? "zen" --> doShift wsWeb,
isDialog --> doFloat, isDialog --> doFloat,
-- Windows that open already fullscreen; ewmhFullscreen only handles later requests -- Windows that open already fullscreen; ewmhFullscreen only handles later requests
isFullscreen --> doFullFloat isFullscreen --> doFullFloat
] ]
<+> namedScratchpadManageHook myScratchpads <+> namedScratchpadManageHook myScratchpads
where where
viewShift = doF . liftM2 (.) safeView W.shift viewShift = doF . liftA2 (.) safeView W.shift
-- Case-insensitive, as GTK4 and firejailed apps capitalise their class differently -- Case-insensitive, as GTK4 and firejailed apps capitalise their class differently
classIn names = (`elem` names) . map toLower <$> className classIn names = (`elem` names) . map toLower <$> className
@@ -452,6 +444,7 @@ myHandleEventHook =
<> Hacks.trayerPaddingXmobarEventHook <> Hacks.trayerPaddingXmobarEventHook
<> Hacks.fixSteamFlicker <> Hacks.fixSteamFlicker
<> pinWindscribe <> pinWindscribe
<> trackDiscoverOverlay
-- Windscribe moves itself to a saved position after mapping: apply its resizes (as core does for floats) but drop moves. -- Windscribe moves itself to a saved position after mapping: apply its resizes (as core does for floats) but drop moves.
pinWindscribe :: Event -> X All pinWindscribe :: Event -> X All
@@ -476,11 +469,34 @@ myLogHook = do
xmonadPropLog =<< dynamicLogString =<< clickablePP myXmobarPP xmonadPropLog =<< dynamicLogString =<< clickablePP myXmobarPP
-- discover-overlay's windows are override-redirect, so xmonad doesn't manage them and -- discover-overlay's windows are override-redirect, so xmonad doesn't manage them and
-- raising a floating window (e.g. a game) covers them; put them back on top after every change -- raising a floating window (e.g. a game) covers them; put them back on top after every change.
raiseDiscoverOverlay :: X () -- They're remembered when mapped, so the log hook doesn't query every window each time.
raiseDiscoverOverlay = withDisplay $ \d -> do newtype OverlayWindows = OverlayWindows [Window]
instance ExtensionClass OverlayWindows where
initialValue = OverlayWindows []
isDiscoverOverlay :: Window -> X Bool
isDiscoverOverlay = runQuery (className =? "Discover-overlay")
-- Startup (incl. xmonad --restart): pick up overlays mapped before the event hook could see them
scanDiscoverOverlay :: X ()
scanDiscoverOverlay = withDisplay $ \d -> do
root <- asks theRoot root <- asks theRoot
(_, _, ws) <- io $ queryTree d root (_, _, ws) <- io $ queryTree d root
forM_ ws $ \w -> do XS.put . OverlayWindows =<< filterM isDiscoverOverlay ws
cls <- io $ getClassHint d w
when (resClass cls == "Discover-overlay") $ io $ raiseWindow d w trackDiscoverOverlay :: Event -> X All
trackDiscoverOverlay MapNotifyEvent {ev_window = w, ev_override_redirect = True} = do
overlay <- isDiscoverOverlay w
when overlay $ XS.modify $ \(OverlayWindows ws) -> OverlayWindows (w : filter (/= w) ws)
pure (All True)
trackDiscoverOverlay DestroyWindowEvent {ev_window = w} = do
XS.modify $ \(OverlayWindows ws) -> OverlayWindows (filter (/= w) ws)
pure (All True)
trackDiscoverOverlay _ = pure (All True)
raiseDiscoverOverlay :: X ()
raiseDiscoverOverlay = do
OverlayWindows ws <- XS.get
unless (null ws) $ withDisplay $ \d -> io $ mapM_ (raiseWindow d) ws