From 3516c210da50dba1fd5d85af66ccbb43db6d2a8d Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 23 Oct 2023 17:22:39 +0200 Subject: WindowServer: Add ability to focus on windows by doing a left click. --- userland/windowserver/ws.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'userland') diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c index 6c7e6ee..8511497 100644 --- a/userland/windowserver/ws.c +++ b/userland/windowserver/ws.c @@ -278,10 +278,24 @@ void update_mouse(void) { return; } +void focus_window(int x, int y) { + for (int i = 0; i < 100; i++) { + if (!clients[i]) + continue; + WINDOW *w = clients[i]->w; + if (w->x < x && x < w->x + w->sx) { + if (w->y < y && y < w->y + w->sy) { + active_client = clients[i]; + } + } + } +} + void parse_mouse_event(int fd) { int16_t xc = 0; int16_t yc = 0; int middle_button = 0; + int left_button = 0; for (;;) { struct mouse_event e[100]; int rc = read(fd, e, sizeof(e)); @@ -293,6 +307,7 @@ void parse_mouse_event(int fd) { uint8_t xs = e[i].buttons & (1 << 4); uint8_t ys = e[i].buttons & (1 << 5); middle_button = e[i].buttons & (1 << 2); + left_button = e[i].buttons & (1 << 0); int16_t x = e[i].x; int16_t y = e[i].y; if (xs) @@ -309,6 +324,9 @@ void parse_mouse_event(int fd) { mouse_x = 0; if (mouse_y < 0) mouse_y = 0; + if (left_button) { + focus_window(mouse_x, mouse_y); + } if (middle_button) { if (active_client) { active_client->w->x += xc; -- cgit v1.2.3