Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
Dennis Kempin | 320aef1 | 2012-06-11 15:26:52 -0700 | [diff] [blame] | 6 | #include <libevdev/libevdev.h> |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 7 | |
| 8 | #include <errno.h> |
| 9 | #include <fcntl.h> |
| 10 | #include <linux/input.h> |
| 11 | #include <stdio.h> |
| 12 | #include <time.h> |
| 13 | #include <unistd.h> |
| 14 | |
Dennis Kempin | 320aef1 | 2012-06-11 15:26:52 -0700 | [diff] [blame] | 15 | #include <libevdev/libevdev_event.h> |
| 16 | #include <libevdev/libevdev_log.h> |
| 17 | #include <libevdev/libevdev_util.h> |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 18 | |
| 19 | /* Number of events to attempt to read from kernel on each SIGIO */ |
| 20 | #define NUM_EVENTS 16 |
| 21 | |
| 22 | #ifndef EVIOCGMTSLOTS |
| 23 | #define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len) |
| 24 | #endif |
| 25 | |
| 26 | /* Set clockid to be used for timestamps */ |
| 27 | #ifndef EVIOCSCLOCKID |
| 28 | #define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
| 29 | #endif |
| 30 | |
Dennis Kempin | 0e26539 | 2013-02-22 12:59:03 -0800 | [diff] [blame] | 31 | static int EvdevWriteBitmask(FILE* fp, const char* name, |
| 32 | unsigned long* bitmask, size_t num_bytes); |
| 33 | static int EvdevReadBitmask(FILE* fp, const char* expected_name, |
| 34 | unsigned long* bitmask, size_t num_bytes); |
| 35 | |
| 36 | #ifndef EVDEV_HOLLOW |
| 37 | |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 38 | static void Absinfo_Print(EvdevPtr device, struct input_absinfo*); |
| 39 | static const char* Event_Property_To_String(int type); |
Che-Liang Chiou | b9fc973 | 2012-11-26 15:49:02 -0800 | [diff] [blame] | 40 | static EvdevClass EvdevProbeClass(EvdevInfoPtr info); |
| 41 | static const char* EvdevClassToString(EvdevClass cls); |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 42 | |
| 43 | int EvdevOpen(EvdevPtr evdev, const char* device) { |
| 44 | evdev->fd = open(device, O_RDWR | O_NONBLOCK, 0); |
| 45 | return evdev->fd; |
| 46 | } |
| 47 | |
| 48 | int EvdevClose(EvdevPtr evdev) { |
| 49 | close(evdev->fd); |
| 50 | evdev->fd = -1; |
| 51 | return evdev->fd; |
| 52 | } |
| 53 | |
| 54 | int EvdevRead(EvdevPtr evdev) { |
| 55 | struct input_event ev[NUM_EVENTS]; |
Andrew de los Reyes | ec02884 | 2012-08-16 18:08:12 -0700 | [diff] [blame] | 56 | EventStatePtr evstate = evdev->evstate; |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 57 | int i; |
| 58 | int len; |
| 59 | bool sync_evdev_state = false; |
| 60 | |
| 61 | do { |
| 62 | len = read(evdev->fd, &ev, sizeof(ev)); |
| 63 | if (len <= 0) |
| 64 | return errno; |
| 65 | |
Andrew de los Reyes | ec02884 | 2012-08-16 18:08:12 -0700 | [diff] [blame] | 66 | /* Read as many whole struct input_event objects as we can into the |
| 67 | circular buffer */ |
| 68 | if (evstate->debug_buf) { |
| 69 | for (i = 0; i < len / sizeof(*ev); i++) { |
| 70 | evstate->debug_buf[evstate->debug_buf_tail] = ev[i]; |
| 71 | evstate->debug_buf_tail = |
| 72 | (evstate->debug_buf_tail + 1) % DEBUG_BUF_SIZE; |
| 73 | } |
| 74 | } |
| 75 | |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 76 | /* kernel always delivers complete events, so len must be sizeof *ev */ |
| 77 | if (len % sizeof(*ev)) |
| 78 | return errno; |
| 79 | |
| 80 | /* Process events ... */ |
| 81 | for (i = 0; i < len / sizeof(ev[0]); i++) { |
| 82 | if (sync_evdev_state) |
| 83 | break; |
| 84 | if (timercmp(&ev[i].time, &evdev->before_sync_time, <)) { |
| 85 | /* Ignore events before last sync time */ |
| 86 | continue; |
| 87 | } else if (timercmp(&ev[i].time, &evdev->after_sync_time, >)) { |
| 88 | /* Event_Process returns TRUE if SYN_DROPPED detected */ |
| 89 | sync_evdev_state = Event_Process(evdev, &ev[i]); |
| 90 | } else { |
| 91 | /* If the event occurred during sync, then sync again */ |
| 92 | sync_evdev_state = true; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | } while (len == sizeof(ev)); |
| 97 | /* Keep reading if kernel supplied NUM_EVENTS events. */ |
| 98 | |
| 99 | if (sync_evdev_state) |
| 100 | Event_Sync_State(evdev); |
| 101 | |
| 102 | return Success; |
| 103 | } |
| 104 | |
| 105 | int EvdevProbe(EvdevPtr device) { |
| 106 | int len, i; |
| 107 | int fd; |
| 108 | EvdevInfoPtr info; |
| 109 | |
| 110 | fd = device->fd; |
| 111 | info = &device->info; |
| 112 | if (ioctl(fd, EVIOCGID, &info->id) < 0) { |
| 113 | LOG_ERROR(device, "ioctl EVIOCGID failed: %s\n", strerror(errno)); |
| 114 | return !Success; |
| 115 | } |
| 116 | |
| 117 | if (ioctl(fd, EVIOCGNAME(sizeof(info->name) - 1), |
| 118 | info->name) < 0) { |
| 119 | LOG_ERROR(device, "ioctl EVIOCGNAME failed: %s\n", strerror(errno)); |
| 120 | return !Success; |
| 121 | } |
| 122 | |
| 123 | len = ioctl(fd, EVIOCGPROP(sizeof(info->prop_bitmask)), |
| 124 | info->prop_bitmask); |
| 125 | if (len < 0) { |
| 126 | LOG_ERROR(device, "ioctl EVIOCGPROP failed: %s\n", strerror(errno)); |
| 127 | return !Success; |
| 128 | } |
| 129 | for (i = 0; i < len*8; i++) { |
| 130 | if (TestBit(i, info->prop_bitmask)) |
| 131 | LOG_DEBUG(device, "Has Property: %d (%s)\n", i, |
| 132 | Event_Property_To_String(i)); |
| 133 | } |
| 134 | |
| 135 | len = ioctl(fd, EVIOCGBIT(0, sizeof(info->bitmask)), |
| 136 | info->bitmask); |
| 137 | if (len < 0) { |
| 138 | LOG_ERROR(device, "ioctl EVIOCGBIT failed: %s\n", |
| 139 | strerror(errno)); |
| 140 | return !Success; |
| 141 | } |
| 142 | for (i = 0; i < len*8; i++) { |
| 143 | if (TestBit(i, info->bitmask)) |
| 144 | LOG_DEBUG(device, "Has Event Type %d = %s\n", i, |
| 145 | Event_Type_To_String(i)); |
| 146 | } |
| 147 | |
| 148 | len = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(info->key_bitmask)), |
| 149 | info->key_bitmask); |
| 150 | if (len < 0) { |
| 151 | LOG_ERROR(device, "ioctl EVIOCGBIT(EV_KEY) failed: %s\n", |
| 152 | strerror(errno)); |
| 153 | return !Success; |
| 154 | } |
| 155 | for (i = 0; i < len*8; i++) { |
| 156 | if (TestBit(i, info->key_bitmask)) |
| 157 | LOG_DEBUG(device, "Has KEY[%d] = %s\n", i, |
| 158 | Event_To_String(EV_KEY, i)); |
| 159 | } |
| 160 | |
| 161 | len = ioctl(fd, EVIOCGBIT(EV_LED, sizeof(info->led_bitmask)), |
| 162 | info->led_bitmask); |
| 163 | if (len < 0) { |
| 164 | LOG_ERROR(device, "ioctl EVIOCGBIT(EV_LED) failed: %s\n", |
| 165 | strerror(errno)); |
| 166 | return !Success; |
| 167 | } |
| 168 | for (i = 0; i < len*8; i++) { |
| 169 | if (TestBit(i, info->led_bitmask)) |
| 170 | LOG_DEBUG(device, "Has LED[%d] = %s\n", i, |
| 171 | Event_To_String(EV_LED, i)); |
| 172 | } |
| 173 | |
| 174 | len = ioctl(fd, EVIOCGBIT(EV_REL, sizeof(info->rel_bitmask)), |
| 175 | info->rel_bitmask); |
| 176 | if (len < 0) { |
| 177 | LOG_ERROR(device, "ioctl EVIOCGBIT(EV_REL) failed: %s\n", |
| 178 | strerror(errno)); |
| 179 | return !Success; |
| 180 | } |
| 181 | for (i = 0; i < len*8; i++) { |
| 182 | if (TestBit(i, info->rel_bitmask)) |
| 183 | LOG_DEBUG(device, "Has REL[%d] = %s\n", i, |
| 184 | Event_To_String(EV_REL, i)); |
| 185 | } |
| 186 | |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 187 | len = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(info->abs_bitmask)), |
| 188 | info->abs_bitmask); |
| 189 | if (len < 0) { |
| 190 | LOG_ERROR(device, "ioctl EVIOCGBIT(EV_ABS) failed: %s\n", |
| 191 | strerror(errno)); |
| 192 | return !Success; |
| 193 | } |
| 194 | |
| 195 | for (i = ABS_X; i <= ABS_MAX; i++) { |
| 196 | if (TestBit(i, info->abs_bitmask)) { |
| 197 | struct input_absinfo* absinfo = &info->absinfo[i]; |
| 198 | LOG_DEBUG(device, "Has ABS[%d] = %s\n", i, |
| 199 | Event_To_String(EV_ABS, i)); |
| 200 | len = ioctl(fd, EVIOCGABS(i), absinfo); |
| 201 | if (len < 0) { |
| 202 | LOG_ERROR(device, "ioctl EVIOCGABS(%d) failed: %s\n", i, |
| 203 | strerror(errno)); |
| 204 | return !Success; |
| 205 | } |
| 206 | |
| 207 | Absinfo_Print(device, absinfo); |
| 208 | } |
| 209 | } |
Che-Liang Chiou | b9fc973 | 2012-11-26 15:49:02 -0800 | [diff] [blame] | 210 | |
| 211 | info->evdev_class = EvdevProbeClass(info); |
| 212 | LOG_DEBUG(device, "Has evdev device class = %s\n", |
| 213 | EvdevClassToString(info->evdev_class)); |
| 214 | if (info->evdev_class == EvdevClassUnknown) { |
| 215 | LOG_ERROR(device, "Couldn't determine evdev class\n"); |
| 216 | return !Success; |
| 217 | } |
| 218 | |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 219 | return Success; |
| 220 | } |
| 221 | |
| 222 | int EvdevProbeAbsinfo(EvdevPtr device, size_t key) { |
| 223 | struct input_absinfo* absinfo; |
| 224 | |
| 225 | absinfo = &device->info.absinfo[key]; |
| 226 | if (ioctl(device->fd, EVIOCGABS(key), absinfo) < 0) { |
Daniel Kurtz | 0d09708 | 2012-09-07 22:27:51 +0800 | [diff] [blame] | 227 | LOG_ERROR(device, "ioctl EVIOCGABS(%zu) failed: %s\n", key, |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 228 | strerror(errno)); |
| 229 | return !Success; |
| 230 | } else { |
| 231 | return Success; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | int EvdevProbeMTSlot(EvdevPtr device, MTSlotInfoPtr req) { |
Dennis Kempin | e9cc264 | 2012-06-25 11:52:24 -0700 | [diff] [blame] | 236 | if (ioctl(device->fd, EVIOCGMTSLOTS((sizeof(*req))), req) < 0) { |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 237 | LOG_ERROR(device, "ioctl EVIOCGMTSLOTS(req.code=%d) failed: %s\n", |
Dennis Kempin | e9cc264 | 2012-06-25 11:52:24 -0700 | [diff] [blame] | 238 | req->code, strerror(errno)); |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 239 | return !Success; |
| 240 | } else { |
| 241 | return Success; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | int EvdevProbeKeyState(EvdevPtr device) { |
| 246 | int len = sizeof(device->key_state_bitmask); |
| 247 | |
| 248 | memset(device->key_state_bitmask, 0, len); |
| 249 | if (ioctl(device->fd, EVIOCGKEY(len), device->key_state_bitmask) < 0) { |
| 250 | LOG_ERROR(device, "ioctl EVIOCGKEY failed: %s\n", strerror(errno)); |
| 251 | return !Success; |
| 252 | } else { |
| 253 | return Success; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | int EvdevEnableMonotonic(EvdevPtr device) { |
| 258 | unsigned int clk = CLOCK_MONOTONIC; |
| 259 | return (ioctl(device->fd, EVIOCSCLOCKID, &clk) == 0) ? Success : !Success; |
| 260 | } |
| 261 | |
Dennis Kempin | 9ec1b7c | 2013-02-19 14:28:48 -0800 | [diff] [blame] | 262 | #endif // #ifndef EVDEV_HOLLOW |
| 263 | |
| 264 | /* |
| 265 | * Check if the device is a single-pressure one which reports ABS_PRESSURE only. |
| 266 | */ |
| 267 | int EvdevIsSinglePressureDevice(EvdevPtr device) { |
| 268 | EvdevInfoPtr info = &device->info; |
| 269 | |
| 270 | return (!TestBit(ABS_MT_PRESSURE, info->abs_bitmask) && |
| 271 | TestBit(ABS_PRESSURE, info->abs_bitmask)); |
| 272 | } |
| 273 | |
Dennis Kempin | 69c91ed | 2013-02-12 14:53:10 -0800 | [diff] [blame] | 274 | int EvdevWriteInfoToFile(FILE* fp, const EvdevInfoPtr info) { |
| 275 | int ret; |
| 276 | |
| 277 | ret = fprintf(fp, "# device: %s\n", info->name); |
| 278 | if (ret <= 0) |
| 279 | return ret; |
| 280 | |
Dennis Kempin | 69c91ed | 2013-02-12 14:53:10 -0800 | [diff] [blame] | 281 | ret = EvdevWriteBitmask(fp, "bit", info->bitmask, sizeof(info->bitmask)); |
| 282 | if (ret <= 0) |
| 283 | return ret; |
| 284 | |
| 285 | ret = EvdevWriteBitmask(fp, "key", info->key_bitmask, |
| 286 | sizeof(info->key_bitmask)); |
| 287 | if (ret <= 0) |
| 288 | return ret; |
| 289 | |
| 290 | ret = EvdevWriteBitmask(fp, "rel", info->rel_bitmask, |
| 291 | sizeof(info->rel_bitmask)); |
| 292 | if (ret <= 0) |
| 293 | return ret; |
| 294 | |
| 295 | ret = EvdevWriteBitmask(fp, "abs", info->abs_bitmask, |
| 296 | sizeof(info->abs_bitmask)); |
| 297 | if (ret <= 0) |
| 298 | return ret; |
| 299 | |
| 300 | ret = EvdevWriteBitmask(fp, "led", info->led_bitmask, |
| 301 | sizeof(info->led_bitmask)); |
| 302 | if (ret <= 0) |
| 303 | return ret; |
| 304 | |
| 305 | ret = EvdevWriteBitmask(fp, "prp", info->prop_bitmask, |
| 306 | sizeof(info->prop_bitmask)); |
| 307 | if (ret <= 0) |
| 308 | return ret; |
| 309 | |
Dennis Kempin | 9ec1b7c | 2013-02-19 14:28:48 -0800 | [diff] [blame] | 310 | // when reading the log we need to know which absinfos |
| 311 | // exist which is stored in the abs bitmask. |
| 312 | // so we have to write absinfo after the bitmasks. |
| 313 | for (int i = ABS_X; i <= ABS_MAX; i++) { |
| 314 | if (TestBit(i, info->abs_bitmask)) { |
| 315 | struct input_absinfo* abs = &info->absinfo[i]; |
| 316 | ret = fprintf(fp, "# absinfo: %d %d %d %d %d %d\n", |
| 317 | i, abs->minimum, abs->maximum, |
| 318 | abs->fuzz, abs->flat, abs->resolution); |
| 319 | if (ret <= 0) |
| 320 | return ret; |
| 321 | } |
| 322 | } |
| 323 | |
Dennis Kempin | 69c91ed | 2013-02-12 14:53:10 -0800 | [diff] [blame] | 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | int EvdevWriteEventToFile(FILE* fp, const struct input_event* ev) { |
Mike Frysinger | 7abec9e | 2012-12-23 13:00:24 -0500 | [diff] [blame^] | 328 | return fprintf(fp, "E: %ld.%06u %04x %04x %d\n", |
| 329 | (long)ev->time.tv_sec, (unsigned)ev->time.tv_usec, |
Dennis Kempin | 69c91ed | 2013-02-12 14:53:10 -0800 | [diff] [blame] | 330 | ev->type, ev->code, ev->value); |
| 331 | } |
| 332 | |
Dennis Kempin | 9ec1b7c | 2013-02-19 14:28:48 -0800 | [diff] [blame] | 333 | int EvdevReadInfoFromFile(FILE* fp, EvdevInfoPtr info) { |
| 334 | int ret; |
| 335 | |
| 336 | ret = fscanf(fp, "# device: %1024s\n", info->name); |
| 337 | if (ret <= 0) |
| 338 | return ret; |
| 339 | |
| 340 | ret = EvdevReadBitmask(fp, "bit", info->bitmask, sizeof(info->bitmask)); |
| 341 | if (ret <= 0) |
| 342 | return ret; |
| 343 | |
| 344 | ret = EvdevReadBitmask(fp, "key", info->key_bitmask, |
| 345 | sizeof(info->key_bitmask)); |
| 346 | if (ret <= 0) |
| 347 | return ret; |
| 348 | |
| 349 | ret = EvdevReadBitmask(fp, "rel", info->rel_bitmask, |
| 350 | sizeof(info->rel_bitmask)); |
| 351 | if (ret <= 0) |
| 352 | return ret; |
| 353 | |
| 354 | ret = EvdevReadBitmask(fp, "abs", info->abs_bitmask, |
| 355 | sizeof(info->abs_bitmask)); |
| 356 | if (ret <= 0) |
| 357 | return ret; |
| 358 | |
| 359 | ret = EvdevReadBitmask(fp, "led", info->led_bitmask, |
| 360 | sizeof(info->led_bitmask)); |
| 361 | if (ret <= 0) |
| 362 | return ret; |
| 363 | |
| 364 | ret = EvdevReadBitmask(fp, "prp", info->prop_bitmask, |
| 365 | sizeof(info->prop_bitmask)); |
| 366 | if (ret <= 0) |
| 367 | return ret; |
| 368 | |
| 369 | for (int i = ABS_X; i <= ABS_MAX; i++) { |
| 370 | if (TestBit(i, info->abs_bitmask)) { |
| 371 | struct input_absinfo abs; |
| 372 | int abs_index; |
| 373 | ret = fscanf(fp, "# absinfo: %d %d %d %d %d %d\n", |
| 374 | &abs_index, &abs.minimum, &abs.maximum, |
| 375 | &abs.fuzz, &abs.flat, &abs.resolution); |
| 376 | if (ret <= 0 || abs_index != i) |
| 377 | return -1; |
| 378 | info->absinfo[i] = abs; |
| 379 | } |
| 380 | } |
| 381 | return 1; |
| 382 | } |
| 383 | |
| 384 | int EvdevReadEventFromFile(FILE* fp, struct input_event* ev) { |
| 385 | unsigned long sec; |
| 386 | unsigned usec, type, code; |
| 387 | int value; |
| 388 | int ret = fscanf(fp, "E: %lu.%06u %04x %04x %d\n", |
| 389 | &sec, &usec, &type, &code, &value); |
| 390 | if (ret <= 0) |
| 391 | return ret; |
| 392 | |
| 393 | ev->time.tv_sec = sec; |
| 394 | ev->time.tv_usec = usec; |
| 395 | ev->type = type; |
| 396 | ev->code = code; |
| 397 | ev->value = value; |
| 398 | return ret; |
| 399 | } |
| 400 | |
| 401 | static int EvdevReadBitmask(FILE* fp, const char* expected_name, |
| 402 | unsigned long* bitmask, size_t num_bytes) { |
| 403 | unsigned char* bytes = (unsigned char*)bitmask; |
| 404 | int ret; |
| 405 | char name[64]; |
| 406 | |
| 407 | ret = fscanf(fp, "# %64s:", name); |
| 408 | if (ret <= 0 || strcmp(name, expected_name) == 0) |
| 409 | return ret; |
| 410 | for (int i = 0; i < num_bytes; ++i) { |
| 411 | unsigned int tmp; |
| 412 | ret = fscanf(fp, " %02X", &tmp); |
| 413 | if (ret <= 0) |
| 414 | return ret; |
| 415 | bytes[i] = (unsigned char)tmp; |
| 416 | } |
| 417 | ret = fscanf(fp, "\n"); |
| 418 | return 1; |
| 419 | } |
| 420 | |
Dennis Kempin | 69c91ed | 2013-02-12 14:53:10 -0800 | [diff] [blame] | 421 | static int EvdevWriteBitmask(FILE* fp, const char* name, |
| 422 | unsigned long* bitmask, size_t num_bytes) { |
| 423 | int ret; |
| 424 | |
| 425 | unsigned char* bytes = (unsigned char*)bitmask; |
| 426 | ret = fprintf(fp, "# %s:", name); |
| 427 | if (ret <= 0) |
| 428 | return ret; |
| 429 | |
| 430 | for (int i = 0; i < num_bytes; ++i) { |
| 431 | ret = fprintf(fp, " %02X", bytes[i]); |
| 432 | if (ret <= 0) |
| 433 | return ret; |
| 434 | } |
| 435 | ret = fprintf(fp, "\n"); |
| 436 | return ret; |
| 437 | } |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 438 | |
Dennis Kempin | 0e26539 | 2013-02-22 12:59:03 -0800 | [diff] [blame] | 439 | #ifndef EVDEV_HOLLOW |
| 440 | |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 441 | static const char* |
| 442 | Event_Property_To_String(int type) { |
| 443 | switch (type) { |
| 444 | case INPUT_PROP_POINTER: return "POINTER"; /* needs a pointer */ |
| 445 | case INPUT_PROP_DIRECT: return "DIRECT"; /* direct input devices */ |
| 446 | case INPUT_PROP_BUTTONPAD: return "BUTTONPAD"; /* has button under pad */ |
| 447 | case INPUT_PROP_SEMI_MT: return "SEMI_MT"; /* touch rectangle only */ |
| 448 | default: return "?"; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | static void |
| 453 | Absinfo_Print(EvdevPtr device, struct input_absinfo* absinfo) |
| 454 | { |
| 455 | LOG_DEBUG(device, " min = %d\n", absinfo->minimum); |
| 456 | LOG_DEBUG(device, " max = %d\n", absinfo->maximum); |
| 457 | if (absinfo->fuzz) |
| 458 | LOG_DEBUG(device, " fuzz = %d\n", absinfo->fuzz); |
| 459 | if (absinfo->resolution) |
| 460 | LOG_DEBUG(device, " res = %d\n", absinfo->resolution); |
| 461 | } |
| 462 | |
Che-Liang Chiou | b9fc973 | 2012-11-26 15:49:02 -0800 | [diff] [blame] | 463 | /* |
| 464 | * Heuristics for determining evdev device class; similar to those of |
| 465 | * xf86-input-evdev. |
| 466 | */ |
| 467 | static EvdevClass EvdevProbeClass(EvdevInfoPtr info) { |
| 468 | int bit; |
| 469 | for (bit = 0; bit < BTN_MISC; bit++) |
| 470 | if (TestBit(bit, info->key_bitmask)) |
| 471 | return EvdevClassKeyboard; |
| 472 | |
| 473 | if (TestBit(REL_X, info->rel_bitmask) && |
Che-Liang Chiou | 7e45cb2 | 2013-01-15 14:57:13 -0800 | [diff] [blame] | 474 | TestBit(REL_Y, info->rel_bitmask)) { |
| 475 | if (TestBit(ABS_MT_POSITION_X, info->abs_bitmask) && |
| 476 | TestBit(ABS_MT_POSITION_Y, info->abs_bitmask)) |
| 477 | return EvdevClassMultitouchMouse; |
| 478 | else |
| 479 | return EvdevClassMouse; |
| 480 | } |
Che-Liang Chiou | b9fc973 | 2012-11-26 15:49:02 -0800 | [diff] [blame] | 481 | |
| 482 | if (TestBit(ABS_X, info->abs_bitmask) && |
| 483 | TestBit(ABS_Y, info->abs_bitmask)) { |
| 484 | |
| 485 | if (TestBit(BTN_TOOL_PEN, info->key_bitmask) || |
| 486 | TestBit(BTN_STYLUS, info->key_bitmask) || |
| 487 | TestBit(BTN_STYLUS2, info->key_bitmask)) |
| 488 | return EvdevClassTablet; |
| 489 | |
| 490 | if (TestBit(ABS_PRESSURE, info->abs_bitmask) || |
| 491 | TestBit(BTN_TOUCH, info->key_bitmask)) { |
| 492 | if (TestBit(BTN_LEFT, info->key_bitmask) || |
| 493 | TestBit(BTN_MIDDLE, info->key_bitmask) || |
| 494 | TestBit(BTN_RIGHT, info->key_bitmask) || |
| 495 | TestBit(BTN_TOOL_FINGER, info->key_bitmask)) |
| 496 | return EvdevClassTouchpad; |
| 497 | else |
| 498 | return EvdevClassTouchscreen; |
| 499 | } |
| 500 | |
| 501 | /* Some touchscreens use BTN_LEFT rather than BTN_TOUCH */ |
| 502 | if (TestBit(BTN_LEFT, info->key_bitmask)) |
| 503 | return EvdevClassTouchscreen; |
| 504 | } |
| 505 | |
| 506 | return EvdevClassUnknown; |
| 507 | } |
| 508 | |
| 509 | static const char* EvdevClassToString(EvdevClass cls) { |
| 510 | switch (cls) { |
| 511 | case EvdevClassUnknown: return "EvdevClassUnknown"; |
| 512 | case EvdevClassKeyboard: return "EvdevClassKeyboard"; |
| 513 | case EvdevClassMouse: return "EvdevClassMouse"; |
Che-Liang Chiou | 7e45cb2 | 2013-01-15 14:57:13 -0800 | [diff] [blame] | 514 | case EvdevClassMultitouchMouse: return "EvdevClassMultitouchMouse"; |
Che-Liang Chiou | b9fc973 | 2012-11-26 15:49:02 -0800 | [diff] [blame] | 515 | case EvdevClassTablet: return "EvdevClassTablet"; |
| 516 | case EvdevClassTouchpad: return "EvdevClassTouchpad"; |
| 517 | case EvdevClassTouchscreen: return "EvdevClassTouchscreen"; |
| 518 | } |
| 519 | return "Unhandled Evdev Class"; |
| 520 | } |
Dennis Kempin | 0e26539 | 2013-02-22 12:59:03 -0800 | [diff] [blame] | 521 | |
| 522 | #endif // #ifndef EVDEV_HOLLOW |