make space for window borders

This commit is contained in:
Devin J. Pohly 2020-04-23 22:56:27 -05:00
parent fb6b16aeee
commit 1870187d62
2 changed files with 17 additions and 11 deletions

View File

@ -1,5 +1,6 @@
/* appearance */ /* appearance */
static const int sloppyfocus = 1; /* focus follows mouse */ static const int sloppyfocus = 1; /* focus follows mouse */
static const unsigned int borderpx = 1; /* border pixel of windows */
static const float rootcolor[] = {0.3, 0.3, 0.3, 1.0}; static const float rootcolor[] = {0.3, 0.3, 0.3, 1.0};
/* tagging */ /* tagging */

27
dwl.c
View File

@ -66,7 +66,8 @@ typedef struct {
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
Monitor *mon; Monitor *mon;
int x, y; /* layout-relative */ int x, y; /* layout-relative, includes border */
int bw;
unsigned int tags; unsigned int tags;
int isfloating; int isfloating;
} Client; } Client;
@ -359,6 +360,7 @@ createnotify(struct wl_listener *listener, void *data)
/* Allocate a Client for this surface */ /* Allocate a Client for this surface */
Client *c = calloc(1, sizeof(*c)); Client *c = calloc(1, sizeof(*c));
c->xdg_surface = xdg_surface; c->xdg_surface = xdg_surface;
c->bw = borderpx;
/* 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);
@ -526,6 +528,7 @@ inputdevice(struct wl_listener *listener, void *data)
createpointer(device); createpointer(device);
break; break;
default: default:
/* XXX handle other input device types */
break; break;
} }
/* We need to let the wlr_seat know what our capabilities are, which is /* We need to let the wlr_seat know what our capabilities are, which is
@ -643,8 +646,9 @@ motionnotify(uint32_t time)
/* If we are currently grabbing the mouse, handle and return */ /* If we are currently grabbing the mouse, handle and return */
if (cursor_mode == CurMove) { if (cursor_mode == CurMove) {
/* Move the grabbed client to the new position. */ /* Move the grabbed client to the new position. */
grabc->x = cursor->x - grabsx; /* XXX assumes the surface is at (0,0) within grabc */
grabc->y = cursor->y - grabsy; grabc->x = cursor->x - grabsx - grabc->bw;
grabc->y = cursor->y - grabsy - grabc->bw;
return; return;
} else if (cursor_mode == CurResize) { } else if (cursor_mode == CurResize) {
/* /*
@ -832,8 +836,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, .x = c->x + c->bw,
.y = c->y, .y = c->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. */
@ -888,7 +892,7 @@ resize(Client *c, int x, int y, int w, int h)
{ {
c->x = x; c->x = x;
c->y = y; c->y = y;
wlr_xdg_toplevel_set_size(c->xdg_surface, w, h); wlr_xdg_toplevel_set_size(c->xdg_surface, w - 2 * c->bw, h - 2 * c->bw);
} }
void void
@ -904,8 +908,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 + sbox.x + sbox.width, grabc->x + sbox.x + sbox.width + 2 * grabc->bw,
grabc->y + sbox.y + sbox.height); grabc->y + sbox.y + sbox.height + 2 * grabc->bw);
/* Float the window and tell motionnotify to resize it */ /* Float the window and tell motionnotify to resize it */
if (!grabc->isfloating && selmon->lt[selmon->sellt]->arrange) if (!grabc->isfloating && selmon->lt[selmon->sellt]->arrange)
@ -1198,11 +1202,11 @@ tile(Monitor *m)
if (i < m->nmaster) { if (i < m->nmaster) {
h = (m->wh - my) / (MIN(n, m->nmaster) - i); h = (m->wh - my) / (MIN(n, m->nmaster) - i);
resize(c, m->wx, m->wy + my, mw, h); resize(c, m->wx, m->wy + my, mw, h);
my += ca.height; my += ca.height + 2 * c->bw;
} else { } else {
h = (m->wh - ty) / (n - i); h = (m->wh - ty) / (n - i);
resize(c, m->wx + mw, m->wy + ty, m->ww - mw, h); resize(c, m->wx + mw, m->wy + ty, m->ww - mw, h);
ty += ca.height; ty += ca.height + 2 * c->bw;
} }
i++; i++;
} }
@ -1272,6 +1276,7 @@ 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? */
/* This iterates over all of our surfaces and attempts to find one under the /* This iterates over all of our surfaces and attempts to find one under the
* cursor. 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;
@ -1290,7 +1295,7 @@ 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, y - c->y, &_sx, &_sy); x - c->x - c->bw, y - c->y - c->bw, &_sx, &_sy);
if (_surface) { if (_surface) {
*sx = _sx; *sx = _sx;