aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-10-12 13:30:28 +0200
committerBad Diode <bd@badd10de.dev>2022-10-12 13:30:28 +0200
commit44acb94e4339e240bb9e7f93d14a7757e2db8962 (patch)
treed84b8b38e0cf3fdff909f15d0823f2e541832e56
parentb9d7ed276d73f671f482ca88958ac38d618f2644 (diff)
downloaduxnfb-44acb94e4339e240bb9e7f93d14a7757e2db8962.tar.gz
uxnfb-44acb94e4339e240bb9e7f93d14a7757e2db8962.zip
[WIP] Add handling of absolute mouse position (touch/graphic tablets)
-rw-r--r--src/main.c19
1 files 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) {
83 // fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); 83 // fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
84 } 84 }
85 85
86 in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); 86 // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
87 in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
87 if (in.mouse_fd == -1) { 88 if (in.mouse_fd == -1) {
88 // NOTE: Some applications may not require a mouse so this is 89 // NOTE: Some applications may not require a mouse so this is
89 // optional, but we are still displaying an error. 90 // optional, but we are still displaying an error.
90 // fprintf(stderr, "error: couldn't open mouse %s: %s.\n", MOUSE_PATH, strerror(errno)); 91 fprintf(stderr, "error: couldn't open mouse %s: %s.\n", MOUSE_PATH, strerror(errno));
91 } 92 }
92} 93}
93 94
@@ -116,6 +117,7 @@ poll_mouse(void) {
116 struct input_event mouse_event; 117 struct input_event mouse_event;
117 if (read(in.mouse_fd, &mouse_event, sizeof(mouse_event)) != -1) { 118 if (read(in.mouse_fd, &mouse_event, sizeof(mouse_event)) != -1) {
118 if (mouse_event.type == EV_REL) { 119 if (mouse_event.type == EV_REL) {
120 printf("MOUSE REL EVENT\n");
119 if (mouse_event.code == REL_X) { 121 if (mouse_event.code == REL_X) {
120 in.mouse.x = CLAMP( 122 in.mouse.x = CLAMP(
121 in.mouse.x + (s32)mouse_event.value, 0, (s32)screen_width); 123 in.mouse.x + (s32)mouse_event.value, 0, (s32)screen_width);
@@ -124,6 +126,7 @@ poll_mouse(void) {
124 in.mouse.y + (s32)mouse_event.value, 0, (s32)screen_height); 126 in.mouse.y + (s32)mouse_event.value, 0, (s32)screen_height);
125 } 127 }
126 } else if (mouse_event.type == EV_KEY) { 128 } else if (mouse_event.type == EV_KEY) {
129 printf("MOUSE KEY EVENT\n");
127 switch (mouse_event.code) { 130 switch (mouse_event.code) {
128 case BTN_LEFT: { 131 case BTN_LEFT: {
129 if (mouse_event.value == 1) { 132 if (mouse_event.value == 1) {
@@ -141,17 +144,21 @@ poll_mouse(void) {
141 } break; 144 } break;
142 default: break; 145 default: break;
143 } 146 }
147 } else if (mouse_event.type == EV_ABS) {
148 printf("MOUSE ABS EVENT\n");
149 if (mouse_event.code == ABS_X) {
150 in.mouse.x = CLAMP((s32)mouse_event.value, 0, (s32)screen_width);
151 } else if (mouse_event.code == ABS_Y) {
152 in.mouse.y = CLAMP((s32)mouse_event.value, 0, (s32)screen_height);
153 }
144 } 154 }
145 in.mouse.update = true; 155 in.mouse.update = true;
146 // DEBUG:
147 // printf("MOUSE: (type: %d, code: %d, value: %d)\n",
148 // mouse_event.type, mouse_event.code, mouse_event.value);
149 } 156 }
150} 157}
151 158
152void 159void
153poll_input(void) { 160poll_input(void) {
154 poll_keyboard(); 161 // poll_keyboard();
155 poll_mouse(); 162 poll_mouse();
156} 163}
157 164