Factor out pprWindowSet (and Xinerama version) from dynamicLog.

This patch lets you pretty-print a WindowSet to a string, rather than always
printing it out to stdout directly.
This commit is contained in:
Shachaf Ben-Kiki
2007-06-19 18:36:57 +00:00
parent 73d1c8d317
commit 4345709445

View File

@@ -21,7 +21,7 @@
module XMonadContrib.DynamicLog ( module XMonadContrib.DynamicLog (
-- * Usage -- * Usage
-- $usage -- $usage
dynamicLog, dynamicLogXinerama dynamicLog, dynamicLogXinerama, pprWindowSet, pprWindowSetXinerama
) where ) where
-- --
@@ -52,17 +52,18 @@ import qualified StackSet as S
-- --
dynamicLog :: X () dynamicLog :: X ()
dynamicLog = withWindowSet $ io . putStrLn . ppr dynamicLog = withWindowSet $ io . putStrLn . pprWindowSet
where
ppr s = concatMap fmt $ sortBy (compare `on` S.tag)
(map S.workspace (S.current s : S.visible s) ++ S.hidden s)
where this = S.tag (S.workspace (S.current s))
visibles = map (S.tag . S.workspace) (S.visible s)
fmt w | S.tag w == this = "[" ++ pprTag w ++ "]" pprWindowSet :: WindowSet -> String
| S.tag w `elem` visibles = "<" ++ pprTag w ++ ">" pprWindowSet s = concatMap fmt $ sortBy (compare `on` S.tag)
| isJust (S.stack w) = " " ++ pprTag w ++ " " (map S.workspace (S.current s : S.visible s) ++ S.hidden s)
| otherwise = "" where this = S.tag (S.workspace (S.current s))
visibles = map (S.tag . S.workspace) (S.visible s)
fmt w | S.tag w == this = "[" ++ pprTag w ++ "]"
| S.tag w `elem` visibles = "<" ++ pprTag w ++ ">"
| isJust (S.stack w) = " " ++ pprTag w ++ " "
| otherwise = ""
-- | -- |
-- Workspace logger with a format designed for Xinerama: -- Workspace logger with a format designed for Xinerama:
@@ -73,13 +74,14 @@ dynamicLog = withWindowSet $ io . putStrLn . ppr
-- and 2 and 7 are non-visible, non-empty workspaces -- and 2 and 7 are non-visible, non-empty workspaces
-- --
dynamicLogXinerama :: X () dynamicLogXinerama :: X ()
dynamicLogXinerama = withWindowSet $ io . putStrLn . ppr dynamicLogXinerama = withWindowSet $ io . putStrLn . pprWindowSetXinerama
where
ppr ws = "[" ++ unwords onscreen ++ "] " ++ unwords offscreen pprWindowSetXinerama :: WindowSet -> String
where onscreen = map (pprTag . S.workspace) pprWindowSetXinerama ws = "[" ++ unwords onscreen ++ "] " ++ unwords offscreen
. sortBy (compare `on` S.screen) $ S.current ws : S.visible ws where onscreen = map (pprTag . S.workspace)
offscreen = map pprTag . filter (isJust . S.stack) . sortBy (compare `on` S.screen) $ S.current ws : S.visible ws
. sortBy (compare `on` S.tag) $ S.hidden ws offscreen = map pprTag . filter (isJust . S.stack)
. sortBy (compare `on` S.tag) $ S.hidden ws
-- util functions -- util functions
pprTag :: Integral i => S.Workspace i a -> String pprTag :: Integral i => S.Workspace i a -> String