From 3973ea5bfe9676bf8673781a966c933b0af0a232 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 30 Apr 2020 10:25:37 -0500 Subject: unify movemouse/resizemouse --- config.def.h | 4 ++-- dwl.c | 42 ++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/config.def.h b/config.def.h index 5487cee..9f8c2e3 100644 --- a/config.def.h +++ b/config.def.h @@ -78,7 +78,7 @@ static const Key keys[] = { }; static const Button buttons[] = { - { MODKEY, BTN_LEFT, movemouse, {0} }, + { MODKEY, BTN_LEFT, moveresize, {.ui = CurMove} }, { MODKEY, BTN_MIDDLE, togglefloating, {0} }, - { MODKEY, BTN_RIGHT, resizemouse, {0} }, + { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, }; diff --git a/dwl.c b/dwl.c index d0fb19b..1060d10 100644 --- a/dwl.c +++ b/dwl.c @@ -148,7 +148,7 @@ static void maprequest(struct wl_listener *listener, void *data); static void motionabsolute(struct wl_listener *listener, void *data); static void motionnotify(uint32_t time); static void motionrelative(struct wl_listener *listener, void *data); -static void movemouse(const Arg *arg); +static void moveresize(const Arg *arg); static void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time); static void quit(const Arg *arg); @@ -157,7 +157,6 @@ static void render(struct wlr_surface *surface, int sx, int sy, void *data); static void renderclients(Monitor *m, struct timespec *now); static void rendermon(struct wl_listener *listener, void *data); static void resize(Client *c, int x, int y, int w, int h, int interact); -static void resizemouse(const Arg *arg); static void run(char *startup_cmd); static void scalebox(struct wlr_box *box, float scale); static Client *selclient(void); @@ -733,7 +732,7 @@ motionrelative(struct wl_listener *listener, void *data) } void -movemouse(const Arg *arg) +moveresize(const Arg *arg) { struct wlr_surface *surface; grabc = xytoclient(cursor->x, cursor->y, &surface, &grabsx, &grabsy); @@ -742,8 +741,20 @@ movemouse(const Arg *arg) /* Float the window and tell motionnotify to grab it */ setfloating(grabc, 1); - cursor_mode = CurMove; - wlr_xcursor_manager_set_cursor_image(cursor_mgr, "fleur", cursor); + switch (cursor_mode = arg->ui) { + case CurMove: + wlr_xcursor_manager_set_cursor_image(cursor_mgr, "fleur", cursor); + break; + case CurResize: + /* Doesn't work for X11 output - the next absolute motion event + * returns the cursor to where it started */ + wlr_cursor_warp_closest(cursor, NULL, + grabc->geom.x + grabc->geom.width, + grabc->geom.y + grabc->geom.height); + wlr_xcursor_manager_set_cursor_image(cursor_mgr, + "bottom_right_corner", cursor); + break; + } } void @@ -939,27 +950,6 @@ resize(Client *c, int x, int y, int w, int h, int interact) c->geom.width - 2 * c->bw, c->geom.height - 2 * c->bw); } -void -resizemouse(const Arg *arg) -{ - struct wlr_surface *surface; - grabc = xytoclient(cursor->x, cursor->y, &surface, &grabsx, &grabsy); - if (!grabc) - return; - - /* Doesn't work for X11 output - the next absolute motion event - * returns the cursor to where it started */ - wlr_cursor_warp_closest(cursor, NULL, - grabc->geom.x + grabc->geom.width, - grabc->geom.y + grabc->geom.height); - - /* Float the window and tell motionnotify to resize it */ - setfloating(grabc, 1); - cursor_mode = CurResize; - wlr_xcursor_manager_set_cursor_image(cursor_mgr, - "bottom_right_corner", cursor); -} - void run(char *startup_cmd) { -- cgit v1.2.3