2020-03-20 15:41:13 -04:00
|
|
|
{-# 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
|
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
module Xmobar.Plugins.IntelBacklight
|
|
|
|
( IntelBacklight(..)
|
|
|
|
, blAlias
|
|
|
|
) where
|
2020-03-20 15:41:13 -04:00
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
import Control.Concurrent
|
|
|
|
import Control.Monad
|
2020-03-20 15:41:13 -04:00
|
|
|
|
2021-11-21 17:54:00 -05:00
|
|
|
import DBus.Client
|
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
import Xmobar
|
2020-03-20 15:41:13 -04:00
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
import XMonad.Internal.DBus.Brightness.IntelBacklight
|
2020-03-20 15:41:13 -04:00
|
|
|
|
|
|
|
newtype IntelBacklight = IntelBacklight String deriving (Read, Show)
|
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
blAlias :: String
|
|
|
|
blAlias = "intelbacklight"
|
|
|
|
|
2020-03-20 15:41:13 -04:00
|
|
|
instance Exec IntelBacklight where
|
2021-06-21 23:41:57 -04:00
|
|
|
alias (IntelBacklight _) = blAlias
|
2020-03-20 15:41:13 -04:00
|
|
|
start (IntelBacklight icon) cb = do
|
2021-11-07 13:35:08 -05:00
|
|
|
_ <- matchSignalIB $ cb . formatBrightness
|
2021-11-21 17:54:00 -05:00
|
|
|
cb . formatBrightness =<< callGetBrightnessIB =<< connectSession
|
2020-03-21 14:46:49 -04:00
|
|
|
forever (threadDelay 5000000)
|
2020-03-20 15:41:13 -04:00
|
|
|
where
|
|
|
|
formatBrightness = \case
|
2021-11-06 10:59:45 -04:00
|
|
|
Just b -> icon ++ show (round b :: Integer) ++ "%"
|
2020-03-20 15:41:13 -04:00
|
|
|
Nothing -> "N/A"
|