summaryrefslogtreecommitdiff
path: root/ar/.local/bin/statusbar/sb-brightness
blob: f6ac628321f1b08f468c170bbe7c2d35b5d7405b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

case $BLOCK_BUTTON in
3) notify-send "🔆 Backlight module
- Scroll up & down changes screen brightness
- Shift + Scroll up & down changes monitor backlight" ;;
4) pkexec brillo -A 5 -q ;;
5) pkexec brillo -U 5 -q ;;
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
9) monitorbright -inc 5 ;;
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}%" "🪟${monitor_brightness}%"
else
  [ -n "$monitor_brightness" ] && printf "%s\n" "🪟${monitor_brightness}%"
fi