diff --git a/home/system/hyprland/default.nix b/home/system/hyprland/default.nix index ae66cbf..07bc2ca 100644 --- a/home/system/hyprland/default.nix +++ b/home/system/hyprland/default.nix @@ -16,6 +16,7 @@ in { ./animations.nix ./bindings.nix ./polkitagent.nix + ./keyboard-backlight.nix # CHANGEME: This is for my laptop only # FIXME: Broken on unstable # ./hyprspace.nix ]; diff --git a/home/system/hyprland/keyboard-backlight.nix b/home/system/hyprland/keyboard-backlight.nix new file mode 100644 index 0000000..1014f01 --- /dev/null +++ b/home/system/hyprland/keyboard-backlight.nix @@ -0,0 +1,32 @@ +# Turn the keyboard red/off when the battery is low +{ pkgs, config, ... }: +let + keyboard-backlight = pkgs.writeShellScriptBin "keyboard-backlight" '' + function set_keyboard_backlight { + local color=$1 + echo $color > /sys/devices/platform/hp-wmi/rgb_zones/zone00 + echo $color > /sys/devices/platform/hp-wmi/rgb_zones/zone01 + echo $color > /sys/devices/platform/hp-wmi/rgb_zones/zone02 + echo $color > /sys/devices/platform/hp-wmi/rgb_zones/zone03 + } + state="white" + while true; do + BATTERY_LEVEL=$(cat /sys/class/power_supply/BAT*/capacity) + if [[ $BATTERY_LEVEL -le 10 ]]; then + if [[ $state == "red" ]];then + state="white" + set_keyboard_backlight "000000" + else + state="red" + set_keyboard_backlight "FF0000" + fi + else + state="white" + set_keyboard_backlight ${config.lib.stylix.colors.base0D} + fi + sleep 2 + done + ''; +in { + wayland.windowManager.hyprland.settings.exec-once = [ keyboard-backlight ]; +}