better flow
This commit is contained in:
parent
b470ed94c1
commit
2b51d14e41
1 changed files with 16 additions and 10 deletions
26
input_dev.c
26
input_dev.c
|
|
@ -2,6 +2,7 @@
|
|||
#include "message.h"
|
||||
#include "queue.h"
|
||||
|
||||
#include <libevdev-1.0/libevdev/libevdev.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
#include <linux/input.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -73,10 +74,12 @@ void* input_read_thread_func(void* ptr) {
|
|||
struct input_ctx* ctx = (struct input_ctx*)ptr;
|
||||
struct libevdev* dev = ctx->dev;
|
||||
|
||||
int has_syn = libevdev_has_event_type(ctx->dev, EV_SYN);
|
||||
|
||||
int rc = 1;
|
||||
|
||||
message_t* msg = NULL;
|
||||
|
||||
|
||||
do {
|
||||
if (msg == NULL) {
|
||||
for (int h = 0; h < MAX_MESSAGES_IN_FLIGHT; ++h) {
|
||||
|
|
@ -96,7 +99,18 @@ void* input_read_thread_func(void* ptr) {
|
|||
struct input_event read_ev;
|
||||
rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_BLOCKING, &read_ev);
|
||||
if (rc == 0) {
|
||||
if ((read_ev.type == EV_SYN) && (read_ev.code == SYN_REPORT)) {
|
||||
|
||||
if ((!has_syn) || ((read_ev.type != EV_SYN) && (read_ev.code != SYN_REPORT))) {
|
||||
if ((msg->ev_count+1) == msg->ev_size) {
|
||||
// TODO: perform a memove
|
||||
} else {
|
||||
// just copy the input event
|
||||
msg->ev[msg->ev_count] = read_ev;
|
||||
++msg->ev_count;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!has_syn) || ((read_ev.type == EV_SYN) && (read_ev.code == SYN_REPORT))) {
|
||||
// clear out flags
|
||||
msg->flags = 0x00000000U;
|
||||
|
||||
|
|
@ -109,14 +123,6 @@ void* input_read_thread_func(void* ptr) {
|
|||
}
|
||||
|
||||
msg = NULL;
|
||||
} else {
|
||||
if ((msg->ev_count+1) == msg->ev_size) {
|
||||
// TODO: perform a memove
|
||||
} else {
|
||||
// just copy the input event
|
||||
msg->ev[msg->ev_count] = read_ev;
|
||||
++msg->ev_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (rc == 1 || rc == 0 || rc == -EAGAIN);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue