|
19 | 19 | #include <inttypes.h> |
20 | 20 | #include <limits.h> |
21 | 21 |
|
22 | | -#include <stdio.h> // FIXME Remove |
23 | 22 | #include <glob.h> |
24 | 23 | #include <fcntl.h> |
25 | 24 | #include <unistd.h> |
@@ -175,6 +174,9 @@ static int create_hook_info(char *path, struct hook_info **info) { |
175 | 174 | err); |
176 | 175 |
|
177 | 176 | hook->uinput = NULL; |
| 177 | + } else { |
| 178 | + // On success, grab the device so we can consume events. |
| 179 | + //libevdev_grab(&hook->evdev, LIBEVDEV_GRAB); |
178 | 180 | } |
179 | 181 |
|
180 | 182 | char *label; |
@@ -302,6 +304,9 @@ static int create_event_listeners(int epoll_fd, struct epoll_event **listeners) |
302 | 304 | return UIOHOOK_SUCCESS; |
303 | 305 | } |
304 | 306 |
|
| 307 | +static int destroy_event_listeners(int epoll_fd, struct epoll_event **listeners) { |
| 308 | + // FIXME Implement |
| 309 | +} |
305 | 310 |
|
306 | 311 |
|
307 | 312 | UIOHOOK_API int hook_run() { |
@@ -338,48 +343,57 @@ UIOHOOK_API int hook_run() { |
338 | 343 | int err; |
339 | 344 | struct input_event ev; |
340 | 345 |
|
| 346 | + // FIXME We need some way of turning this off. |
341 | 347 | while (1) { |
342 | | - printf("\nPolling for input...\n"); |
343 | 348 | event_count = epoll_wait(epoll_fd, event_buffer, EVENT_BUFFER_SIZE, EVENT_BUFFER_WAIT * 1000); |
344 | | - printf("%d ready events\n", event_count); |
345 | | - for (int i = 0; i < event_count; i++) { |
346 | | - printf("Reading file descriptor %p '%d' -- ", event_buffer[i].data.ptr, event_buffer[i].data.fd); |
347 | 349 |
|
348 | | - struct hook_info *device = (struct hook_info *) event_buffer[i].data.ptr; |
| 350 | + for (int i = 0; i < event_count; i++) { |
| 351 | + struct hook_info *info = event_buffer[i].data.ptr; |
349 | 352 |
|
350 | | - err = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_NORMAL, &ev); |
| 353 | + err = libevdev_next_event(info->evdev, LIBEVDEV_READ_FLAG_NORMAL, &ev); |
351 | 354 | if (err == LIBEVDEV_READ_STATUS_SUCCESS) { |
| 355 | + if (ev.type == EV_KEY) { |
| 356 | + logger(LOG_LEVEL_DEBUG, "%s [%u]: Keyboard FD: %d -- KEY: '%u' '%d'.\n", |
| 357 | + __FUNCTION__, __LINE__, |
| 358 | + info->fd, ev.code, ev.value); |
| 359 | + } else if (ev.type == EV_REL) { |
| 360 | + logger(LOG_LEVEL_DEBUG, "%s [%u]: Keyboard FD: %d -- MOVE: '%u' '%d'.\n", |
| 361 | + __FUNCTION__, __LINE__, |
| 362 | + info->fd, ev.code, ev.value); |
| 363 | + } |
| 364 | + |
352 | 365 | /* |
353 | 366 | if (ev.type == EV_KEY && ev.code == KEY_HOME) { |
354 | 367 | ev.code = KEY_B; |
| 368 | + libevdev_uinput_write_event(info->uinput, ev.type, ev.code, ev.value); |
355 | 369 | } |
356 | | - */ |
357 | | - |
358 | | - //libevdev_uinput_write_event(device->uinput, ev.type, ev.code, ev.value); |
359 | | - printf("LIBEVDEV_READ_STATUS_SUCCESS\n"); |
| 370 | + //*/ |
360 | 371 | } else if (err == LIBEVDEV_READ_STATUS_SYNC) { |
361 | 372 | do { |
362 | | - err = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_SYNC, &ev); |
| 373 | + err = libevdev_next_event(info->evdev, LIBEVDEV_READ_FLAG_SYNC, &ev); |
363 | 374 | } while (err != -EAGAIN); |
364 | 375 |
|
365 | | - printf("LIBEVDEV_READ_STATUS_SYNC\n"); |
| 376 | + logger(LOG_LEVEL_ERROR, "%s [%u]: LIBEVDEV_READ_STATUS_SYNC!\n", |
| 377 | + __FUNCTION__, __LINE__); |
366 | 378 | } else if (err == -EAGAIN) { |
367 | | - printf("EAGAIN\n"); |
| 379 | + logger(LOG_LEVEL_ERROR, "%s [%u]: EAGAIN!\n", |
| 380 | + __FUNCTION__, __LINE__); |
368 | 381 | continue; |
369 | 382 | } else { |
370 | | - printf("????\n"); |
| 383 | + logger(LOG_LEVEL_ERROR, "%s [%u]: ?!\n", |
| 384 | + __FUNCTION__, __LINE__); |
371 | 385 | // Error reading event |
372 | 386 | break; |
373 | 387 | } |
374 | 388 | } |
375 | 389 | } |
376 | 390 |
|
377 | 391 | if (close(epoll_fd)) { |
378 | | - fprintf(stderr, "Failed to close epoll file descriptor\n"); |
379 | | - return 1; |
| 392 | + logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to close epoll file descriptor!\n", |
| 393 | + __FUNCTION__, __LINE__); |
| 394 | + // FIXME What exactly should we do here? Return error, set epoll_fd to null? |
380 | 395 | } |
381 | 396 |
|
382 | | - |
383 | 397 | logger(LOG_LEVEL_DEBUG, "%s [%u]: Something, something, something, complete.\n", |
384 | 398 | __FUNCTION__, __LINE__); |
385 | 399 |
|
|
0 commit comments