~mil/sxmo-utils

ref: 5b705dc91b5ef06268ed00cb22bbed40c754c2de sxmo-utils/scripts/core/sxmo_inputhandler.sh -rwxr-xr-x 5.0 KiB
5b705dc9baroque reduce notification spam in volume/brightness 4 months ago
                                                                                
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
#!/usr/bin/env sh

# This script handles input actions, it is called by lisgd for gestures
# and by dwm for button presses

ACTION="$1"

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

lock_screen() {
	if [ "$SXMO_LOCK_SCREEN_OFF" = "1" ]; then
		sxmo_screenlock.sh off
	else
		sxmo_screenlock.sh lock
	fi
	if [ "$SXMO_LOCK_SUSPEND" = "1" ]; then
		sxmo_screenlock.sh crust
	fi
}

XPROPOUT="$(sxmo_wm.sh focusedwindow)"
WMCLASS="$(printf %s "$XPROPOUT" | grep app: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]')"
WMNAME="$(printf %s "$XPROPOUT" | grep title: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]')"

if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler ]; then
	#hook script must exit with a zero exit code ONLY if it has handled the gesture!
	"$XDG_CONFIG_HOME"/sxmo/hooks/inputhandler "$WMCLASS" "$WMNAME" "$@" && exit
fi

if [ "$(sxmo_screenlock.sh getCurState)" != "unlock" ]; then
	case "$ACTION" in
		"volup_three")
			sxmo_screenlock.sh crust
			;;
		"voldown_three")
			if [ "$(sxmo_screenlock.sh getCurState)" = "lock" ]; then
				sxmo_screenlock.sh off
			else
				lock_screen
			fi
			;;
		"powerbutton_three")
			sxmo_screenlock.sh unlock
			;;
	esac
	exit
fi

if sxmo_dmenu.sh isopen; then
	case "$ACTION" in
		"volup_one")
			sxmo_type.sh -k Up
			exit
			;;
		"voldown_one")
			sxmo_type.sh -k Down
			exit
			;;
		"powerbutton_one")
			sxmo_type.sh -k Return
			exit
			;;
	esac
fi

#special context-sensitive handling
case "$WMCLASS" in
	*"foot"*)
		# First we try to handle the app running inside st:
		case "$WMNAME" in
			*"tuir"*)
				if [ "$ACTION" = "rightbottomcorner" ]; then
					sxmo_type.sh o
					exit 0
				elif [ "$ACTION" = "leftbottomcorner" ]; then
					sxmo_type.sh s
					exit 0
				fi
				;;
			*"less"*)
				case "$ACTION" in
					"leftbottomcorner")
						sxmo_type.sh q
						exit 0
						;;
					"leftrightcorner_short")
						sxmo_type.sh q
						exit 0
						;;
					*"onedown")
						sxmo_type.sh u
						exit 0
						;;
					*"oneup")
						sxmo_type.sh d
						exit 0
						;;
					*"oneleft")
						sxmo_type.sh ":n" -k Return
						exit 0
						;;
					*"oneright")
						sxmo_type.sh ":p" -k Return
						exit 0
						;;
				esac
				;;
			*"amfora"*)
				case "$ACTION" in
					"downright")
						sxmo_type.sh -k Tab
						exit 0
						;;
					"upleft")
						sxmo_type.sh -M Shift -k Tab
						exit 0
						;;
					*"onedown")
						sxmo_type.sh u
						exit 0
						;;
					*"oneup")
						sxmo_type.sh d
						exit 0
						;;
					*"oneright")
						sxmo_type.sh -k Return
						exit 0
						;;
					"upright")
						sxmo_type.sh -M Ctrl t
						exit 0
						;;
					*"oneleft")
						sxmo_type.sh b
						exit 0
						;;
					"downleft")
						sxmo_type.sh -M Ctrl w
						exit 0
						;;
				esac
				;;
		esac
		# Now we try generic st actions
		case "$ACTION" in
			*"onedown")
				sxmo_type.sh -M Shift -k Page_Up
				exit 0
				;;
			*"oneup")
				sxmo_type.sh -M Shift -k Page_Down
				exit 0
				;;
		esac
esac

#standard handling
case "$ACTION" in
	"powerbutton_one")
		if echo "$WMCLASS" | grep -i "megapixels"; then
			sxmo_type.sh -k space
		else
			sxmo_keyboard.sh toggle
		fi
			exit 0
		;;
	"powerbutton_two")
		sxmo_blinkled.sh blue; $TERMCMD "$SHELL"
		exit 0
		;;
	"powerbutton_three")
		sxmo_blinkled.sh blue; $BROWSER
		exit 0
		;;
	"voldown_one")
		swaymsg layout toggle splith splitv tabbed
		exit
		;;
	"voldown_two")
		swaymsg focus tiling
		exit
		;;
	"voldown_three")
		sxmo_killwindow.sh
		exit
		;;
	"volup_one")
		sxmo_appmenu.sh
		exit
		;;
	"volup_two")
		sxmo_appmenu.sh sys
		exit
		;;
	"volup_three")
		lock_screen
		exit
		;;
	"rightleftcorner")
		sxmo_workspace.sh previous
		exit 0
		;;
	"leftrightcorner")
		sxmo_workspace.sh next
		exit 0
		;;
	"twoleft")
		sxmo_workspace.sh move-previous
		exit 0
		;;
	"tworight")
		sxmo_workspace.sh move-next
		exit 0
		;;
	"righttopcorner")
		sxmo_brightness.sh up &
		exit 0
		;;
	"lefttopcorner")
		sxmo_brightness.sh down &
		exit 0
		;;
	"upleftcorner")
		sxmo_vol.sh up &
		exit 0
		;;
	"downleftcorner")
		sxmo_vol.sh down &
		exit 0
		;;
	"upbottomcorner")
		sxmo_keyboard.sh open
		exit 0
		;;
	"downbottomcorner")
		sxmo_keyboard.sh close
		exit 0
		;;
	"downtopcorner")
		sxmo_dmenu.sh isopen || sxmo_appmenu.sh &
		exit 0
		;;
	"twodowntopcorner")
		sxmo_dmenu.sh isopen || sxmo_appmenu.sh sys &
		exit 0
		;;
	"uptopcorner")
		sxmo_dmenu.sh close
		dunstctl close-all
		exit 0
		;;
	"twodownbottomcorner")
		sxmo_killwindow.sh
		exit 0
		;;
	"uprightcorner")
		sxmo_type.sh -k Up
		exit 0
		;;
	"downrightcorner")
		sxmo_type.sh -k Down
		exit 0
		;;
	"leftrightcorner_short")
		sxmo_type.sh -k Left
		exit 0
		;;
	"rightrightcorner_short")
		sxmo_type.sh -k Right
		exit 0
		;;
	"rightbottomcorner")
		sxmo_type.sh -k Return
		exit 0
		;;
	"leftbottomcorner")
		sxmo_type.sh -k BackSpace
		exit 0
		;;
	"topleftcorner")
		sxmo_appmenu.sh sys &
		exit 0
		;;
	"toprightcorner")
		sxmo_appmenu.sh scripts &
		exit 0
		;;
	"bottomleftcorner")
		sxmo_dmenu.sh close && lock_screen
		exit 0
		;;
	"bottomrightcorner")
		sxmo_rotate.sh &
		exit 0
		;;
esac