ENH generalize brightness

This commit is contained in:
Nathan Dwarshuis 2022-12-30 17:11:15 -05:00
parent e508f29bd8
commit b9a10df606
1 changed files with 13 additions and 9 deletions

View File

@ -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