2022-12-26 14:45:49 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
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
|
|
|
|
|
2022-07-09 17:44:14 -04:00
|
|
|
import Data.Internal.DBus
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
import qualified RIO.Text as T
|
|
|
|
|
2021-11-25 00:12:00 -05:00
|
|
|
import Xmobar.Plugins.Common
|
2021-11-23 18:28:38 -05:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
startBacklight :: RealFrac a => ((Maybe a -> IO ()) -> SesClient -> IO ())
|
2022-12-26 14:45:49 -05:00
|
|
|
-> (SesClient -> IO (Maybe a)) -> T.Text -> Callback -> IO ()
|
2021-11-23 18:28:38 -05:00
|
|
|
startBacklight matchSignal callGetBrightness icon cb = do
|
2022-12-30 10:56:09 -05:00
|
|
|
withDBusClientConnection cb $ \c -> do
|
|
|
|
matchSignal display c
|
|
|
|
display =<< callGetBrightness c
|
2021-11-23 18:28:38 -05:00
|
|
|
where
|
2022-12-26 14:45:49 -05:00
|
|
|
formatBrightness b = return $ T.concat [icon, T.pack $ show (round b :: Integer), "%"]
|
2022-12-30 10:56:09 -05:00
|
|
|
display = displayMaybe cb formatBrightness
|