xmonad-config/lib/Xmobar/Plugins/Common.hs

35 lines
951 B
Haskell
Raw Normal View History

module Xmobar.Plugins.Common
2021-11-24 01:14:23 -05:00
( chooseColor
, startListener
2021-11-25 00:12:00 -05:00
, na
2021-11-24 01:14:23 -05:00
)
where
2021-11-24 01:14:23 -05:00
import DBus
import DBus.Client
import Data.Maybe
import XMonad.Hooks.DynamicLog (xmobarColor)
import XMonad.Internal.DBus.Common
startListener :: IsVariant a => MatchRule -> (Client -> IO [Variant])
2021-11-25 00:12:00 -05:00
-> ([Variant] -> SignalMatch a) -> (a -> String) -> (String -> IO ())
-> Client -> IO ()
startListener rule getProp fromSignal toColor cb client = do
reply <- getProp client
procMatch $ maybe Failure Match $ fromVariant =<< listToMaybe reply
addMatchCallback rule (procMatch . fromSignal) client
2021-11-24 01:14:23 -05:00
where
procMatch (Match t) = cb $ toColor t
2021-11-25 00:12:00 -05:00
procMatch Failure = cb na
2021-11-24 01:14:23 -05:00
procMatch NoMatch = return ()
chooseColor :: String -> String -> String -> Bool -> String
chooseColor text colorOn colorOff state =
xmobarColor (if state then colorOn else colorOff) "" text
2021-11-25 00:12:00 -05:00
na :: String
na = "N/A"