diff --git a/README.org b/README.org index 526627c..8c7b2dc 100644 --- a/README.org +++ b/README.org @@ -7,6 +7,7 @@ - [[#welcome][Welcome]] - [[#dwl---dwm-for-wayland][dwl - dwm for Wayland]] - [[#patches][Patches]] + - [[#always-center][Always Center]] - [[#attach-top][Attach Top]] - [[#auto-start][Auto Start]] - [[#foreign-toplevel-management][Foreign Toplevel Management]] @@ -57,6 +58,14 @@ See [[./README.md][Upstream README]] for details on project. * Patches +** [[https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/alwayscenter][Always Center]] + +Automatically center floating windows. + +#+BEGIN_SRC c :tangle patches.def.h +#define ALWAYSCENTER_PATCH 1 +#+END_SRC + ** [[https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/attachtop][Attach Top]] This is a port of attachtop patch for dwm: https://dwm.suckless.org/patches/attachtop diff --git a/dwl.c b/dwl.c index b36a92a..475beff 100644 --- a/dwl.c +++ b/dwl.c @@ -613,6 +613,14 @@ applyrules(Client *c) } } } + +#if ALWAYSCENTER_PATCH + if (mon) { + c->geom.x = (mon->w.width - c->geom.width) / 2 + mon->m.x; + c->geom.y = (mon->w.height - c->geom.height) / 2 + mon->m.y; + } +#endif // ALWAYSCENTER_PATCH + setmon(c, mon, newtags); } @@ -2383,6 +2391,12 @@ mapnotify(struct wl_listener *listener, void *data) * try to apply rules for them */ if ((p = client_get_parent(c))) { c->isfloating = 1; +#if ALWAYSCENTER_PATCH + 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; + } +#endif // ALWAYSCENTER_PATCH setmon(c, p->mon, p->tags); } else { applyrules(c); diff --git a/patches.def.h b/patches.def.h index c2cd99e..5753fe7 100644 --- a/patches.def.h +++ b/patches.def.h @@ -1,3 +1,5 @@ +#define ALWAYSCENTER_PATCH 1 + #define ATTACHTOP_PATCH 1 #define AUTOSTART_PATCH 1 diff --git a/patches/alwayscenter-20240605.patch b/patches/alwayscenter-20240605.patch new file mode 100644 index 0000000..a046ef7 --- /dev/null +++ b/patches/alwayscenter-20240605.patch @@ -0,0 +1,38 @@ +From 6616470ef135019ef4c767003a66df76df45f53e Mon Sep 17 00:00:00 2001 +From: Guido Cella +Date: Wed, 5 Jun 2024 12:05:16 +0200 +Subject: [PATCH] center floating windows + +--- + dwl.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/dwl.c b/dwl.c +index 6f041a0..79ace52 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -472,6 +472,10 @@ applyrules(Client *c) + } + } + } ++ if (mon) { ++ c->geom.x = (mon->w.width - c->geom.width) / 2 + mon->m.x; ++ c->geom.y = (mon->w.height - c->geom.height) / 2 + mon->m.y; ++ } + setmon(c, mon, newtags); + } + +@@ -1677,6 +1681,10 @@ mapnotify(struct wl_listener *listener, void *data) + * try to apply rules for them */ + if ((p = client_get_parent(c))) { + c->isfloating = 1; ++ 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); +-- +2.45.1 +