Add dwindle layout patch

This commit is contained in:
C4FE1 2026-03-20 21:24:14 -03:00
parent ee75e70f79
commit 06ef8524bb
2 changed files with 149 additions and 0 deletions

55
patches/dwindle/README.md Normal file
View File

@ -0,0 +1,55 @@
### Description
Adds a dwindle (fibonacci-style) layout to dwl.
Windows are arranged by recursively splitting the remaining space,
alternating between horizontal and vertical splits
With two windows:
```
┌───────────────┬────────────────┐
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
│ │ │
└───────────────┴────────────────┘
```
With three windows:
```
┌───────────────┬────────────────┐
│ │ │
│ │ │
│ │ │
│ │ │
│ ├────────────────┤
│ │ │
│ │ │
│ │ │
│ │ │
└───────────────┴────────────────┘
```
With four windows:
```
┌───────────────┬────────────────┐
│ │ │
│ │ │
│ │ │
│ │ │
│ ├───────┬────────┤
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
└───────────────┴───────┴────────┘
```
### Download
- [0.8](/dwl/dwl-patches/raw/branch/main/patches/dwindle/dwindle.patch)
### Authors
[cana cronica](https://codeberg.org/cana)

View File

@ -0,0 +1,94 @@
From e985b17e951f326e1459601cc39893609058c5ed Mon Sep 17 00:00:00 2001
From: C4FE1 <heitorcdesousa13@gmail.com>
Date: Fri, 20 Mar 2026 21:07:24 -0300
Subject: [PATCH] dwl: add dwindle layout
---
config.def.h | 1 +
dwl.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/config.def.h b/config.def.h
index 8a6eda0..e1b823e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -31,6 +31,7 @@ static const Rule rules[] = {
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile },
+ { "[\\]", dwindle },
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
};
diff --git a/dwl.c b/dwl.c
index 101a45f..3b08073 100644
--- a/dwl.c
+++ b/dwl.c
@@ -335,6 +335,7 @@ static void startdrag(struct wl_listener *listener, void *data);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
+static void dwindle(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void toggletag(const Arg *arg);
@@ -2745,6 +2746,56 @@ tile(Monitor *m)
}
}
+void
+dwindle(Monitor *m)
+{
+ unsigned int i, n = 0;
+ Client *c;
+
+ /* count clients */
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
+ n++;
+
+ if (n == 0)
+ return;
+
+ int nx = m->w.x;
+ int ny = m->w.y;
+ int nw = m->w.width;
+ int nh = m->w.height;
+
+ int horizontal = 1; // toggle split direction
+ i = 0;
+
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+
+ if (i == n - 1) {
+ /* last window gets remaining space */
+ resize(c, (struct wlr_box){nx, ny, nw, nh}, 0);
+ } else if (horizontal) {
+ int w = nw / 2;
+
+ resize(c, (struct wlr_box){nx, ny, w, nh}, 0);
+
+ nx += w;
+ nw -= w;
+ } else {
+ int h = nh / 2;
+
+ resize(c, (struct wlr_box){nx, ny, nw, h}, 0);
+
+ ny += h;
+ nh -= h;
+ }
+
+ horizontal = !horizontal;
+ i++;
+ }
+}
+
void
togglefloating(const Arg *arg)
{
--
2.53.0