Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created August 22, 2020 06:43
Show Gist options
  • Save LeifW/15a1997d53eebbef8674a8d5ef0a5a06 to your computer and use it in GitHub Desktop.
Save LeifW/15a1997d53eebbef8674a8d5ef0a5a06 to your computer and use it in GitHub Desktop.
Modify screen brightness from Haskell (for use from XMonad)
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