-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrightness
executable file
·94 lines (83 loc) · 2.13 KB
/
brightness
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
#!/bin/bash
set -x
bright=$(cat /sys/class/backlight/intel_backlight/brightness)
max=$(cat /sys/class/backlight/intel_backlight/max_brightness)
level=
direction=
step=
param=1
#echo "$bright/$max"
#if [[ $# -eq 0 ]]; then
#result=$(qalc "$bright / $max" | cut -f2 -d '=' | cut -f2 -d ' ')
#echo $((100 * $bright / $max))
#echo $bright
#else
if [[ $# -gt 0 ]]; then
case ${!param} in
up)
level=1
param=$(($param + 1))
;;
down)
level=-1
param=$(($param + 1))
;;
set)
level=0
param=$(($param + 1))
#bright=${!param}
;;
*)
level=1
;;
esac
if [[ ${!param} > 0 ]]; then
step=${!param}
else
step=.1
fi
fi
case $BLOCK_BUTTON in
1) # Left Click
#level=0
#step=1
sudo ~/.config/i3/i3tools/brightness set 1
;;
2) # Middle Click
#level=0
#step=.4
sudo ~/.config/i3/i3tools/brightness set .4
;;
3) # Right Click
#level=0
#step=.2
sudo ~/.config/i3/i3tools/brightness set .2
;;
4) # Wheel Up
#level=1
#step=.05
sudo ~/.config/i3/i3tools/brightness up .05
;;
5) # Wheel Down
#level=-1
#step=.05
sudo ~/.config/i3/i3tools/brightness down .05
;;
*)
;;
esac
if [[ -n $level ]]; then
#step=$(qalc "$step * $max" | cut -f2 -d'=' | cut -f2 -d' ')
step=$(echo "scale=0; ($step * $max) / 1" | bc)
if [[ $level -eq 0 ]]; then
bright=$step
else
#result=$(qalc "max(0, min(1, $bright + $level * $step))" | cut -f2 -d '=' | cut -f2 -d ' ')
bright=$(qalc "round(max(0, min($max, ($level * $step) + $bright)))" | cut -f2 -d '=' | cut -f2 -d ' ')
fi
echo "|$level $step $bright $BLOCK_BUTTON|" >> /tmp/bright.log
echo $bright | tee /sys/class/backlight/intel_backlight/brightness > /dev/zero
fi
#result=$(qalc "100 * $bright / $max" | cut -f2 -d'=' | cut -f2 -d' ')
result=$(echo "scale=0; (100 * $bright / $max) / 1" | bc)
echo $result"%"