2021-11-24 00:43:58 -05:00
|
|
|
|
|
|
|
module Xmobar.Plugins.Common
|
2021-11-24 01:14:23 -05:00
|
|
|
( chooseColor
|
|
|
|
, startListener
|
|
|
|
)
|
2021-11-24 00:43:58 -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])
|
|
|
|
-> ([Variant] -> SignalMatch a) -> (a -> String) -> (String -> IO ()) -> IO ()
|
|
|
|
startListener rule getProp fromSignal toColor cb = do
|
|
|
|
withDBusClientConnection_ True $ \c -> do
|
|
|
|
reply <- getProp c
|
|
|
|
procMatch $ maybe Failure Match $ fromVariant =<< listToMaybe reply
|
|
|
|
addMatchCallback rule (procMatch . fromSignal) c
|
|
|
|
where
|
|
|
|
procMatch (Match t) = cb $ toColor t
|
|
|
|
procMatch Failure = cb "N/A"
|
|
|
|
procMatch NoMatch = return ()
|
2021-11-24 00:43:58 -05:00
|
|
|
|
|
|
|
chooseColor :: String -> String -> String -> Bool -> String
|
|
|
|
chooseColor text colorOn colorOff state =
|
|
|
|
xmobarColor (if state then colorOn else colorOff) "" text
|