diff --git a/.config/xmonad/xmonad.hs b/.config/xmonad/xmonad.hs index c3c4e1e..6b24ed4 100644 --- a/.config/xmonad/xmonad.hs +++ b/.config/xmonad/xmonad.hs @@ -3,11 +3,11 @@ import Data.Monoid import Data.Bits (complement, (.&.)) 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 Data.Maybe (isJust) import XMonad -import XMonad.Actions.OnScreen (greedyViewOnScreen) +import XMonad.Actions.OnScreen (Focus (FocusNew), onScreen) import XMonad.Actions.PhysicalScreens import XMonad.Hooks.EwmhDesktops import XMonad.Hooks.ManageDocks @@ -15,6 +15,7 @@ import XMonad.Hooks.ManageHelpers import XMonad.Hooks.Rescreen import XMonad.Hooks.StatusBar import XMonad.Hooks.StatusBar.PP +import XMonad.Hooks.UrgencyHook (NoUrgencyHook (..), withUrgencyHook) import XMonad.Layout.Grid import XMonad.Layout.Magnifier import XMonad.Layout.NoBorders @@ -45,6 +46,7 @@ main = . setEwmhSwitchDesktopHook safeView . ewmh . docks + . withUrgencyHook NoUrgencyHook . rescreenHook def {afterRescreenHook = restartStatusBars, rescreenWorkspacesHook = Last (Just safeRescreen)} . addRandrChangeHook (spawn myScreenHotplug) $ myConfig @@ -65,17 +67,12 @@ myNormBorderColor = "#1f2335" myFocusBorderColor :: String myFocusBorderColor = "#41a6b5" -myKeyboardLayoutIT :: String -myKeyboardLayoutIT = " -layout it" - -myKeyboardLayoutUS :: String -myKeyboardLayoutUS = " -layout us" - -myKeyboardLayoutSK :: String -myKeyboardLayoutSK = " -layout sk -variant qwerty" +myEarbuds :: String +myEarbuds = "F4:9D:8A:B9:8C:EE" +-- Expanded by sh, as spawn runs it myScreenshotDir :: String -myScreenshotDir = "/home/fuxino/Pictures/Screenshots/" +myScreenshotDir = "~/Pictures/Screenshots/" myScreenshotName :: String myScreenshotName = "Screenshot-%Y-%m-%d-%H%M%S.png" @@ -96,18 +93,17 @@ myScreenHotplug = myScreenLayout ++ " --keep-wallpaper" myScratchpads :: [NamedScratchpad] myScratchpads = [ 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), - NS "Music" spawnMusic (className =? "scratch-music") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), - NS "Mail" spawnMail (className =? "scratch-mail") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), - NS "Cal" spawnCal (className =? "scratch-cal") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6), - NS "Btop" spawnBtop (className =? "scratch-btop") (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6) + termPad "Terminal" "kitty-float" "", + termPad "Music" "ncmpcpp" "ncmpcpp", + termPad "Mail" "mutt" "bash -c 'pushd ~/Downloads > /dev/null; mutt; popd > /dev/null'", + termPad "Cal" "calcurse" "calcurse", + termPad "Btop" "btop" "btop" ] where - spawnTerminal = myTerminal ++ " --class scratch-terminal -T kitty-float" - spawnMusic = myTerminal ++ " --class scratch-music -T ncmpcpp ncmpcpp" - spawnMail = myTerminal ++ " --class scratch-mail -T mutt bash -c 'pushd ~/Downloads > /dev/null; mutt; popd > /dev/null'" - spawnCal = myTerminal ++ " --class scratch-cal -T calcurse calcurse" - spawnBtop = myTerminal ++ " --class scratch-btop -T btop btop" + -- Centred kitty with class scratch-, window title t, running cmd + termPad name t cmd = + let cls = "scratch-" ++ map toLower name + in NS name (unwords [myTerminal, "--class", cls, "-T", t, cmd]) (className =? cls) (customFloating $ W.RationalRect 0.2 0.2 0.6 0.6) -- Config myConfig = @@ -164,11 +160,11 @@ myCustomKeys c = ("M-C-n", addName "Close all notifications" $ spawn "dunstctl close-all"), ("M-b", addName "Toggle the status bar gap" $ sendMessage ToggleStruts), ("M-f", addName "Tabbed layout" $ sendMessage $ JumpToLayout "Tabbed"), - ("M-i", addName "Keyboard: Italian" $ spawn $ "setxkbmap" ++ myKeyboardLayoutIT), - ("M-u", addName "Keyboard: US" $ spawn $ "setxkbmap" ++ myKeyboardLayoutUS), - ("M-s", addName "Keyboard: Slovak" $ spawn $ "setxkbmap" ++ myKeyboardLayoutSK), - ("M-x", addName "Connect earbuds" $ spawn "bluetoothctl connect F4:9D:8A:B9:8C:EE"), - ("M-S-x", addName "Disconnect earbuds" $ spawn "bluetoothctl disconnect F4:9D:8A:B9:8C:EE") + ("M-i", addName "Keyboard: Italian" $ spawn "setxkbmap -layout it"), + ("M-u", addName "Keyboard: US" $ spawn "setxkbmap -layout us"), + ("M-s", addName "Keyboard: Slovak" $ spawn "setxkbmap -layout sk -variant qwerty"), + ("M-x", addName "Connect earbuds" $ spawn $ "bluetoothctl connect " ++ myEarbuds), + ("M-S-x", addName "Disconnect earbuds" $ spawn $ "bluetoothctl disconnect " ++ myEarbuds) ] ), ( "screenshots", @@ -178,8 +174,8 @@ myCustomKeys c = ] ), ( "media keys", - [ ("", addName "Mute" $ spawn "pactl set-sink-mute $(pactl get-default-sink) toggle"), - ("", addName "Volume down" $ spawn "pactl set-sink-volume $(pactl get-default-sink) -10%"), + [ ("", addName "Mute" $ spawn "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"), + ("", addName "Volume down" $ spawn "wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%-"), ("", addName "Volume up" $ spawn "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 10%+"), ("", addName "Play/pause" $ spawn "playerctl play-pause"), ("", addName "Pause" $ spawn "playerctl pause"), @@ -214,10 +210,10 @@ showKeys ks = addName "Show keybindings" $ do fixMod (x : r) = x : fixMod r 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 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 | otherwise = W.greedyView i ws @@ -241,7 +237,7 @@ safeRescreen = do -- Workspaces 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 wsTerm, wsWeb, wsGames, wsChat, wsMedia, wsDocs, wsVM :: String @@ -254,12 +250,15 @@ wsDocs = "6:\xede2 " wsVM = "7:\xf108 " -- 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 - myWebLayout = avoidStruts $ renamed [CutWordsLeft 1] $ spacingWithEdge 3 $ myTabbed ||| tiled ||| Mirror tiled ||| threeCol ||| Grid ||| spiral 0.856 - myGamesLayout = avoidStruts $ smartBorders Full - myVideoLayout = avoidStruts $ smartBorders Full - myDefaultLayout = avoidStruts $ renamed [CutWordsLeft 1] $ spacingWithEdge 3 $ tiled ||| Mirror tiled ||| myTabbed ||| threeCol ||| Grid ||| spiral 0.856 + -- CutWordsLeft drops the "Spacing" prefix from the layout names + spaced l = renamed [CutWordsLeft 1] $ spacingWithEdge 3 l + others = threeCol ||| Grid ||| spiral 0.856 threeCol = renamed [Replace "ThreeCol"] $ magnifiercz' 1.3 $ @@ -309,11 +308,16 @@ myXmobarPP = _ -> tag, -- 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, - ppOrder = \[ws, l, _, wins] -> [ws, l, wins], + ppOrder = dropTitle, ppLayout = layoutIcon, ppExtras = [budgetTitles] } 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 l = case l of "Tall" -> "\xf0bcc" @@ -330,11 +334,12 @@ myXmobarPP = budgetTitles = do n <- gets $ length . W.integrate' . W.stack . W.workspace . W.current . windowset 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 formatUnfocused w = wrap (outerspace "[") (outerspace "]") . cultured . ppWindow w + formatUrgent w = wrap (keylime "!") (keylime "!") . sunsetorange . ppWindow w ppWindow :: Int -> String -> String ppWindow w = xmobarRaw . (\t -> if null t then "untitled" else t) . shorten' "…" w @@ -350,6 +355,7 @@ myXmobarPP = myStartupHook :: X () myStartupHook = do restartStatusBars + scanDiscoverOverlay spawnOnce myScreenSetup spawnOnce "systemctl --user start fehbg.timer" spawnOnce "xsetroot -cursor_name left_ptr" @@ -378,44 +384,30 @@ myManageHook = [ -- Proton games are steam_app_; Wine windows are named after their .exe className ^? "steam_app_" --> doShift wsGames, className $? ".exe" --> doShift wsGames, - className =? "Gpodder" --> doShift wsMedia, - className =? "An Anime Game Launcher" --> doShift wsGames, - className =? "Qalculate-gtk" --> doFloat, + classIn ["steam", "an anime game launcher"] --> doShift wsGames, title =? "Genshin Impact" --> doShift wsGames, - classIn ["gimp", "audacity"] --> doShift wsMedia, - classIn ["pavucontrol", "org.pulseaudio.pavucontrol", "zenity", "org.gnome.zenity", "lxappearance", "qt5ct", "qt6ct"] --> doFloat, + classIn ["steam_app_109600", "steam_app_289070"] --> doFloat, + classIn ["zen", "vivaldi-stable", "transmission-gtk"] --> doShift wsWeb, classIn ["signal", "discord"] --> doShift wsChat, - className =? "Spotify" --> doShift wsMedia, - className =? "Transmission-gtk" --> doShift wsWeb, - className =? "Viewnior" --> doFloat, - className =? "Vivaldi-stable" --> doShift wsWeb, - className =? "Xmessage" --> doFloat, - 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, + classIn ["gpodder", "spotify", "freetube", "scrcpy", "gimp", "audacity"] --> doShift wsMedia, + classIn ["xreader", "calibre", "library_manager", "libreoffice-calc", "libreoffice-writer"] --> doShift wsDocs, + classIn ["virtualbox manager"] --> doShift wsVM, + className =? "VirtualBox Machine" --> doFullFloat <+> doShift wsVM, + className =? "mpv" --> doFullFloat <+> viewShift wsMedia, className =? myTerminal --> doShift wsTerm, - className =? "scrcpy" --> doShift wsMedia, - className =? "steam" --> doShift wsGames, - className =? "steam_app_109600" --> doFloat, - className =? "steam_app_289070" --> doFloat, - className =? "VirtualBox Machine" --> doShift wsVM, - className =? "VirtualBox Machine" --> doFullFloat, - className =? "VirtualBox Manager" --> doShift wsVM, - className =? "zen" --> doShift wsWeb, + classIn + [ "qalculate-gtk", "viewnior", "xmessage", "feh", "lxappearance", "qt5ct", "qt6ct", + "pavucontrol", "org.pulseaudio.pavucontrol", "zenity", "org.gnome.zenity" + ] + --> doFloat, + title =? "glxgears" --> doFloat, isDialog --> doFloat, -- Windows that open already fullscreen; ewmhFullscreen only handles later requests isFullscreen --> doFullFloat ] <+> namedScratchpadManageHook myScratchpads where - viewShift = doF . liftM2 (.) safeView W.shift + viewShift = doF . liftA2 (.) safeView W.shift -- Case-insensitive, as GTK4 and firejailed apps capitalise their class differently classIn names = (`elem` names) . map toLower <$> className @@ -452,6 +444,7 @@ myHandleEventHook = <> Hacks.trayerPaddingXmobarEventHook <> Hacks.fixSteamFlicker <> pinWindscribe + <> trackDiscoverOverlay -- Windscribe moves itself to a saved position after mapping: apply its resizes (as core does for floats) but drop moves. pinWindscribe :: Event -> X All @@ -476,11 +469,34 @@ myLogHook = do xmonadPropLog =<< dynamicLogString =<< clickablePP myXmobarPP -- 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 -raiseDiscoverOverlay :: X () -raiseDiscoverOverlay = withDisplay $ \d -> do +-- raising a floating window (e.g. a game) covers them; put them back on top after every change. +-- They're remembered when mapped, so the log hook doesn't query every window each time. +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 (_, _, ws) <- io $ queryTree d root - forM_ ws $ \w -> do - cls <- io $ getClassHint d w - when (resClass cls == "Discover-overlay") $ io $ raiseWindow d w + XS.put . OverlayWindows =<< filterM isDiscoverOverlay ws + +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