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

23 lines
853 B
Haskell
Raw Normal View History

2021-11-23 18:28:38 -05:00
--------------------------------------------------------------------------------
-- | Common backlight plugin bits
--
-- Use the custom DBus interface exported by the XMonad process so I can react
-- to signals spawned by commands
module Xmobar.Plugins.BacklightCommon (startBacklight) where
import DBus.Client
2021-11-25 00:12:00 -05:00
import XMonad.Internal.DBus.Common
import Xmobar.Plugins.Common
2021-11-23 18:28:38 -05:00
startBacklight :: RealFrac a => ((Maybe a -> IO ()) -> Client -> IO ())
-> (Client -> IO (Maybe a)) -> String -> (String -> IO ()) -> IO ()
startBacklight matchSignal callGetBrightness icon cb = do
2021-11-25 00:12:00 -05:00
withDBusClientConnection_ False $ \c -> do
2021-11-23 18:28:38 -05:00
matchSignal (cb . formatBrightness) c
cb . formatBrightness =<< callGetBrightness c
where
2021-11-25 00:12:00 -05:00
formatBrightness = maybe na $
2021-11-23 18:28:38 -05:00
\b -> icon ++ show (round b :: Integer) ++ "%"