Fix 32bit event mapping

This commit is contained in:
mae 2024-11-10 16:39:26 +01:00
parent 166f5384c0
commit ab2d25343a

View file

@ -8,8 +8,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct input_event32 {
__u32 __sec;
__u32 __usec;
__u16 type;
__u16 code;
__s32 value;
};
int read_input_event(struct input_event *ie) { 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)) { if (feof(stdin)) {
return EOF; return EOF;
} else { } else {
@ -19,6 +28,11 @@ int read_input_event(struct input_event *ie) {
return 1; 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; return 0;
} }
@ -134,18 +148,21 @@ int process_events(FILE *dev) {
while (true) { while (true) {
int res; int res;
struct input_event ie; struct input_event ie;
while ((!(res = read_input_event(&ie))) && while ((!(res = read_input_event(&ie)))) {
(ie.type != EV_ABS && (ie.code != ABS_MT_TOOL_TYPE) && if (ie.type == EV_ABS && ie.code == ABS_MT_TOOL_TYPE &&
(ie.value != MT_TOOL_PEN))) { (ie.value == MT_TOOL_PEN))
break;
} }
if (res == EOF) if (res == EOF)
return EXIT_SUCCESS; return EXIT_SUCCESS;
if (res != 0) if (res != 0)
return EXIT_FAILURE; return EXIT_FAILURE;
while (!(res = read_input_event(&ie) && (ie.type == EV_ABS) && while (!(res = read_input_event(&ie))) {
(ie.code == ABS_MT_TOOL_TYPE) && if (ie.type == EV_ABS && (ie.code == ABS_MT_TOOL_TYPE) &&
(ie.value != MT_TOOL_PEN))) { (ie.value != MT_TOOL_PEN)) {
break;
}
if (rewrite_pen_event(&ie)) if (rewrite_pen_event(&ie))
forward_event(dev, &ie); forward_event(dev, &ie);
}; };
@ -162,5 +179,5 @@ int main(void) {
} }
res = process_events(dev); res = process_events(dev);
cleanup(dev); cleanup(dev);
return EXIT_SUCCESS; return res;
} }