From ab2d25343aaefb6fbcfd3e8706458be46d913286 Mon Sep 17 00:00:00 2001 From: mae Date: Sun, 10 Nov 2024 16:39:26 +0100 Subject: [PATCH] Fix 32bit event mapping --- src/main.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 5727789..068768e 100644 --- a/src/main.c +++ b/src/main.c @@ -8,8 +8,17 @@ #include #include +struct input_event32 { + __u32 __sec; + __u32 __usec; + __u16 type; + __u16 code; + __s32 value; +}; + int read_input_event(struct input_event *ie) { - if (fread(ie, sizeof(struct input_event), 1, stdin) != 1) { + struct input_event32 ie32 = {0}; + if (fread(&ie32, sizeof(struct input_event32), 1, stdin) != 1) { if (feof(stdin)) { return EOF; } else { @@ -19,6 +28,11 @@ int read_input_event(struct input_event *ie) { return 1; } } + ie->input_event_sec = ie32.__sec; + ie->input_event_usec = ie32.__usec; + ie->code = ie32.code; + ie->type = ie32.type; + ie->value = ie32.value; return 0; } @@ -134,18 +148,21 @@ int process_events(FILE *dev) { while (true) { int res; struct input_event ie; - while ((!(res = read_input_event(&ie))) && - (ie.type != EV_ABS && (ie.code != ABS_MT_TOOL_TYPE) && - (ie.value != MT_TOOL_PEN))) { + while ((!(res = read_input_event(&ie)))) { + if (ie.type == EV_ABS && ie.code == ABS_MT_TOOL_TYPE && + (ie.value == MT_TOOL_PEN)) + break; } if (res == EOF) return EXIT_SUCCESS; if (res != 0) return EXIT_FAILURE; - while (!(res = read_input_event(&ie) && (ie.type == EV_ABS) && - (ie.code == ABS_MT_TOOL_TYPE) && - (ie.value != MT_TOOL_PEN))) { + while (!(res = read_input_event(&ie))) { + if (ie.type == EV_ABS && (ie.code == ABS_MT_TOOL_TYPE) && + (ie.value != MT_TOOL_PEN)) { + break; + } if (rewrite_pen_event(&ie)) forward_event(dev, &ie); }; @@ -162,5 +179,5 @@ int main(void) { } res = process_events(dev); cleanup(dev); - return EXIT_SUCCESS; + return res; }