diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2020-04-11 21:29:27 -0500 |
---|---|---|
committer | Devin J. Pohly <djpohly@gmail.com> | 2020-04-11 21:29:27 -0500 |
commit | edf90816b1437d2a6de3f38db7560731cf38a75c (patch) | |
tree | 9891588eaaf31d3c6181d9d9287f9150c91456ec | |
parent | bbe24fa8d43debd8646f0a9294e7a89414dee8ac (diff) |
implement Button: movemouse, resizemouse
-rw-r--r-- | config.h | 5 | ||||
-rw-r--r-- | dwl.c | 47 |
2 files changed, 52 insertions, 0 deletions
@@ -12,3 +12,8 @@ static const Key keys[] = { { MODKEY, XKB_KEY_Escape, quit, {0} }, { MODKEY, XKB_KEY_F1, focusnext, {0} }, }; + +static const Button buttons[] = { + { MODKEY, BTN_LEFT, movemouse, {0} }, + { MODKEY, BTN_RIGHT, resizemouse, {0} }, +}; @@ -8,6 +8,7 @@ #include <stdio.h> #include <time.h> #include <unistd.h> +#include <linux/input-event-codes.h> #include <wayland-server-core.h> #include <wlr/backend.h> #include <wlr/render/wlr_renderer.h> @@ -111,8 +112,17 @@ typedef struct { const Arg arg; } Key; +typedef struct { + unsigned int mod; + unsigned int button; + void (*func)(struct dwl_server *, const Arg *); + const Arg arg; +} Button; + static void focusnext(struct dwl_server *, const Arg *); +static void movemouse(struct dwl_server *, const Arg *); static void quit(struct dwl_server *, const Arg *); +static void resizemouse(struct dwl_server *, const Arg *); #include "config.h" @@ -513,6 +523,16 @@ static void server_cursor_button(struct wl_listener *listener, void *data) { } else { /* Focus that client if the button was _pressed_ */ focus_view(view, surface); + + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); + uint32_t mods = wlr_keyboard_get_modifiers(keyboard); + for (int i = 0; i < LENGTH(buttons); i++) { + if (event->button == buttons[i].button && + CLEANMASK(mods) == CLEANMASK(buttons[i].mod) && + buttons[i].func) { + buttons[i].func(server, &buttons[i].arg); + } + } } } @@ -757,6 +777,33 @@ static void begin_interactive(struct dwl_view *view, server->resize_edges = edges; } +static void movemouse(struct dwl_server *server, const Arg *unused) { + double sx, sy; + struct wlr_surface *surface; + struct dwl_view *view = desktop_view_at(server, + server->cursor->x, server->cursor->y, &surface, &sx, &sy); + if (!view) { + return; + } + begin_interactive(view, DWL_CURSOR_MOVE, 0); +} + +static void resizemouse(struct dwl_server *server, const Arg *unused) { + double sx, sy; + struct wlr_surface *surface; + struct dwl_view *view = desktop_view_at(server, + server->cursor->x, server->cursor->y, &surface, &sx, &sy); + if (!view) { + return; + } + struct wlr_box geo_box; + wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box); + wlr_cursor_warp_closest(server->cursor, NULL, + view->x + geo_box.x + geo_box.width, + view->y + geo_box.y + geo_box.height); + begin_interactive(view, DWL_CURSOR_RESIZE, WLR_EDGE_BOTTOM|WLR_EDGE_RIGHT); +} + static void xdg_toplevel_request_move( struct wl_listener *listener, void *data) { /* This event is raised when a client would like to begin an interactive |