From 1cab211bf068f33b77ecb073d699b70d1962d886 Mon Sep 17 00:00:00 2001 From: slotThe Date: Tue, 17 Aug 2021 08:35:24 +0200 Subject: [PATCH] X.U.Loggers: Add logTitlesOnScreen This works like logTitles, but gets an explicit screen to log the window titles on. This may be useful when having status bars for each screen that show all windows on their respective visible workspaces. --- XMonad/Util/Loggers.hs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/XMonad/Util/Loggers.hs b/XMonad/Util/Loggers.hs index 984c66a1..c01217bc 100644 --- a/XMonad/Util/Loggers.hs +++ b/XMonad/Util/Loggers.hs @@ -36,7 +36,7 @@ module XMonad.Util.Loggers ( -- * XMonad: Screen-specific Loggers -- $xmonad-screen , logCurrentOnScreen, logLayoutOnScreen - , logTitleOnScreen, logWhenActive + , logTitleOnScreen, logWhenActive, logTitlesOnScreen -- * Formatting Utilities -- $format , onLogger @@ -174,8 +174,8 @@ maildirNew mdir = logFileCount (mdir ++ "/new/") (not . isPrefixOf ".") logTitle :: Logger logTitle = withWindowSet $ traverse (fmap show . getName) . W.peek --- | Get the titles of all windows on the current workspace and format --- them according to the given functions. +-- | Get the titles of all windows on the visible workspace of the given +-- screen and format them according to the given functions. -- -- ==== __Example__ -- @@ -188,14 +188,14 @@ logTitle = withWindowSet $ traverse (fmap show . getName) . W.peek -- > formatFocused = wrap "[" "]" . xmobarColor "#ff79c6" "" . shorten 50 . xmobarStrip -- > formatUnfocused = wrap "(" ")" . xmobarColor "#bd93f9" "" . shorten 30 . xmobarStrip -- -logTitles - :: (String -> String) -- ^ Formatting for the focused window +logTitlesOnScreen + :: ScreenId -- ^ Screen to log the titles on + -> (String -> String) -- ^ Formatting for the focused window -> (String -> String) -- ^ Formatting for the unfocused window -> Logger -logTitles formatFoc formatUnfoc = do - winset <- gets windowset - let focWin = W.peek winset - wins = W.index winset +logTitlesOnScreen sid formatFoc formatUnfoc = (`withScreen` sid) $ \screen -> do + let focWin = fmap W.focus . W.stack . W.workspace $ screen + wins = maybe [] W.integrate . W.stack . W.workspace $ screen winNames <- traverse (fmap show . getName) wins pure . Just . unwords @@ -203,6 +203,13 @@ logTitles formatFoc formatUnfoc = do wins winNames +-- | Like 'logTitlesOnScreen', but directly use the "focused" screen +-- (the one with the currently focused workspace). +logTitles :: (String -> String) -> (String -> String) -> Logger +logTitles formatFoc formatUnfoc = do + sid <- gets $ W.screen . W.current . windowset + logTitlesOnScreen sid formatFoc formatUnfoc + -- | Get the name of the current layout. logLayout :: Logger logLayout = withWindowSet $ return . Just . ld