-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXconfigure.sh
More file actions
executable file
·266 lines (224 loc) · 7.74 KB
/
Xconfigure.sh
File metadata and controls
executable file
·266 lines (224 loc) · 7.74 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
#
#
# Copyright © 2024 Quintor B.V.
#
# BCLD is gelicentieerd onder de EUPL, versie 1.2 of
# – zodra ze zullen worden goedgekeurd door de Europese Commissie -
# latere versies van de EUPL (de "Licentie");
# U mag BCLD alleen gebruiken in overeenstemming met de licentie.
# U kunt een kopie van de licentie verkrijgen op:
#
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# Tenzij vereist door de toepasselijke wetgeving of overeengekomen in
# schrijven, wordt software onder deze licentie gedistribueerd
# gedistribueerd op een "AS IS"-basis,
# ZONDER ENIGE GARANTIES OF VOORWAARDEN, zowel
# expliciet als impliciet.
# Zie de licentie voor de specifieke taal die van toepassing is
# en de beperkingen van de licentie.
#
#
# Copyright © 2024 Quintor B.V.
#
# BCLD is licensed under the EUPL, Version 1.2 or
# – as soon they will be approved by the European Commission -
# subsequent versions of the EUPL (the "Licence");
# You may not use BCLD except in compliance with the Licence.
# You may obtain a copy of the License at:
#
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the License is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the License for the specific language governing
# permissions and limitations under the License.
#
#
# BCLD X Configure
# Most of the functions in this script have to do with setting graphical
# settings related to the X11 window management system that can run
# Openbox and start the Chromium webkiosk.
#
# This script takes important BCLD video parameters from bcld.cfg and
# utilizes these to configure the graphical X system.
#
# X configurations, this script starts with Openbox (autostart).
source "/bin/log_tools.sh"
# ENVs
TAG='RUN-GRAPHICS'
/usr/bin/echo -e '\nStarting Xconfigure...\nOutput should not be visible in RELEASE!\n\n'
# Functions
## Function to wait for xbindkeys to start
function wait_xbindkeys () {
if /usr/bin/pgrep -f 'xbindkeys' > /dev/null; then
/usr/bin/echo 'xbindkeys started!'
else
/usr/bin/echo 'Waiting for xbindkeys...'
/usr/bin/sleep 1s
fi
}
## Set BCLD_RESOLUTION and BCLD_TRUE_SCALING based on BCLD_PRESET
function import_preset (){
if [[ $(/usr/bin/xrandr -q | /usr/bin/grep -ci "${1}") -gt 0 ]]; then
log_item "Setting preset: ${BCLD_PRESET^^}"
BCLD_RESOLUTION="${1}"
BCLD_TRUE_SCALING=${2}
else
log_item "Preset not found or resolution not supported!"
fi
}
## Translate BCLD_BRIGHTNESS to BCLD_TRUE_BRIGHTNESS
function true_brightness (){
BCLD_TRUE_BRIGHTNESS="$(/usr/bin/bc <<< "scale=2; ${1}/100")"
}
## Translate BCLD_SCALING to BCLD_TRUE_SCALING
function true_scaling (){
BCLD_TRUE_SCALING="$(/usr/bin/bc <<< "scale=2; (200-${1})/100")"
}
# Logging
log_whitespace
log_header "Configuring X settings"
log_first 'Checking keyboard settings...'
# Bindings
## Xkbmap for disabling TTY switching
/usr/bin/setxkbmap -option srvrkeys:none
## Escaping
if [[ "${BCLD_MODEL}" != 'debug' ]]; then
# Always load xmodmap and xbindkeys for RELEASE and TEST
/usr/bin/xmodmap "${HOME}/.xmodmap" # config file for disabling key mappings
/usr/bin/xbindkeys -f "${HOME}/.xbindkeysrc" # daemon with config file for disabling custom key combinations
# Check if xbindkeys was started, take 10s max
for n in $(/usr/bin/seq 1 10); do
wait_xbindkeys # Output status or wait 1s
# If started, break out immediately
if /usr/bin/pgrep -f 'xbindkeys' > /dev/null; then
break
fi
done
if ! /usr/bin/pgrep -f 'xbindkeys' > /dev/null; then
/usr/bin/echo 'xbindkeys could not be started!'
log_item 'xbindkeys could not be started!'
fi
else
# Xkbmap for allowing escape in DEBUG
/usr/bin/setxkbmap -option terminate:ctrl_alt_bksp
fi
log_item 'Checking BCLD boot parameters...'
## Mouse button swap
if [[ "${BCLD_VENDOR}" == 'vendorless' ]]; then
# Since M2 is already disabled in Vendorless BCLD, always swap M2 and M3
# This allows for the usage of tabs on laptops
# xmodmap will automatically detect the current mouse and only change the appropriate buttons
/usr/bin/echo -e "\nVendorless BCLD detected!"
/usr/bin/echo "Swapping mouse buttons 2 and 3..."
/usr/bin/xmodmap -e "pointer = 1 3 2"
fi
## Check if DISPLAY is set
if [[ -z ${DISPLAY} ]]; then
/usr/bin/echo -e "\nDISPLAY is not set!"
/usr/bin/echo "Cannot launch BCLD app. Exiting..."
exit 1
fi
## Detect default display
BCLD_DISPLAY="$(/usr/bin/xrandr \
| /usr/bin/grep 'connected' \
| /usr/bin/grep -v 'disconnected' \
| /usr/bin/awk '{print $1}')"
export BCLD_DISPLAY
## X Settings
/usr/bin/xset s off
/usr/bin/xset s noblank
# xset -dpms # Only throwing errors
# xsetroot -grey # Doesn't really seem to work
# Xrandr configurations
# Only execute these, if the variables are set...
# If not, darkness...
# Must be in all caps
case ${BCLD_PRESET^^} in
4K)
import_preset '3840x2160' 0.5
;;
1080P)
import_preset '1920x1080' 1
;;
HD+)
import_preset '1600x900' 1
;;
768P)
import_preset '1368x768' 1
;;
XGA)
import_preset '1280x1024' 1.1
;;
*)
log_item "Preset ${BCLD_PRESET^^} not found..."
;;
esac
## Configure resolution
if [[ -n "${BCLD_RESOLUTION}" ]] && [[ $(/usr/bin/xrandr -q | /usr/bin/grep -ci "${BCLD_RESOLUTION}") -gt 0 ]]; then
log_item "Setting resolution: ${BCLD_RESOLUTION,,}"
/usr/bin/xrandr -s "${BCLD_RESOLUTION,,}"
fi
## Configure rotation
if [[ -n "${BCLD_ROTATION}" ]]; then
log_item "Setting rotation: ${BCLD_ROTATION,,}"
/usr/bin/xrandr -o "${BCLD_ROTATION,,}"
fi
## Configure scaling (requires DISPLAY)
if [[ -n "${BCLD_DISPLAY}" ]] && [[ -n "${BCLD_SCALING}" ]]; then
log_item "Setting scaling: ${BCLD_SCALING}"
true_scaling "${BCLD_SCALING}" # Generate BCLD_TRUE_SCALING
/usr/bin/xrandr --output "${BCLD_DISPLAY}" --scale "${BCLD_TRUE_SCALING}" --filter nearest
fi
## Configure brightness (requires DISPLAY)
if [[ -n "${BCLD_DISPLAY}" ]] && [[ -n "${BCLD_BRIGHTNESS}" ]]; then
log_item "Setting brightness: ${BCLD_BRIGHTNESS}"
true_brightness "${BCLD_BRIGHTNESS}" # Generate BCLD_TRUE_BRIGHTNESS
/usr/bin/xrandr --output "${BCLD_DISPLAY}" --brightness "${BCLD_TRUE_BRIGHTNESS}"
fi
# Screensaver
log_item "Starting XScreenSaver:"
SS_CONFIG="/home/${USER}/.xscreensaver"
DEFAULT_SS_TIMEOUT='0:15:00' # 15 minutes
# Set to default unless a BCLD parameter is given
if [[ "${BCLD_SCREENSAVER}" == '0' ]]; then
# Disable xscreensaver if the value is 0
/usr/bin/echo "BCLD_SCREENSAVER found, but set to: ${BCLD_SCREENSAVER}"
/usr/bin/echo "xscreensaver disabled!"
# Do not start xscreensaver
elif [[ -n "${BCLD_SCREENSAVER}" ]]; then
# If the value is anything else, use that instead
BCLD_SS_TIMEOUT="0:${BCLD_SCREENSAVER}:00"
/usr/bin/echo "BCLD_SCREENSAVER found!: ${BCLD_SS_TIMEOUT}"
/usr/bin/echo -e "\ntimeout: ${BCLD_SS_TIMEOUT}" >> "${SS_CONFIG}"
# Start xscreensaver
/usr/bin/xscreensaver &
else
# If there is no value, use the default
/usr/bin/echo "BCLD_SCREENSAVER not found! Using default: ${DEFAULT_SS_TIMEOUT}"
/usr/bin/echo -e "\ntimeout: ${DEFAULT_SS_TIMEOUT}" >> "${SS_CONFIG}"
# Start xscreensaver
/usr/bin/xscreensaver &
fi
log_last 'X settings configured!'
# For adding XORG logs to the journal
TAG="LOG-GRAPHICS"
# Graphics
log_whitespace
log_header "Getting graphics information"
log_whitespace
log_line "── X-Org:"
output_file "${XORG_USR_LOG}"
log_whitespace
log_line "── XRandR"
log_line "$(/usr/bin/xrandr -d ${DISPLAY} -q)"
log_whitespace
log_line "── XRandR properties:"
log_line "$(/usr/bin/xrandr --props)"
log_whitespace
/usr/bin/echo 'Xconfigure complete!'