forked from shownb/FBrowser
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfbrowser
More file actions
executable file
·383 lines (364 loc) · 11.6 KB
/
fbrowser
File metadata and controls
executable file
·383 lines (364 loc) · 11.6 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
ARGS="$@"
static_settings() {
EXECUTABLE=fbrowser-bin
}
load_settings() {
echo "Loading settings..."
if [ ! -e "config.json" ]; then
echo -e '{\n"url":"http://google.com",\n"wsServerPort":0,\n"width": 0,\n"height": 0,\n"proxyHost": "",\n"proxyPort": 0\n}' > config.json
fi
if [ ! -e "$HOME/.config/fbrowser/config" ];then
need_configure
fi
if [[ $(grep -L "BACKEND_DEV" "$HOME/.config/fbrowser/config") ]]; then
need_configure
fi
if [[ $(grep -L "KEYBOARD_DEV" "$HOME/.config/fbrowser/config") ]]; then
need_configure
fi
source <(grep = $HOME/.config/fbrowser/config)
echo "Settings loaded"
if [ "$BACKEND_DEV" == "fb" ];then
echo "Selected video backend: fb"
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:nographicsmodeswitch=1
# Disable libinput support for fb
export QT_QPA_FB_NO_LIBINPUT=1
# Force full screen mode
export QT_QPA_FB_FORCE_FULLSCREEN=1
elif [ "$BACKEND_DEV" == "eglfs" ];then
echo "Selected video backend: eglfs"
# Enable eglfs backend
export QT_QPA_PLATFORM=eglfs
# Use the KMS/DRM backend.
export QT_QPA_EGLFS_INTEGRATION=eglfs_kms
# Disable libinput support for eglfs
export QT_QPA_EGLFS_NO_LIBINPUT=1
# Enable eglfs debug logging
#export QT_QPA_EGLFS_DEBUG=1
else
need_configure
fi
if [ "$TOUCHSCREEN_DEV" != "" ];then
# Touchscreen support, see info using utility evtest
export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/${TOUCHSCREEN_DEV}
fi
if [ "$KEYBOARD_DEV" != "" ];then
# Keyboard support, see info using utility evtest
export QT_QPA_EVDEV_KEYBOARD_PARAMETERS=/dev/input/${KEYBOARD_DEV}:grab=1
fi
# debug input logging
#export QT_LOGGING_RULES=qt.qpa.input=true
# attempt to disable the terminal keyboard on application startup by setting the tty's keyboard mode to K_OFF
export QT_QPA_ENABLE_TERMINAL_KEYBOARD=0
}
launch() {
exes=0
# where are the executable of the program ?
if [ -e "/usr/local/bin/${EXECUTABLE}" ];then
EXE="/usr/local/bin/${EXECUTABLE}"
exes=$((exes+1))
fi
if [ -e "/usr/local/bin/${EXECUTABLE}-kiosk" ];then
EXE="/usr/local/bin/${EXECUTABLE}-kiosk"
exes=$((exes+1))
fi
if [ -e "build/FBrowser" ];then
EXE="./build/FBrowser"
else
if [ "$exes" == 2 ]; then
echo "We have detected two versions of fbrowser on your system"
echo "One is standard and another is kiosk mode"
echo "Which one would you like to use ?"
echo "1 -> Standard"
echo "2 -> Kiosk mode"
while true; do
echo 'Enter ID:'
read ans
if [ "$ans" == 1 ];then
EXE="/usr/local/bin/${EXECUTABLE}"
break
elif [ "$ans" == 2 ];then
EXE="/usr/local/bin/${EXECUTABLE}-kiosk"
break
else
echo 'Please enter valid number 1, 2'
echo "You wrote: $ans"
fi
done
fi
fi
if [ "$BACKEND_DEV" == "fb" ];then
# turn off tty1 cursor blinking
setterm -cursor off > /dev/tty1
fi
if [ "$EXE" == "" ];then
echo "Program executable not found, are you compiled or installed the program?"
else
if [ "$ARGS" == "" ];then
$EXE
else
$EXE "${ARGS}"
fi
fi
if [ "$BACKEND_DEV" == "fb" ];then
# clear framebuffer
cat /dev/zero 1>/dev/fb0 2>/dev/null
# back on tt1 cursor blinking
setterm -cursor on > /dev/tty1
fi
}
configure_auto() {
echo "Detecting input devices..."
KEYBOARD=`cat /proc/bus/input/devices | awk '/[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]/{for(a=0;a>=0;a++){getline;{if(/kbd/==1){ print $NF;exit 0;}}}}'`
echo "Keyboard found as: $KEYBOARD"
MOUSE=`cat /proc/bus/input/devices | awk '/[Kk][Ee][Yy][Bb][Oo][Aa][Rr][Dd]/{for(a=0;a>=0;a++){getline;{if(/mouse/==1){ print $NF;exit 0;}}}}'`
echo "Mouse/Touchpad found as: $MOUSE"
save_setting "KEYBOARD_DEV" ${KEYBOARD}
save_setting "MOUSE_DEV" ${MOUSE}
save_setting "BACKEND_DEV" fb
echo "We detected only these devices, keep in mind that devices might be detected incorrectly, depending on your configuration"
echo "If you have many devices, like running laptop with touchscreen, touchpad and mouse or keyboard attached, please configure manually"
echo "Also note that depending on configuration, linux can mix devices names (/dev/input/eventX) on every boot"
echo "It's very adviceable to use udev rules, making the devices symlinked with the static names"
echo "Please read more about static device name: https://www.emanuelepapa.dev/assign-static-device-name-using-udev-rules/"
echo "Thank you for understanding!"
read -n 1 -s -r -p "Press any key to continue"
}
confirm_dialog() {
while true; do
echo 'Are you sure "y/n" ?:'
read confirmation
if [ "$confirmation" == "y" ]; then
echo "$confirmation"
break
elif [ "$confirmation" == "n" ];then
echo "$confirmation"
break
else
echo 'Please enter valid answer "y/n"'
fi
done
}
# Save setting
save_setting() {
local name=${1//\//\\/}
local value=${2//\//\\/}
if [ ! -d "$HOME/.config/fbrowser" ];then
mkdir -p "$HOME/.config/fbrowser"
fi
if [ ! -e "$HOME/.config/fbrowser/config" ];then
echo "" > "$HOME/.config/fbrowser/config"
fi
sed -i \
-e '/^#\?\(\s*'"${name}"'\s*=\s*\).*/{s//\1'"${value}"'/;:a;n;ba;q}' \
-e '$a'"${name}"'='"${value}" "$HOME/.config/fbrowser/config"
}
# del setting based on device name
del_setting() {
local SETTING="$1"
echo "Deleting setting $SETTING"
sed -i '/$SETTING/d' "$HOME/.config/fbrowser/config"
}
config_device() {
local dev=$1
name=`cat /sys/class/input/event${1}/device/name`
echo "Configuring ${name} ID: ${dev}"
while true; do
echo 'Enter ID or b (back), q (quit):'
echo '0 -> None (remove setting if exists)'
echo '1 -> Keyboard'
echo '2 -> Mouse'
echo '3 -> Touchpad'
echo '4 -> Touchscreen'
read devtip
if [ -n "$devtip" ] && [ "$devtip" -eq "$devtip" ] 2>/dev/null; then
confirm_dialog
if [ $confirmation == "y" ];then
echo "You confirmed and we are proceeding to save the setting.."
# remove setting
if [ "$devtip" == 0 ];then
del_setting "event${dev}"
echo "Settings deleted!"
# keyboard
elif [ "$devtip" == 1 ];then
echo "You selected keyboard"
save_setting "KEYBOARD_DEV" event${dev}
echo "Settings saved!"
# mouse
elif [ "$devtip" == 2 ];then
echo "You have selected Mouse"
save_setting "MOUSE_DEV" event${dev}
echo "Settings saved!"
# touchpad
elif [ "$devtip" == 3 ];then
echo "You have selected Touchpad"
save_setting "TOUCHPAD_DEV" event${dev}
echo "Settings saved!"
# touchscreen
elif [ "$devtip" == 4 ];then
echo "You have selected Touchscreen"
save_setting "TOUCHSCREEN_DEV" event${dev}
echo "Settings saved!"
else
echo "Wrong device type specified, aborting.."
fi
fi
break
elif [ "$devtip" == "b" ];then
break
elif [ "$devtip" == "q" ];then
exit 1
else
echo 'Please enter valid number or b (back), q (quit)'
echo "You wrote: $devtip"
fi
done
}
configure_manual() {
echo -e "\n\n\nSelect video backend:"
echo "1 -> linux framebuffer (default fb)"
echo "2 -> egls implementation using kernel mode setting and video card drivers (works only with supported video cards)"
if [[ $(grep "BACKEND_DEV" "$HOME/.config/fbrowser/config") ]]; then
echo "3 -> continue without (use previous settings)"
fi
while true; do
echo 'Enter ID:'
read vga
if [ "$vga" == 1 ];then
echo "You have selected fb"
save_setting "BACKEND_DEV" "fb"
echo "Settings saved!"
break
elif [ "$vga" == 2 ];then
echo "You have selected eglfs"
save_setting "BACKEND_DEV" "eglfs"
echo "Settings saved!"
break
elif [ "$vga" == 3 ];then
break
else
echo 'Please enter valid number'
echo "You wrote: $vga"
fi
done
echo -e "\n\n\nInput device list: "
while true; do
find /dev/input/ -maxdepth 1 -exec basename {} \;|grep -o '[[:digit:]]\+'|sort -un|awk '{dev=$1;printf "ID: " $0" Name: ";system("cat /sys/class/input/event"dev"/device/name");}'
echo "Enter device ID (number) which you want to configure, q to exit: "
while true; do
echo 'Enter ID:'
read dev
if [ -n "$dev" ] && [ "$dev" -eq "$dev" ] 2>/dev/null; then
config_device $dev
break
elif [ "$dev" == "b" ];then
break
elif [ "$dev" == "q" ];then
exit 1
else
echo 'Please enter valid number or q (quit)'
echo "You wrote: $dev"
fi
done
done
}
need_configure() {
echo -e "\n\n\nWe where unable to load application settings!!!"
echo "You will have to configure it"
echo "Make your choice:"
echo "1 -> Configure automatically"
echo "2 -> Configure manually"
echo "3 -> Reset config"
echo "4 -> Exit"
while true; do
echo 'Enter ID:'
read ans
if [ "$ans" == 1 ];then
configure_auto
break
elif [ "$ans" == 2 ];then
configure_manual
break
elif [ "$ans" == 3 ];then
if [ ! -d "$HOME/.config/fbrowser" ];then
mkdir -p "$HOME/.config/fbrowser"
fi
echo "" > $HOME/.config/fbrowser/config
echo "Configuration reset done!"
elif [ "$ans" == 4 ];then
exit 0
else
echo 'Please enter valid number 1, 2, 3 or 4 (quit)'
echo "You wrote: $ans"
fi
done
}
test_hardware() {
echo "Not implemented yet!"
}
test_devices() {
#type evtest >/dev/null 2>&1 || { echo >&2 "The required tool 'evtest' was not found. Aborting."; exit 1; }
while true; do
find /dev/input/ -maxdepth 1 -exec basename {} \;|grep -o '[[:digit:]]\+'|sort -un|awk '{dev=$1;printf "ID: " $0" Name: ";system("cat /sys/class/input/event"dev"/device/name");}'
echo "Enter device ID (number) which you want to test, q to exit: "
while true; do
echo 'Enter ID:'
read dev
if [ -n "$dev" ] && [ "$dev" -eq "$dev" ] 2>/dev/null; then
evtest /dev/input/event${dev}
break
elif [ "$dev" == "q" ];then
exit 1
else
echo 'Please enter valid number or q (quit)'
echo "You wrote: $dev"
fi
done
done
}
banner() {
echo "Welcome to Framebuffer browser (c) 2022 e1z0"
echo "https://github.com/e1z0/Framebuffer-browser"
echo -e "\n\nThe following parameters are available:"
echo "$0 configure -> manually configure the browser"
echo "$0 autoconfigure -> try to automatically configure the browser"
echo "$0 reset -> reset configuration"
echo "$0 testinput -> test device input capabilities"
echo "$0 test -> test hardware capabilities"
exit 0
}
main() {
if [ ! -d "$HOME/.config/fbrowser" ];then
need_configure
fi
load_settings
launch
}
static_settings
if [ "$1" = "-h" -o "$1" = "--help" ]; then
banner
exit 0
fi
if [ "$1" = "configure" ];then
configure_manual
exit 0
fi
if [ "$1" = "autoconfigure" ];then
configure_auto
exit 0
fi
if [ "$1" = "reset" ];then
echo "" > $HOME/.config/fbrowser/config
echo "Done"
exit 0
fi
if [ "$1" = "test" ];then
test_hardware
exit 0
fi
if [ "$1" = "testinput" ];then
test_devices
exit 0
fi
main