From 9b1399e0e607b3f33e27816626b33124766e8763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Tue, 18 Nov 2025 20:18:16 +0800 Subject: [PATCH] vanadium/xmonad: rewrite dynamic hooks for composability --- .../vanadium/home/xmonad/xmonad.hs | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/nix/configurations/vanadium/home/xmonad/xmonad.hs b/nix/configurations/vanadium/home/xmonad/xmonad.hs index 701e8fcb..a9b6cd0e 100644 --- a/nix/configurations/vanadium/home/xmonad/xmonad.hs +++ b/nix/configurations/vanadium/home/xmonad/xmonad.hs @@ -148,27 +148,35 @@ myManageHook = ] <> namedScratchpadManageHook myScratchpads +-- TODO: is there a way to always open certain sites in new windows in firefox? +-- TODO: stop full screen when move happens myEventHandleHook :: Event -> X All myEventHandleHook = - -- TODO: is there a way to always open certain sites in new windows in firefox? - -- TODO: stop full screen when move happens - onTitleChange $ composeAll - [ isSpotify --> doShiftAndViewIfCurrent multimediaWS - , isYouTube --> doShiftAndViewIfCurrent multimediaWS - , isDiscord --> doShiftAndViewIfCurrent chatWS - , isWhatsApp --> doShiftAndViewIfCurrent chatWS - , isElement --> doShiftAndViewIfCurrent chatWS + -- If the title changes in the background, we don't want to greedy view that workspace. + -- Imagine Spotify playing in the background, a track change would focus that workspace. + -- We prevent this by checking if the window is in the current workspace + onTitleChange + $ (windowIsInCurrentWorkspace -->) + $ composeAll + [ isSpotify --> doShiftAndGreedyView multimediaWS + , isYouTube --> doShiftAndGreedyView multimediaWS + , isDiscord --> doShiftAndGreedyView chatWS + , isWhatsApp --> doShiftAndGreedyView chatWS + , isElement --> doShiftAndGreedyView chatWS ] --- | If the title changes in the background, we don't want to greedy view that workspace. --- Imagine Spotify playing in the background, a track change would focus that workspace. --- We prevent this by checking if the window is in the current workspace -doShiftAndViewIfCurrent :: WorkspaceId -> Query (Endo WindowSet) -doShiftAndViewIfCurrent n = doF . go =<< ask +doShiftAndGreedyView :: WorkspaceId -> Query (Endo WindowSet) +doShiftAndGreedyView n = doF . go =<< ask where go :: Window -> WindowSet -> WindowSet - go w s = case W.findTag w s of - Just from | from == W.currentTag s -> W.greedyView n $ W.shiftWin n w s - _ -> s + go w s = W.greedyView n $ W.shiftWin n w s + +hasProp :: (Window -> WindowSet -> Bool) -> Query Bool +hasProp f = f <$> ask <*> (liftX $ gets windowset) + +windowIsInCurrentWorkspace :: Query Bool +windowIsInCurrentWorkspace = hasProp $ \w s -> case W.findTag w s of + Just from | from == W.currentTag s -> True + _ -> False myStartupHook :: X () myStartupHook = do