-
Notifications
You must be signed in to change notification settings - Fork 0
/
brightness.sh
executable file
·69 lines (56 loc) · 1.5 KB
/
brightness.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Script to adjust brightness and show an indicator using dunst
# Call it like this:
# $./brightness.sh up
# $./brightness.sh down
# Requirements:
# dunst (obviously)
# dunstify
# xbacklight
# Papirus icon theme
# Inspired by:
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
# Lock to assert only a single instance is running
LOCKFILE="/tmp/.`basename $0`.lock"
TIMEOUT=0.1
touch $LOCKFILE
exec {FD}<>$LOCKFILE
if ! flock -x -w $TIMEOUT $FD; then
echo "Failed to obtain a lock within $TIMEOUT seconds"
echo "Another instance of `basename $0` is probably running."
exit 1
fi
# Function to repeat a character (because seq is ugly)
# arg $1: number of repetitions
# arg $2: char to be printed
function repChar {
for (( i = 0; i < $1; i++ )); do
printf "$2"
done
}
# Bar is printed with a fixed width and a padding character ("░")
# so it can be used in a dynamically sized dunst frame and
# is therefore at least somewhat portable between hidpi
# and normal screens
function send_notification {
bl=$(xbacklight -get | cut -d '.' -f 1)
length=25 # Number characters for the bar
div=$((100 / $length))
total=$((100 / $div))
left=$(($bl / $div))
right=$(($total - $left))
bar=$(repChar $left "█")$(repChar $right "░")
# Send the notification
dunstify -i display-brightness-symbolic -r 2594 -u normal "$bar"
#dunstify -i NUL -r 2594 -u normal " $bar"
}
case $1 in
up)
xbacklight +8
send_notification
;;
down)
xbacklight -8
send_notification
;;
esac