mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-16 12:43:53 -07:00
Factor out some of dzenPP's goodies
This commit is contained in:
@@ -29,8 +29,9 @@ module XMonadContrib.DynamicLog (
|
|||||||
pprWindowSet,
|
pprWindowSet,
|
||||||
pprWindowSetXinerama,
|
pprWindowSetXinerama,
|
||||||
|
|
||||||
PP(..), defaultPP, sjanssenPP,
|
PP(..), defaultPP, dzenPP, sjanssenPP,
|
||||||
wrap, dzenColor, xmobarColor, shorten
|
wrap, pad, shorten,
|
||||||
|
xmobarColor, dzenColor, dzenEscape
|
||||||
) where
|
) where
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -69,30 +70,6 @@ import XMonadContrib.NamedWindows
|
|||||||
dynamicLog :: X ()
|
dynamicLog :: X ()
|
||||||
dynamicLog = dynamicLogWithPP defaultPP
|
dynamicLog = dynamicLogWithPP defaultPP
|
||||||
|
|
||||||
-- | An example log hook that emulates dwm's status bar, using colour codes printed to dzen
|
|
||||||
-- Requires dzen. Workspaces, xinerama, layouts and the window title are handled.
|
|
||||||
--
|
|
||||||
dynamicLogDzen :: X ()
|
|
||||||
dynamicLogDzen = dynamicLogWithPP dzenPP
|
|
||||||
where
|
|
||||||
dzenPP = defaultPP { ppCurrent = dzenColor "white" "#2b4f98" . pad
|
|
||||||
, ppVisible = dzenColor "black" "#999999" . pad
|
|
||||||
, ppHidden = dzenColor "black" "#cccccc" . pad
|
|
||||||
, ppHiddenNoWindows = const ""
|
|
||||||
, ppWsSep = ""
|
|
||||||
, ppSep = ""
|
|
||||||
, ppLayout = dzenColor "black" "#cccccc" .
|
|
||||||
(\ x -> case x of
|
|
||||||
"TilePrime Horizontal" -> " TTT "
|
|
||||||
"TilePrime Vertical" -> " []= "
|
|
||||||
"Hinted Full" -> " [ ] "
|
|
||||||
_ -> pad x
|
|
||||||
)
|
|
||||||
, ppTitle = ("^bg(#324c80) " ++) . escape
|
|
||||||
}
|
|
||||||
escape = concatMap (\x -> if x == '^' then "^^" else [x])
|
|
||||||
pad = wrap " " " "
|
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- A log function that uses the 'PP' hooks to customize output.
|
-- A log function that uses the 'PP' hooks to customize output.
|
||||||
dynamicLogWithPP :: PP -> X ()
|
dynamicLogWithPP :: PP -> X ()
|
||||||
@@ -110,6 +87,13 @@ dynamicLogWithPP pp = do
|
|||||||
, ppTitle pp wt
|
, ppTitle pp wt
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- | An example log hook that emulates dwm's status bar, using colour codes printed to dzen
|
||||||
|
-- Requires dzen. Workspaces, xinerama, layouts and the window title are handled.
|
||||||
|
--
|
||||||
|
dynamicLogDzen :: X ()
|
||||||
|
dynamicLogDzen = dynamicLogWithPP dzenPP
|
||||||
|
|
||||||
|
|
||||||
pprWindowSet :: PP -> WindowSet -> String
|
pprWindowSet :: PP -> WindowSet -> String
|
||||||
pprWindowSet pp s = sepBy (ppWsSep pp) $ map fmt $ sortBy cmp
|
pprWindowSet pp s = sepBy (ppWsSep pp) $ map fmt $ sortBy cmp
|
||||||
(map S.workspace (S.current s : S.visible s) ++ S.hidden s)
|
(map S.workspace (S.current s : S.visible s) ++ S.hidden s)
|
||||||
@@ -153,6 +137,9 @@ wrap :: String -> String -> String -> String
|
|||||||
wrap _ _ "" = ""
|
wrap _ _ "" = ""
|
||||||
wrap l r m = l ++ m ++ r
|
wrap l r m = l ++ m ++ r
|
||||||
|
|
||||||
|
pad :: String -> String
|
||||||
|
pad = wrap " " " "
|
||||||
|
|
||||||
shorten :: Int -> String -> String
|
shorten :: Int -> String -> String
|
||||||
shorten n xs | length xs < n = xs
|
shorten n xs | length xs < n = xs
|
||||||
| otherwise = (take (n - length end) xs) ++ end
|
| otherwise = (take (n - length end) xs) ++ end
|
||||||
@@ -169,6 +156,10 @@ dzenColor fg bg = wrap (fg1++bg1) (fg2++bg2)
|
|||||||
(bg1,bg2) | null bg = ("","")
|
(bg1,bg2) | null bg = ("","")
|
||||||
| otherwise = ("^bg(" ++ bg ++ ")","^bg()")
|
| otherwise = ("^bg(" ++ bg ++ ")","^bg()")
|
||||||
|
|
||||||
|
-- | Escape any dzen metacharaters.
|
||||||
|
dzenEscape :: String -> String
|
||||||
|
dzenEscape = concatMap (\x -> if x == '^' then "^^" else [x])
|
||||||
|
|
||||||
xmobarColor :: String -> String -> String -> String
|
xmobarColor :: String -> String -> String -> String
|
||||||
xmobarColor fg bg = wrap t "</fc>"
|
xmobarColor fg bg = wrap t "</fc>"
|
||||||
where t = concat ["<fc=", fg, if null bg then "" else "," ++ bg, ">"]
|
where t = concat ["<fc=", fg, if null bg then "" else "," ++ bg, ">"]
|
||||||
@@ -194,6 +185,24 @@ defaultPP = PP { ppCurrent = wrap "[" "]"
|
|||||||
, ppLayout = id
|
, ppLayout = id
|
||||||
, ppOrder = id }
|
, ppOrder = id }
|
||||||
|
|
||||||
|
-- | Settings to emulate dwm's statusbar, dzen only
|
||||||
|
dzenPP :: PP
|
||||||
|
dzenPP = defaultPP { ppCurrent = dzenColor "white" "#2b4f98" . pad
|
||||||
|
, ppVisible = dzenColor "black" "#999999" . pad
|
||||||
|
, ppHidden = dzenColor "black" "#cccccc" . pad
|
||||||
|
, ppHiddenNoWindows = const ""
|
||||||
|
, ppWsSep = ""
|
||||||
|
, ppSep = ""
|
||||||
|
, ppLayout = dzenColor "black" "#cccccc" .
|
||||||
|
(\ x -> case x of
|
||||||
|
"TilePrime Horizontal" -> " TTT "
|
||||||
|
"TilePrime Vertical" -> " []= "
|
||||||
|
"Hinted Full" -> " [ ] "
|
||||||
|
_ -> pad x
|
||||||
|
)
|
||||||
|
, ppTitle = ("^bg(#324c80) " ++) . dzenEscape
|
||||||
|
}
|
||||||
|
|
||||||
-- | The options that sjanssen likes to use, as an example. Note the use of
|
-- | The options that sjanssen likes to use, as an example. Note the use of
|
||||||
-- 'xmobarColor' and the record update on defaultPP
|
-- 'xmobarColor' and the record update on defaultPP
|
||||||
sjanssenPP :: PP
|
sjanssenPP :: PP
|
||||||
|
Reference in New Issue
Block a user