spkp

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

commit 99f831765709a109e30d4a5ef5343ed2e55ea3fc
parent 813ab37ef9e0a2606ec13c78c3abac5f5655fb56
Author: Willy Goiffon <dev@z3bra.org>
Date:   Thu, 12 Nov 2020 14:42:37 +0100

Add move/resize by dragging borders

Diffstat:
Mcompositor.c | 38+++++++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/compositor.c b/compositor.c @@ -32,6 +32,11 @@ enum { RESIZE, }; +enum { + CONTENT, + BORDER, +}; + /* Internal compositor state */ struct state { struct wl_display *dpy; @@ -92,6 +97,7 @@ struct window { struct wlr_surface *topmost; double sx, sy; + int area; struct wl_listener map; struct wl_listener unmap; @@ -658,10 +664,18 @@ cb_click(struct wl_listener *listener, void *data) kb = wlr_seat_get_keyboard(server->seat); ev = data; - if (kb->modifiers.depressed & WLR_MODIFIER_LOGO + w = underneath(server, server->cursor->x, server->cursor->y); + + /* don't enter grab mode when there is no window under the pointer */ + if (!w) { + wlr_seat_pointer_clear_focus(server->seat); + server->grabmode = NORMAL; + return; + } + + if ((w->area == BORDER || (kb->modifiers.depressed & WLR_MODIFIER_LOGO)) && ev->state == WLR_BUTTON_PRESSED && server->grabmode == NORMAL) { - switch (ev->button) { case BTN_LEFT: server->grabmode = MOVE; @@ -683,13 +697,6 @@ cb_click(struct wl_listener *listener, void *data) return; } - /* don't enter grab mode when there is no window under the pointer */ - if (!(w = underneath(server, server->cursor->x, server->cursor->y))) { - wlr_seat_pointer_clear_focus(server->seat); - server->grabmode = NORMAL; - return; - } - /* * Save which window was clicked, and the coordinates * of the event on that surface. @@ -818,7 +825,6 @@ render(struct wlr_surface *surface, int x, int y, void *data) } wlr_matrix_project_box(matrix, &box, transform, 0, output->transform_matrix); - wlr_render_texture_with_matrix(rdata->renderer, texture, matrix, 1); wlr_surface_send_frame_done(surface, &rdata->when); } @@ -900,8 +906,18 @@ underneath(struct state *server, double x, double y) w->topmost = wlr_xdg_surface_surface_at(w->toplevel, x - w->x, y - w->y, &w->sx, &w->sy); - if (w->topmost) + if (w->topmost) { + w->area = CONTENT; + return w; + } + + if (server->cursor->x > w->x - bordersize + && server->cursor->y > w->y - bordersize + && server->cursor->x < w->x + w->toplevel->surface->current.width + bordersize + && server->cursor->y < w->y + w->toplevel->surface->current.height + bordersize) { + w->area = BORDER; return w; + } } return NULL;