spkp

Stacking wayland compositor
git clone git://git.z3bra.org/sp:kp.git
Log | Files | Refs

commit 948970631cb014fc86a1e0433accd01c612b5fc0
parent 685f7e2b3c1c5c18db7b5efdc1d0a69c3640ccee
Author: Willy Goiffon <dev@z3bra.org>
Date:   Tue, 10 Nov 2020 11:51:55 +0100

Refactor move/resize mouse operations

Diffstat:
Mcompositor.c | 51++++++++++++++++++++++++++++++---------------------
1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/compositor.c b/compositor.c @@ -44,6 +44,7 @@ struct state { struct wlr_seat *seat; int grabmode; + double gx, gy; struct window *grabbed; struct wlr_cursor *cursor; @@ -498,8 +499,8 @@ cb_motion(struct state *server, uint32_t time) switch(server->grabmode) { case MOVE: wlr_xdg_surface_get_geometry(w->toplevel, &geom); - w->x = server->cursor->x - geom.width/2; - w->y = server->cursor->y - geom.height/2; + w->x = server->cursor->x - server->gx; + w->y = server->cursor->y - server->gy; return; /* NOTREACHED */; break; case RESIZE: @@ -584,38 +585,46 @@ cb_click(struct wl_listener *listener, void *data) kb = wlr_seat_get_keyboard(server->seat); ev = data; - w = underneath(server, server->cursor->x, server->cursor->y); - if (kb->modifiers.depressed & WLR_MODIFIER_LOGO && ev->state == WLR_BUTTON_PRESSED) { - switch (ev->button) { - case BTN_LEFT: - server->grabbed = w; - server->grabmode = MOVE; - break; - case BTN_RIGHT: - server->grabbed = w; - server->grabmode = RESIZE; - break; - } - } - - wlr_seat_pointer_notify_button(server->seat, ev->time_msec, ev->button, ev->state); + if (server->grabmode == NORMAL) + wlr_seat_pointer_notify_button(server->seat, + ev->time_msec, ev->button, ev->state); if (ev->state == WLR_BUTTON_RELEASED) { server->grabmode = NORMAL; return; } - if (!w) { + if (!(w = underneath(server, server->cursor->x, server->cursor->y))) { wlr_seat_pointer_clear_focus(server->seat); return; } - /* reinsert window on top of the stack */ + if (kb->modifiers.depressed & WLR_MODIFIER_LOGO + && ev->state == WLR_BUTTON_PRESSED + && server->grabmode == NORMAL) { + + /* + * Save which window was clicked, and the coordinates + * of the event on that surface. + */ + server->grabbed = w; + server->gx = w->sx; + server->gy = w->sy; + + switch (ev->button) { + case BTN_LEFT: + server->grabmode = MOVE; + break; + case BTN_RIGHT: + server->grabmode = RESIZE; + break; + } + } + + /* bring window to the front */ wl_list_remove(&w->link); wl_list_insert(&server->windows, &w->link); - wlr_seat_pointer_notify_enter(server->seat, w->topmost, w->sx, w->sy); - focus(w); }