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