From d0b1b523a1cf4901aa848e20a9fff59154b3f3c8 Mon Sep 17 00:00:00 2001 From: sesankm <26676400+sesankm@users.noreply.github.com> Date: Tue, 30 Sep 2025 14:29:08 -0500 Subject: [PATCH] Add gaps when only one window is open --- config.def.h | 8 +++++--- dwm.c | 33 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/config.def.h b/config.def.h index 81c3fc0..b6a0b7d 100644 --- a/config.def.h +++ b/config.def.h @@ -2,6 +2,8 @@ /* appearance */ static const unsigned int borderpx = 1; /* border pixel of windows */ +static const unsigned int gapx = 120; /* horizontal gap */ +static const unsigned int gapy = 40; /* vertical gap */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ @@ -26,9 +28,9 @@ static const Rule rules[] = { * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ - /* class instance title tags mask isfloating monitor */ - { "Gimp", NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, + /* class instance title tags mask isfloating monitor disablegap */ + { "Gimp", NULL, NULL, 0, 1, -1, 0}, + { "Firefox", NULL, NULL, 1 << 8, 0, -1, 1}, }; /* layout(s) */ diff --git a/dwm.c b/dwm.c index 4f345ee..1633c38 100644 --- a/dwm.c +++ b/dwm.c @@ -92,6 +92,7 @@ struct Client { int bw, oldbw; unsigned int tags; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + int disablegaps; Client *next; Client *snext; Monitor *mon; @@ -138,6 +139,7 @@ typedef struct { unsigned int tags; int isfloating; int monitor; + int disablegaps; } Rule; /* function declarations */ @@ -286,6 +288,7 @@ applyrules(Client *c) /* rule matching */ c->isfloating = 0; c->tags = 0; + c->disablegaps = 0; XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; @@ -302,6 +305,8 @@ applyrules(Client *c) if (m) c->mon = m; } + if (strstr(class, r->class) || strstr(instance, r->class)) + c->disablegaps = r->disablegaps; } if (ch.res_class) XFree(ch.res_class); @@ -1686,28 +1691,36 @@ tagmon(const Arg *arg) void tile(Monitor *m) { - unsigned int i, n, h, mw, my, ty; + unsigned int i, n, h, mw, my, ty, ns, gx = 0, gy = 0; Client *c; + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if (n == 0) return; + else if (n == 1 && ((nexttiled(m->clients)))->disablegaps == 0) { + gx = gapx; + gy = gapy; + } - if (n > m->nmaster) + if (n > m->nmaster) { mw = m->nmaster ? m->ww * m->mfact : 0; - else + ns = m->nmaster > 0 ? 2 : 1; + } else { mw = m->ww; - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + ns = 1; + } + for(i = 0, my = ty = gy, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) if (i < m->nmaster) { - h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); + h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gy; + resize(c, m->wx + gx, m->wy + my, mw - (2*c->bw) - gx*(5-ns)/2, h - (2*c->bw), False); if (my + HEIGHT(c) < m->wh) - my += HEIGHT(c); + my += HEIGHT(c) + gy; } else { - h = (m->wh - ty) / (n - i); - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); + h = (m->wh - ty) / (n - i) - gy; + resize(c, m->wx + mw + gx/ns, m->wy + ty, m->ww - mw - (2*c->bw) - gx*(5-ns)/2, h - (2*c->bw), False); if (ty + HEIGHT(c) < m->wh) - ty += HEIGHT(c); + ty += HEIGHT(c) + gy; } } -- 2.49.1