summaryrefslogtreecommitdiff
path: root/completion/zsh/_libinput
blob: e793109a60e87628c5686eb0f40b22ce11a98af7 (plain)
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
#compdef libinput

(( $+functions[_libinput_commands] )) || _libinput_commands()
{
	local -a commands
	commands=(
		"list-devices:List all devices recognized by libinput"
		"debug-events:Print all events as seen by libinput"
		"debug-gui:Show a GUI to visualize libinput's events"
		"debug-tablet:Show tablet axis and button values"
		"measure:Measure various properties of devices"
		"analyze:Analyze device data"
		"record:Record the events from a device"
		"replay:Replay the events from a device"
	)

	_describe -t commands 'command' commands
}

__all_seats()
{
	# Obviously only works with logind
	local -a seats
	seats=${(f)"$(loginctl --no-legend --no-pager list-seats 2>/dev/null)"}
	if [[ -z $seats ]]; then
		# Can always offer seat0, even if we can't enumerate the seats
		compadd "$@" - seat0
	else
		compadd "$@" - $seats
	fi
}

(( $+functions[_libinput_list-devices] )) || _libinput_list-devices()
{
	_arguments \
		'--help[Show help and exit]' \
		'--version[show version information and exit]'
}

(( $+functions[_libinput_debug-events] )) || _libinput_debug-events()
{
	_arguments \
		'--help[Show debug-events help and exit]' \
		'--quiet[Only print libinput messages and nothing from this tool]' \
		'--verbose[Use verbose output]' \
		'--show-keycodes[Make all keycodes visible]' \
		'--grab[Exclusively grab all opened devices]' \
		'--device=[Use the given device with the path backend]:device:_files -W /dev/input/ -P /dev/input/' \
		'--udev=[Listen for notifications on the given seat]:seat:__all_seats' \
		'--apply-to=[Apply configuration options where the device name matches the pattern]:pattern' \
		'--disable-sendevents=[Disable send-events option for the devices matching the pattern]:pattern' \
		'--set-click-method=[Set the desired click method]:click-method:(none clickfinger buttonareas)' \
		'--set-scroll-method=[Set the desired scroll method]:scroll-method:(none twofinger edge button)' \
		'--set-scroll-button=[Set the button to the given button code]' \
		'--set-profile=[Set pointer acceleration profile]:accel-profile:(adaptive flat)' \
		'--set-speed=[Set pointer acceleration speed (within range \[-1, 1\])]' \
		'--set-tap-map=[Set button mapping for tapping]:tap-map:((  \
			lrm\:2-fingers\ right-click\ /\ 3-fingers\ middle-click \
			lmr\:2-fingers\ middle-click\ /\ 3-fingers\ right-click \
		))' \
		+ '(tap-to-click)' \
		'--enable-tap[Enable tap-to-click]' \
		'--disable-tap[Disable tap-to-click]' \
		+ '(drag)' \
		'--enable-drag[Enable tap-and-drag]' \
		'--disable-drag[Disable tap-and-drag]' \
		+ '(drag-lock)' \
		'--enable-drag-lock[Enable drag-lock]' \
		'--disable-drag-lock[Disable drag-lock]' \
		+ '(natural-scrolling)' \
		'--enable-natural-scrolling[Enable natural scrolling]' \
		'--disable-natural-scrolling[Disable natural scrolling]' \
		+ '(left-handed)' \
		'--enable-left-handed[Enable left handed button configuration]' \
		'--disable-left-handed[Disable left handed button configuration]' \
		+ '(middlebutton)' \
		'--enable-middlebutton[Enable middle button emulation]' \
		'--disable-middlebutton[Disable middle button emulation]' \
		+ '(dwt)' \
		'--enable-dwt[Enable disable-while-typing]' \
		'--disable-dwt[Disable disable-while-typing]'
}

(( $+functions[_libinput_debug-gui] )) || _libinput_debug-gui()
{
	_arguments \
		'--help[Show debug-gui help and exit]' \
		'--verbose[Use verbose output]' \
		'--grab[Exclusively grab all opened devices]' \
		'--device=[Use the given device with the path backend]:device:_files -W /dev/input/ -P /dev/input/' \
		'--udev=[Listen for notifications on the given seat]:seat:_libinput_all_seats'
}

(( $+functions[_libinput_debug-tablet] )) || _libinput_debug-tablet()
{
	_arguments \
		'--help[Show debug-tablet help and exit]' \
		'--device=[Use the given device with the path backend]:device:_files -W /dev/input/ -P /dev/input/' \
		'--udev=[Use the first tablet device on the given seat]:seat:_libinput_all_seats'
}


(( $+functions[_libinput_measure] )) || _libinput_measure()
{
	local curcontext=$curcontext state line ret=1
	local features
	features=(
		"fuzz:Measure touch fuzz to avoid pointer jitter"
		"touch-size:Measure touch size and orientation"
		"touchpad-tap:Measure tap-to-click time"
		"touchpad-pressure:Measure touch pressure"
	)

	_arguments -C \
		'--help[Print help and exit]' \
		':feature:->feature' \
		'*:: :->option-or-argument'

	case $state in
		(feature)
			_describe -t features 'feature' features
			;;
		(option-or-argument)
			curcontext=${curcontext%:*:*}:libinput-measure-$words[1]:
			if ! _call_function ret _libinput_measure_$words[1]; then
				_message "unknown feature: $words[1]"
			fi
			;;
	esac
	return ret
}

(( $+functions[_libinput_measure_fuzz] )) || _libinput_measure_fuzz()
{
	_arguments \
		'--help[Show help message and exit]' \
		':device:_files -W /dev/input/ -P /dev/input/'
}

(( $+functions[_libinput_measure_touch-size] )) || _libinput_measure_touch-size()
{
	_arguments \
		'--help[Show help message and exit]' \
		'--touch-threshold=[Assume a touch pressure threshold of "down:up"]' \
		'--palm-threshold=[Assume a palm threshold of N]' \
		':device:_files -W /dev/input/ -P /dev/input/'
}

(( $+functions[_libinput_measure_touchpad-pressure] )) || _libinput_measure_touchpad-pressure()
{
	_arguments \
		'--help[Show help message and exit]' \
		'--touch-threshold=[Assume a touch pressure threshold of "down:up"]' \
		'--palm-threshold=[Assume a palm threshold of N]' \
		':device:_files -W /dev/input/ -P /dev/input/'
}

(( $+functions[_libinput_measure_touchpad-tap] )) || _libinput_measure_touchpad-tap()
{
	_arguments \
		'--help[Show help message and exit]' \
		'--format=dat[Specify the data format to be printed. The default is "summary"]'
		':device:_files -W /dev/input/ -P /dev/input/'
}

(( $+functions[_libinput_analyze] )) || _libinput_analyze()
{
	local curcontext=$curcontext state line ret=1
	local features
	features=(
		"per-slot-delta:analyze relative movement per touch per slot"
	)

	_arguments -C \
		'--help[Print help and exit]' \
		':feature:->feature' \
		'*:: :->option-or-argument'

	case $state in
		(feature)
			_describe -t features 'feature' features
			;;
		(option-or-argument)
			curcontext=${curcontext%:*:*}:libinput-analyze-$words[1]:
			if ! _call_function ret _libinput_analyze_$words[1]; then
				_message "unknown feature: $words[1]"
			fi
			;;
	esac
	return ret
}

(( $+functions[_libinput_record] )) || _libinput_record()
{
	_arguments \
		'--help[Show help message and exit]' \
		'--all[Record all /dev/input/event* devices available on the system]' \
		'--autorestart=[Terminate the current recording after s seconds of device inactivity]' \
		{-o+,--output=}'[Specify the output file to use]:file:_files -g "*.yml"' \
		'--multiple[Record multiple devices at once]' \
		'--show-keycodes[Show keycodes as-is in the recording]' \
		'--with-libinput[Record libinput events alongside device events]' \
		'*::device:_files -W /dev/input/ -P /dev/input/'
}

(( $+functions[_libinput_replay] )) || _libinput_replay()
{
	_arguments \
		'--help[Show help message and exit]' \
		':recording:_files'
}

_libinput()
{
	local curcontext=$curcontext state line ret=1

	_arguments -C \
		{-h,--help}'[Show help message and exit]' \
		'--version[Show version information and exit]' \
		':command:->command' \
		'*:: :->option-or-argument' && return

	case $state in
		(command)
			_libinput_commands && ret=0
			;;
		(option-or-argument)
			curcontext=${curcontext%:*:*}:libinput-$words[1]:
			if ! _call_function ret _libinput_$words[1]; then
				_message "unknown libinput command: $words[1]"
			fi
			;;
	esac
	return ret
}

_libinput