inline xytosurface

This commit is contained in:
Devin J. Pohly 2020-05-03 11:37:44 -05:00
parent f7d2524435
commit 1b87831e00

36
dwl.c
View file

@ -186,8 +186,6 @@ static void unmapnotify(struct wl_listener *listener, void *data);
static void view(const Arg *arg); static void view(const Arg *arg);
static Client *xytoclient(double x, double y); static Client *xytoclient(double x, double y);
static Monitor *xytomon(double x, double y); static Monitor *xytomon(double x, double y);
static Client *xytosurface(double x, double y,
struct wlr_surface **surface, double *sx, double *sy);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
@ -319,9 +317,12 @@ buttonpress(struct wl_listener *listener, void *data)
switch (event->state) { switch (event->state) {
case WLR_BUTTON_PRESSED:; case WLR_BUTTON_PRESSED:;
/* Change focus if the button was _pressed_ over a client */ /* Change focus if the button was _pressed_ over a client */
c = xytosurface(cursor->x, cursor->y, &surface, NULL, NULL); if ((c = xytoclient(cursor->x, cursor->y))) {
if (c) surface = wlr_xdg_surface_surface_at(c->xdg_surface,
cursor->x - c->geom.x - c->bw,
cursor->y - c->geom.y - c->bw, NULL, NULL);
focusclient(c, surface, 1); focusclient(c, surface, 1);
}
keyboard = wlr_seat_get_keyboard(seat); keyboard = wlr_seat_get_keyboard(seat);
mods = wlr_keyboard_get_modifiers(keyboard); mods = wlr_keyboard_get_modifiers(keyboard);
@ -774,7 +775,10 @@ motionnotify(uint32_t time)
} }
/* Otherwise, find the client under the pointer and send the event along. */ /* Otherwise, find the client under the pointer and send the event along. */
c = xytosurface(cursor->x, cursor->y, &surface, &sx, &sy); if ((c = xytoclient(cursor->x, cursor->y)))
surface = wlr_xdg_surface_surface_at(c->xdg_surface,
cursor->x - c->geom.x - c->bw,
cursor->y - c->geom.y - c->bw, &sx, &sy);
/* If there's no client surface under the cursor, set the cursor image to a /* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it * default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */ * off of a client or over its border. */
@ -1415,28 +1419,6 @@ xytomon(double x, double y)
return o ? o->data : NULL; return o ? o->data : NULL;
} }
Client *
xytosurface(double x, double y,
struct wlr_surface **surface, double *sx, double *sy)
{
Client *c = xytoclient(x, y);
/*
* XDG toplevels may have nested surfaces, such as popup windows
* for context menus or tooltips. This function tests if any of
* those are underneath the coordinates x and y (in layout
* coordinates). If so, it sets the surface pointer to that
* wlr_surface and the sx and sy coordinates to the coordinates
* relative to that surface's top-left corner.
*/
/* XXX set *surface to xdg_surface->surface otherwise? what should
* sx/sy be in that case? */
if (c)
*surface = wlr_xdg_surface_surface_at(c->xdg_surface,
x - c->geom.x - c->bw,
y - c->geom.y - c->bw, sx, sy);
return c;
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {