-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrobar-brightness-server
executable file
·43 lines (34 loc) · 1.06 KB
/
robar-brightness-server
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
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
set -eu
__help="Usage: ${0##*/} [OPTIONS]
Display the screen brightness using robar when the ACPI sysfs directory for
screen brightness changes.
Options:
-h, --help display this help and exit"
while [ ! $# -eq 0 ]; do
case "$1" in
-h | --help)
echo "$__help"
exit 0
;;
*)
break;
;;
esac
shift
done
[ -z "$*" ] || { echo "Error: unexpected positional arguments: $*." && exit 1; }
while ! pgrep --exact --full "robar start" >/dev/null; do sleep 1; done
brightness_file='/sys/class/backlight/intel_backlight/brightness'
max_brightness_file='/sys/class/backlight/intel_backlight/max_brightness'
max_brightness=$(cat $max_brightness_file)
last_brightness=100
while true; do
inotifywait --quiet --monitor --event close_write /sys/class/backlight/intel_backlight/brightness | while read -r; do
brightness=$(cat $brightness_file)
if [ "$last_brightness" -ne "$brightness" ]; then
echo "default $((brightness * 100 / max_brightness))"
last_brightness=$brightness
fi
done | robar show-stream
done