implement Button: movemouse, resizemouse

This commit is contained in:
Devin J. Pohly 2020-04-11 21:29:27 -05:00
parent bbe24fa8d4
commit edf90816b1
2 changed files with 52 additions and 0 deletions

View file

@ -12,3 +12,8 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_Escape, quit, {0} }, { MODKEY, XKB_KEY_Escape, quit, {0} },
{ MODKEY, XKB_KEY_F1, focusnext, {0} }, { MODKEY, XKB_KEY_F1, focusnext, {0} },
}; };
static const Button buttons[] = {
{ MODKEY, BTN_LEFT, movemouse, {0} },
{ MODKEY, BTN_RIGHT, resizemouse, {0} },
};

47
dwl.c
View file

@ -8,6 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <linux/input-event-codes.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
@ -111,8 +112,17 @@ typedef struct {
const Arg arg; const Arg arg;
} Key; } 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 focusnext(struct dwl_server *, const Arg *);
static void movemouse(struct dwl_server *, const Arg *);
static void quit(struct dwl_server *, const Arg *); static void quit(struct dwl_server *, const Arg *);
static void resizemouse(struct dwl_server *, const Arg *);
#include "config.h" #include "config.h"
@ -513,6 +523,16 @@ static void server_cursor_button(struct wl_listener *listener, void *data) {
} else { } else {
/* Focus that client if the button was _pressed_ */ /* Focus that client if the button was _pressed_ */
focus_view(view, surface); 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; 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( static void xdg_toplevel_request_move(
struct wl_listener *listener, void *data) { struct wl_listener *listener, void *data) {
/* This event is raised when a client would like to begin an interactive /* This event is raised when a client would like to begin an interactive