From b9a10df606abefe32a4a228441b90b0c6f9c48b2 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Fri, 30 Dec 2022 17:11:15 -0500 Subject: [PATCH] ENH generalize brightness --- lib/XMonad/Internal/DBus/Brightness/Common.hs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/XMonad/Internal/DBus/Brightness/Common.hs b/lib/XMonad/Internal/DBus/Brightness/Common.hs index e767c77..2033ca5 100644 --- a/lib/XMonad/Internal/DBus/Brightness/Common.hs +++ b/lib/XMonad/Internal/DBus/Brightness/Common.hs @@ -14,13 +14,12 @@ module XMonad.Internal.DBus.Brightness.Common ) where -import Control.Monad (void) import DBus import DBus.Client import qualified DBus.Introspection as I -import Data.Int (Int32) import Data.Internal.DBus import Data.Internal.Dependency +import RIO import qualified RIO.Text as T import XMonad.Core (io) import XMonad.Internal.DBus.Common @@ -69,10 +68,10 @@ brightnessControls q bc cl = cb = callBacklight q cl bc callGetBrightness - :: (SafeClient c, Num n) + :: (MonadUnliftIO m, SafeClient c, Num n) => BrightnessConfig a b -> c - -> IO (Maybe n) + -> m (Maybe n) callGetBrightness BrightnessConfig {bcPath = p, bcInterface = i} client = either (const Nothing) bodyGetBrightness <$> callMethod client xmonadBusName p i memGet @@ -82,11 +81,11 @@ signalDep BrightnessConfig {bcPath = p, bcInterface = i} = Endpoint [] xmonadBusName p i $ Signal_ memCur matchSignal - :: (SafeClient c, Num n) + :: (MonadUnliftIO m, SafeClient c, Num n) => BrightnessConfig a b - -> (Maybe n -> IO ()) + -> (Maybe n -> m ()) -> c - -> IO () + -> m () matchSignal BrightnessConfig {bcPath = p, bcInterface = i} cb = void . addMatchCallback brMatcher (cb . bodyGetBrightness) where @@ -148,9 +147,14 @@ exportBrightnessControls' bc cl = io $ do ] } -emitBrightness :: RealFrac b => BrightnessConfig a b -> Client -> b -> IO () +emitBrightness + :: (MonadUnliftIO m, RealFrac b) + => BrightnessConfig a b + -> Client + -> b + -> m () emitBrightness BrightnessConfig {bcPath = p, bcInterface = i} client cur = - emit client $ sig {signalBody = [toVariant (round cur :: Int32)]} + liftIO $ emit client $ sig {signalBody = [toVariant (round cur :: Int32)]} where sig = signal p i memCur