diff --git a/bin/xmobar.hs b/bin/xmobar.hs
index dc72aca..96f14fa 100644
--- a/bin/xmobar.hs
+++ b/bin/xmobar.hs
@@ -24,6 +24,7 @@ import System.IO.Error
import System.Process (readProcessWithExitCode)
import Xmobar.Plugins.Bluetooth
+import Xmobar.Plugins.ClevoKeyboard
import Xmobar.Plugins.Device
import Xmobar.Plugins.IntelBacklight
import Xmobar.Plugins.Screensaver
@@ -171,6 +172,12 @@ blCmd = CmdSpec
, csRunnable = Run $ IntelBacklight "\xf185"
}
+ckCmd :: CmdSpec
+ckCmd = CmdSpec
+ { csAlias = ckAlias
+ , csRunnable = Run $ ClevoKeyboard ("\xf40b", T.fgColor, T.backdropFgColor) 5
+ }
+
ssCmd :: CmdSpec
ssCmd = CmdSpec
{ csAlias = ssAlias
@@ -291,6 +298,7 @@ getAllCommands = do
, getAlsa
, getBattery
, getBl
+ , noSetup ckCmd
, getSs
, noSetup lockCmd
, noSetup dateCmd
@@ -334,23 +342,18 @@ barFont = T.fmtFontXFT T.font
, T.weight = Just T.Bold
}
-iconFont :: String
-iconFont = T.fmtFontXFT T.font
+nerdFont :: Int -> String
+nerdFont size = T.fmtFontXFT T.font
{ T.family = "Symbols Nerd Font"
, T.size = Nothing
- , T.pixelsize = Just 13
+ , T.pixelsize = Just size
}
+iconFont :: String
+iconFont = nerdFont 13
+
iconFontLarge :: String
-iconFontLarge = T.fmtFontXFT T.font
- { T.family = "Symbols Nerd Font"
- , T.size = Nothing
- , T.pixelsize = Just 15
- }
+iconFontLarge = nerdFont 15
iconFontXLarge :: String
-iconFontXLarge = T.fmtFontXFT T.font
- { T.family = "Symbols Nerd Font"
- , T.size = Nothing
- , T.pixelsize = Just 20
- }
+iconFontXLarge = nerdFont 20
diff --git a/lib/Xmobar/Plugins/ClevoKeyboard.hs b/lib/Xmobar/Plugins/ClevoKeyboard.hs
new file mode 100644
index 0000000..b09bcfd
--- /dev/null
+++ b/lib/Xmobar/Plugins/ClevoKeyboard.hs
@@ -0,0 +1,51 @@
+--------------------------------------------------------------------------------
+-- | 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
+
+import Data.Char
+import Data.Text (unpack)
+import Data.Text.IO as T (readFile)
+
+import Xmobar
+
+import XMonad.Hooks.DynamicLog (xmobarColor)
+
+-- import XMonad.Internal.DBus.IntelBacklight
+
+data ClevoKeyboard = ClevoKeyboard (String, String, String) Int
+ deriving (Read, Show)
+
+ckAlias :: String
+ckAlias = "clevokeyboard"
+
+brightnessFile :: FilePath
+brightnessFile = "/sys/devices/platform/tuxedo_keyboard/brightness"
+
+stateFile :: FilePath
+stateFile = "/sys/devices/platform/tuxedo_keyboard/state"
+
+readBrightness :: FilePath -> IO Integer
+readBrightness file = read . takeWhile isDigit . unpack <$> T.readFile file
+
+readState :: FilePath -> IO Bool
+readState file = (==1) <$> readBrightness file
+
+instance Exec ClevoKeyboard where
+ alias (ClevoKeyboard _ _) = ckAlias
+ rate (ClevoKeyboard _ r) = r
+ run (ClevoKeyboard (icon, colorOn, colorOff) _) = do
+ b <- readBrightness brightnessFile
+ s <- readState stateFile
+ return $ formatBrightness s (fromIntegral b :: Double)
+ where
+ formatBrightness s b =
+ let iconColor = if s then colorOn else colorOff
+ n = show (round $ b / 255 * 100 :: Integer) ++ "%"
+ in xmobarColor iconColor "" icon ++ n
diff --git a/my-xmonad.cabal b/my-xmonad.cabal
index f81a9a2..1d82876 100644
--- a/my-xmonad.cabal
+++ b/my-xmonad.cabal
@@ -21,6 +21,7 @@ library
, XMonad.Internal.DBus.Screensaver
, XMonad.Internal.Process
, Xmobar.Plugins.Bluetooth
+ , Xmobar.Plugins.ClevoKeyboard
, Xmobar.Plugins.Device
, Xmobar.Plugins.IntelBacklight
, Xmobar.Plugins.Screensaver