Repository navigation
Expand file tree
/
Copy pathbacklight
More file actions
executable file
·109 lines (95 loc) · 2.71 KB
/
Copy pathbacklight
File metadata and controls
executable file
·109 lines (95 loc) · 2.71 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/bash
set -eu
source "$HOME/dotfiles/linux/variables.env"
declare -ar BRIGHTNESS_ICONS=("" "" "")
declare -ar BRIGHTNESS_IMAGES=(sun-dim sun-medium sun)
preferences_helper="$(dirname "$(readlink -f "$0")")/../config/system-settings/settings.py"
LOCK_FILE="${XDG_RUNTIME_DIR:-/tmp}/u_backlight.lock"
STEP=$(python3 "$(dirname "$(readlink -f "$0")")/../config/system-settings/settings.py" get display.brightnessStep)
get_value() {
light -G 2>&- | cut -f1 -d .
}
adjust() { # inc|dec
local direction=$1 current target
current=$(get_value)
case "$direction" in
inc) target=$(( (current / STEP + 1) * STEP )) ;;
dec) target=$(( ((current + STEP - 1) / STEP - 1) * STEP )) ;;
esac
(( target < 0 )) && target=0
(( target > 100 )) && target=100
(( target == current )) && return 1
flock -n "$LOCK_FILE" light -S "$target" 2>&-
}
brightness_level() {
local value=$1
if (( value < 34 )); then
printf '0'
elif (( value < 67 )); then
printf '1'
else
printf '2'
fi
}
icon() {
local index
index=$(brightness_level "$1")
printf '%s\n' "${BRIGHTNESS_ICONS[index]}"
}
audio_tick() {
play "$HOME/dotfiles/sounds/audio-volume-change.oga" &> /dev/null &
}
show() {
local value index
value=$(get_value)
index=$(brightness_level "$value")
notify-send -a System \
-i "$LUCIDE_PATH/${BRIGHTNESS_IMAGES[index]}.svg" \
-h string:wired-tag:system \
-h int:value:"$value" \
"Brightness"
}
link_state() {
python3 "$preferences_helper" get display.linkBrightness
}
link_toggle() {
local enabled
enabled=$(link_state)
if [[ $enabled == true ]]; then enabled=false; else enabled=true; fi
python3 "$preferences_helper" set display.linkBrightness "$enabled" > /dev/null
link_state
}
## When "link devices" is on, dragging the laptop slider also drives the
## keyboard and any DDC-capable external displays at the same percentage.
maybe_link() {
[[ "$(link_state)" == true ]] || return 0
local pct=$1
u_keeb-backlight set "$pct" quiet &> /dev/null &
u_monitors brightness set "$pct" quiet &> /dev/null &
}
case $1 in
icon) echo "$(icon "$(get_value)")" ;;
get) get_value ;;
set) maybe_link "$2"; flock "$LOCK_FILE" light -S "$2" ;;
dim)
light -O -s sysfs/leds/tpacpi::kbd_backlight
light -S 0 -s sysfs/leds/tpacpi::kbd_backlight
;;
restore)
light -I
light -I -s sysfs/leds/tpacpi::kbd_backlight
;;
show) show ;;
inc)
adjust inc || exit 0
[[ "${2:-}" == "quiet" ]] || audio_tick
show ;;
dec)
adjust dec || exit 0
[[ "${2:-}" == "quiet" ]] || audio_tick
show ;;
link-get) link_state ;;
link-toggle) link_toggle ;;
if)
light -L 2>&- | grep -q auto && echo true || echo false ;;
esac