Skip to content

Commit 9a70f51

Browse files
committed
Small bits of cleanup
1 parent fe83144 commit 9a70f51

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/evdev/input_hook.c

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <inttypes.h>
2020
#include <limits.h>
2121

22-
#include <stdio.h> // FIXME Remove
2322
#include <glob.h>
2423
#include <fcntl.h>
2524
#include <unistd.h>
@@ -175,6 +174,9 @@ static int create_hook_info(char *path, struct hook_info **info) {
175174
err);
176175

177176
hook->uinput = NULL;
177+
} else {
178+
// On success, grab the device so we can consume events.
179+
//libevdev_grab(&hook->evdev, LIBEVDEV_GRAB);
178180
}
179181

180182
char *label;
@@ -302,6 +304,9 @@ static int create_event_listeners(int epoll_fd, struct epoll_event **listeners)
302304
return UIOHOOK_SUCCESS;
303305
}
304306

307+
static int destroy_event_listeners(int epoll_fd, struct epoll_event **listeners) {
308+
// FIXME Implement
309+
}
305310

306311

307312
UIOHOOK_API int hook_run() {
@@ -338,48 +343,57 @@ UIOHOOK_API int hook_run() {
338343
int err;
339344
struct input_event ev;
340345

346+
// FIXME We need some way of turning this off.
341347
while (1) {
342-
printf("\nPolling for input...\n");
343348
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);
347349

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;
349352

350-
err = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
353+
err = libevdev_next_event(info->evdev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
351354
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+
352365
/*
353366
if (ev.type == EV_KEY && ev.code == KEY_HOME) {
354367
ev.code = KEY_B;
368+
libevdev_uinput_write_event(info->uinput, ev.type, ev.code, ev.value);
355369
}
356-
*/
357-
358-
//libevdev_uinput_write_event(device->uinput, ev.type, ev.code, ev.value);
359-
printf("LIBEVDEV_READ_STATUS_SUCCESS\n");
370+
//*/
360371
} else if (err == LIBEVDEV_READ_STATUS_SYNC) {
361372
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);
363374
} while (err != -EAGAIN);
364375

365-
printf("LIBEVDEV_READ_STATUS_SYNC\n");
376+
logger(LOG_LEVEL_ERROR, "%s [%u]: LIBEVDEV_READ_STATUS_SYNC!\n",
377+
__FUNCTION__, __LINE__);
366378
} else if (err == -EAGAIN) {
367-
printf("EAGAIN\n");
379+
logger(LOG_LEVEL_ERROR, "%s [%u]: EAGAIN!\n",
380+
__FUNCTION__, __LINE__);
368381
continue;
369382
} else {
370-
printf("????\n");
383+
logger(LOG_LEVEL_ERROR, "%s [%u]: ?!\n",
384+
__FUNCTION__, __LINE__);
371385
// Error reading event
372386
break;
373387
}
374388
}
375389
}
376390

377391
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?
380395
}
381396

382-
383397
logger(LOG_LEVEL_DEBUG, "%s [%u]: Something, something, something, complete.\n",
384398
__FUNCTION__, __LINE__);
385399

0 commit comments

Comments
 (0)