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.
This commit is contained in:
slotThe
2021-08-17 08:35:24 +02:00
parent a9ad56be11
commit 1cab211bf0

View File

@@ -36,7 +36,7 @@ module XMonad.Util.Loggers (
-- * XMonad: Screen-specific Loggers -- * XMonad: Screen-specific Loggers
-- $xmonad-screen -- $xmonad-screen
, logCurrentOnScreen, logLayoutOnScreen , logCurrentOnScreen, logLayoutOnScreen
, logTitleOnScreen, logWhenActive , logTitleOnScreen, logWhenActive, logTitlesOnScreen
-- * Formatting Utilities -- * Formatting Utilities
-- $format -- $format
, onLogger , onLogger
@@ -174,8 +174,8 @@ maildirNew mdir = logFileCount (mdir ++ "/new/") (not . isPrefixOf ".")
logTitle :: Logger logTitle :: Logger
logTitle = withWindowSet $ traverse (fmap show . getName) . W.peek logTitle = withWindowSet $ traverse (fmap show . getName) . W.peek
-- | Get the titles of all windows on the current workspace and format -- | Get the titles of all windows on the visible workspace of the given
-- them according to the given functions. -- screen and format them according to the given functions.
-- --
-- ==== __Example__ -- ==== __Example__
-- --
@@ -188,14 +188,14 @@ logTitle = withWindowSet $ traverse (fmap show . getName) . W.peek
-- > formatFocused = wrap "[" "]" . xmobarColor "#ff79c6" "" . shorten 50 . xmobarStrip -- > formatFocused = wrap "[" "]" . xmobarColor "#ff79c6" "" . shorten 50 . xmobarStrip
-- > formatUnfocused = wrap "(" ")" . xmobarColor "#bd93f9" "" . shorten 30 . xmobarStrip -- > formatUnfocused = wrap "(" ")" . xmobarColor "#bd93f9" "" . shorten 30 . xmobarStrip
-- --
logTitles logTitlesOnScreen
:: (String -> String) -- ^ Formatting for the focused window :: ScreenId -- ^ Screen to log the titles on
-> (String -> String) -- ^ Formatting for the focused window
-> (String -> String) -- ^ Formatting for the unfocused window -> (String -> String) -- ^ Formatting for the unfocused window
-> Logger -> Logger
logTitles formatFoc formatUnfoc = do logTitlesOnScreen sid formatFoc formatUnfoc = (`withScreen` sid) $ \screen -> do
winset <- gets windowset let focWin = fmap W.focus . W.stack . W.workspace $ screen
let focWin = W.peek winset wins = maybe [] W.integrate . W.stack . W.workspace $ screen
wins = W.index winset
winNames <- traverse (fmap show . getName) wins winNames <- traverse (fmap show . getName) wins
pure . Just pure . Just
. unwords . unwords
@@ -203,6 +203,13 @@ logTitles formatFoc formatUnfoc = do
wins wins
winNames 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. -- | Get the name of the current layout.
logLayout :: Logger logLayout :: Logger
logLayout = withWindowSet $ return . Just . ld logLayout = withWindowSet $ return . Just . ld