src/brightness: add

This commit is contained in:
Luc Bijl 2025-08-14 20:34:21 +00:00
parent b5796746f2
commit c56fc16b7d

26
src/brightness Executable file
View file

@ -0,0 +1,26 @@
#!/bin/sh
# Define icon theme and path
icon_theme="Tela-circle-black-dark"
icon_path="/usr/share/icons/${icon_theme}/24/panel"
# Define icon file
brightness_lcd="${icon_path}/gpm-brightness-lcd.svg"
# Loop through each backlight
for backlight_path in /sys/class/backlight/*; do
# Extract backlight from path
backlight="${backlight_path##*/}"
# Read the last brightness notification ID from state, or set default if it does not exist.
last_notify_id="$(cat "$HOME/.local/state/brightness/$backlight" || echo "1024")"
# Get the brightness percentage of the backlight
brightness="$(( 100 * $(cat "$backlight_path/brightness") / $(cat "$backlight_path/max_brightness") ))"
# Send the brightness notification
last_notify_id="$(notify-send "Brightness ${brightness}%" -h int:value:$brightness -h string:synchronous: -i $brightness_lcd -t 2000 -r $last_notify_id -p)"
# Write the last brightness notification ID to state
echo "$last_notify_id" > "$HOME/.local/state/brightness/$backlight"
done