From 95d377e8d048760bc159794c9c093210e5a93dea Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Sun, 15 Oct 2023 14:40:12 +0200 Subject: [PATCH] add brightness statusbar script --- .local/bin/statusbar/sb-bright | 39 +++++++++++++++++++++++++++++++ .local/bin/statusbar/sb-getbright | 2 -- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100755 .local/bin/statusbar/sb-bright delete mode 100755 .local/bin/statusbar/sb-getbright diff --git a/.local/bin/statusbar/sb-bright b/.local/bin/statusbar/sb-bright new file mode 100755 index 0000000..c9d059e --- /dev/null +++ b/.local/bin/statusbar/sb-bright @@ -0,0 +1,39 @@ +#!/bin/sh +# A small script manually writing into the /sys/class/backlight/* files +# If multiple go through all and apply changes/printout status +# if no first argument is given prints out current status +# else: apply changes (+/- -> relative, only number: -> absolute) +# numbers in percentages + +for backlight in "/sys/class/backlight/"*; do + max_brightness=$(cat $backlight/max_brightness) + current_brightness_abs=$(cat $backlight/brightness) + current_brightness_rel="$(echo "$current_brightness_abs * 100 / $max_brightness" | bc -l | xargs printf '%.0f')" + + # For statusbar + if [ -z $1 ]; then + echo "☀️$current_brightness_rel%" + # continue as relative changes can result in differing brightness for multiple backlights + continue + fi + + max(){ + echo $(( $1 > $2 ? $1 : $2 )) + } + min(){ + echo $(( $1 < $2 ? $1 : $2 )) + } + limit(){ + echo $(min $(max $1 0) 100) + } + + if echo $1 | grep -q '^[+-]'; then + new_brightness_rel=$(limit $(echo $current_brightness_rel $1 | bc)) + else + new_brightness_rel=$(limit $1) + fi + new_brightness_abs=$(echo "($new_brightness_rel * $max_brightness)/ 100" | bc) + echo "$new_brightness_abs" | sudo tee $backlight/brightness > /dev/null +done +[ -z $1 ] || + pkill -RTMIN+2 dwmblocks diff --git a/.local/bin/statusbar/sb-getbright b/.local/bin/statusbar/sb-getbright deleted file mode 100755 index 59146d5..0000000 --- a/.local/bin/statusbar/sb-getbright +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo ☀$(bc <<< "scale=0; $(cat /sys/class/backlight/intel_backlight/brightness) /9.37")%