ADD xmobar indicator for keyboad backlight (kinda)

This commit is contained in:
Nathan Dwarshuis 2021-11-05 21:15:37 -04:00
parent 33d41fe88a
commit 3ca6bc222d
3 changed files with 68 additions and 13 deletions

View File

@ -24,6 +24,7 @@ import System.IO.Error
import System.Process (readProcessWithExitCode) import System.Process (readProcessWithExitCode)
import Xmobar.Plugins.Bluetooth import Xmobar.Plugins.Bluetooth
import Xmobar.Plugins.ClevoKeyboard
import Xmobar.Plugins.Device import Xmobar.Plugins.Device
import Xmobar.Plugins.IntelBacklight import Xmobar.Plugins.IntelBacklight
import Xmobar.Plugins.Screensaver import Xmobar.Plugins.Screensaver
@ -171,6 +172,12 @@ blCmd = CmdSpec
, csRunnable = Run $ IntelBacklight "<fn=1>\xf185</fn>" , csRunnable = Run $ IntelBacklight "<fn=1>\xf185</fn>"
} }
ckCmd :: CmdSpec
ckCmd = CmdSpec
{ csAlias = ckAlias
, csRunnable = Run $ ClevoKeyboard ("<fn=1>\xf40b</fn>", T.fgColor, T.backdropFgColor) 5
}
ssCmd :: CmdSpec ssCmd :: CmdSpec
ssCmd = CmdSpec ssCmd = CmdSpec
{ csAlias = ssAlias { csAlias = ssAlias
@ -291,6 +298,7 @@ getAllCommands = do
, getAlsa , getAlsa
, getBattery , getBattery
, getBl , getBl
, noSetup ckCmd
, getSs , getSs
, noSetup lockCmd , noSetup lockCmd
, noSetup dateCmd , noSetup dateCmd
@ -334,23 +342,18 @@ barFont = T.fmtFontXFT T.font
, T.weight = Just T.Bold , T.weight = Just T.Bold
} }
iconFont :: String nerdFont :: Int -> String
iconFont = T.fmtFontXFT T.font nerdFont size = T.fmtFontXFT T.font
{ T.family = "Symbols Nerd Font" { T.family = "Symbols Nerd Font"
, T.size = Nothing , T.size = Nothing
, T.pixelsize = Just 13 , T.pixelsize = Just size
} }
iconFont :: String
iconFont = nerdFont 13
iconFontLarge :: String iconFontLarge :: String
iconFontLarge = T.fmtFontXFT T.font iconFontLarge = nerdFont 15
{ T.family = "Symbols Nerd Font"
, T.size = Nothing
, T.pixelsize = Just 15
}
iconFontXLarge :: String iconFontXLarge :: String
iconFontXLarge = T.fmtFontXFT T.font iconFontXLarge = nerdFont 20
{ T.family = "Symbols Nerd Font"
, T.size = Nothing
, T.pixelsize = Just 20
}

View File

@ -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

View File

@ -21,6 +21,7 @@ library
, XMonad.Internal.DBus.Screensaver , XMonad.Internal.DBus.Screensaver
, XMonad.Internal.Process , XMonad.Internal.Process
, Xmobar.Plugins.Bluetooth , Xmobar.Plugins.Bluetooth
, Xmobar.Plugins.ClevoKeyboard
, Xmobar.Plugins.Device , Xmobar.Plugins.Device
, Xmobar.Plugins.IntelBacklight , Xmobar.Plugins.IntelBacklight
, Xmobar.Plugins.Screensaver , Xmobar.Plugins.Screensaver