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 "util.h" 27 28 #include <stdbool.h> 29 #include <stdint.h> 30 #include <syslog.h> 31 32 /** 33 * Handle to the quirks context. 34 */ 35 struct quirks_context; 36 37 /** 38 * Contains all quirks set for a single device. 39 */ 40 struct quirks; 41 42 struct quirk_dimensions { 43 size_t x, y; 44 }; 45 46 struct quirk_range { 47 int lower, upper; 48 }; 49 50 struct quirk_tuples { 51 struct { 52 int first; 53 int second; 54 int third; 55 } tuples[32]; 56 size_t ntuples; 57 }; 58 59 /** 60 * Quirks known to libinput. Moused does not support all of them. 61 */ 62 enum quirk { 63 QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD = 100, 64 QUIRK_MODEL_APPLE_TOUCHPAD, 65 QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON, 66 QUIRK_MODEL_BOUNCING_KEYS, 67 QUIRK_MODEL_CHROMEBOOK, 68 QUIRK_MODEL_CLEVO_W740SU, 69 QUIRK_MODEL_DELL_CANVAS_TOTEM, 70 QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD, 71 QUIRK_MODEL_HP_ZBOOK_STUDIO_G3, 72 QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING, 73 QUIRK_MODEL_LENOVO_SCROLLPOINT, 74 QUIRK_MODEL_LENOVO_T450_TOUCHPAD, 75 QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD, 76 QUIRK_MODEL_LENOVO_X230, 77 QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD, 78 QUIRK_MODEL_SYSTEM76_BONOBO, 79 QUIRK_MODEL_SYSTEM76_GALAGO, 80 QUIRK_MODEL_SYSTEM76_KUDU, 81 QUIRK_MODEL_TABLET_MODE_NO_SUSPEND, 82 QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE, 83 QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER, 84 QUIRK_MODEL_TRACKBALL, 85 QUIRK_MODEL_WACOM_TOUCHPAD, 86 QUIRK_MODEL_PRESSURE_PAD, 87 QUIRK_MODEL_TOUCHPAD_PHANTOM_CLICKS, 88 89 _QUIRK_LAST_MODEL_QUIRK_, /* Guard: do not modify */ 90 91 QUIRK_ATTR_SIZE_HINT = 300, 92 QUIRK_ATTR_TOUCH_SIZE_RANGE, 93 QUIRK_ATTR_PALM_SIZE_THRESHOLD, 94 QUIRK_ATTR_LID_SWITCH_RELIABILITY, 95 QUIRK_ATTR_KEYBOARD_INTEGRATION, 96 QUIRK_ATTR_TRACKPOINT_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_TABLET_SMOOTHING, 105 QUIRK_ATTR_THUMB_SIZE_THRESHOLD, 106 QUIRK_ATTR_MSC_TIMESTAMP, 107 QUIRK_ATTR_EVENT_CODE, 108 QUIRK_ATTR_INPUT_PROP, 109 110 _QUIRK_LAST_ATTR_QUIRK_, /* Guard: do not modify */ 111 112 113 /* Daemon parameters */ 114 MOUSED_GRAB_DEVICE = 1000, 115 MOUSED_IGNORE_DEVICE, 116 117 /* Standard moused parameters */ 118 MOUSED_CLICK_THRESHOLD, 119 MOUSED_DRIFT_TERMINATE, 120 MOUSED_DRIFT_DISTANCE, 121 MOUSED_DRIFT_TIME, 122 MOUSED_DRIFT_AFTER, 123 MOUSED_EMULATE_THIRD_BUTTON, 124 MOUSED_EMULATE_THIRD_BUTTON_TIMEOUT, 125 MOUSED_EXPONENTIAL_ACCEL, 126 MOUSED_EXPONENTIAL_OFFSET, 127 MOUSED_LINEAR_ACCEL_X, 128 MOUSED_LINEAR_ACCEL_Y, 129 MOUSED_LINEAR_ACCEL_Z, 130 MOUSED_MAP_Z_AXIS, 131 MOUSED_VIRTUAL_SCROLL_ENABLE, 132 MOUSED_HOR_VIRTUAL_SCROLL_ENABLE, 133 MOUSED_VIRTUAL_SCROLL_SPEED, 134 MOUSED_VIRTUAL_SCROLL_THRESHOLD, 135 MOUSED_WMODE, 136 137 /* Touchpad parameters from psm(4) driver */ 138 MOUSED_TWO_FINGER_SCROLL, 139 MOUSED_NATURAL_SCROLL, 140 MOUSED_THREE_FINGER_DRAG, 141 MOUSED_SOFTBUTTON2_X, 142 MOUSED_SOFTBUTTON3_X, 143 MOUSED_SOFTBUTTONS_Y, 144 MOUSED_TAP_TIMEOUT, 145 MOUSED_TAP_PRESSURE_THRESHOLD, 146 MOUSED_TAP_MAX_DELTA, 147 MOUSED_TAPHOLD_TIMEOUT, 148 MOUSED_VSCROLL_MIN_DELTA, 149 MOUSED_VSCROLL_HOR_AREA, 150 MOUSED_VSCROLL_VER_AREA, 151 152 _MOUSED_LAST_OPTION_ /* Guard: do not modify */ 153 }; 154 155 /** 156 * Returns a printable name for the quirk. This name is for developer 157 * tools, not user consumption. Do not display this in a GUI. 158 */ 159 const char* 160 quirk_get_name(enum quirk q); 161 162 /** 163 * Log priorities used if custom logging is enabled. 164 */ 165 enum quirks_log_priorities { 166 QLOG_NOISE = LOG_DEBUG + 1, 167 QLOG_DEBUG = LOG_DEBUG, 168 QLOG_INFO = LOG_INFO, 169 QLOG_ERROR = LOG_ERR, 170 QLOG_PARSER_ERROR = LOG_CRIT, 171 }; 172 173 /** 174 * Log type to be used for logging. Use the moused logging to hook up a 175 * moused log handler. This will cause the quirks to reduce the noise and 176 * only provide useful messages. 177 * 178 * QLOG_CUSTOM_LOG_PRIORITIES enables more fine-grained and verbose logging, 179 * allowing debugging tools to be more useful. 180 */ 181 enum quirks_log_type { 182 QLOG_MOUSED_LOGGING, 183 QLOG_CUSTOM_LOG_PRIORITIES, 184 }; 185 186 /** 187 * Initialize the quirks subsystem. This function must be called 188 * before anything else. 189 * 190 * If log_type is QLOG_CUSTOM_LOG_PRIORITIES, the log handler is called with 191 * the custom QLOG_* log priorities. Otherwise, the log handler only uses 192 * the moused (syslog) log priorities. 193 * 194 * @param config_file A file path to main configuration file 195 * @param quirks_path The directory containing the various quirk files 196 * @param log_handler The moused log handler called for debugging output 197 * 198 * @return an opaque handle to the context 199 */ 200 struct quirks_context * 201 quirks_init_subsystem(const char *config_file, 202 const char *quirks_path, 203 moused_log_handler log_handler, 204 enum quirks_log_type log_type); 205 206 /** 207 * Clean up after ourselves. This function must be called 208 * as the last call to the quirks subsystem. 209 * 210 * All quirks returned to the caller in quirks_fetch_for_device() must be 211 * unref'd before this call. 212 * 213 * @return Always NULL 214 */ 215 struct quirks_context * 216 quirks_context_unref(struct quirks_context *ctx); 217 218 DEFINE_UNREF_CLEANUP_FUNC(quirks_context); 219 220 struct quirks_context * 221 quirks_context_ref(struct quirks_context *ctx); 222 223 /** 224 * Fetch the quirks for a given device. If no quirks are defined, this 225 * function returns NULL. 226 * 227 * @return A new quirks struct, use quirks_unref() to release 228 */ 229 struct quirks * 230 quirks_fetch_for_device(struct quirks_context *ctx, 231 struct device *device); 232 233 /** 234 * Reduce the refcount by one. When the refcount reaches zero, the 235 * associated struct is released. 236 * 237 * @return Always NULL 238 */ 239 struct quirks * 240 quirks_unref(struct quirks *q); 241 242 DEFINE_UNREF_CLEANUP_FUNC(quirks); 243 244 /** 245 * Returns true if the given quirk applies is in this quirk list. 246 */ 247 bool 248 quirks_has_quirk(struct quirks *q, enum quirk which); 249 250 /** 251 * Get the value of the given quirk, as unsigned integer. 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 * @return true if the quirk value is valid, false otherwise. 257 */ 258 bool 259 quirks_get_uint32(struct quirks *q, 260 enum quirk which, 261 uint32_t *val); 262 263 /** 264 * Get the value of the given quirk, as signed integer. 265 * This function will assert if the quirk type does not match the 266 * requested type. If the quirk is not set for this device, val is 267 * unchanged. 268 * 269 * @return true if the quirk value is valid, false otherwise. 270 */ 271 bool 272 quirks_get_int32(struct quirks *q, 273 enum quirk which, 274 int32_t *val); 275 276 /** 277 * Get the value of the given quirk, as double. 278 * This function will assert if the quirk type does not match the 279 * requested type. If the quirk is not set for this device, val is 280 * unchanged. 281 * 282 * @return true if the quirk value is valid, false otherwise. 283 */ 284 bool 285 quirks_get_double(struct quirks *q, 286 enum quirk which, 287 double *val); 288 289 /** 290 * Get the value of the given quirk, as string. 291 * This function will assert if the quirk type does not match the 292 * requested type. If the quirk is not set for this device, val is 293 * unchanged. 294 * 295 * val is set to the string, do not modify or free it. The lifetime of the 296 * returned string is bound to the lifetime of the quirk. 297 * 298 * @return true if the quirk value is valid, false otherwise. 299 */ 300 bool 301 quirks_get_string(struct quirks *q, 302 enum quirk which, 303 char **val); 304 305 /** 306 * Get the value of the given quirk, as bool. 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, val is 309 * unchanged. 310 * 311 * @return true if the quirk value is valid, false otherwise. 312 */ 313 bool 314 quirks_get_bool(struct quirks *q, 315 enum quirk which, 316 bool *val); 317 318 /** 319 * Get the value of the given quirk, as dimension. 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, val is 322 * unchanged. 323 * 324 * @return true if the quirk value is valid, false otherwise. 325 */ 326 bool 327 quirks_get_dimensions(struct quirks *q, 328 enum quirk which, 329 struct quirk_dimensions *val); 330 331 /** 332 * Get the value of the given quirk, as range. 333 * This function will assert if the quirk type does not match the 334 * requested type. If the quirk is not set for this device, val is 335 * unchanged. 336 * 337 * @return true if the quirk value is valid, false otherwise. 338 */ 339 bool 340 quirks_get_range(struct quirks *q, 341 enum quirk which, 342 struct quirk_range *val); 343 344 /** 345 * Get the tuples of the given quirk. 346 * This function will assert if the quirk type does not match the 347 * requested type. If the quirk is not set for this device, tuples is 348 * unchanged. 349 * 350 * @return true if the quirk value is valid, false otherwise. 351 */ 352 bool 353 quirks_get_tuples(struct quirks *q, 354 enum quirk which, 355 const struct quirk_tuples **tuples); 356 357 /** 358 * Get the uint32 array of the given quirk. 359 * This function will assert if the quirk type does not match the 360 * requested type. If the quirk is not set for this device, tuples is 361 * unchanged. 362 * 363 * @return true if the quirk value is valid, false otherwise. 364 */ 365 bool 366 quirks_get_uint32_array(struct quirks *q, 367 enum quirk which, 368 const uint32_t **array, 369 size_t *nelements); 370