Add centeredmaster_always setting

Credits: @metalcranium
This commit is contained in:
Nikita Ivanov 2026-04-13 18:37:26 +02:00
parent 4e2adff067
commit 8809817422
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
2 changed files with 35 additions and 14 deletions

View File

@ -22,6 +22,8 @@ With one and two clients in master respectively this results in:
+------------------------------+ +------------------------------+
```
Version 0.8 includes `centeredmaster_always` setting to always center a window
even if only 1 window is visible on a tag.
### Download
- [0.8](/dwl/dwl-patches/raw/branch/main/patches/centeredmaster/centeredmaster-0.8.patch)
@ -32,3 +34,4 @@ With one and two clients in master respectively this results in:
### Authors
- [Nikita Ivanov](https://codeberg.org/nikitaivanov) ([GitHub](https://github.com/NikitaIvanovV))
- [wochap](https://codeberg.org/wochap)
- [metalcranium](https://codeberg.org/metalcranium)

View File

@ -1,18 +1,26 @@
From 1fb8c15bb02c50279a5ccbd410dc1293abb747f3 Mon Sep 17 00:00:00 2001
From d3d0000c3e2baa8c2a4633581186f768c909667a Mon Sep 17 00:00:00 2001
From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
Date: Sat, 8 Feb 2025 16:10:25 +0100
Date: Mon, 13 Apr 2026 18:24:17 +0200
Subject: [PATCH] Add centeredmaster layout
---
config.def.h | 2 ++
dwl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
config.def.h | 3 +++
dwl.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
diff --git a/config.def.h b/config.def.h
index 8a6eda0..70954cc 100644
index 8a6eda0..15cbe32 100644
--- a/config.def.h
+++ b/config.def.h
@@ -33,6 +33,7 @@ static const Layout layouts[] = {
@@ -7,6 +7,7 @@
static const int sloppyfocus = 1; /* focus follows mouse */
static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
static const unsigned int borderpx = 1; /* border pixel of windows */
+static const int centeredmaster_always = 0; /* always center even if only 1 window */
static const float rootcolor[] = COLOR(0x222222ff);
static const float bordercolor[] = COLOR(0x444444ff);
static const float focuscolor[] = COLOR(0x005577ff);
@@ -33,6 +34,7 @@ static const Layout layouts[] = {
{ "[]=", tile },
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
@ -20,7 +28,7 @@ index 8a6eda0..70954cc 100644
};
/* monitors */
@@ -135,6 +136,7 @@ static const Key keys[] = {
@@ -135,6 +137,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
@ -29,7 +37,7 @@ index 8a6eda0..70954cc 100644
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
diff --git a/dwl.c b/dwl.c
index 44f3ad9..bf859b0 100644
index 44f3ad9..98ba318 100644
--- a/dwl.c
+++ b/dwl.c
@@ -248,6 +248,7 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
@ -40,7 +48,7 @@ index 44f3ad9..bf859b0 100644
static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
static void cleanup(void);
@@ -672,6 +673,68 @@ buttonpress(struct wl_listener *listener, void *data)
@@ -672,6 +673,78 @@ buttonpress(struct wl_listener *listener, void *data)
event->time_msec, event->button, event->state);
}
@ -58,15 +66,25 @@ index 44f3ad9..bf859b0 100644
+ return;
+
+ /* initialize areas */
+ if (centeredmaster_always) {
+ mw = m->w.width / 2;
+ mx = m->w.width / 4;
+ } else {
+ mw = m->w.width;
+ mx = 0;
+ }
+ my = 0;
+ tw = mw;
+
+ if (n > m->nmaster) {
+ /* go mfact box in the center if more than nmaster clients */
+ if (centeredmaster_always) {
+ mw = m->nmaster ? (int)roundf(m->w.width / 2) : 0;
+ tw = mw / 2;
+ } else {
+ mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
+ tw = m->w.width - mw;
+ }
+
+ if (n - m->nmaster > 1) {
+ /* only one client */