diff options
author | Anton Kling <anton@kling.gg> | 2024-06-25 18:56:42 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-06-25 18:56:42 +0200 |
commit | 31743482bbdceeb2a0e52ae430ce1afad853e7e9 (patch) | |
tree | c6d6980d6613d4cc0eb3ac3b824b39660589dab5 /userland | |
parent | 90a8be18547040cab8c395c64d681be1f95ec517 (diff) |
Optimize mouse driver to perform more work in kernel
Instead of sending every event to userland they now get handeld in the
kernel when possible. It will now only send out events when buttons are
clicked or the mouse position is requested by userland.
Diffstat (limited to 'userland')
-rw-r--r-- | userland/windowserver/ws.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c index b177358..7a1b7d6 100644 --- a/userland/windowserver/ws.c +++ b/userland/windowserver/ws.c @@ -5,13 +5,13 @@ #include <fcntl.h> #include <math.h> #include <poll.h> -#include <sys/socket.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> +#include <sys/socket.h> #include <unistd.h> #define WINDOW_SERVER_SOCKET "/windowserver" @@ -347,8 +347,8 @@ int windowserver_key_events(struct KEY_EVENT ev, int *redraw) { struct mouse_event { uint8_t buttons; - uint8_t x; - uint8_t y; + int x; + int y; }; void send_resize(WINDOW *w, int x, int y) { @@ -360,42 +360,36 @@ void send_resize(WINDOW *w, int x, int y) { } void parse_mouse_event(int fd) { - int16_t xc = 0; - int16_t yc = 0; + int xc = 0; + int yc = 0; int middle_button = 0; int right_button = 0; int left_button = 0; - struct mouse_event e[100]; - for (;;) { - int rc = read(fd, e, sizeof(e)); - if (rc <= 0) - break; + struct mouse_event e; + int rc = read(fd, &e, sizeof(e)); + if (rc <= 0) + return; - int n = rc / sizeof(e[0]); - for (int i = 0; i < n; i++) { - uint8_t xs = e[i].buttons & (1 << 4); - uint8_t ys = e[i].buttons & (1 << 5); - middle_button = e[i].buttons & (1 << 2); - right_button = e[i].buttons & (1 << 1); - left_button = e[i].buttons & (1 << 0); - int16_t x = e[i].x; - int16_t y = e[i].y; - if (xs) - x |= 0xFF00; - if (ys) - y |= 0xFF00; - xc += x; - yc += y; - } - } - mouse_x += xc; - mouse_y -= yc; + uint8_t xs = e.buttons & (1 << 4); + uint8_t ys = e.buttons & (1 << 5); + middle_button = e.buttons & (1 << 2); + right_button = e.buttons & (1 << 1); + left_button = e.buttons & (1 << 0); + + xc = -mouse_x; + yc = mouse_y; + + mouse_x = e.x; + mouse_y = e.y; if (mouse_x < 0) { mouse_x = 0; } if (mouse_y < 0) { mouse_y = 0; } + + xc += mouse_x; + yc -= mouse_y; if (mouse_left_down && !left_button) { mouse_left_up = 1; } else { |