xmonad-config/lib/XMonad/Internal/DBus/Brightness/IntelBacklight.hs

115 lines
3.1 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
-- | DBus module for Intel Backlight control
module XMonad.Internal.DBus.Brightness.IntelBacklight
( callGetBrightnessIB
, matchSignalIB
, exportIntelBacklight
, intelBacklightControls
, intelBacklightSignalDep
, blPath
) where
import Data.Int (Int32)
2022-07-09 17:44:14 -04:00
import Data.Internal.DBus
import Data.Internal.Dependency
import DBus
2022-12-26 14:55:17 -05:00
import RIO.FilePath
import XMonad.Internal.DBus.Brightness.Common
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)
steps :: Int
steps = 16
2021-11-21 00:42:40 -05:00
minRawBrightness :: RawBrightness
minRawBrightness = 1
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-21 00:42:40 -05:00
minBrightness :: RawBounds -> IO Brightness
minBrightness bounds = writePercentMin bounds curFile
2021-11-21 00:42:40 -05:00
maxBrightness :: RawBounds -> IO Brightness
maxBrightness bounds = writePercentMax bounds curFile
2021-11-21 00:42:40 -05:00
incBrightness :: RawBounds -> IO Brightness
incBrightness = incPercent steps curFile
2021-11-21 00:42:40 -05:00
decBrightness :: RawBounds -> IO Brightness
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
, bcPath = blPath
, bcInterface = interface
, bcName = "Intel backlight"
}
--------------------------------------------------------------------------------
-- | Exported haskell API
curFileDep :: IODependency_
curFileDep = pathRW curFile []
maxFileDep :: IODependency_
maxFileDep = pathR maxFile []
2022-07-09 17:08:10 -04:00
intelBacklightSignalDep :: DBusDependency_ SesClient
intelBacklightSignalDep = signalDep intelBacklightConfig
2022-07-09 17:08:10 -04:00
exportIntelBacklight :: Maybe SesClient -> SometimesIO
exportIntelBacklight = brightnessExporter xpfIntelBacklight []
[curFileDep, maxFileDep] intelBacklightConfig
2022-07-09 17:08:10 -04:00
intelBacklightControls :: Maybe SesClient -> BrightnessControls
intelBacklightControls = brightnessControls xpfIntelBacklight intelBacklightConfig
2022-07-09 17:08:10 -04:00
callGetBrightnessIB :: SesClient -> IO (Maybe Brightness)
2022-07-09 17:44:14 -04:00
callGetBrightnessIB = callGetBrightness intelBacklightConfig
2022-07-09 17:08:10 -04:00
matchSignalIB :: (Maybe Brightness -> IO ()) -> SesClient -> IO ()
2022-07-09 17:44:14 -04:00
matchSignalIB = matchSignal intelBacklightConfig