From 519ef454289d724b3b62e68b2e384b58fb47aeb4 Mon Sep 17 00:00:00 2001
From: Guido Cella <guido@guidocella.xyz>
Date: Sat, 17 Apr 2021 08:59:55 +0200
Subject: [PATCH] center floating windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Credits to Benjamin Chausse for fixing this with multiple monitors.

Modified-by: Leonardo Hernández Hernández <leohdz172@proton.me>
---
 dwl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/dwl.c b/dwl.c
index e474f46..66d21f0 100644
--- a/dwl.c
+++ b/dwl.c
@@ -473,6 +473,8 @@ applyrules(Client *c)
 		}
 	}
 	wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
+	c->geom.x = mon ? (mon->w.width - c->geom.width) / 2 + mon->m.x : 0;
+	c->geom.y = mon ? (mon->w.height - c->geom.height) / 2 + mon->m.y : 0;
 	wlr_scene_node_reparent(&c->scene->node, layers[c->isfloating ? LyrFloat : LyrTile]);
 	setmon(c, mon, newtags);
 }
@@ -1744,6 +1746,10 @@ mapnotify(struct wl_listener *listener, void *data)
 	if (c->type == XDGShell && (p = client_get_parent(c))) {
 		c->isfloating = 1;
 		wlr_scene_node_reparent(&c->scene->node, layers[LyrFloat]);
+		if (p->mon) {
+			c->geom.x = (p->mon->w.width - c->geom.width) / 2 + p->mon->m.x;
+			c->geom.y = (p->mon->w.height - c->geom.height) / 2 + p->mon->m.y;
+		}
 		setmon(c, p->mon, p->tags);
 	} else {
 		applyrules(c);