Merge pull request #596 from slotThe/logTitlesOnScreen

X.U.Loggers: Add `logTitlesOnScreen`
This commit is contained in:
slotThe
2021-08-19 08:40:01 +02:00
committed by GitHub
2 changed files with 19 additions and 10 deletions

View File

@@ -501,7 +501,9 @@
- Added `logConst` to log a constant `String`, and `logDefault` (infix: `.|`) - Added `logConst` to log a constant `String`, and `logDefault` (infix: `.|`)
to combine loggers. to combine loggers.
- Added `logTitles` to log all window titles (focused and unfocused ones). - Added `logTitles` to log all window titles (focused and unfocused
ones) on the focused workspace, as well as `logTitlesOnScreen` as
a screen-specific variant thereof.
* `XMonad.Layout.Minimize` * `XMonad.Layout.Minimize`

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