[WIP] Add handling of absolute mouse position (touch/graphic tablets)
This commit is contained in:
parent
b9d7ed276d
commit
44acb94e43
src
19
src/main.c
19
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue