Re: [dev] [dwm] default window attaching behaviour

From: lincoln auster <lincolnauster_AT_gmail.com>
Date: Tue, 30 Nov 2021 07:46:01 -0700

Hi,

> My tendency is to launch a few "big" programs, most of which can't
> easily run in a terminal (a browser, a terminal running tmux and/or an
> image editor), and only launch new "temporary" terminals when I need
> to run and see the output of a command. If I need an TUI volume mixer
> or something, I'd launch it as a tmux window or in floating mode to
> avoid disturbing my layout.

I do something pretty similar with dwm, under the (usually correct)
assumptions that windows made earlier stick around for less time. I
found I really like unilaterally opening windows floating and centered
by default and then popping them into the tiled layout if I need them to
stick around. It's a pretty simple modification, but I've attached the
patch I use just in case you or anyone on this list would find it helpful!

--
lincoln auster
they/them


From 10f3e8380ee4d1c8acbf7f2da97a47dada93f03e Mon Sep 17 00:00:00 2001
From: elm auster <auster.elm_AT_gmail.com>
Date: Thu, 16 Sep 2021 21:51:40 -0600
Subject: [PATCH] center and float windows by default

---
 dwm.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/dwm.c b/dwm.c
index 5e4d494..77dea02 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -286,7 +286,7 @@ applyrules(Client *c)
 	XClassHint ch = { NULL, NULL };
 
 	/* rule matching */
-	c->isfloating = 0;
+	c->isfloating = 1;
 	c->tags = 0;
 	XGetClassHint(dpy, c->win, &ch);
 	class    = ch.res_class ? ch.res_class : broken;
_AT_@ -1040,11 +1040,13 @@ manage(Window w, XWindowAttributes *wa)
 		applyrules(c);
 	}
 
-	if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
-		c->x = c->mon->mx + c->mon->mw - WIDTH(c);
-	if (c->y + HEIGHT(c) > c->mon->my + c->mon->mh)
-		c->y = c->mon->my + c->mon->mh - HEIGHT(c);
+	/* center the window */
+	c->x = c->mon->mx + c->mon->mw / 2 - c->w / 2;
+	c->y = c->mon->my + c->mon->mh / 2 - c->h / 2;
+
 	c->x = MAX(c->x, c->mon->mx);
+	c->y = MAX(c->y, c->mon->my);
+
 	/* only fix client y-offset, if the client center might cover the bar */
 	c->y = MAX(c->y, ((c->mon->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx)
 		&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
-- 
2.31.1
Received on Tue Nov 30 2021 - 15:46:01 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 30 2021 - 19:48:08 CET