-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouch
More file actions
executable file
·147 lines (136 loc) · 4.76 KB
/
touch
File metadata and controls
executable file
·147 lines (136 loc) · 4.76 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
#!/bin/bash
verbosity=$(echo "$@" | grep -q '.-v'; echo "${PIPESTATUS[1]}")
if [[ $verbosity = 0 ]]; then
verbose=true
else
verbose=false
fi
helptext(){
echo "Touch-Input control"
echo -e "USAGE:\ttouch [OPTIONS]"
echo -e "OPTIONS:"
echo -e "\t-m [Absolute|Relative]\tset input mode to absolute or relative"
echo -e "\t-t [time]\t\tdefine popup duration in [seconds]"
echo -e "\t-d [DISPLAY]\t\tset output display to map touch\n\t\t\t\tinput to (e.g. LVDS-1)"
echo -e "\t-q\t\t\tDisable popup message"
echo -e "\t-v\t\t\tverbose"
echo -e "\t-h\t\t\tPrint this help message."
}
explain(){
if [[ $verbose = true ]]; then
echo "$@"
fi
}
get_displays(){
displays_found=""
while read disp; do
grepstring="-e $disp"
displays_found="$displays_found $grepstring"
done < <(xrandr --listmonitors | awk '{print $NF}' | tail -n +2)
echo "$displays_found"
}
xct(){
explain "Detect the name of the display in use"
local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
explain "Display: $display"
explain "executing command $@"
sudo -u kallefornia env -i DISPLAY=${display} DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /bin/bash -c "$@"
}
explain "setting default variables:"
popup_duration=5
output_display="LVDS-1"
mode="absolute"
sleep_time=0
quiet=false
explain "popup_duration=$popup_duration"
explain "output_display=$output_display"
explain "mode=$mode"
explain "quiet=$quiet"
explain "verbose=$verbose"
explain "checking for command options"
while getopts m:t:d:s:vqh flags; do
case $flags in
m)
explain "matched option '-m', checking if arguments are valid..."
mode_match=$(echo $OPTARG | grep -q -e Relative -e Absolute; echo ${PIPESTATUS[1]})
explain "check returned the following result: $mode_match"
if [[ $mode_match = 0 ]]; then
mode="$OPTARG"
explain "mode set to $mode"
else
echo -e "\tError: option '-m' must be followed by"
echo -e "\t'Absolute' or 'Relative'"
exit 1
fi
;;
t)
explain "matched option '-t'"
popup_duration="$OPTARG"
explain "setting popup_duration to $popup_duration, checking if arguments are valid..."
re_isanum='^[0-9]+$' # Regex: match whole numbers only
if ! [[ $popup_duration =~ $re_isanum ]] ; then # if $TIMES not whole:
echo -e "\tError:\t-t <NUMBER> must be a positive, whole number."
exit 1
elif [[ popup_duration = ? ]]; then
echo -e "\tError:\t-t <NUMBER> not recognised, setting to default"
echo -e "\t\t(5 seconds)"
popup_duration=5
fi
;;
d)
explain "matched option '-d', looking for available displays"
disp_grep=$(get_displays)
explain "found these displays to check argument against: $disp_grep"
explain "checking if arguments are valid..."
display_match=$(echo $OPTARG | grep -iq $disp_grep; echo ${PIPESTATUS[1]})
explain "check returned the following result: $display_match"
if [[ $display_match = 0 ]]; then
output_display="$OPTARG"
explain "output_display set to $output_display"
else
disp_help="$(echo $disp_grep | sed 's/-e//g')"
echo -e "\tError: option '-d' must be followed by"
echo -e "\ta valid display name: [$disp_help]"
exit 1
fi
;;
s)
sleep_time="$OPTARG"
;;
:)
echo -e "\tError: -$OPTARG needs an argument."
helptext
;;
v)
explain "verbose is true"
verbose=true
;;
q)
explain "quiet is true"
quiet=true
;;
h)
helptext
exit 0
;;
*)
echo -e "\tError: $@ not a valid option"
helptext
exit 1
;;
esac
done
sleep $sleep_time
explain "running for loop for input methods (9, 10, 15)"
for id in 9 10 15; do
explain "Mapping device no. $id to $output_display"
xct "xsetwacom --set $id MapToOutput $output_display"
explain "setting mode for device no $id to $mode"
xct "xsetwacom --set $id Mode $mode"
done
if [[ $quiet = false ]]; then
popup_duration_sec=$((popup_duration * 1000))
explain "starting popup for $popup_duration seconds"
xct "notify-send --expire-time=$popup_duration_sec Touch-Input 'Touch input mapped to $output_display in $mode mode.'"
fi
exit 0