xref: /third_party/libinput/src/quirks.h (revision a46c0ec8)
1/*
2 * Copyright © 2018 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#pragma once
25
26#include "config.h"
27
28#include <stdbool.h>
29#include <stdint.h>
30
31#include <libudev.h>
32
33#include "libinput.h"
34
35/**
36 * Handle to the quirks context.
37 */
38struct quirks_context;
39
40/**
41 * Contains all quirks set for a single device.
42 */
43struct quirks;
44
45struct quirk_dimensions {
46	size_t x, y;
47};
48
49struct quirk_range {
50	int lower, upper;
51};
52
53struct quirk_tuples {
54	struct {
55		int first;
56		int second;
57		int third;
58	} tuples[32];
59	size_t ntuples;
60};
61
62/**
63 * Quirks known to libinput
64 */
65enum quirk {
66	QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD = 100,
67	QUIRK_MODEL_APPLE_TOUCHPAD,
68	QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON,
69	QUIRK_MODEL_BOUNCING_KEYS,
70	QUIRK_MODEL_CHROMEBOOK,
71	QUIRK_MODEL_CLEVO_W740SU,
72	QUIRK_MODEL_DELL_CANVAS_TOTEM,
73	QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD,
74	QUIRK_MODEL_HP_ZBOOK_STUDIO_G3,
75	QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING,
76	QUIRK_MODEL_LENOVO_SCROLLPOINT,
77	QUIRK_MODEL_LENOVO_T450_TOUCHPAD,
78	QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD,
79	QUIRK_MODEL_LENOVO_X230,
80	QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD,
81	QUIRK_MODEL_SYSTEM76_BONOBO,
82	QUIRK_MODEL_SYSTEM76_GALAGO,
83	QUIRK_MODEL_SYSTEM76_KUDU,
84	QUIRK_MODEL_TABLET_MODE_NO_SUSPEND,
85	QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE,
86	QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER,
87	QUIRK_MODEL_TRACKBALL,
88	QUIRK_MODEL_WACOM_TOUCHPAD,
89	QUIRK_MODEL_PRESSURE_PAD,
90	QUIRK_MODEL_TOUCHPAD_PHANTOM_CLICKS,
91
92	_QUIRK_LAST_MODEL_QUIRK_, /* Guard: do not modify */
93
94	QUIRK_ATTR_SIZE_HINT = 300,
95	QUIRK_ATTR_TOUCH_SIZE_RANGE,
96	QUIRK_ATTR_PALM_SIZE_THRESHOLD,
97	QUIRK_ATTR_LID_SWITCH_RELIABILITY,
98	QUIRK_ATTR_KEYBOARD_INTEGRATION,
99	QUIRK_ATTR_TRACKPOINT_INTEGRATION,
100	QUIRK_ATTR_TPKBCOMBO_LAYOUT,
101	QUIRK_ATTR_PRESSURE_RANGE,
102	QUIRK_ATTR_PALM_PRESSURE_THRESHOLD,
103	QUIRK_ATTR_RESOLUTION_HINT,
104	QUIRK_ATTR_TRACKPOINT_MULTIPLIER,
105	QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD,
106	QUIRK_ATTR_USE_VELOCITY_AVERAGING,
107	QUIRK_ATTR_TABLET_SMOOTHING,
108	QUIRK_ATTR_THUMB_SIZE_THRESHOLD,
109	QUIRK_ATTR_MSC_TIMESTAMP,
110	QUIRK_ATTR_EVENT_CODE,
111	QUIRK_ATTR_INPUT_PROP,
112
113	_QUIRK_LAST_ATTR_QUIRK_, /* Guard: do not modify */
114};
115
116/**
117 * Returns a printable name for the quirk. This name is for developer
118 * tools, not user consumption. Do not display this in a GUI.
119 */
120const char*
121quirk_get_name(enum quirk q);
122
123/**
124 * Log priorities used if custom logging is enabled.
125 */
126enum quirks_log_priorities {
127	QLOG_NOISE,
128	QLOG_DEBUG = LIBINPUT_LOG_PRIORITY_DEBUG,
129	QLOG_INFO = LIBINPUT_LOG_PRIORITY_INFO,
130	QLOG_ERROR = LIBINPUT_LOG_PRIORITY_ERROR,
131	QLOG_PARSER_ERROR,
132};
133
134/**
135 * Log type to be used for logging. Use the libinput logging to hook up a
136 * libinput log handler. This will cause the quirks to reduce the noise and
137 * only provide useful messages.
138 *
139 * QLOG_CUSTOM_LOG_PRIORITIES enables more fine-grained and verbose logging,
140 * allowing debugging tools to be more useful.
141 */
142enum quirks_log_type {
143	QLOG_LIBINPUT_LOGGING,
144	QLOG_CUSTOM_LOG_PRIORITIES,
145};
146
147/**
148 * Initialize the quirks subsystem. This function must be called
149 * before anything else.
150 *
151 * If log_type is QLOG_CUSTOM_LOG_PRIORITIES, the log handler is called with
152 * the custom QLOG_* log priorities. Otherwise, the log handler only uses
153 * the libinput log priorities.
154 *
155 * @param data_path The directory containing the various data files
156 * @param override_file A file path containing custom overrides
157 * @param log_handler The libinput log handler called for debugging output
158 * @param libinput The libinput struct passed to the log handler
159 *
160 * @return an opaque handle to the context
161 */
162struct quirks_context *
163quirks_init_subsystem(const char *data_path,
164		      const char *override_file,
165		      libinput_log_handler log_handler,
166		      struct libinput *libinput,
167		      enum quirks_log_type log_type);
168
169/**
170 * Clean up after ourselves. This function must be called
171 * as the last call to the quirks subsystem.
172 *
173 * All quirks returned to the caller in quirks_fetch_for_device() must be
174 * unref'd before this call.
175 *
176 * @return Always NULL
177 */
178struct quirks_context *
179quirks_context_unref(struct quirks_context *ctx);
180
181struct quirks_context *
182quirks_context_ref(struct quirks_context *ctx);
183
184/**
185 * Fetch the quirks for a given device. If no quirks are defined, this
186 * function returns NULL.
187 *
188 * @return A new quirks struct, use quirks_unref() to release
189 */
190struct quirks *
191quirks_fetch_for_device(struct quirks_context *ctx,
192			struct udev_device *device);
193
194/**
195 * Reduce the refcount by one. When the refcount reaches zero, the
196 * associated struct is released.
197 *
198 * @return Always NULL
199 */
200struct quirks *
201quirks_unref(struct quirks *q);
202
203/**
204 * Returns true if the given quirk applies is in this quirk list.
205 */
206bool
207quirks_has_quirk(struct quirks *q, enum quirk which);
208
209/**
210 * Get the value of the given quirk, as unsigned integer.
211 * This function will assert if the quirk type does not match the
212 * requested type. If the quirk is not set for this device, val is
213 * unchanged.
214 *
215 * @return true if the quirk value is valid, false otherwise.
216 */
217bool
218quirks_get_uint32(struct quirks *q,
219		  enum quirk which,
220		  uint32_t *val);
221
222/**
223 * Get the value of the given quirk, as signed integer.
224 * This function will assert if the quirk type does not match the
225 * requested type. If the quirk is not set for this device, val is
226 * unchanged.
227 *
228 * @return true if the quirk value is valid, false otherwise.
229 */
230bool
231quirks_get_int32(struct quirks *q,
232		 enum quirk which,
233		 int32_t *val);
234
235/**
236 * Get the value of the given quirk, as double.
237 * This function will assert if the quirk type does not match the
238 * requested type. If the quirk is not set for this device, val is
239 * unchanged.
240 *
241 * @return true if the quirk value is valid, false otherwise.
242 */
243bool
244quirks_get_double(struct quirks *q,
245		  enum quirk which,
246		  double *val);
247
248/**
249 * Get the value of the given quirk, as string.
250 * This function will assert if the quirk type does not match the
251 * requested type. If the quirk is not set for this device, val is
252 * unchanged.
253 *
254 * val is set to the string, do not modify or free it. The lifetime of the
255 * returned string is bound to the lifetime of the quirk.
256 *
257 * @return true if the quirk value is valid, false otherwise.
258 */
259bool
260quirks_get_string(struct quirks *q,
261		  enum quirk which,
262		  char **val);
263
264/**
265 * Get the value of the given quirk, as bool.
266 * This function will assert if the quirk type does not match the
267 * requested type. If the quirk is not set for this device, val is
268 * unchanged.
269 *
270 * @return true if the quirk value is valid, false otherwise.
271 */
272bool
273quirks_get_bool(struct quirks *q,
274		enum quirk which,
275		bool *val);
276
277/**
278 * Get the value of the given quirk, as dimension.
279 * This function will assert if the quirk type does not match the
280 * requested type. If the quirk is not set for this device, val is
281 * unchanged.
282 *
283 * @return true if the quirk value is valid, false otherwise.
284 */
285bool
286quirks_get_dimensions(struct quirks *q,
287		      enum quirk which,
288		      struct quirk_dimensions *val);
289
290/**
291 * Get the value of the given quirk, as range.
292 * This function will assert if the quirk type does not match the
293 * requested type. If the quirk is not set for this device, val is
294 * unchanged.
295 *
296 * @return true if the quirk value is valid, false otherwise.
297 */
298bool
299quirks_get_range(struct quirks *q,
300		 enum quirk which,
301		 struct quirk_range *val);
302
303/**
304 * Get the tuples of the given quirk.
305 * This function will assert if the quirk type does not match the
306 * requested type. If the quirk is not set for this device, tuples is
307 * unchanged.
308 *
309 * @return true if the quirk value is valid, false otherwise.
310 */
311bool
312quirks_get_tuples(struct quirks *q,
313		  enum quirk which,
314		  const struct quirk_tuples **tuples);
315
316/**
317 * Get the uint32 array of the given quirk.
318 * This function will assert if the quirk type does not match the
319 * requested type. If the quirk is not set for this device, tuples is
320 * unchanged.
321 *
322 * @return true if the quirk value is valid, false otherwise.
323 */
324bool
325quirks_get_uint32_array(struct quirks *q,
326			enum quirk which,
327			const uint32_t **array,
328			size_t *nelements);
329