From 44acb94e4339e240bb9e7f93d14a7757e2db8962 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 12 Oct 2022 13:30:28 +0200 Subject: [WIP] Add handling of absolute mouse position (touch/graphic tablets) --- src/main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index f2d373b..cdc8530 100644 --- a/src/main.c +++ b/src/main.c @@ -83,11 +83,12 @@ init_input(void) { // fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); } - in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); + // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); + in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK); if (in.mouse_fd == -1) { // NOTE: Some applications may not require a mouse so this is // optional, but we are still displaying an error. - // fprintf(stderr, "error: couldn't open mouse %s: %s.\n", MOUSE_PATH, strerror(errno)); + fprintf(stderr, "error: couldn't open mouse %s: %s.\n", MOUSE_PATH, strerror(errno)); } } @@ -116,6 +117,7 @@ poll_mouse(void) { struct input_event mouse_event; if (read(in.mouse_fd, &mouse_event, sizeof(mouse_event)) != -1) { if (mouse_event.type == EV_REL) { + printf("MOUSE REL EVENT\n"); if (mouse_event.code == REL_X) { in.mouse.x = CLAMP( in.mouse.x + (s32)mouse_event.value, 0, (s32)screen_width); @@ -124,6 +126,7 @@ poll_mouse(void) { in.mouse.y + (s32)mouse_event.value, 0, (s32)screen_height); } } else if (mouse_event.type == EV_KEY) { + printf("MOUSE KEY EVENT\n"); switch (mouse_event.code) { case BTN_LEFT: { if (mouse_event.value == 1) { @@ -141,17 +144,21 @@ poll_mouse(void) { } break; default: break; } + } else if (mouse_event.type == EV_ABS) { + printf("MOUSE ABS EVENT\n"); + if (mouse_event.code == ABS_X) { + in.mouse.x = CLAMP((s32)mouse_event.value, 0, (s32)screen_width); + } else if (mouse_event.code == ABS_Y) { + in.mouse.y = CLAMP((s32)mouse_event.value, 0, (s32)screen_height); + } } in.mouse.update = true; - // DEBUG: - // printf("MOUSE: (type: %d, code: %d, value: %d)\n", - // mouse_event.type, mouse_event.code, mouse_event.value); } } void poll_input(void) { - poll_keyboard(); + // poll_keyboard(); poll_mouse(); } -- cgit v1.2.1