ENH generalize backlight common plugin

This commit is contained in:
Nathan Dwarshuis 2022-12-30 16:58:21 -05:00
parent cc0465194a
commit 6738f8a4c7
1 changed files with 8 additions and 7 deletions

View File

@ -7,20 +7,21 @@
module Xmobar.Plugins.BacklightCommon (startBacklight) where
import Data.Internal.DBus
import RIO
import qualified RIO.Text as T
import Xmobar.Plugins.Common
startBacklight
:: RealFrac a
=> ((Maybe a -> IO ()) -> SesClient -> IO ())
-> (SesClient -> IO (Maybe a))
:: (MonadUnliftIO m, RealFrac a)
=> ((Maybe a -> m ()) -> SesClient -> m ())
-> (SesClient -> m (Maybe a))
-> T.Text
-> Callback
-> IO ()
-> m ()
startBacklight matchSignal callGetBrightness icon cb = do
withDBusClientConnection cb $ \c -> do
matchSignal display c
display =<< callGetBrightness c
matchSignal dpy c
dpy =<< callGetBrightness c
where
formatBrightness b = return $ T.concat [icon, T.pack $ show (round b :: Integer), "%"]
display = displayMaybe cb formatBrightness
dpy = displayMaybe cb formatBrightness