added dynamicLogXinerama, a workspace logger that's nicer for Xinerama

This commit is contained in:
Jason Creighton 2007-06-11 05:18:10 +00:00
parent d18e7045e5
commit fe70ba49d8

View File

@ -14,7 +14,7 @@
-- --
-- Don Stewart -- Don Stewart
module XMonadContrib.DynamicLog where module XMonadContrib.DynamicLog (dynamicLog, dynamicLogXinerama) where
-- --
-- Useful imports -- Useful imports
@ -38,14 +38,34 @@ import qualified StackSet as S
dynamicLog :: X () dynamicLog :: X ()
dynamicLog = withWindowSet $ io . putStrLn . ppr dynamicLog = withWindowSet $ io . putStrLn . ppr
where where
ppr s = concatMap fmt $ sortBy tags ppr s = concatMap fmt $ sortBy (compare `on` S.tag)
(map S.workspace (S.current s : S.visible s) ++ S.hidden s) (map S.workspace (S.current s : S.visible s) ++ S.hidden s)
where tags a b = S.tag a `compare` S.tag b where this = S.tag (S.workspace (S.current s))
this = S.tag (S.workspace (S.current s))
pprTag = show . (+(1::Int)) . fromIntegral . S.tag
visibles = map (S.tag . S.workspace) (S.visible s) visibles = map (S.tag . S.workspace) (S.visible s)
fmt w | S.tag w == this = "[" ++ pprTag w ++ "]" fmt w | S.tag w == this = "[" ++ pprTag w ++ "]"
| S.tag w `elem` visibles = "<" ++ pprTag w ++ ">" | S.tag w `elem` visibles = "<" ++ pprTag w ++ ">"
| S.stack w /= S.Empty = " " ++ pprTag w ++ " " | S.stack w /= S.Empty = " " ++ pprTag w ++ " "
| otherwise = "" | otherwise = ""
--
-- Workspace logger with a format designed for Xinerama:
--
-- [1 9 3] 2 7
--
-- where 1, 9, and 3 are the workspaces on screens 1, 2 and 3, respectively,
-- and 2 and 7 are non-visible, non-empty workspaces
--
dynamicLogXinerama :: X ()
dynamicLogXinerama = withWindowSet $ io . putStrLn . ppr
where
ppr ws = "[" ++ unwords onscreen ++ "] " ++ unwords offscreen
where onscreen = map (pprTag . S.workspace) . sortBy (compare `on` S.screen) $ S.current ws : S.visible ws
offscreen = map pprTag . filter ((/= S.Empty) . S.stack) . sortBy (compare `on` S.tag) $ S.hidden ws
-- util functions
pprTag :: Integral i => S.Workspace i a -> String
pprTag = show . (+(1::Int)) . fromIntegral . S.tag
on :: (a -> a -> c) -> (b -> a) -> b -> b -> c
on f g a b = (g a) `f` (g b)