-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrightness-laptop
More file actions
executable file
·45 lines (39 loc) · 999 Bytes
/
brightness-laptop
File metadata and controls
executable file
·45 lines (39 loc) · 999 Bytes
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
44
45
#!/usr/bin/env bash
receive_pipe="/tmp/waybar-laptop-brightness-module-rx"
step=2
rm -rf "$receive_pipe"
mkfifo "$receive_pipe"
print_brightness() {
if brightness=$("$@"); then
brightness=$(echo "$brightness" | cut -d ',' -f4 | tr -d '%')
else
brightness=-1
fi
echo "{ \"text\": \"$brightness\", \"tooltip\": \"Laptop monitor: $brightness%\" }"
}
# main brightnessctl command
brightnessctl_command() {
brightnessctl -m "$@"
}
# in case waybar restarted the script after restarting/replugging a monitor
print_brightness brightnessctl_command
while true; do
read -r command < "$receive_pipe"
case $command in
+)
print_brightness brightnessctl_command set +"$step"%
;;
-)
print_brightness brightnessctl_command set "$step"%-
;;
max)
print_brightness brightnessctl_command set 100%
;;
min)
print_brightness brightnessctl_command set 1
;;
*)
print_brightness brightnessctl_command
;;
esac
done