Created
August 22, 2020 06:43
-
-
Save LeifW/15a1997d53eebbef8674a8d5ef0a5a06 to your computer and use it in GitHub Desktop.
Modify screen brightness from Haskell (for use from XMonad)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Brightness (inc, dec) where | |
import System.IO | |
import Control.Monad.IO.Class (MonadIO, liftIO) | |
modifyFile :: (String -> String) -> Handle -> IO () | |
modifyFile f h = f <$> hGetLine h >>= hPutStr h | |
modifyBrightness :: MonadIO m => (Int -> Int) -> m () | |
modifyBrightness f = liftIO $ withFile "/sys/class/backlight/intel_backlight/brightness" ReadWriteMode $ modifyFile (show . f . read) | |
inc, dec :: MonadIO m => Int -> m () | |
inc i = modifyBrightness (+ i) | |
dec i = modifyBrightness (subtract i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment