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_SCROLLPOINT, 76 QUIRK_MODEL_LENOVO_T450_TOUCHPAD, 77 QUIRK_MODEL_LENOVO_TRACKPOINT_KEYBOARD_2, 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_DELL_CANVAS_TOTEM, 90 91 _QUIRK_LAST_MODEL_QUIRK_, /* Guard: do not modify */ 92 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_DISABLE, 111 QUIRK_ATTR_EVENT_CODE_ENABLE, 112 QUIRK_ATTR_INPUT_PROP_DISABLE, 113 QUIRK_ATTR_INPUT_PROP_ENABLE, 114 115 _QUIRK_LAST_ATTR_QUIRK_, /* Guard: do not modify */ 116 }; 117 118 /** 119 * Returns a printable name for the quirk. This name is for developer 120 * tools, not user consumption. Do not display this in a GUI. 121 */ 122 const char* 123 quirk_get_name(enum quirk q); 124 125 /** 126 * Log priorities used if custom logging is enabled. 127 */ 128 enum quirks_log_priorities { 129 QLOG_NOISE, 130 QLOG_DEBUG = LIBINPUT_LOG_PRIORITY_DEBUG, 131 QLOG_INFO = LIBINPUT_LOG_PRIORITY_INFO, 132 QLOG_ERROR = LIBINPUT_LOG_PRIORITY_ERROR, 133 QLOG_PARSER_ERROR, 134 }; 135 136 /** 137 * Log type to be used for logging. Use the libinput logging to hook up a 138 * libinput log handler. This will cause the quirks to reduce the noise and 139 * only provide useful messages. 140 * 141 * QLOG_CUSTOM_LOG_PRIORITIES enables more fine-grained and verbose logging, 142 * allowing debugging tools to be more useful. 143 */ 144 enum quirks_log_type { 145 QLOG_LIBINPUT_LOGGING, 146 QLOG_CUSTOM_LOG_PRIORITIES, 147 }; 148 149 /** 150 * Initialize the quirks subsystem. This function must be called 151 * before anything else. 152 * 153 * If log_type is QLOG_CUSTOM_LOG_PRIORITIES, the log handler is called with 154 * the custom QLOG_* log priorities. Otherwise, the log handler only uses 155 * the libinput log priorities. 156 * 157 * @param data_path The directory containing the various data files 158 * @param override_file A file path containing custom overrides 159 * @param log_handler The libinput log handler called for debugging output 160 * @param libinput The libinput struct passed to the log handler 161 * 162 * @return an opaque handle to the context 163 */ 164 struct quirks_context * 165 quirks_init_subsystem(const char *data_path, 166 const char *override_file, 167 libinput_log_handler log_handler, 168 struct libinput *libinput, 169 enum quirks_log_type log_type); 170 171 /** 172 * Clean up after ourselves. This function must be called 173 * as the last call to the quirks subsystem. 174 * 175 * All quirks returned to the caller in quirks_fetch_for_device() must be 176 * unref'd before this call. 177 * 178 * @return Always NULL 179 */ 180 struct quirks_context * 181 quirks_context_unref(struct quirks_context *ctx); 182 183 struct quirks_context * 184 quirks_context_ref(struct quirks_context *ctx); 185 186 /** 187 * Fetch the quirks for a given device. If no quirks are defined, this 188 * function returns NULL. 189 * 190 * @return A new quirks struct, use quirks_unref() to release 191 */ 192 struct quirks * 193 quirks_fetch_for_device(struct quirks_context *ctx, 194 struct udev_device *device); 195 196 /** 197 * Reduce the refcount by one. When the refcount reaches zero, the 198 * associated struct is released. 199 * 200 * @return Always NULL 201 */ 202 struct quirks * 203 quirks_unref(struct quirks *q); 204 205 /** 206 * Returns true if the given quirk applies is in this quirk list. 207 */ 208 bool 209 quirks_has_quirk(struct quirks *q, enum quirk which); 210 211 /** 212 * Get the value of the given quirk, as unsigned integer. 213 * This function will assert if the quirk type does not match the 214 * requested type. If the quirk is not set for this device, val is 215 * unchanged. 216 * 217 * @return true if the quirk value is valid, false otherwise. 218 */ 219 bool 220 quirks_get_uint32(struct quirks *q, 221 enum quirk which, 222 uint32_t *val); 223 224 /** 225 * Get the value of the given quirk, as signed integer. 226 * This function will assert if the quirk type does not match the 227 * requested type. If the quirk is not set for this device, val is 228 * unchanged. 229 * 230 * @return true if the quirk value is valid, false otherwise. 231 */ 232 bool 233 quirks_get_int32(struct quirks *q, 234 enum quirk which, 235 int32_t *val); 236 237 /** 238 * Get the value of the given quirk, as double. 239 * This function will assert if the quirk type does not match the 240 * requested type. If the quirk is not set for this device, val is 241 * unchanged. 242 * 243 * @return true if the quirk value is valid, false otherwise. 244 */ 245 bool 246 quirks_get_double(struct quirks *q, 247 enum quirk which, 248 double *val); 249 250 /** 251 * Get the value of the given quirk, as string. 252 * This function will assert if the quirk type does not match the 253 * requested type. If the quirk is not set for this device, val is 254 * unchanged. 255 * 256 * val is set to the string, do not modify or free it. The lifetime of the 257 * returned string is bound to the lifetime of the quirk. 258 * 259 * @return true if the quirk value is valid, false otherwise. 260 */ 261 bool 262 quirks_get_string(struct quirks *q, 263 enum quirk which, 264 char **val); 265 266 /** 267 * Get the value of the given quirk, as bool. 268 * This function will assert if the quirk type does not match the 269 * requested type. If the quirk is not set for this device, val is 270 * unchanged. 271 * 272 * @return true if the quirk value is valid, false otherwise. 273 */ 274 bool 275 quirks_get_bool(struct quirks *q, 276 enum quirk which, 277 bool *val); 278 279 /** 280 * Get the value of the given quirk, as dimension. 281 * This function will assert if the quirk type does not match the 282 * requested type. If the quirk is not set for this device, val is 283 * unchanged. 284 * 285 * @return true if the quirk value is valid, false otherwise. 286 */ 287 bool 288 quirks_get_dimensions(struct quirks *q, 289 enum quirk which, 290 struct quirk_dimensions *val); 291 292 /** 293 * Get the value of the given quirk, as range. 294 * This function will assert if the quirk type does not match the 295 * requested type. If the quirk is not set for this device, val is 296 * unchanged. 297 * 298 * @return true if the quirk value is valid, false otherwise. 299 */ 300 bool 301 quirks_get_range(struct quirks *q, 302 enum quirk which, 303 struct quirk_range *val); 304 305 /** 306 * Get the tuples of the given quirk. 307 * This function will assert if the quirk type does not match the 308 * requested type. If the quirk is not set for this device, tuples is 309 * unchanged. 310 * 311 * @return true if the quirk value is valid, false otherwise. 312 */ 313 bool 314 quirks_get_tuples(struct quirks *q, 315 enum quirk which, 316 const struct quirk_tuples **tuples); 317 318 /** 319 * Get the uint32 array of the given quirk. 320 * This function will assert if the quirk type does not match the 321 * requested type. If the quirk is not set for this device, tuples is 322 * unchanged. 323 * 324 * @return true if the quirk value is valid, false otherwise. 325 */ 326 bool 327 quirks_get_uint32_array(struct quirks *q, 328 enum quirk which, 329 const uint32_t **array, 330 size_t *nelements); 331