use wlr_box for client geometry

This commit is contained in:
Devin J. Pohly 2020-04-26 22:12:08 -05:00
parent a25ad1c327
commit 34d5045d84

66
dwl.c
View file

@ -65,8 +65,8 @@ typedef struct {
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wlr_box geom; /* layout-relative, includes border */
Monitor *mon; Monitor *mon;
int x, y, w, h; /* layout-relative, includes border */
int bw; int bw;
unsigned int tags; unsigned int tags;
int isfloating; int isfloating;
@ -220,17 +220,17 @@ void
applybounds(Client *c, struct wlr_box *bbox) applybounds(Client *c, struct wlr_box *bbox)
{ {
/* set minimum possible */ /* set minimum possible */
c->w = MAX(1, c->w); c->geom.width = MAX(1, c->geom.width);
c->h = MAX(1, c->h); c->geom.height = MAX(1, c->geom.height);
if (c->x >= bbox->x + bbox->width) if (c->geom.x >= bbox->x + bbox->width)
c->x = bbox->x + bbox->width - c->w; c->geom.x = bbox->x + bbox->width - c->geom.width;
if (c->y >= bbox->y + bbox->height) if (c->geom.y >= bbox->y + bbox->height)
c->y = bbox->y + bbox->height - c->h; c->geom.y = bbox->y + bbox->height - c->geom.height;
if (c->x + c->w + 2 * c->bw <= bbox->x) if (c->geom.x + c->geom.width + 2 * c->bw <= bbox->x)
c->x = bbox->x; c->geom.x = bbox->x;
if (c->y + c->h + 2 * c->bw <= bbox->y) if (c->geom.y + c->geom.height + 2 * c->bw <= bbox->y)
c->y = bbox->y; c->geom.y = bbox->y;
} }
void void
@ -403,10 +403,9 @@ createnotify(struct wl_listener *listener, void *data)
Client *c = xdg_surface->data = calloc(1, sizeof(*c)); Client *c = xdg_surface->data = calloc(1, sizeof(*c));
c->xdg_surface = xdg_surface; c->xdg_surface = xdg_surface;
c->bw = borderpx; c->bw = borderpx;
struct wlr_box geom; wlr_xdg_surface_get_geometry(c->xdg_surface, &c->geom);
wlr_xdg_surface_get_geometry(c->xdg_surface, &geom); c->geom.width += 2 * c->bw;
c->w = geom.width + 2 * c->bw; c->geom.height += 2 * c->bw;
c->h = geom.height + 2 * c->bw;
/* Tell the client not to try anything fancy */ /* Tell the client not to try anything fancy */
wlr_xdg_toplevel_set_tiled(c->xdg_surface, true); wlr_xdg_toplevel_set_tiled(c->xdg_surface, true);
@ -694,11 +693,11 @@ motionnotify(uint32_t time)
/* XXX assumes the surface is at (0,0) within grabc */ /* XXX assumes the surface is at (0,0) within grabc */
resize(grabc, cursor->x - grabsx - grabc->bw, resize(grabc, cursor->x - grabsx - grabc->bw,
cursor->y - grabsy - grabc->bw, cursor->y - grabsy - grabc->bw,
grabc->w, grabc->h, 1); grabc->geom.width, grabc->geom.height, 1);
return; return;
} else if (cursor_mode == CurResize) { } else if (cursor_mode == CurResize) {
resize(grabc, grabc->x, grabc->y, resize(grabc, grabc->geom.x, grabc->geom.y,
cursor->x - grabc->x, cursor->y - grabc->y, 1); cursor->x - grabc->geom.x, cursor->y - grabc->geom.y, 1);
return; return;
} }
@ -852,14 +851,11 @@ renderclients(Monitor *m, struct timespec *now)
Client *c; Client *c;
wl_list_for_each_reverse(c, &stack, slink) { wl_list_for_each_reverse(c, &stack, slink) {
/* Only render visible clients which show on this monitor */ /* Only render visible clients which show on this monitor */
struct wlr_box cbox = {
.x = c->x, .y = c->y, .width = c->w, .height = c->h,
};
if (!VISIBLEON(c, c->mon) || !wlr_output_layout_intersects( if (!VISIBLEON(c, c->mon) || !wlr_output_layout_intersects(
output_layout, m->wlr_output, &cbox)) output_layout, m->wlr_output, &c->geom))
continue; continue;
double ox = c->x, oy = c->y; double ox = c->geom.x, oy = c->geom.y;
wlr_output_layout_output_coords(output_layout, m->wlr_output, wlr_output_layout_output_coords(output_layout, m->wlr_output,
&ox, &oy); &ox, &oy);
int w = c->xdg_surface->surface->current.width; int w = c->xdg_surface->surface->current.width;
@ -880,8 +876,8 @@ renderclients(Monitor *m, struct timespec *now)
struct render_data rdata = { struct render_data rdata = {
.output = m->wlr_output, .output = m->wlr_output,
.when = now, .when = now,
.x = c->x + c->bw, .x = c->geom.x + c->bw,
.y = c->y + c->bw, .y = c->geom.y + c->bw,
}; };
/* This calls our render function for each surface among the /* This calls our render function for each surface among the
* xdg_surface's toplevel and popups. */ * xdg_surface's toplevel and popups. */
@ -932,14 +928,14 @@ resize(Client *c, int x, int y, int w, int h, int interact)
* the new size, then commit any movement that was prepared. * the new size, then commit any movement that was prepared.
*/ */
struct wlr_box *bbox = interact ? &sgeom : &c->mon->w; struct wlr_box *bbox = interact ? &sgeom : &c->mon->w;
c->x = x; c->geom.x = x;
c->y = y; c->geom.y = y;
c->w = w; c->geom.width = w;
c->h = h; c->geom.height = h;
applybounds(c, bbox); applybounds(c, bbox);
/* wlroots makes this a no-op if size hasn't changed */ /* wlroots makes this a no-op if size hasn't changed */
wlr_xdg_toplevel_set_size(c->xdg_surface, wlr_xdg_toplevel_set_size(c->xdg_surface,
c->w - 2 * c->bw, c->h - 2 * c->bw); c->geom.width - 2 * c->bw, c->geom.height - 2 * c->bw);
} }
void void
@ -953,7 +949,8 @@ resizemouse(const Arg *arg)
/* Doesn't work for X11 output - the next absolute motion event /* Doesn't work for X11 output - the next absolute motion event
* returns the cursor to where it started */ * returns the cursor to where it started */
wlr_cursor_warp_closest(cursor, NULL, wlr_cursor_warp_closest(cursor, NULL,
grabc->x + grabc->w, grabc->y + grabc->h); grabc->geom.x + grabc->geom.width,
grabc->geom.y + grabc->geom.height);
/* Float the window and tell motionnotify to resize it */ /* Float the window and tell motionnotify to resize it */
setfloating(grabc, 1); setfloating(grabc, 1);
@ -1279,11 +1276,11 @@ tile(Monitor *m)
if (i < m->nmaster) { if (i < m->nmaster) {
h = (m->w.height - my) / (MIN(n, m->nmaster) - i); h = (m->w.height - my) / (MIN(n, m->nmaster) - i);
resize(c, m->w.x, m->w.y + my, mw, h, 0); resize(c, m->w.x, m->w.y + my, mw, h, 0);
my += c->h; my += c->geom.height;
} else { } else {
h = (m->w.height - ty) / (n - i); h = (m->w.height - ty) / (n - i);
resize(c, m->w.x + mw, m->w.y + ty, m->w.width - mw, h, 0); resize(c, m->w.x + mw, m->w.y + ty, m->w.width - mw, h, 0);
ty += c->h; ty += c->geom.height;
} }
i++; i++;
} }
@ -1372,7 +1369,8 @@ xytoclient(double x, double y,
double _sx, _sy; double _sx, _sy;
struct wlr_surface *_surface = NULL; struct wlr_surface *_surface = NULL;
_surface = wlr_xdg_surface_surface_at(c->xdg_surface, _surface = wlr_xdg_surface_surface_at(c->xdg_surface,
x - c->x - c->bw, y - c->y - c->bw, &_sx, &_sy); x - c->geom.x - c->bw, y - c->geom.y - c->bw,
&_sx, &_sy);
if (_surface) { if (_surface) {
*sx = _sx; *sx = _sx;