From 93e9672953d849288f27ff3d977cc1c1ff111da8 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Mon, 4 Oct 2021 11:33:07 -0700 Subject: feat(wm): keyboard focus corrected --- sys/cmd/wm/input.c | 127 +++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 58 deletions(-) (limited to 'sys/cmd/wm/input.c') diff --git a/sys/cmd/wm/input.c b/sys/cmd/wm/input.c index d9e6285..eb5fdd1 100644 --- a/sys/cmd/wm/input.c +++ b/sys/cmd/wm/input.c @@ -109,52 +109,33 @@ make_keyboard(struct wlr_input_device *device) static void -cursormove(uint32 time) { - server.grab.x = server.cursor.dot->x - server.grab.x; - server.grab.y = server.cursor.dot->y - server.grab.y; -} - -static -void -cursorresize(uint32 time) +focus_surface(Client *client, struct wlr_surface *surface, double sx, double sy, uint32 time) { - struct wlr_box box; - Client *client = server.grab.client; - double bx = server.cursor.dot->x - server.grab.x; - double by = server.cursor.dot->y - server.grab.y; - int new_left = server.grab.box.x; - int new_right = server.grab.box.x + server.grab.box.width; - int new_top = server.grab.box.y; - int new_bottom = server.grab.box.y + server.grab.box.height; - int new_width, new_height; - - if(server.resize & WLR_EDGE_TOP) { - new_top = by; - if (new_top >= new_bottom) - new_top = new_bottom - 1; - }else if (server.resize & WLR_EDGE_BOTTOM) { - new_bottom = by; - if (new_bottom <= new_top) - new_bottom = new_top + 1; + struct timespec now; + int lift = time; + + if(client && !surface) + surface = client->xdg->surface; + + if(!surface){ + wlr_seat_pointer_notify_clear_focus(server.input.seat); + return; } - if(server.resize & WLR_EDGE_LEFT) { - new_left = bx; - if (new_left >= new_right) - new_left = new_right - 1; - } else if(server.resize & WLR_EDGE_RIGHT) { - new_right = bx; - if (new_right <= new_left) - new_right = new_left + 1; + if(!time) { + clock_gettime(CLOCK_MONOTONIC, &now); + time = now.tv_sec * 1000 + now.tv_nsec / 1000000; } - wlr_xdg_surface_get_geometry(client->xdg, &box); - client->geometry.x = new_left - box.x; - client->geometry.y = new_top - box.y; + if(surface == server.input.seat->pointer_state.focused_surface) { + wlr_seat_pointer_notify_motion(server.input.seat, time, sx, sy); + return; + } + + wlr_seat_pointer_notify_enter(server.input.seat, surface, sx, sy); - new_width = new_right - new_left; - new_height = new_bottom - new_top; - wlr_xdg_toplevel_set_size(client->xdg, new_width, new_height); + if(cfg·sloppyfocus && lift) + focus(client, 0); } static @@ -163,9 +144,14 @@ move(uint32 time) { double sx, sy; Client *client; - struct wlr_seat *seat; struct wlr_surface *surface; + if(time) { + wlr_idle_notify_activity(server.input.idle, server.input.seat); + if(cfg·sloppyfocus) + server.monitor.selected = monitor_at(server.cursor.dot->x, server.cursor.dot->y); + } + if(server.cursor.mode == CursorMove) { resize(server.grab.client, server.cursor.dot->x - server.grab.x, @@ -189,18 +175,20 @@ move(uint32 time) } /* Otherwise, find the client under the pointer and send the event along. */ - seat = server.input.seat; - surface = nil; - client = client_at(server.cursor.dot->x, server.cursor.dot->y, &surface, &sx, &sy); - if(!client) + client = client_at(server.cursor.dot->x, server.cursor.dot->y); + if(!client) { wlr_xcursor_manager_set_cursor_image(server.cursor.manager, "left_ptr", server.cursor.dot); - - if(surface) { - wlr_seat_pointer_notify_enter(seat, surface, sx, sy); - wlr_seat_pointer_notify_motion(seat, time, sx, sy); - } else { - wlr_seat_pointer_clear_focus(seat); + return; } + + surface = client_surface_at( + client, + server.cursor.dot->x - client->geometry.x - client->border, + server.cursor.dot->y - client->geometry.y - client->border, + &sx, &sy + ); + + focus_surface(client, surface, sx, sy, time); } void @@ -223,16 +211,39 @@ void cursor_button(struct wl_listener *l, void *data) { Client *client; - double sx, sy; - struct wlr_surface *surface; + uint32 modifier; + Button *button; + struct wlr_keyboard *keyboard; struct wlr_event_pointer_button *event = data; + wlr_idle_notify_activity(server.input.idle, server.input.seat); + + switch(event->state) { + case WLR_BUTTON_PRESSED: + if((client=client_at(server.cursor.dot->x, server.cursor.dot->y))) + focus(client,1); + + keyboard = wlr_seat_get_keyboard(server.input.seat); + modifier = wlr_keyboard_get_modifiers(keyboard); + for(button=cfg·button; button != cfg·endbutton; ++button) { + if(modifier == button->modifier && event->button == button->code && button->function) { + button->function(&button->arg); + return; + } + } + break; + case WLR_BUTTON_RELEASED: + if(server.cursor.mode != CursorNormal) { + wlr_xcursor_manager_set_cursor_image(server.cursor.manager, "left_ptr", server.cursor.dot); + server.cursor.mode = CursorNormal; + /* Drop the window off on its new monitor */ + server.monitor.selected = monitor_at(server.cursor.dot->x, server.cursor.dot->y); + attach(server.grab.client, server.monitor.selected, 0); + return; + } + } + wlr_seat_pointer_notify_button(server.input.seat, event->time_msec, event->button, event->state); - client = client_at(server.cursor.dot->x, server.cursor.dot->y, &surface, &sx, &sy); - if (event->state == WLR_BUTTON_RELEASED) - server.cursor.mode = CursorPassthrough; - else - focus(client, 1); } void -- cgit v1.2.1