diff --git a/input_dev.c b/input_dev.c index b5c3550..c5475b1 100644 --- a/input_dev.c +++ b/input_dev.c @@ -19,11 +19,11 @@ static const char *input_path = "/dev/input/"; static const char *iio_path = "/sys/bus/iio/devices/"; -int input_filter_identity(struct input_event* events, size_t* size, uint32_t* count) { - return INPUT_FILTER_RESULT_OK; +uint32_t input_filter_identity(struct input_event* events, size_t* size, uint32_t* count) { + return INPUT_FILTER_FLAGS_NONE; } -int input_filter_asus_kb(struct input_event* events, size_t* size, uint32_t* count) { +uint32_t input_filter_asus_kb(struct input_event* events, size_t* size, uint32_t* count) { static int F15_status = 0; if ((*count >= 2) && (events[0].type == EV_MSC) && (events[0].code == MSC_SCAN)) { @@ -35,36 +35,36 @@ int input_filter_asus_kb(struct input_event* events, size_t* size, uint32_t* cou // Do nothing effectively discarding the input } - return INPUT_FILTER_RESULT_DO_NOT_EMIT; + return INPUT_FILTER_FLAGS_DO_NOT_EMIT; } else if (events[0].value == -13565784) { - return INPUT_FILTER_RESULT_DO_NOT_EMIT; + return INPUT_FILTER_FLAGS_DO_NOT_EMIT; } else if ((*count == 2) && (events[0].value == 458860) && (events[1].type == EV_KEY) && (events[1].code == KEY_F17)) { if (events[1].value < 2) { *count = 1; events[0].type = EV_KEY; events[0].code = BTN_GEAR_DOWN; events[0].value = events[1].value; - return INPUT_FILTER_RESULT_OK; + return INPUT_FILTER_FLAGS_NONE; } - return INPUT_FILTER_RESULT_DO_NOT_EMIT; + return INPUT_FILTER_FLAGS_DO_NOT_EMIT; } else if ((*count == 2) && (events[0].value == 458861) && (events[1].type == EV_KEY) && (events[1].code == KEY_F18)) { if (events[1].value < 2) { *count = 1; events[0].type = EV_KEY; events[0].code = BTN_GEAR_UP; events[0].value = events[1].value; - return INPUT_FILTER_RESULT_OK; + return INPUT_FILTER_FLAGS_NONE; } - return INPUT_FILTER_RESULT_DO_NOT_EMIT; + return INPUT_FILTER_FLAGS_DO_NOT_EMIT; } else if ((*count == 2) && (events[0].value == -13565786) && (events[1].type == EV_KEY) && (events[1].code == KEY_F16)) { *count = 1; events[0].type = EV_KEY; events[0].code = BTN_MODE; events[0].value = events[1].value; - return INPUT_FILTER_RESULT_OK; + return INPUT_FILTER_FLAGS_NONE; } else if ((*count == 2) && (events[0].value == -13565787) && (events[1].type == EV_KEY) && (events[1].code == KEY_F15)) { if (events[1].value == 0) { if (F15_status > 0) { @@ -84,7 +84,7 @@ int input_filter_asus_kb(struct input_event* events, size_t* size, uint32_t* cou } } - return INPUT_FILTER_RESULT_DO_NOT_EMIT; + return INPUT_FILTER_FLAGS_DO_NOT_EMIT; } else if ((*count == 2) && (*size >= 3) && (events[0].value == -13565896) && (events[1].type == EV_KEY) && (events[1].code == KEY_PROG1)) { *count = 3; @@ -111,11 +111,11 @@ int input_filter_asus_kb(struct input_event* events, size_t* size, uint32_t* cou events[4].code = BTN_SOUTH; events[4].value = 0; */ - return INPUT_FILTER_RESULT_OK; + return INPUT_FILTER_FLAGS_NONE; } } - return INPUT_FILTER_RESULT_OK; + return INPUT_FILTER_FLAGS_NONE; } static struct libevdev* ev_matches(const char* sysfs_entry, const uinput_filters_t* const filters) { @@ -314,7 +314,8 @@ static void* input_read_thread_func(void* ptr) { // clear out flags msg->flags = 0x00000000U; - if (ctx->input_filter_fn(msg->ev, &msg->ev_size, &msg->ev_count) != INPUT_FILTER_RESULT_DO_NOT_EMIT) { + const uint32_t input_filter_res = ctx->input_filter_fn(msg->ev, &msg->ev_size, &msg->ev_count); + if (((input_filter_res & INPUT_FILTER_FLAGS_DO_NOT_EMIT) == 0) && (msg->ev_count > 0)) { if (queue_push(ctx->queue, (void*)msg) != 0) { fprintf(stderr, "Error pushing event.\n"); diff --git a/input_dev.h b/input_dev.h index c298e9c..bbe456b 100644 --- a/input_dev.h +++ b/input_dev.h @@ -38,6 +38,6 @@ void *input_dev_thread_func(void *ptr); int open_and_hide_input(); -int input_filter_identity(struct input_event* events, size_t* size, uint32_t* count); +uint32_t input_filter_identity(struct input_event* events, size_t* size, uint32_t* count); -int input_filter_asus_kb(struct input_event*, size_t*, uint32_t*); \ No newline at end of file +uint32_t input_filter_asus_kb(struct input_event*, size_t*, uint32_t*); \ No newline at end of file diff --git a/message.h b/message.h index afdfed9..78844b9 100644 --- a/message.h +++ b/message.h @@ -14,7 +14,8 @@ typedef struct message { volatile uint32_t flags; } message_t; -#define INPUT_FILTER_RESULT_OK 0 -#define INPUT_FILTER_RESULT_DO_NOT_EMIT 1 +#define INPUT_FILTER_FLAGS_NONE 0x00000000U +#define INPUT_FILTER_FLAGS_DO_NOT_EMIT 0x00000001U +#define INPUT_FILTER_FLAGS_PRESERVE_TIME 0x00000002U -typedef int (*input_filter_t)(struct input_event*, size_t*, uint32_t*); \ No newline at end of file +typedef uint32_t (*input_filter_t)(struct input_event*, size_t*, uint32_t*); \ No newline at end of file diff --git a/output_dev.c b/output_dev.c index 3ad6aca..2cd05a2 100644 --- a/output_dev.c +++ b/output_dev.c @@ -402,18 +402,21 @@ void *output_dev_thread_func(void *ptr) { void *raw_ev; const int pop_res = queue_pop_timeout(out_dev->queue, &raw_ev, 1000); if (pop_res == 0) { - message_t *const msg = (message_t *)raw_ev; + message_t *const msg = (message_t*)raw_ev; for (uint32_t i = 0; i < msg->ev_count; ++i) { - gettimeofday(&now, NULL); - - /*const*/ struct input_event ev = { + struct input_event ev = { .code = msg->ev[i].code, .type = msg->ev[i].type, .value = msg->ev[i].value, - .time = now, + .time = msg->ev[i].time, }; + if ((msg->flags & INPUT_FILTER_FLAGS_PRESERVE_TIME) == 0) { + gettimeofday(&now, NULL); + ev.time = now; + } + /* if ((ev.type == EV_KEY) && (ev.code == KEY_PROG1)) { // To be wired to F16 ev.code = KEY_F12;