include border in xytoclient

If there isn't an actual surface under the cursor, *surface will be set
to NULL, which is safe now that focus functions handle a NULL surface
safely.
This commit is contained in:
Devin J. Pohly 2020-04-30 12:32:50 -05:00
parent 2c134faa40
commit 87f8e6687b

22
dwl.c
View file

@ -1346,14 +1346,11 @@ Client *
xytoclient(double x, double y, xytoclient(double x, double y,
struct wlr_surface **surface, double *sx, double *sy) struct wlr_surface **surface, double *sx, double *sy)
{ {
/* XXX what if (x,y) is within a window's border? */ /* Find the topmost visible client (if any) under the cursor, including
/* This iterates over all of our surfaces and attempts to find one under the * borders. This relies on stack being ordered from top to bottom. */
* cursor. This relies on stack being ordered from top-to-bottom. */
Client *c; Client *c;
wl_list_for_each(c, &stack, slink) { wl_list_for_each(c, &stack, slink) {
/* Skip clients that aren't visible */ if (VISIBLEON(c, c->mon) && wlr_box_contains_point(&c->geom, x, y)) {
if (!VISIBLEON(c, c->mon))
continue;
/* /*
* XDG toplevels may have nested surfaces, such as popup windows * XDG toplevels may have nested surfaces, such as popup windows
* for context menus or tooltips. This function tests if any of * for context menus or tooltips. This function tests if any of
@ -1362,16 +1359,11 @@ xytoclient(double x, double y,
* wlr_surface and the sx and sy coordinates to the coordinates * wlr_surface and the sx and sy coordinates to the coordinates
* relative to that surface's top-left corner. * relative to that surface's top-left corner.
*/ */
double _sx, _sy; /* XXX set *surface to xdg_surface->surface instead of
struct wlr_surface *_surface = NULL; * NULL? what should sx/sy be in that case? */
_surface = wlr_xdg_surface_surface_at(c->xdg_surface, *surface = wlr_xdg_surface_surface_at(c->xdg_surface,
x - c->geom.x - c->bw, y - c->geom.y - c->bw, x - c->geom.x - c->bw, y - c->geom.y - c->bw,
&_sx, &_sy); sx, sy);
if (_surface) {
*sx = _sx;
*sy = _sy;
*surface = _surface;
return c; return c;
} }
} }