From 85e625776ae9db922d33092b5df18bcf2f817162 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Mon, 31 Jul 2023 15:50:52 +0300 Subject: [PATCH] home/wm: add kb to change keybord brightness --- .../window_manager/scripts/kdb_brightness.sh | 30 +++++++++++++++++++ home/modules/window_manager/xmonad.nix | 1 + home/modules/window_manager/xmonad_config.hs | 6 +++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 home/modules/window_manager/scripts/kdb_brightness.sh diff --git a/home/modules/window_manager/scripts/kdb_brightness.sh b/home/modules/window_manager/scripts/kdb_brightness.sh new file mode 100755 index 0000000..6e124ab --- /dev/null +++ b/home/modules/window_manager/scripts/kdb_brightness.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +function SetKeyboardBrightness() { + echo $1 | sudo tee /sys/class/leds/asus\:\:kbd_backlight/brightness +} + +min_brightness="0" +max_brightness=$(cat /sys/class/leds/asus\:\:kbd_backlight/max_brightness) +current_brightness=$(cat /sys/class/leds/asus\:\:kbd_backlight/brightness) + +case "$1" in + "up") + if [ "$current_brightness" != "$max_brightness" ]; then + let 'current_brightness+=1' + fi + ;; + + "down") + if [ "$current_brightness" != "$bin_brightness" ]; then + let 'current_brightness-=1' + fi + ;; + + *) + echo "Usage: $0 {up|down}" + exit 1 + ;; +esac + +SetKeyboardBrightness $current_brightness diff --git a/home/modules/window_manager/xmonad.nix b/home/modules/window_manager/xmonad.nix index 9195c7e..9c8518b 100644 --- a/home/modules/window_manager/xmonad.nix +++ b/home/modules/window_manager/xmonad.nix @@ -27,6 +27,7 @@ let themeCfg = config.local.theme; in inherit (themeCfg.window) activeBorder inactiveBorder; inherit (themeCfg.highlights) critical warning success; inherit (themeCfg.syntax) mark1 mark2 mark3; + kdbBrightnessScriptPath = "${./scripts/kdb_brightness.sh}"; }; }; diff --git a/home/modules/window_manager/xmonad_config.hs b/home/modules/window_manager/xmonad_config.hs index 57efef4..997963f 100644 --- a/home/modules/window_manager/xmonad_config.hs +++ b/home/modules/window_manager/xmonad_config.hs @@ -358,8 +358,12 @@ myKeys conf = -- Change volume ("", spawn "amixer -q sset Master toggle"), ("", spawn "amixer -q sset Master 5%+"), - ("", spawn "amixer -q sset Master 5%-") + ("", spawn "amixer -q sset Master 5%-"), + -- Change keyboard brightness + ("", spawn (kdbBrightness "up")), + ("", spawn (kdbBrightness "down")) ] + where kdbBrightness cmd = myTerminal ++ " -- @kdbBrightnessScriptPath@ " ++ cmd ------------------------------------------------------------------------ -- Mouse bindings: default actions bound to mouse events