From b6fa9dc31ee64e708ed888eac4555485ffa7d364 Mon Sep 17 00:00:00 2001 From: antistereov Date: Fri, 6 Mar 2026 19:35:59 +0100 Subject: [PATCH] feat(hypr): implement display and keyboard backlight dimming --- hypr/hypridle.conf | 16 ++++++++++++++-- hypr/scripts/dim-display.sh | 35 +++++++++++++++++++++++++++++++++++ hypr/scripts/dim-keyboard.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100755 hypr/scripts/dim-display.sh create mode 100755 hypr/scripts/dim-keyboard.sh diff --git a/hypr/hypridle.conf b/hypr/hypridle.conf index db14455..53ebff2 100644 --- a/hypr/hypridle.conf +++ b/hypr/hypridle.conf @@ -6,10 +6,22 @@ general { } listener { - timeout = 300 # 5min - on-timeout = loginctl lock-session # lock screen when timeout has passed + timeout = 290 + on-timeout = ~/.config/hypr/scripts/dim-display.sh dim + on-resume = ~/.config/hypr/scripts/dim-display.sh restore } +listener { + timeout = 300 + on-timeout = loginctl lock-session +} + +listener { + timeout = 300 + on-timeout = ~/.config/hypr/scripts/dim-keyboard.sh dim + on-resume = ~/.config/hypr/scripts/dim-keyboard.sh restore + } + listener { timeout = 300 # 5.5min on-timeout = hyprctl dispatch dpms off # screen off when timeout has passed diff --git a/hypr/scripts/dim-display.sh b/hypr/scripts/dim-display.sh new file mode 100755 index 0000000..a7c0adb --- /dev/null +++ b/hypr/scripts/dim-display.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCREEN_DEVICE="amdgpu_bl1" + +STATE_DIR="${XDG_RUNTIME_DIR:-/tmp}/hypridle" +SCREEN_STATE_FILE="$STATE_DIR/screen" + +mkdir -p "$STATE_DIR" + +save_current() { + brightnessctl -d "$SCREEN_DEVICE" g >"$SCREEN_STATE_FILE" +} + +dim() { + save_current + brightnessctl -d "$SCREEN_DEVICE" set 10% +} + +restore() { + [[ -f "$SCREEN_STATE_FILE" ]] && brightnessctl -d "$SCREEN_DEVICE" s "$(cat "$SCREEN_STATE_FILE")" +} + +case "${1:-}" in +dim) + dim + ;; +restore) + restore + ;; +*) + echo "Usage: $0 {dim|restore}" + exit 1 + ;; +esac diff --git a/hypr/scripts/dim-keyboard.sh b/hypr/scripts/dim-keyboard.sh new file mode 100755 index 0000000..cc8b822 --- /dev/null +++ b/hypr/scripts/dim-keyboard.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +KBD_DEVICE="chromeos::kbd_backlight" + +STATE_DIR="${XDG_RUNTIME_DIR:-/tmp}/hypridle" +KBD_STATE_FILE="$STATE_DIR/kbd" + +mkdir -p "$STATE_DIR" + +save_current() { + brightnessctl -d "$KBD_DEVICE" g >"$KBD_STATE_FILE" +} + +dim() { + save_current + brightnessctl -d "$KBD_DEVICE" set 0 +} + +restore() { + [[ -f "$KBD_STATE_FILE" ]] && brightnessctl -d "$KBD_DEVICE" s "$(cat "$KBD_STATE_FILE")" +} + +case "${1:-}" in +dim) + dim + ;; +restore) + restore + ;; +*) + echo "Usage: $0 {dim|restore}" + exit 1 + ;; +esac