2021-11-07 13:35:08 -05:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | DBus module for Intel Backlight control
|
|
|
|
|
|
|
|
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
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Int (Int32)
|
|
|
|
|
|
|
|
import DBus
|
|
|
|
import DBus.Client
|
|
|
|
|
|
|
|
import System.FilePath.Posix
|
|
|
|
|
|
|
|
import XMonad.Internal.DBus.Brightness.Common
|
2021-11-07 18:41:25 -05:00
|
|
|
import XMonad.Internal.Dependency
|
2021-11-07 13:35:08 -05:00
|
|
|
import XMonad.Internal.IO
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Low level sysfs functions
|
|
|
|
--
|
|
|
|
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
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | DBus interface
|
|
|
|
|
|
|
|
blPath :: ObjectPath
|
|
|
|
blPath = objectPath_ "/intelbacklight"
|
|
|
|
|
|
|
|
interface :: InterfaceName
|
|
|
|
interface = interfaceName_ "org.xmonad.Brightness"
|
|
|
|
|
|
|
|
intelBacklightConfig :: BrightnessConfig RawBrightness Brightness
|
|
|
|
intelBacklightConfig = BrightnessConfig
|
|
|
|
{ bcMin = minBrightness
|
|
|
|
, bcMax = maxBrightness
|
|
|
|
, bcInc = incBrightness
|
|
|
|
, bcDec = decBrightness
|
|
|
|
, bcGet = getBrightness
|
|
|
|
, bcGetMax = getMaxRawBrightness
|
2021-11-21 00:42:40 -05:00
|
|
|
, bcMinRaw = minRawBrightness
|
2021-11-07 13:35:08 -05:00
|
|
|
, bcPath = blPath
|
|
|
|
, bcInterface = interface
|
2021-11-20 19:35:24 -05:00
|
|
|
, bcName = "Intel backlight"
|
2021-11-07 13:35:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Exported haskell API
|
|
|
|
|
2021-11-20 11:48:05 -05:00
|
|
|
curFileDep :: Dependency
|
2021-11-09 00:59:17 -05:00
|
|
|
curFileDep = pathRW curFile
|
|
|
|
|
2021-11-20 11:48:05 -05:00
|
|
|
maxFileDep :: Dependency
|
2021-11-09 00:59:17 -05:00
|
|
|
maxFileDep = pathR maxFile
|
|
|
|
|
2021-11-22 23:02:23 -05:00
|
|
|
intelBacklightSignalDep :: DBusDep
|
2021-11-20 19:35:24 -05:00
|
|
|
intelBacklightSignalDep = signalDep intelBacklightConfig
|
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
exportIntelBacklight :: Maybe Client -> FeatureIO
|
2021-11-09 00:59:17 -05:00
|
|
|
exportIntelBacklight =
|
2021-11-20 12:40:53 -05:00
|
|
|
brightnessExporter [curFileDep, maxFileDep] intelBacklightConfig
|
|
|
|
|
2021-11-21 22:47:43 -05:00
|
|
|
intelBacklightControls :: Maybe Client -> BrightnessControls
|
2021-11-20 12:40:53 -05:00
|
|
|
intelBacklightControls = brightnessControls intelBacklightConfig
|
2021-11-07 13:35:08 -05:00
|
|
|
|
2021-11-21 17:54:00 -05:00
|
|
|
callGetBrightnessIB :: Client -> IO (Maybe Brightness)
|
2021-11-07 13:35:08 -05:00
|
|
|
callGetBrightnessIB = callGetBrightness intelBacklightConfig
|
|
|
|
|
2021-11-23 18:28:38 -05:00
|
|
|
matchSignalIB :: (Maybe Brightness -> IO ()) -> Client -> IO ()
|
2021-11-07 13:35:08 -05:00
|
|
|
matchSignalIB = matchSignal intelBacklightConfig
|