diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2023-06-06 14:10:14 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-09-23 20:33:11 +0000 |
| commit | c2ba92be4ee2e7964d60c3dbbb1b00e66ff28cd2 (patch) | |
| tree | 88758ed2eb7632130d6a62c2225113e324ae8edb /dwl.c | |
| parent | 002c7d22043da56a54511b5d234c2e3bd997d119 (diff) | |
Patch: mouse-follows-focus
Diffstat (limited to 'dwl.c')
| -rw-r--r-- | dwl.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -351,6 +351,7 @@ static void urgent(struct wl_listener *listener, void *data); static void view(const Arg *arg); static void virtualkeyboard(struct wl_listener *listener, void *data); static void virtualpointer(struct wl_listener *listener, void *data); +static void warpcursortoclient(Client *c); static Monitor *xytomon(double x, double y); static void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc, LayerSurface **pl, double *nx, double *ny); @@ -514,6 +515,8 @@ arrange(Monitor *m) if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); motionnotify(0, NULL, 0, 0, 0, 0); + + if (c && mousefollowsfocus) warpcursortoclient(c); checkidleinhibitor(NULL); } @@ -1410,12 +1413,17 @@ void focusmon(const Arg *arg) { int i = 0, nmons = wl_list_length(&mons); + Client *c = NULL; if (nmons) { do /* don't switch to disabled mons */ selmon = dirtomon(arg->i); while (!selmon->wlr_output->enabled && i++ < nmons); } - focusclient(focustop(selmon), 1); + + c = focustop(selmon); + focusclient(c, 1); + + if (mousefollowsfocus) warpcursortoclient(c); } void @@ -1442,6 +1450,7 @@ focusstack(const Arg *arg) } /* If only one client is visible on selmon, then c == sel */ focusclient(c, 1); + if (mousefollowsfocus) warpcursortoclient(c); } /* We probably should change the name of this, it sounds like @@ -2942,6 +2951,16 @@ virtualpointer(struct wl_listener *listener, void *data) wlr_cursor_map_input_to_output(cursor, device, event->suggested_output); } +void +warpcursortoclient(Client *c) { + struct wlr_box mg = c->mon->m; + struct wlr_box cg = c->geom; + if (!VISIBLEON(c, selmon)) return; + wlr_cursor_warp_absolute(cursor, NULL, + ((double)cg.x + (double)cg.width / 2.0) / (double)mg.width, + ((double)cg.y + (double)cg.height / 2.0) / (double)mg.height); +} + Monitor * xytomon(double x, double y) { |
