xmonad-config/lib/Xmobar/Plugins/IntelBacklight.hs

38 lines
1.0 KiB
Haskell
Raw Normal View History

{-# LANGUAGE LambdaCase #-}
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Intel backlight plugin
--
-- Use the custom DBus interface exported by the XMonad process so I can react
-- to signals spawned by commands
module Xmobar.Plugins.IntelBacklight
( IntelBacklight(..)
, blAlias
) where
2020-04-01 20:17:47 -04:00
import Control.Concurrent
import Control.Monad
2021-11-21 17:54:00 -05:00
import DBus.Client
2020-04-01 20:17:47 -04:00
import Xmobar
import XMonad.Internal.DBus.Brightness.IntelBacklight
newtype IntelBacklight = IntelBacklight String deriving (Read, Show)
blAlias :: String
blAlias = "intelbacklight"
instance Exec IntelBacklight where
alias (IntelBacklight _) = blAlias
start (IntelBacklight icon) cb = do
_ <- matchSignalIB $ cb . formatBrightness
2021-11-21 17:54:00 -05:00
cb . formatBrightness =<< callGetBrightnessIB =<< connectSession
forever (threadDelay 5000000)
where
formatBrightness = \case
Just b -> icon ++ show (round b :: Integer) ++ "%"
Nothing -> "N/A"