• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
38 struct quirks_context;
39 
40 /**
41  * Contains all quirks set for a single device.
42  */
43 struct quirks;
44 
45 struct quirk_dimensions {
46 	size_t x, y;
47 };
48 
49 struct quirk_range {
50 	int lower, upper;
51 };
52 
53 struct quirk_tuples {
54 	struct {
55 		int first;
56 		int second;
57 	} tuples[32];
58 	size_t ntuples;
59 };
60 
61 /**
62  * Quirks known to libinput
63  */
64 enum quirk {
65 	QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD = 100,
66 	QUIRK_MODEL_APPLE_TOUCHPAD,
67 	QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON,
68 	QUIRK_MODEL_BOUNCING_KEYS,
69 	QUIRK_MODEL_CHROMEBOOK,
70 	QUIRK_MODEL_CLEVO_W740SU,
71 	QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD,
72 	QUIRK_MODEL_HP_STREAM11_TOUCHPAD,
73 	QUIRK_MODEL_HP_ZBOOK_STUDIO_G3,
74 	QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING,
75 	QUIRK_MODEL_LENOVO_L380_TOUCHPAD,
76 	QUIRK_MODEL_LENOVO_SCROLLPOINT,
77 	QUIRK_MODEL_LENOVO_T450_TOUCHPAD,
78 	QUIRK_MODEL_LENOVO_T480S_TOUCHPAD,
79 	QUIRK_MODEL_LENOVO_T490S_TOUCHPAD,
80 	QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD,
81 	QUIRK_MODEL_LENOVO_X230,
82 	QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD,
83 	QUIRK_MODEL_SYSTEM76_BONOBO,
84 	QUIRK_MODEL_SYSTEM76_GALAGO,
85 	QUIRK_MODEL_SYSTEM76_KUDU,
86 	QUIRK_MODEL_TABLET_MODE_NO_SUSPEND,
87 	QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE,
88 	QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER,
89 	QUIRK_MODEL_TRACKBALL,
90 	QUIRK_MODEL_WACOM_TOUCHPAD,
91 	QUIRK_MODEL_DELL_CANVAS_TOTEM,
92 
93 	_QUIRK_LAST_MODEL_QUIRK_, /* Guard: do not modify */
94 
95 
96 	QUIRK_ATTR_SIZE_HINT = 300,
97 	QUIRK_ATTR_TOUCH_SIZE_RANGE,
98 	QUIRK_ATTR_PALM_SIZE_THRESHOLD,
99 	QUIRK_ATTR_LID_SWITCH_RELIABILITY,
100 	QUIRK_ATTR_KEYBOARD_INTEGRATION,
101 	QUIRK_ATTR_TRACKPOINT_INTEGRATION,
102 	QUIRK_ATTR_TPKBCOMBO_LAYOUT,
103 	QUIRK_ATTR_PRESSURE_RANGE,
104 	QUIRK_ATTR_PALM_PRESSURE_THRESHOLD,
105 	QUIRK_ATTR_RESOLUTION_HINT,
106 	QUIRK_ATTR_TRACKPOINT_MULTIPLIER,
107 	QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD,
108 	QUIRK_ATTR_USE_VELOCITY_AVERAGING,
109 	QUIRK_ATTR_THUMB_SIZE_THRESHOLD,
110 	QUIRK_ATTR_MSC_TIMESTAMP,
111 	QUIRK_ATTR_EVENT_CODE_DISABLE,
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  */
120 const char*
121 quirk_get_name(enum quirk which);
122 
123 /**
124  * Log priorities used if custom logging is enabled.
125  */
126 enum 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  */
142 enum 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  */
162 struct quirks_context *
163 quirks_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  */
178 struct quirks_context *
179 quirks_context_unref(struct quirks_context *ctx);
180 
181 struct quirks_context *
182 quirks_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  */
190 struct quirks *
191 quirks_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  */
200 struct quirks *
201 quirks_unref(struct quirks *q);
202 
203 /**
204  * Returns true if the given quirk applies is in this quirk list.
205  */
206 bool
207 quirks_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  */
217 bool
218 quirks_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  */
230 bool
231 quirks_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  */
243 bool
244 quirks_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  */
259 bool
260 quirks_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  */
272 bool
273 quirks_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  */
285 bool
286 quirks_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  */
298 bool
299 quirks_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  */
311 bool
312 quirks_get_tuples(struct quirks *q,
313 		  enum quirk which,
314 		  const struct quirk_tuples **tuples);
315