-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfunctions.sh
More file actions
143 lines (126 loc) · 3.26 KB
/
functions.sh
File metadata and controls
143 lines (126 loc) · 3.26 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
function prepare_fullscreen {
clear
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
}
function show_prompt {
prompt=$1
if [[ -z ${2+x} ]]; then
style='banner'
else
style=$2
fi
figlet -c -w 180 -f $style -k -- "$prompt"
echo ""
echo ""
echo ""
}
function block_until_press_on_target {
TARGET_X_MIN=26500
TARGET_Y_MIN=25000
TARGET_X_MAX=37000
TARGET_Y_MAX=42000
TOUCHSCREEN_ID=$(xinput --list 2>/dev/null | grep -i -m 1 'touch' | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')
touch_x=0
touch_y=0
while (( $touch_x < $TARGET_X_MIN )) || (( $touch_x > $TARGET_X_MAX )) || (( $touch_y < $TARGET_Y_MIN )) || (( $touch_y > $TARGET_Y_MAX )); do
_show_run_prompt
block_until_mouse_click
touch_state=$(xinput --query-state $TOUCHSCREEN_ID 2>/dev/null)
if [[ $touch_state =~ valuator\[0]=([0-9]*) ]]; then
touch_x=${BASH_REMATCH[1]}
fi
if [[ $touch_state =~ valuator\[1]=([0-9]*) ]]; then
touch_y=${BASH_REMATCH[1]}
fi
done
}
function block_until_mouse_click {
echo -e "\e[?1000h"
read -n 12
}
function disable_sleep {
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target >/dev/null 2>&1
}
function reenable_sleep {
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target >/dev/null 2>&1
}
brightness_file=/sys/class/backlight/amdgpu_bl0/brightness
function set_brightness_to_minimum {
# Backup current brightness
cat $brightness_file >./brightness_bak
# Set to minimum
echo 0 >$brightness_file
# Prevent Steam from changing brightness (make read-only)
chmod 444 $brightness_file
}
function restore_brightness {
# Allow Steam to change brightness again (make read-write)
chmod 666 $brightness_file
# Restore original brightness
cat ./brightness_bak >$brightness_file
rm ./brightness_bak
}
function start_virtualhere {
virtualhere/vhusbdx86_64 >/dev/null 2>&1 &
echo $! >./virtualhere_pid
}
function stop_virtualhere {
kill -s SIGINT $(cat ./virtualhere_pid)
wait $(cat ./virtualhere_pid)
rm ./virtualhere_pid
}
function start_prompt {
# Deprecated
prepare_fullscreen
show_prompt "Starting in . . . 3"
sleep 1
prepare_fullscreen
show_prompt "Starting in . . . 2"
sleep 1
prepare_fullscreen
show_prompt "Starting in . . . 1"
sleep 1
}
function quit_prompt {
sleep_time=0.6
prepare_fullscreen
show_prompt "Quitting"
sleep $sleep_time
prepare_fullscreen
show_prompt "Quitting ."
sleep $sleep_time
prepare_fullscreen
show_prompt "Quitting . ."
sleep $sleep_time
prepare_fullscreen
show_prompt "Quitting . . ."
}
function _show_run_prompt {
battery=$(cat /sys/class/power_supply/BAT1/capacity)
prepare_fullscreen
show_prompt "Press to Quit"
show_prompt "-> O <-"
show_prompt "$battery %"
}
function _do_run_prompt {
while true; do
sleep 10
_show_run_prompt
done
}
function run_prompt_start {
_do_run_prompt &
echo $! >./run_prompt_pid
}
function run_prompt_stop {
kill -s SIGKILL $(cat ./run_prompt_pid)
rm ./run_prompt_pid
}