blob: 9d7b7b9fdf643c7d222a7908176fa4e830d579f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
module Dfetch.Brightness
( Brightness(..)
, fetchBrightness
, allBs
) where
import System.Directory (listDirectory)
import System.FilePath ((</>))
basePath :: FilePath
basePath = "/sys/class/backlight/"
data Brightness = Brightness
{ bright :: Int
, maxbright :: Int
} deriving Show
backlights :: IO [String]
backlights = listDirectory basePath
fetchBrightness :: String -> IO Brightness
fetchBrightness device = Brightness
<$> (read <$> readFile (path </> "brightness"))
<*> (read <$> readFile (path </> "max_brightness"))
where
path = basePath </> device
allBs :: IO [Brightness]
allBs = backlights >>= mapM fetchBrightness
|