sites

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

dwm-centeronlywindow-20260911-44dbc68.diff (2428B)


      1 From 71c84fd35126ffdaa64bf79b55b0b984476d9a75 Mon Sep 17 00:00:00 2001
      2 From: Niky Kovalski <nikykovalski@gmail.com>
      3 Date: Fri, 11 Sep 2026 17:25:04 -0400
      4 Subject: [PATCH] centeronlywindow
      5 
      6 add a rule to center a window in tiled mode when it is the only window
      7 ---
      8  config.def.h | 7 ++++---
      9  dwm.c        | 7 +++++++
     10  2 files changed, 11 insertions(+), 3 deletions(-)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 81c3fc0..84f36c1 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -26,9 +26,10 @@ static const Rule rules[] = {
     17  	 *	WM_CLASS(STRING) = instance, class
     18  	 *	WM_NAME(STRING) = title
     19  	 */
     20 -	/* class      instance    title       tags mask     isfloating   monitor */
     21 -	{ "Gimp",     NULL,       NULL,       0,            1,           -1 },
     22 -	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
     23 +	/* class      instance    title       tags mask     isfloating   iscenteredalone   monitor */
     24 +	{ "st",       NULL,       NULL,       0,            1,           1,                -1 },
     25 +	{ "Gimp",     NULL,       NULL,       0,            1,           0,                -1 },
     26 +	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           0,                -1 },
     27  };
     28  
     29  /* layout(s) */
     30 diff --git a/dwm.c b/dwm.c
     31 index ab3a84c..2710c1f 100644
     32 --- a/dwm.c
     33 +++ b/dwm.c
     34 @@ -92,6 +92,7 @@ struct Client {
     35  	int bw, oldbw;
     36  	unsigned int tags;
     37  	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
     38 +    int iscenteredalone;
     39  	Client *next;
     40  	Client *snext;
     41  	Monitor *mon;
     42 @@ -137,6 +138,7 @@ typedef struct {
     43  	const char *title;
     44  	unsigned int tags;
     45  	int isfloating;
     46 +    int iscenteredalone;
     47  	int monitor;
     48  } Rule;
     49  
     50 @@ -285,6 +287,7 @@ applyrules(Client *c)
     51  
     52  	/* rule matching */
     53  	c->isfloating = 0;
     54 +    c->iscenteredalone = 0;
     55  	c->tags = 0;
     56  	XGetClassHint(dpy, c->win, &ch);
     57  	class    = ch.res_class ? ch.res_class : broken;
     58 @@ -297,6 +300,7 @@ applyrules(Client *c)
     59  		&& (!r->instance || strstr(instance, r->instance)))
     60  		{
     61  			c->isfloating = r->isfloating;
     62 +            c->iscenteredalone = r->iscenteredalone;
     63  			c->tags |= r->tags;
     64  			for (m = mons; m && m->num != r->monitor; m = m->next);
     65  			if (m)
     66 @@ -1710,6 +1714,9 @@ tile(Monitor *m)
     67  			if (ty + HEIGHT(c) < m->wh)
     68  				ty += HEIGHT(c);
     69  		}
     70 +
     71 +    if (n == 1 && (c = nexttiled(m->clients))->iscenteredalone)
     72 +        resizeclient(c, m->mw / 4, m->mh / 4, m->mw / 2, m->mh / 2);
     73  }
     74  
     75  void
     76 -- 
     77 2.55.0
     78