From 4fedb93eb5eda39fd3024dc9ce712b8aae269a41 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Fri, 27 Mar 2026 09:14:57 +0900 Subject: modified bin/monitorbright, modified statusbar/sb-brightness --- ar/.local/bin/monitorbright | 39 +++++++++++++++++++---------------- ar/.local/bin/statusbar/sb-brightness | 25 ++++++++++++---------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/ar/.local/bin/monitorbright b/ar/.local/bin/monitorbright index db2bcf3..6e69614 100755 --- a/ar/.local/bin/monitorbright +++ b/ar/.local/bin/monitorbright @@ -1,20 +1,23 @@ #!/bin/sh -monitor=$(xrandr --query | grep -i '\sconnected' | grep '[0-9]x[0-9]' | grep -i 'primary' | cut -d ' ' -f1) -[ -z "$monitor" ] && monitor=$(xrandr --query | grep -i '\sconnected' | grep '[0-9]x[0-9]' | cut -d ' ' -f1) -case "$monitor" in -*DP* | *HDMI*) - current_brightness=$(xrandr --verbose | grep -i "^$monitor connected" -A5 | grep -i "Brightness:" | cut -d ' ' -f2) - [ -z "$current_brightness" ] && exit 1 - if [ "$#" -eq 2 ]; then - scale_change=$(echo "$2 / 100" | bc -l) - case "$1" in - "-inc") new_brightness=$(echo "$current_brightness + $scale_change" | bc -l) ;; - "-dec") new_brightness=$(echo "$current_brightness - $scale_change" | bc -l) ;; - *) echo "Invalid argument $1. Use -inc or -dec." && exit 1 ;; - esac - new_brightness=$(echo "if ($new_brightness > 1) 1 else if ($new_brightness < 0) 0 else $new_brightness" | bc -l) - xrandr --output "$monitor" --brightness "$new_brightness" - fi - ;; -esac +xrandr_verbose=$(xrandr --verbose) +monitors=$(echo "$xrandr_verbose" | grep -i '\sconnected' | grep '[0-9]x[0-9]' | cut -d ' ' -f1) + +for monitor in $monitors; do + case "$monitor" in + *DP* | *DisplayPort* | *HDMI*) + current_brightness=$(echo "$xrandr_verbose" | grep -i "^$monitor connected" -A5 | grep -i "Brightness:" | cut -d ' ' -f2) + [ -z "$current_brightness" ] && continue + if [ "$#" -eq 2 ]; then + scale_change=$(echo "$2 / 100" | bc -l) + case "$1" in + "-inc") new_brightness=$(echo "$current_brightness + $scale_change" | bc -l) ;; + "-dec") new_brightness=$(echo "$current_brightness - $scale_change" | bc -l) ;; + *) echo "Invalid argument $1. Use -inc or -dec." && exit 1 ;; + esac + new_brightness=$(echo "if ($new_brightness > 1) 1 else if ($new_brightness < 0) 0 else $new_brightness" | bc -l) + xrandr --output "$monitor" --brightness "$new_brightness" + fi + ;; + esac +done diff --git a/ar/.local/bin/statusbar/sb-brightness b/ar/.local/bin/statusbar/sb-brightness index 37cdf0b..f6ac628 100755 --- a/ar/.local/bin/statusbar/sb-brightness +++ b/ar/.local/bin/statusbar/sb-brightness @@ -1,14 +1,5 @@ #!/bin/sh -monitor=$(xrandr --query | grep -i '\sconnected' | grep '[0-9]x[0-9]' | grep -i 'primary' | cut -d ' ' -f1) -[ -z "$monitor" ] && monitor=$(xrandr --query | grep -i '\sconnected' | grep '[0-9]x[0-9]' | cut -d ' ' -f1) -case "$monitor" in -*DP* | *HDMI*) - current_brightness=$(xrandr --verbose | grep -i "^$monitor connected" -A5 | grep -i "Brightness:" | cut -d ' ' -f2) - current_brightness=$(printf "%.0f\n" "$(echo "$current_brightness * 100" | bc -l)") - ;; -esac - case $BLOCK_BUTTON in 3) notify-send "🔆 Backlight module - Scroll up & down changes screen brightness @@ -20,11 +11,23 @@ case $BLOCK_BUTTON in 10) monitorbright -dec 5 ;; esac +xrandr_verbose=$(xrandr --verbose) +monitors=$(echo "$xrandr_verbose" | grep -i '\sconnected' | grep '[0-9]x[0-9]' | cut -d ' ' -f1) +monitor_brightness="" +for monitor in $monitors; do + case "$monitor" in + *DP* | *DisplayPort* | *HDMI*) + b=$(echo "$xrandr_verbose" | grep -i "^$monitor connected" -A5 | grep -i "Brightness:" | cut -d ' ' -f2) + [ -n "$b" ] && { monitor_brightness=$(printf "%.0f" "$(echo "$b * 100" | bc -l)"); break; } + ;; + esac +done + if [ -r /sys/class/backlight/*/brightness ]; then curr_brightness=$(cat /sys/class/backlight/*/brightness) max_brightness=$(cat /sys/class/backlight/*/max_brightness) brightness_per=$((100 * curr_brightness / max_brightness)) - printf "%s %s\n" "💡${brightness_per}%" "🪟$current_brightness" + printf "%s %s\n" "💡${brightness_per}%" "🪟${monitor_brightness}%" else - printf "%s\n" "🪟$current_brightness" + [ -n "$monitor_brightness" ] && printf "%s\n" "🪟${monitor_brightness}%" fi -- cgit v1.2.3