diff options
| -rw-r--r-- | config.def.h | 1 | ||||
| -rw-r--r-- | dwl.c | 21 |
2 files changed, 21 insertions, 1 deletions
diff --git a/config.def.h b/config.def.h index 22d2171..f8f8f1a 100644 --- a/config.def.h +++ b/config.def.h @@ -5,6 +5,7 @@ (hex & 0xFF) / 255.0f } /* appearance */ static const int sloppyfocus = 1; /* focus follows mouse */ +static const int mousefollowsfocus = 1; /* mouse follows focus */ static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ static const unsigned int borderpx = 1; /* border pixel of windows */ static const float rootcolor[] = COLOR(0x222222ff); @@ -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) { |
