forked from mattgyver83/flipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flipper.sh
executable file
·183 lines (154 loc) · 3.72 KB
/
flipper.sh
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
#!/bin/bash
# script for using acer r3-471t in "tablet mode"
# disables keyboard and touchpad with a reversable mode
# update the config section to match the device names or id gathered by xinput
## config ##
###############
keyboard_name='AT Translated Set 2 keyboard' # can be id or name
touchpad_name='SYN1B7B:01 06CB:2969 UNKNOWN' # can be id or name
osd_bin='/usr/bin/onboard'
notify='on' #set to anything else to disable
debug='off' #set to on for verbose output or run with -v
###############
## end ##
##### function area #####
function disable_keyboard {
xinput disable "$keyboard_name"
if [ $debug = "on" ]; then
echo "I: Keyboard Disabled"
fi
}
function enable_keyboard {
xinput enable "$keyboard_name"
if [ $debug = "on" ]; then
echo "I: Keyboard Enabled"
fi
}
function get_keyboard_state {
kbstate=$(xinput list-props "$keyboard_name" | grep Enabled | awk '{print $4}')
}
function print_keyboard_state {
if [ $debug = "on" ]; then
echo "I: Keyboard: '$keyboard_name' Current State: $kbstate"
if [ $kbstate != 0 ]; then
echo "I: assuming keyboard enabled.."
else
echo "I: assuming keyboard disabled.."
fi
fi
}
function set_keyboard_state {
print_keyboard_state
if [ $kbstate != 0 ]; then
disable_keyboard
eval '$osd_bin &'
else
enable_keyboard
eval "/usr/bin/pkill -f $osd_bin"
fi
}
function get_touchpad_state {
tpstate=$(xinput list-props "$touchpad_name" | grep Enabled | awk '{print $4}')
}
function print_touchpad_state {
if [ $debug = "on" ]; then
echo "I: Touchpad: '$touchpad_name' Current State: $tpstate"
if [ $tpstate != 0 ]; then
echo "I: assuming touchpad enabled.."
else
echo "I: assuming touchpad disabled.."
fi
fi
}
function set_touchpad_state {
print_touchpad_state
if [ $tpstate != 0 ]; then
disable_touchpad
else
enable_touchpad
fi
}
function disable_touchpad {
xinput disable "$touchpad_name"
if [ $debug = "on" ]; then
echo "I: Touchpad Disabled"
fi
}
function enable_touchpad {
xinput enable "$touchpad_name"
if [ $debug = "on" ]; then
echo "I: Touchpad Enabled"
fi
}
function notify_user {
# This will only work if notify=on and libnotify and notify-send are installed
# Logic currently permits this from prompting on start and only prompts on end
# Currently reporting is incorrect, unclear or proper order yet
if [ $notify = "on" ]; then
if ([ $tpstate = 0 ] && [ $kbstate = 0 ]); then
notify-send -i computer "Disabling Tablet mode"
else
notify-send -i input-tablet "Enabling Tablet mode"
fi
fi
}
function error_detection {
if [ $kbstate != $tpstate ]; then
echo "E: Incostitent States detected"
echo "E: Touchpad: '$touchpad_name' Current State = $tpstate"
echo "E: Keyboard: '$keyboard_name' Current State = $kbstate"
echo "E: Manually correct states in order for flipper to work"
if [ $notify = "on" ]; then
notify-send -i dialog-error "Not enabling tablet mode due to state errors, use -n to view"
fi
exit
fi
}
function get_input_states {
get_touchpad_state
get_keyboard_state
}
function toggle_tablet_mode {
set_touchpad_state
set_keyboard_state
}
function flipper_go {
get_input_states
error_detection
notify_user
toggle_tablet_mode
}
function flipper_go_dry {
get_input_states
print_touchpad_state
print_keyboard_state
}
#########################
## end ##
##### argument area #####
while getopts "vn" opt; do
case $opt in
v)
echo "I: verbose debugging enabled"
debug="on"
flipper_go
exit
;;
n)
echo "I: Dry-run, reporting state information only!"
debug="on"
flipper_go_dry
echo "I: TURN THIS THING OFF IM DRYYYYYYY"
exit
;;
\?)
echo "Invalid argument, quitting"
exit
;;
esac
done
#########################
## end ##
# exec w/o args
flipper_go
exit