-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdimscreen
executable file
·187 lines (180 loc) · 5.45 KB
/
dimscreen
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
#
# @author Zeus Intuivo <[email protected]>
#
#
BRIGHTNESS=.7
[[ -n "${1}" ]] && BRIGHTNESS="${1}"
#echo "Scann all connected monitors, get the first word ls HMD1 -list, then apply brightness to each word passwed from the list"
#echo "xrandr --current --verbose | grep \" connected\" | cut -d\" \" -f1 | xargs -I {} xrandr --output {} --brightness \"${BRIGHTNESS}\""
function _get_current_brightnessctl_percentage() {
local -i _cb=0
_cb=$(brightnessctl | grep "Current" | cut -d'(' -f2 | cut -d')' -f1 | cut -d'%' -f1)
echo ${_cb}
return 0
}
function _get_all_active_monitors(){
local monitors=""
monitors=$(xrandr --current --verbose | grep " connected" | cut -d" " -f1)
echo "${monitors}"
return 0
} # end _get_all_active_monitors
function _get_percentage_conversion(){
local -i _b=0
_b=$(sed 's/\.//g' <<< "${1}")
# echo $_b
if [ ${_b} -gt 10 ] && [ ${_b} -lt 100 ] ; then
{
echo ${_b}
return 0
}
fi
local -i testb=$(( _b * 10 ))
if [ ${1} == "1" ] ; then
{
testb=100
}
fi
# res=$(( _b * 100 ))
local -i res=${testb}
if [ ${res} -lt 10 ] ; then
{
res=10
}
fi
if [ ${res} -gt 100 ] ; then
{
res=100
}
fi
# REF: https://unix.stackexchange.com/questions/526653/control-screen-brightness-in-i3
# brightnessctl set 20%- down and brightnessctl set +20% up (position of the - and + matter)
echo ${res}
return 0
} # end _get_percentage_conversion
function test_get_percentage_conversion(){
local _bright_percentage=""
_bright_percentage="$(_get_percentage_conversion "${BRIGHTNESS}")"
echo "_bright_percentage:${_bright_percentage}%"
} # end test_get_percentage_conversion
test_get_percentage_conversion
# exit 0
function _get_day_or_night(){
# REF: https://unix.stackexchange.com/questions/395933/how-to-check-if-the-current-time-is-between-2300-and-0630
local currenttime=""
currenttime=$(date +%H:%M)
if [[ "${currenttime}" > "06:00" ]] \
&& [[ "${currenttime}" < "11:30" ]]; then
{
echo 'day-morgen'
return 0
}
elif [[ "${currenttime}" > "11:29" ]] \
&& [[ "${currenttime}" < "17:30" ]]; then
{
echo 'day-mittag'
return 0
}
elif [[ "${currenttime}" > "17:29" ]] \
&& [[ "${currenttime}" < "20:30" ]]; then
{
echo 'day-aben'
return 0
}
elif [[ "${currenttime}" > "20:29" ]] \
&& [[ "${currenttime}" < "22:30" ]]; then
{
echo 'night-aben'
return 0
}
fi
echo 'night'
return 0
} # end _get_day_or_night
function test_get_day_or_night(){
local _day_or_night=""
_day_or_night="$(_get_day_or_night)"
echo "_day_or_night:${_day_or_night}"
} # end test_get_percentage_conversion
test_get_day_or_night
function _set_brightness(){
# xrandr --current --verbose | grep " connected" \
# | cut -d" " -f1 | xargs -I {} xrandr --output {} --brightness "${BRIGHTNESS}"
local monitors=""
monitors="$(_get_all_active_monitors)"
local _bright_percentage=""
_bright_percentage="$(_get_percentage_conversion "${BRIGHTNESS}")"
local _day_or_night=""
_day_or_night="$(_get_day_or_night)"
local _current_brightness_percentage=""
_current_brightness_percentage="$(_get_current_brightnessctl_percentage)"
echo "_instruction_called:${BRIGHTNESS}"
echo "_current_brightness_percentag:${_current_brightness_percentage}"
if (echo "${BRIGHTNESS}" | grep "+" >/dev/null 2>&1; ) ; then
{
if [[ "${BRIGHTNESS}" == "+.01" ]] ; then
{
_bright_percentage=$(( _current_brightness_percentage + 1 ))
}
elif [[ "${BRIGHTNESS}" == "+.05" ]] ; then
{
_bright_percentage=$(( _current_brightness_percentage + 5 ))
}
else
{
_bright_percentage=$(( _current_brightness_percentage + _bright_percentage ))
}
fi
_bright_percentage="$(_get_percentage_conversion ${_bright_percentage})"
BRIGHTNESS=".${_bright_percentage}"
echo "_plus_new_brightness:${_bright_percentage}"
}
fi
if (echo "${BRIGHTNESS}" | grep "-" >/dev/null 2>&1; ) ; then
{
if [[ "${BRIGHTNESS}" == "-.01" ]] ; then
{
_bright_percentage=$(( _current_brightness_percentage - 1 ))
}
elif [[ "${BRIGHTNESS}" == "-.05" ]] ; then
{
_bright_percentage=$(( _current_brightness_percentage - 5 ))
}
else
{
_bright_percentage=$(( _current_brightness_percentage - _bright_percentage ))
}
fi
_bright_percentage="$(_get_percentage_conversion ${_bright_percentage})"
BRIGHTNESS=".${_bright_percentage}"
echo "_minus_new_brightness:${_bright_percentage}"
}
fi
local monitor
while read -r monitor; do
{
[[ -z ${monitor} ]] && continue
if [[ "${_day_or_night}" == *"day"* ]] ; then
{
echo Running Day xrandr --output "${monitor}" --gamma 1:1:1 --brightness "${BRIGHTNESS}"
xrandr --output "${monitor}" --gamma 1:1:1 --brightness "${BRIGHTNESS}"
}
elif [[ "${_day_or_night}" == "night-aben" ]] ; then
{
echo Running Night xrandr --output "${monitor}" --gamma 1:1:0.5 --brightness "${BRIGHTNESS}"
xrandr --output "${monitor}" --gamma 1:1:0.5 --brightness "${BRIGHTNESS}"
}
else
{
echo Running Night xrandr --output "${monitor}" --gamma 1.0:0.88:0.76 --brightness "${BRIGHTNESS}"
xrandr --output "${monitor}" --gamma 1.0:0.88:0.76 --brightness "${BRIGHTNESS}"
}
fi
echo brightnessctl set "${_bright_percentage}%"
brightnessctl set "${_bright_percentage}%"
brightnessctl --device='tpacpi::kbd_backlight' set 0
}
done <<< "${monitors}"
return 0
} # end _set_brightness
_set_brightness