Update: brightness script for external monitors

This commit is contained in:
Akemi Izuko 2023-12-23 20:14:11 -07:00
parent 0902684746
commit 53f7255d4e
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -1,13 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Locks the screen and lowers-brightness. Restores brightness on unlock # Locks the screens and lowers-brightness. Restores brightness on unlock
declare brightness_lvl;
if ! command -v ddcutil &>/dev/null && command -v light &>/dev/null; then # Defaults for levels when restored
declare light_restore=3
declare ddc_restore=3
# Levels when dimmed
declare -ri light_dim=1
declare -ri ddc_dim=1
get_brightness() {
local lvl
if command light &>/dev/null; then
lvl="$(light -G)" lvl="$(light -G)"
(swaylock; light -S "$lvl") & if [[ $lvl =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
light -S 1 light_restore="$lvl"
elif command -v ddcutil &>/dev/null; then fi
fi
if command ddcutil &>/dev/null; then
lvl="$(ddcutil getvcp 10 | awk '{ lvl="$(ddcutil getvcp 10 | awk '{
gsub(" ",""); # Remove spaces gsub(" ",""); # Remove spaces
split($0, a, "="); split($0, a, "=");
@ -15,14 +28,25 @@ elif command -v ddcutil &>/dev/null; then
print a[1] print a[1]
}')" }')"
if [[ "$lvl" =~ ^[0-9]+$ ]]; then if [[ $lvl =~ ^[0-9]+$ ]]; then
(swaylock; ddcutil setvcp 10 "$lvl") & ddc_restore="$lvl"
ddcutil setvcp 10 1
else
swaylock
fi fi
else fi
swaylock }
set_brightness() {
local -r light_lvl="$1"
local -r ddc_lvl="$2"
if command light &>/dev/null; then
light -S "$light_lvl"
fi fi
if command ddcutil &>/dev/null; then
ddcutil setvcp 10 "$ddc_lvl"
fi
}
get_brightness
(swaylock; set_brightness $light_restore $ddc_restore) &
set_brightness $light_dim $ddc_dim