sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-singlegap-6.6.diff (3961B)


      1 From d0b1b523a1cf4901aa848e20a9fff59154b3f3c8 Mon Sep 17 00:00:00 2001
      2 From: sesankm <26676400+sesankm@users.noreply.github.com>
      3 Date: Tue, 30 Sep 2025 14:29:08 -0500
      4 Subject: [PATCH] Add gaps when only one window is open
      5 
      6 ---
      7  config.def.h |  8 +++++---
      8  dwm.c        | 33 +++++++++++++++++++++++----------
      9  2 files changed, 28 insertions(+), 13 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 81c3fc0..b6a0b7d 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -2,6 +2,8 @@
     16  
     17  /* appearance */
     18  static const unsigned int borderpx  = 1;        /* border pixel of windows */
     19 +static const unsigned int gapx      = 120;      /* horizontal gap */
     20 +static const unsigned int gapy      = 40;       /* vertical gap */
     21  static const unsigned int snap      = 32;       /* snap pixel */
     22  static const int showbar            = 1;        /* 0 means no bar */
     23  static const int topbar             = 1;        /* 0 means bottom bar */
     24 @@ -26,9 +28,9 @@ static const Rule rules[] = {
     25  	 *	WM_CLASS(STRING) = instance, class
     26  	 *	WM_NAME(STRING) = title
     27  	 */
     28 -	/* class      instance    title       tags mask     isfloating   monitor */
     29 -	{ "Gimp",     NULL,       NULL,       0,            1,           -1 },
     30 -	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
     31 +	/* class      instance    title       tags mask     isfloating   monitor    disablegap */
     32 +	{ "Gimp",     NULL,       NULL,       0,            1,           -1,        0},
     33 +	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           -1,        1},
     34  };
     35  
     36  /* layout(s) */
     37 diff --git a/dwm.c b/dwm.c
     38 index 4f345ee..1633c38 100644
     39 --- a/dwm.c
     40 +++ b/dwm.c
     41 @@ -92,6 +92,7 @@ struct Client {
     42  	int bw, oldbw;
     43  	unsigned int tags;
     44  	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
     45 +	int disablegaps;
     46  	Client *next;
     47  	Client *snext;
     48  	Monitor *mon;
     49 @@ -138,6 +139,7 @@ typedef struct {
     50  	unsigned int tags;
     51  	int isfloating;
     52  	int monitor;
     53 +	int disablegaps;
     54  } Rule;
     55  
     56  /* function declarations */
     57 @@ -286,6 +288,7 @@ applyrules(Client *c)
     58  	/* rule matching */
     59  	c->isfloating = 0;
     60  	c->tags = 0;
     61 +	c->disablegaps = 0;
     62  	XGetClassHint(dpy, c->win, &ch);
     63  	class    = ch.res_class ? ch.res_class : broken;
     64  	instance = ch.res_name  ? ch.res_name  : broken;
     65 @@ -302,6 +305,8 @@ applyrules(Client *c)
     66  			if (m)
     67  				c->mon = m;
     68  		}
     69 +        if (strstr(class, r->class) || strstr(instance, r->class))
     70 +            c->disablegaps = r->disablegaps;
     71  	}
     72  	if (ch.res_class)
     73  		XFree(ch.res_class);
     74 @@ -1686,28 +1691,36 @@ tagmon(const Arg *arg)
     75  void
     76  tile(Monitor *m)
     77  {
     78 -	unsigned int i, n, h, mw, my, ty;
     79 +	unsigned int i, n, h, mw, my, ty, ns, gx = 0, gy = 0;
     80  	Client *c;
     81  
     82 +
     83  	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
     84  	if (n == 0)
     85  		return;
     86 +	else if (n == 1 && ((nexttiled(m->clients)))->disablegaps == 0) {
     87 +		gx = gapx;
     88 +		gy = gapy;
     89 +	}
     90  
     91 -	if (n > m->nmaster)
     92 +	if (n > m->nmaster) {
     93  		mw = m->nmaster ? m->ww * m->mfact : 0;
     94 -	else
     95 +		ns = m->nmaster > 0 ? 2 : 1;
     96 +	} else {
     97  		mw = m->ww;
     98 -	for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
     99 +		ns = 1;
    100 +	}
    101 +	for(i = 0, my = ty = gy, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    102  		if (i < m->nmaster) {
    103 -			h = (m->wh - my) / (MIN(n, m->nmaster) - i);
    104 -			resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
    105 +			h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gy;
    106 +			resize(c, m->wx + gx, m->wy + my, mw - (2*c->bw) - gx*(5-ns)/2, h - (2*c->bw), False);
    107  			if (my + HEIGHT(c) < m->wh)
    108 -				my += HEIGHT(c);
    109 +				my += HEIGHT(c) + gy;
    110  		} else {
    111 -			h = (m->wh - ty) / (n - i);
    112 -			resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
    113 +			h = (m->wh - ty) / (n - i) - gy;
    114 +			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);
    115  			if (ty + HEIGHT(c) < m->wh)
    116 -				ty += HEIGHT(c);
    117 +				ty += HEIGHT(c) + gy;
    118  		}
    119  }
    120  
    121 -- 
    122 2.49.1
    123