2022-12-26 14:45:49 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- DBus module for Intel Backlight control
|
2021-11-07 13:35:08 -05:00
|
|
|
|
|
|
|
module XMonad.Internal.DBus.Brightness.IntelBacklight
|
|
|
|
( callGetBrightnessIB
|
|
|
|
, matchSignalIB
|
|
|
|
, exportIntelBacklight
|
2021-11-20 12:40:53 -05:00
|
|
|
, intelBacklightControls
|
2021-11-20 19:35:24 -05:00
|
|
|
, intelBacklightSignalDep
|
2021-11-07 13:35:08 -05:00
|
|
|
, blPath
|
2022-12-30 14:58:23 -05:00
|
|
|
)
|
|
|
|
where
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2022-12-30 14:58:23 -05:00
|
|
|
import DBus
|
|
|
|
import Data.Internal.DBus
|
2023-01-01 18:33:02 -05:00
|
|
|
import Data.Internal.XIO
|
2022-12-31 15:26:22 -05:00
|
|
|
import RIO
|
2022-12-30 14:58:23 -05:00
|
|
|
import RIO.FilePath
|
|
|
|
import XMonad.Internal.DBus.Brightness.Common
|
|
|
|
import XMonad.Internal.IO
|
2021-11-07 13:35:08 -05:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Low level sysfs functions
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
type Brightness = Float
|
|
|
|
|
|
|
|
type RawBrightness = Int32
|
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
type RawBounds = (RawBrightness, RawBrightness)
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
steps :: Int
|
|
|
|
steps = 16
|
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
minRawBrightness :: RawBrightness
|
|
|
|
minRawBrightness = 1
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
backlightDir :: FilePath
|
|
|
|
backlightDir = "/sys/class/backlight/intel_backlight/"
|
|
|
|
|
|
|
|
maxFile :: FilePath
|
|
|
|
maxFile = backlightDir </> "max_brightness"
|
|
|
|
|
|
|
|
curFile :: FilePath
|
|
|
|
curFile = backlightDir </> "brightness"
|
|
|
|
|
|
|
|
getMaxRawBrightness :: IO RawBrightness
|
|
|
|
getMaxRawBrightness = readInt maxFile
|
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
getBrightness :: RawBounds -> IO Brightness
|
|
|
|
getBrightness bounds = readPercent bounds curFile
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
minBrightness :: RawBounds -> IO Brightness
|
|
|
|
minBrightness bounds = writePercentMin bounds curFile
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
maxBrightness :: RawBounds -> IO Brightness
|
|
|
|
maxBrightness bounds = writePercentMax bounds curFile
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
incBrightness :: RawBounds -> IO Brightness
|
2021-11-07 13:35:08 -05:00
|
|
|
incBrightness = incPercent steps curFile
|
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
decBrightness :: RawBounds -> IO Brightness
|
2021-11-07 13:35:08 -05:00
|
|
|
decBrightness = decPercent steps curFile
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- DBus interface
|
2021-11-07 13:35:08 -05:00
|
|
|
|
|
|
|
blPath :: ObjectPath
|
|
|
|
blPath = objectPath_ "/intelbacklight"
|
|
|
|
|
|
|
|
interface :: InterfaceName
|
|
|
|
interface = interfaceName_ "org.xmonad.Brightness"
|
|
|
|
|
|
|
|
intelBacklightConfig :: BrightnessConfig RawBrightness Brightness
|
2022-12-30 14:58:23 -05:00
|
|
|
intelBacklightConfig =
|
|
|
|
BrightnessConfig
|
|
|
|
{ bcMin = minBrightness
|
|
|
|
, bcMax = maxBrightness
|
|
|
|
, bcInc = incBrightness
|
|
|
|
, bcDec = decBrightness
|
|
|
|
, bcGet = getBrightness
|
|
|
|
, bcGetMax = getMaxRawBrightness
|
|
|
|
, bcMinRaw = minRawBrightness
|
|
|
|
, bcPath = blPath
|
|
|
|
, bcInterface = interface
|
|
|
|
, bcName = "Intel backlight"
|
|
|
|
}
|
2021-11-07 13:35:08 -05:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Exported haskell API
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2022-06-26 19:05:25 -04:00
|
|
|
curFileDep :: IODependency_
|
2022-07-09 01:02:37 -04:00
|
|
|
curFileDep = pathRW curFile []
|
2021-11-09 00:59:17 -05:00
|
|
|
|
2022-06-26 19:05:25 -04:00
|
|
|
maxFileDep :: IODependency_
|
2022-07-09 01:02:37 -04:00
|
|
|
maxFileDep = pathR maxFile []
|
2021-11-09 00:59:17 -05:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
intelBacklightSignalDep :: DBusDependency_ SesClient
|
2021-11-20 19:35:24 -05:00
|
|
|
intelBacklightSignalDep = signalDep intelBacklightConfig
|
|
|
|
|
2023-01-01 13:32:46 -05:00
|
|
|
exportIntelBacklight
|
|
|
|
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
|
|
|
|
=> Maybe SesClient
|
|
|
|
-> Sometimes (m (), m ())
|
2022-12-30 14:58:23 -05:00
|
|
|
exportIntelBacklight =
|
|
|
|
brightnessExporter
|
|
|
|
xpfIntelBacklight
|
|
|
|
[]
|
|
|
|
[curFileDep, maxFileDep]
|
|
|
|
intelBacklightConfig
|
2021-11-20 12:40:53 -05:00
|
|
|
|
2023-01-02 18:30:17 -05:00
|
|
|
intelBacklightControls :: MonadUnliftIO m => Maybe SesClient -> BrightnessControls m
|
2022-07-08 20:01:35 -04:00
|
|
|
intelBacklightControls = brightnessControls xpfIntelBacklight intelBacklightConfig
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2022-12-31 15:26:22 -05:00
|
|
|
callGetBrightnessIB :: MonadUnliftIO m => SesClient -> m (Maybe Brightness)
|
2022-07-09 17:44:14 -04:00
|
|
|
callGetBrightnessIB = callGetBrightness intelBacklightConfig
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2022-12-31 15:26:22 -05:00
|
|
|
matchSignalIB
|
|
|
|
:: MonadUnliftIO m
|
|
|
|
=> (Maybe Brightness -> m ())
|
|
|
|
-> SesClient
|
|
|
|
-> m ()
|
2022-07-09 17:44:14 -04:00
|
|
|
matchSignalIB = matchSignal intelBacklightConfig
|