2022-12-26 14:45:49 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Common backlight plugin bits
|
2021-11-23 18:28:38 -05:00
|
|
|
--
|
|
|
|
-- 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-12-30 14:58:23 -05:00
|
|
|
import Data.Internal.DBus
|
2022-12-30 16:58:21 -05:00
|
|
|
import RIO
|
2022-12-30 14:58:23 -05:00
|
|
|
import qualified RIO.Text as T
|
|
|
|
import Xmobar.Plugins.Common
|
2021-11-23 18:28:38 -05:00
|
|
|
|
2022-12-30 14:58:23 -05:00
|
|
|
startBacklight
|
2022-12-30 16:58:21 -05:00
|
|
|
:: (MonadUnliftIO m, RealFrac a)
|
2023-01-03 23:33:08 -05:00
|
|
|
=> Maybe FilePath
|
2023-01-03 22:18:55 -05:00
|
|
|
-> ((Maybe a -> DIO SimpleApp SesClient ()) -> DIO SimpleApp SesClient ())
|
|
|
|
-> DIO SimpleApp SesClient (Maybe a)
|
2022-12-30 14:58:23 -05:00
|
|
|
-> T.Text
|
|
|
|
-> Callback
|
2022-12-30 16:58:21 -05:00
|
|
|
-> m ()
|
2023-01-01 22:29:29 -05:00
|
|
|
startBacklight name matchSignal callGetBrightness icon cb = do
|
2023-01-03 22:18:55 -05:00
|
|
|
withDBusClientConnection cb name $ \c -> withDIO c $ do
|
|
|
|
matchSignal dpy
|
|
|
|
dpy =<< callGetBrightness
|
2022-12-30 14:58:23 -05:00
|
|
|
where
|
|
|
|
formatBrightness b = return $ T.concat [icon, T.pack $ show (round b :: Integer), "%"]
|
2022-12-30 16:58:21 -05:00
|
|
|
dpy = displayMaybe cb formatBrightness
|