2021-11-21 00:42:40 -05:00
|
|
|
{-# LANGUAGE LambdaCase #-}
|
|
|
|
|
2021-11-05 21:15:37 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Clevo Keyboard plugin
|
|
|
|
--
|
|
|
|
-- Use the custom DBus interface exported by the XMonad process so I can react
|
|
|
|
-- to signals spawned by commands
|
|
|
|
|
|
|
|
module Xmobar.Plugins.ClevoKeyboard
|
|
|
|
( ClevoKeyboard(..)
|
|
|
|
, ckAlias
|
|
|
|
) where
|
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
import Control.Concurrent
|
|
|
|
import Control.Monad
|
2021-11-05 21:15:37 -04:00
|
|
|
|
2021-11-21 17:54:00 -05:00
|
|
|
import DBus.Client
|
|
|
|
|
2021-11-05 21:15:37 -04:00
|
|
|
import Xmobar
|
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
import XMonad.Internal.DBus.Brightness.ClevoKeyboard
|
2021-11-05 21:15:37 -04:00
|
|
|
|
2021-11-21 17:54:00 -05:00
|
|
|
newtype ClevoKeyboard = ClevoKeyboard String deriving (Read, Show)
|
2021-11-05 21:15:37 -04:00
|
|
|
|
|
|
|
ckAlias :: String
|
|
|
|
ckAlias = "clevokeyboard"
|
|
|
|
|
|
|
|
instance Exec ClevoKeyboard where
|
2021-11-21 00:42:40 -05:00
|
|
|
alias (ClevoKeyboard _) = ckAlias
|
|
|
|
start (ClevoKeyboard icon) cb = do
|
|
|
|
_ <- matchSignalCK $ cb . formatBrightness
|
2021-11-21 17:54:00 -05:00
|
|
|
-- TODO this could fail, and also should try to reuse client objects when
|
|
|
|
-- possible
|
|
|
|
cb . formatBrightness =<< callGetBrightnessCK =<< connectSession
|
2021-11-21 00:42:40 -05:00
|
|
|
forever (threadDelay 5000000)
|
2021-11-05 21:15:37 -04:00
|
|
|
where
|
2021-11-21 00:42:40 -05:00
|
|
|
formatBrightness = \case
|
|
|
|
Just b -> icon ++ show (round b :: Integer) ++ "%"
|
|
|
|
Nothing -> "N/A"
|