btrtile: Spring update pt2

- Simplified the resizing logic to avoid full arrange calls from
motionnotify
- Minor intend fixes
This commit is contained in:
julmajustus
2026-05-21 00:54:00 +03:00
parent 7f06b4c1a3
commit 03de6e2ada
4 changed files with 445 additions and 458 deletions
+34 -37
View File
@@ -1,23 +1,24 @@
From ad32bb92157d5238340eb53322254dc8127477db Mon Sep 17 00:00:00 2001
From 1520d1f200ef0fb381683c1bcd58e553b52ac289 Mon Sep 17 00:00:00 2001
From: julmajustus <julmajustus@tutanota.com>
Date: Sun, 17 May 2026 22:49:07 +0300
Subject: [PATCH] btrtile resizing refactor
Date: Thu, 21 May 2026 00:42:07 +0300
Subject: [PATCH] btrtile: Spring update pt2
- Refactored the tiled client resizing logic to be more logical. Insted
of resizing based on clients split nodes, now btrtile handles client resizing based on the nearest edge client edge on the resize direction. Now it handles also resizing of the clientless splitnodes and should feel more intuitive.
- Simplified the resizing logic to avoid full arrange calls from
motionnotify
- Minor intend fixes
---
btrtile.c | 582 +++++++++++++++++++++++++++++++++++++++++++++++++++
btrtile.c | 583 +++++++++++++++++++++++++++++++++++++++++++++++++++
config.def.h | 12 ++
dwl.c | 160 +++++++++++---
3 files changed, 727 insertions(+), 27 deletions(-)
dwl.c | 152 +++++++++++---
3 files changed, 720 insertions(+), 27 deletions(-)
create mode 100644 btrtile.c
diff --git a/btrtile.c b/btrtile.c
new file mode 100644
index 0000000..c63e59f
index 0000000..f05a30f
--- /dev/null
+++ b/btrtile.c
@@ -0,0 +1,582 @@
@@ -0,0 +1,583 @@
+/* ************************************************************************** */
+/* @@@ @@@@@@@@ */
+/* @@@ @@@@@@@@@@ */
@@ -28,7 +29,7 @@ index 0000000..c63e59f
+/* By: julmajustus <julmajustus@tutanota.com> !!: !!:! !!! */
+/* ::! :!: !:! */
+/* Created: 2024/12/15 00:26:07 by julmajustus :: ::::::: :: */
+/* Updated: 2026/05/17 22:00:31 by julmajustus : : : : : : */
+/* Updated: 2026/05/20 22:38:02 by julmajustus : : : : : : */
+/* */
+/* ************************************************************************** */
+
@@ -63,7 +64,6 @@ index 0000000..c63e59f
+static unsigned int visible_count(LayoutNode *node, Monitor *m);
+static Client *xytoclient(double x, double y);
+
+static int resizing_from_mouse = 0;
+static double resize_last_update_x, resize_last_update_y;
+static uint32_t last_resize_time = 0;
+
@@ -91,6 +91,9 @@ index 0000000..c63e59f
+ c = node->client;
+ if (!c || !VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ return;
+ if (area.x == c->old_geom.x && area.y == c->old_geom.y &&
+ area.width == c->old_geom.width && area.height == c->old_geom.height)
+ return;
+ resize(c, area, 0);
+ c->old_geom = area;
+ return;
@@ -460,10 +463,9 @@ index 0000000..c63e59f
+ new_ratio = 0.95f;
+ split_node->split_ratio = new_ratio;
+
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ /* Skip the arrange when called from motionnotify; that path calls
+ * arrange itself after rate-limiting. */
+ if (!resizing_from_mouse)
+ arrange(selmon);
+}
+
+void
@@ -639,7 +641,7 @@ index 8a6eda0..bc04e3f 100644
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
diff --git a/dwl.c b/dwl.c
index 44f3ad9..d37e235 100644
index 44f3ad9..a121efc 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1,6 +1,7 @@
@@ -721,7 +723,7 @@ index 44f3ad9..d37e235 100644
b->func(&b->arg);
return;
}
@@ -655,6 +664,27 @@ buttonpress(struct wl_listener *listener, void *data)
@@ -655,6 +664,21 @@ buttonpress(struct wl_listener *listener, void *data)
/* If you released any buttons, we exit interactive move/resize mode. */
/* TODO: should reset to the pointer focus's current setcursor */
if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) {
@@ -736,20 +738,14 @@ index 44f3ad9..d37e235 100644
+ selmon->root = create_client_node(c);
+
+ setfloating(c, 0);
+ arrange(selmon);
+
+ } else if (cursor_mode == CurResize && !c->isfloating) {
+ resizing_from_mouse = 0;
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ }
+ } else {
+ if (cursor_mode == CurResize && resizing_from_mouse)
+ resizing_from_mouse = 0;
+ }
+ /* Default behaviour */
wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
cursor_mode = CurNormal;
/* Drop the window off on its new monitor */
@@ -746,6 +776,7 @@ cleanupmon(struct wl_listener *listener, void *data)
@@ -746,6 +770,7 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_output_layout_remove(output_layout, m->wlr_output);
wlr_scene_output_destroy(m->scene_output);
@@ -757,7 +753,7 @@ index 44f3ad9..d37e235 100644
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
free(m);
@@ -1090,6 +1121,7 @@ createmon(struct wl_listener *listener, void *data)
@@ -1090,6 +1115,7 @@ createmon(struct wl_listener *listener, void *data)
wl_list_insert(&mons, &m->link);
printstatus();
@@ -765,13 +761,16 @@ index 44f3ad9..d37e235 100644
/* The xdg-protocol specifies:
*
@@ -1332,6 +1364,14 @@ destroynotify(struct wl_listener *listener, void *data)
@@ -1329,9 +1355,17 @@ destroynotify(struct wl_listener *listener, void *data)
{
/* Called when the xdg_toplevel is destroyed. */
Client *c = wl_container_of(listener, c, destroy);
+ Monitor *mon;
wl_list_remove(&c->destroy.link);
wl_list_remove(&c->set_title.link);
wl_list_remove(&c->fullscreen.link);
+ /* We check if the destroyed client was part of any tiled_list, to catch
+ * client removals even if they would not be currently managed by btrtile */
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
+ remove_client(mon, c);
@@ -780,7 +779,7 @@ index 44f3ad9..d37e235 100644
#ifdef XWAYLAND
if (c->type != XDGShell) {
wl_list_remove(&c->activate.link);
@@ -1862,7 +1902,8 @@ void
@@ -1862,7 +1896,8 @@ void
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
double dx_unaccel, double dy_unaccel)
{
@@ -790,13 +789,13 @@ index 44f3ad9..d37e235 100644
Client *c = NULL, *w = NULL;
LayerSurface *l = NULL;
struct wlr_surface *surface = NULL;
@@ -1916,18 +1957,56 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
@@ -1916,18 +1951,55 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* Update drag icon's position */
wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
- /* If we are currently grabbing the mouse, handle and return */
+ /* Skip if internal call or already resizing */
+ if (time == 0 && resizing_from_mouse)
+ /* Skip if internal call */
+ if (time == 0)
+ goto focus;
+
+ tiled = grabc && !grabc->isfloating && !grabc->isfullscreen;
@@ -818,7 +817,7 @@ index 44f3ad9..d37e235 100644
- resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y,
- .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1);
- return;
+ if (tiled && resizing_from_mouse) {
+ if (tiled) {
+ dx_total = cursor->x - resize_last_update_x;
+ dy_total = cursor->y - resize_last_update_y;
+
@@ -831,7 +830,6 @@ index 44f3ad9..d37e235 100644
+ a.f = (float)(dy_total * resize_factor);
+ setratio_v(&a);
+ }
+ arrange(selmon);
+
+ last_resize_time = time;
+ resize_last_update_x = cursor->x;
@@ -854,7 +852,7 @@ index 44f3ad9..d37e235 100644
/* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */
@@ -1961,22 +2040,41 @@ moveresize(const Arg *arg)
@@ -1961,22 +2033,40 @@ moveresize(const Arg *arg)
if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen)
return;
@@ -889,7 +887,6 @@ index 44f3ad9..d37e235 100644
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ resize_last_update_x = cursor->x;
+ resize_last_update_y = cursor->y;
+ resizing_from_mouse = 1;
+ break;
+ }
+ } else {
@@ -912,11 +909,11 @@ index 44f3ad9..d37e235 100644
}
}
@@ -2826,6 +2924,14 @@ unmapnotify(struct wl_listener *listener, void *data)
@@ -2826,6 +2916,14 @@ unmapnotify(struct wl_listener *listener, void *data)
focusclient(focustop(selmon), 1);
}
} else {
+ // btrtile remove clients for each monitor
+ /* btrtile remove clients for each monitor */
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
+34 -37
View File
@@ -1,23 +1,24 @@
From 7ef8c161eb3cd801f608784e7d888fe12e94b9d4 Mon Sep 17 00:00:00 2001
From 618e3b70204520b6eb2c5040e072087ac0a3b3f7 Mon Sep 17 00:00:00 2001
From: julmajustus <julmajustus@tutanota.com>
Date: Sun, 17 May 2026 22:39:30 +0300
Subject: [PATCH] btrtile resizing refactor
Date: Thu, 21 May 2026 00:40:54 +0300
Subject: [PATCH] btrtile: Spring update pt2
- Refactored the tiled client resizing logic to be more logical. Insted
of resizing based on clients split nodes, now btrtile handles client resizing based on the nearest edge client edge on the resize direction. Now it handles also resizing of the clientless splitnodes and should feel more intuitive.
- Simplified the resizing logic to avoid full arrange calls from
motionnotify
- Minor intend fixes
---
btrtile.c | 563 +++++++++++++++++++++++++++++++++++++++++++++++++++
btrtile.c | 564 +++++++++++++++++++++++++++++++++++++++++++++++++++
config.def.h | 12 ++
dwl.c | 160 ++++++++++++---
3 files changed, 708 insertions(+), 27 deletions(-)
dwl.c | 152 +++++++++++---
3 files changed, 701 insertions(+), 27 deletions(-)
create mode 100644 btrtile.c
diff --git a/btrtile.c b/btrtile.c
new file mode 100644
index 0000000..ad810bf
index 0000000..357ffb9
--- /dev/null
+++ b/btrtile.c
@@ -0,0 +1,563 @@
@@ -0,0 +1,564 @@
+/* ************************************************************************** */
+/* @@@ @@@@@@@@ */
+/* @@@ @@@@@@@@@@ */
@@ -28,7 +29,7 @@ index 0000000..ad810bf
+/* By: julmajustus <julmajustus@tutanota.com> !!: !!:! !!! */
+/* ::! :!: !:! */
+/* Created: 2024/12/15 00:26:07 by julmajustus :: ::::::: :: */
+/* Updated: 2026/05/17 22:09:15 by julmajustus : : : : : : */
+/* Updated: 2026/05/20 22:51:54 by julmajustus : : : : : : */
+/* */
+/* ************************************************************************** */
+
@@ -63,7 +64,6 @@ index 0000000..ad810bf
+static unsigned int visible_count(LayoutNode *node, Monitor *m);
+static Client *xytoclient(double x, double y);
+
+static int resizing_from_mouse = 0;
+static double resize_last_update_x, resize_last_update_y;
+static uint32_t last_resize_time = 0;
+
@@ -84,6 +84,9 @@ index 0000000..ad810bf
+ c = node->client;
+ if (!c || !VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ return;
+ if (area.x == c->old_geom.x && area.y == c->old_geom.y &&
+ area.width == c->old_geom.width && area.height == c->old_geom.height)
+ return;
+ resize(c, area, 0);
+ c->old_geom = area;
+ return;
@@ -441,10 +444,9 @@ index 0000000..ad810bf
+ new_ratio = 0.95f;
+ split_node->split_ratio = new_ratio;
+
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ /* Skip the arrange when called from motionnotify; that path calls
+ * arrange itself after rate-limiting. */
+ if (!resizing_from_mouse)
+ arrange(selmon);
+}
+
+void
@@ -620,7 +622,7 @@ index 8a6eda0..bc04e3f 100644
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
diff --git a/dwl.c b/dwl.c
index 44f3ad9..d37e235 100644
index 44f3ad9..a121efc 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1,6 +1,7 @@
@@ -702,7 +704,7 @@ index 44f3ad9..d37e235 100644
b->func(&b->arg);
return;
}
@@ -655,6 +664,27 @@ buttonpress(struct wl_listener *listener, void *data)
@@ -655,6 +664,21 @@ buttonpress(struct wl_listener *listener, void *data)
/* If you released any buttons, we exit interactive move/resize mode. */
/* TODO: should reset to the pointer focus's current setcursor */
if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) {
@@ -717,20 +719,14 @@ index 44f3ad9..d37e235 100644
+ selmon->root = create_client_node(c);
+
+ setfloating(c, 0);
+ arrange(selmon);
+
+ } else if (cursor_mode == CurResize && !c->isfloating) {
+ resizing_from_mouse = 0;
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ }
+ } else {
+ if (cursor_mode == CurResize && resizing_from_mouse)
+ resizing_from_mouse = 0;
+ }
+ /* Default behaviour */
wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
cursor_mode = CurNormal;
/* Drop the window off on its new monitor */
@@ -746,6 +776,7 @@ cleanupmon(struct wl_listener *listener, void *data)
@@ -746,6 +770,7 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_output_layout_remove(output_layout, m->wlr_output);
wlr_scene_output_destroy(m->scene_output);
@@ -738,7 +734,7 @@ index 44f3ad9..d37e235 100644
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
free(m);
@@ -1090,6 +1121,7 @@ createmon(struct wl_listener *listener, void *data)
@@ -1090,6 +1115,7 @@ createmon(struct wl_listener *listener, void *data)
wl_list_insert(&mons, &m->link);
printstatus();
@@ -746,13 +742,16 @@ index 44f3ad9..d37e235 100644
/* The xdg-protocol specifies:
*
@@ -1332,6 +1364,14 @@ destroynotify(struct wl_listener *listener, void *data)
@@ -1329,9 +1355,17 @@ destroynotify(struct wl_listener *listener, void *data)
{
/* Called when the xdg_toplevel is destroyed. */
Client *c = wl_container_of(listener, c, destroy);
+ Monitor *mon;
wl_list_remove(&c->destroy.link);
wl_list_remove(&c->set_title.link);
wl_list_remove(&c->fullscreen.link);
+ /* We check if the destroyed client was part of any tiled_list, to catch
+ * client removals even if they would not be currently managed by btrtile */
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
+ remove_client(mon, c);
@@ -761,7 +760,7 @@ index 44f3ad9..d37e235 100644
#ifdef XWAYLAND
if (c->type != XDGShell) {
wl_list_remove(&c->activate.link);
@@ -1862,7 +1902,8 @@ void
@@ -1862,7 +1896,8 @@ void
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
double dx_unaccel, double dy_unaccel)
{
@@ -771,13 +770,13 @@ index 44f3ad9..d37e235 100644
Client *c = NULL, *w = NULL;
LayerSurface *l = NULL;
struct wlr_surface *surface = NULL;
@@ -1916,18 +1957,56 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
@@ -1916,18 +1951,55 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* Update drag icon's position */
wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
- /* If we are currently grabbing the mouse, handle and return */
+ /* Skip if internal call or already resizing */
+ if (time == 0 && resizing_from_mouse)
+ /* Skip if internal call */
+ if (time == 0)
+ goto focus;
+
+ tiled = grabc && !grabc->isfloating && !grabc->isfullscreen;
@@ -799,7 +798,7 @@ index 44f3ad9..d37e235 100644
- resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y,
- .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1);
- return;
+ if (tiled && resizing_from_mouse) {
+ if (tiled) {
+ dx_total = cursor->x - resize_last_update_x;
+ dy_total = cursor->y - resize_last_update_y;
+
@@ -812,7 +811,6 @@ index 44f3ad9..d37e235 100644
+ a.f = (float)(dy_total * resize_factor);
+ setratio_v(&a);
+ }
+ arrange(selmon);
+
+ last_resize_time = time;
+ resize_last_update_x = cursor->x;
@@ -835,7 +833,7 @@ index 44f3ad9..d37e235 100644
/* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */
@@ -1961,22 +2040,41 @@ moveresize(const Arg *arg)
@@ -1961,22 +2033,40 @@ moveresize(const Arg *arg)
if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen)
return;
@@ -870,7 +868,6 @@ index 44f3ad9..d37e235 100644
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ resize_last_update_x = cursor->x;
+ resize_last_update_y = cursor->y;
+ resizing_from_mouse = 1;
+ break;
+ }
+ } else {
@@ -893,11 +890,11 @@ index 44f3ad9..d37e235 100644
}
}
@@ -2826,6 +2924,14 @@ unmapnotify(struct wl_listener *listener, void *data)
@@ -2826,6 +2916,14 @@ unmapnotify(struct wl_listener *listener, void *data)
focusclient(focustop(selmon), 1);
}
} else {
+ // btrtile remove clients for each monitor
+ /* btrtile remove clients for each monitor */
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
@@ -1,23 +1,24 @@
From b8d84c87f13681118865b83312387a881ab10b73 Mon Sep 17 00:00:00 2001
From c11b1a8c93c27fad3782e9dbc1b094a4a7b78088 Mon Sep 17 00:00:00 2001
From: julmajustus <julmajustus@tutanota.com>
Date: Sun, 17 May 2026 23:10:49 +0300
Subject: [PATCH] btrtile resizing refactor
Date: Thu, 21 May 2026 00:38:45 +0300
Subject: [PATCH] btrtile: Spring update pt2
- Refactored the tiled client resizing logic to be more logical. Insted
of resizing based on clients split nodes, now btrtile handles client resizing based on the nearest edge client edge on the resize direction. Now it handles also resizing of the clientless splitnodes and should feel more intuitive.
- Simplified the resizing logic to avoid full arrange calls from
motionnotify
- Minor intend fixes
---
btrtile.c | 582 +++++++++++++++++++++++++++++++++++++++++++++++++++
btrtile.c | 583 +++++++++++++++++++++++++++++++++++++++++++++++++++
config.def.h | 12 ++
dwl.c | 161 +++++++++++---
3 files changed, 728 insertions(+), 27 deletions(-)
dwl.c | 152 +++++++++++---
3 files changed, 720 insertions(+), 27 deletions(-)
create mode 100644 btrtile.c
diff --git a/btrtile.c b/btrtile.c
new file mode 100644
index 0000000..c63e59f
index 0000000..f05a30f
--- /dev/null
+++ b/btrtile.c
@@ -0,0 +1,582 @@
@@ -0,0 +1,583 @@
+/* ************************************************************************** */
+/* @@@ @@@@@@@@ */
+/* @@@ @@@@@@@@@@ */
@@ -28,7 +29,7 @@ index 0000000..c63e59f
+/* By: julmajustus <julmajustus@tutanota.com> !!: !!:! !!! */
+/* ::! :!: !:! */
+/* Created: 2024/12/15 00:26:07 by julmajustus :: ::::::: :: */
+/* Updated: 2026/05/17 22:00:31 by julmajustus : : : : : : */
+/* Updated: 2026/05/20 22:38:02 by julmajustus : : : : : : */
+/* */
+/* ************************************************************************** */
+
@@ -63,7 +64,6 @@ index 0000000..c63e59f
+static unsigned int visible_count(LayoutNode *node, Monitor *m);
+static Client *xytoclient(double x, double y);
+
+static int resizing_from_mouse = 0;
+static double resize_last_update_x, resize_last_update_y;
+static uint32_t last_resize_time = 0;
+
@@ -91,6 +91,9 @@ index 0000000..c63e59f
+ c = node->client;
+ if (!c || !VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ return;
+ if (area.x == c->old_geom.x && area.y == c->old_geom.y &&
+ area.width == c->old_geom.width && area.height == c->old_geom.height)
+ return;
+ resize(c, area, 0);
+ c->old_geom = area;
+ return;
@@ -460,10 +463,9 @@ index 0000000..c63e59f
+ new_ratio = 0.95f;
+ split_node->split_ratio = new_ratio;
+
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ /* Skip the arrange when called from motionnotify; that path calls
+ * arrange itself after rate-limiting. */
+ if (!resizing_from_mouse)
+ arrange(selmon);
+}
+
+void
@@ -639,7 +641,7 @@ index 8a6eda0..bc04e3f 100644
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
diff --git a/dwl.c b/dwl.c
index 8101ffa..32a94c4 100644
index 8101ffa..c9650c1 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1,6 +1,7 @@
@@ -721,7 +723,7 @@ index 8101ffa..32a94c4 100644
b->func(&b->arg);
return;
}
@@ -659,6 +668,27 @@ buttonpress(struct wl_listener *listener, void *data)
@@ -659,6 +668,21 @@ buttonpress(struct wl_listener *listener, void *data)
/* If you released any buttons, we exit interactive move/resize mode. */
/* TODO: should reset to the pointer focus's current setcursor */
if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) {
@@ -736,20 +738,14 @@ index 8101ffa..32a94c4 100644
+ selmon->root = create_client_node(c);
+
+ setfloating(c, 0);
+ arrange(selmon);
+
+ } else if (cursor_mode == CurResize && !c->isfloating) {
+ resizing_from_mouse = 0;
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ }
+ } else {
+ if (cursor_mode == CurResize && resizing_from_mouse)
+ resizing_from_mouse = 0;
+ }
+ /* Default behaviour */
wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
cursor_mode = CurNormal;
/* Drop the window off on its new monitor */
@@ -750,6 +780,7 @@ cleanupmon(struct wl_listener *listener, void *data)
@@ -750,6 +774,7 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_output_layout_remove(output_layout, m->wlr_output);
wlr_scene_output_destroy(m->scene_output);
@@ -757,7 +753,7 @@ index 8101ffa..32a94c4 100644
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
free(m);
@@ -1094,6 +1125,7 @@ createmon(struct wl_listener *listener, void *data)
@@ -1094,6 +1119,7 @@ createmon(struct wl_listener *listener, void *data)
wl_list_insert(&mons, &m->link);
printstatus();
@@ -765,14 +761,17 @@ index 8101ffa..32a94c4 100644
/* The xdg-protocol specifies:
*
@@ -1336,6 +1368,15 @@ destroynotify(struct wl_listener *listener, void *data)
@@ -1332,10 +1358,18 @@ void
destroynotify(struct wl_listener *listener, void *data)
{
/* Called when the xdg_toplevel is destroyed. */
+ Monitor *mon;
Client *c = wl_container_of(listener, c, destroy);
wl_list_remove(&c->destroy.link);
wl_list_remove(&c->set_title.link);
wl_list_remove(&c->fullscreen.link);
+ /* We check if the destroyed client was part of any tiled_list, to catch
+ * client removals even if they would not be currently managed by btrtile */
+ // btrtile remove clients for each monitor
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
+ remove_client(mon, c);
@@ -781,7 +780,7 @@ index 8101ffa..32a94c4 100644
#ifdef XWAYLAND
if (c->type != XDGShell) {
wl_list_remove(&c->activate.link);
@@ -1866,7 +1907,8 @@ void
@@ -1866,7 +1900,8 @@ void
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
double dx_unaccel, double dy_unaccel)
{
@@ -791,13 +790,13 @@ index 8101ffa..32a94c4 100644
Client *c = NULL, *w = NULL;
LayerSurface *l = NULL;
struct wlr_surface *surface = NULL;
@@ -1920,18 +1962,56 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
@@ -1920,18 +1955,55 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* Update drag icon's position */
wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
- /* If we are currently grabbing the mouse, handle and return */
+ /* Skip if internal call or already resizing */
+ if (time == 0 && resizing_from_mouse)
+ /* Skip if internal call */
+ if (time == 0)
+ goto focus;
+
+ tiled = grabc && !grabc->isfloating && !grabc->isfullscreen;
@@ -819,7 +818,7 @@ index 8101ffa..32a94c4 100644
- resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y,
- .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1);
- return;
+ if (tiled && resizing_from_mouse) {
+ if (tiled) {
+ dx_total = cursor->x - resize_last_update_x;
+ dy_total = cursor->y - resize_last_update_y;
+
@@ -832,7 +831,6 @@ index 8101ffa..32a94c4 100644
+ a.f = (float)(dy_total * resize_factor);
+ setratio_v(&a);
+ }
+ arrange(selmon);
+
+ last_resize_time = time;
+ resize_last_update_x = cursor->x;
@@ -855,7 +853,7 @@ index 8101ffa..32a94c4 100644
/* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */
@@ -1965,22 +2045,41 @@ moveresize(const Arg *arg)
@@ -1965,22 +2037,40 @@ moveresize(const Arg *arg)
if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen)
return;
@@ -890,7 +888,6 @@ index 8101ffa..32a94c4 100644
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ resize_last_update_x = cursor->x;
+ resize_last_update_y = cursor->y;
+ resizing_from_mouse = 1;
+ break;
+ }
+ } else {
@@ -913,11 +910,11 @@ index 8101ffa..32a94c4 100644
}
}
@@ -2833,6 +2932,14 @@ unmapnotify(struct wl_listener *listener, void *data)
@@ -2833,6 +2923,14 @@ unmapnotify(struct wl_listener *listener, void *data)
focusclient(focustop(selmon), 1);
}
} else {
+ // btrtile remove clients for each monitor
+ /* btrtile remove clients for each monitor */
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
@@ -1,23 +1,24 @@
From 3c78ee7e48fb24276d1a8d722ca1e715ea07d17f Mon Sep 17 00:00:00 2001
From 47cb7ad9f669643765cafa4c2ecd1a4850bca893 Mon Sep 17 00:00:00 2001
From: julmajustus <julmajustus@tutanota.com>
Date: Sun, 17 May 2026 23:28:41 +0300
Subject: [PATCH] btrtile resizing refactor
Date: Thu, 21 May 2026 00:39:56 +0300
Subject: [PATCH] btrtile: Spring update pt2
- Refactored the tiled client resizing logic to be more logical. Insted
of resizing based on clients split nodes, now btrtile handles client resizing based on the nearest edge client edge on the resize direction. Now it handles also resizing of the clientless splitnodes and should feel more intuitive.
- Simplified the resizing logic to avoid full arrange calls from
motionnotify
- Minor intend fixes
---
btrtile.c | 563 +++++++++++++++++++++++++++++++++++++++++++++++++++
btrtile.c | 564 +++++++++++++++++++++++++++++++++++++++++++++++++++
config.def.h | 12 ++
dwl.c | 161 ++++++++++++---
3 files changed, 709 insertions(+), 27 deletions(-)
dwl.c | 152 +++++++++++---
3 files changed, 701 insertions(+), 27 deletions(-)
create mode 100644 btrtile.c
diff --git a/btrtile.c b/btrtile.c
new file mode 100644
index 0000000..7e70478
index 0000000..357ffb9
--- /dev/null
+++ b/btrtile.c
@@ -0,0 +1,563 @@
@@ -0,0 +1,564 @@
+/* ************************************************************************** */
+/* @@@ @@@@@@@@ */
+/* @@@ @@@@@@@@@@ */
@@ -28,7 +29,7 @@ index 0000000..7e70478
+/* By: julmajustus <julmajustus@tutanota.com> !!: !!:! !!! */
+/* ::! :!: !:! */
+/* Created: 2024/12/15 00:26:07 by julmajustus :: ::::::: :: */
+/* Updated: 2026/05/17 23:26:25 by julmajustus : : : : : : */
+/* Updated: 2026/05/20 22:51:54 by julmajustus : : : : : : */
+/* */
+/* ************************************************************************** */
+
@@ -63,7 +64,6 @@ index 0000000..7e70478
+static unsigned int visible_count(LayoutNode *node, Monitor *m);
+static Client *xytoclient(double x, double y);
+
+static int resizing_from_mouse = 0;
+static double resize_last_update_x, resize_last_update_y;
+static uint32_t last_resize_time = 0;
+
@@ -84,6 +84,9 @@ index 0000000..7e70478
+ c = node->client;
+ if (!c || !VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ return;
+ if (area.x == c->old_geom.x && area.y == c->old_geom.y &&
+ area.width == c->old_geom.width && area.height == c->old_geom.height)
+ return;
+ resize(c, area, 0);
+ c->old_geom = area;
+ return;
@@ -441,10 +444,9 @@ index 0000000..7e70478
+ new_ratio = 0.95f;
+ split_node->split_ratio = new_ratio;
+
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ /* Skip the arrange when called from motionnotify; that path calls
+ * arrange itself after rate-limiting. */
+ if (!resizing_from_mouse)
+ arrange(selmon);
+}
+
+void
@@ -620,7 +622,7 @@ index 8a6eda0..bc04e3f 100644
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
diff --git a/dwl.c b/dwl.c
index 8101ffa..32a94c4 100644
index 8101ffa..bf52c6c 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1,6 +1,7 @@
@@ -702,7 +704,7 @@ index 8101ffa..32a94c4 100644
b->func(&b->arg);
return;
}
@@ -659,6 +668,27 @@ buttonpress(struct wl_listener *listener, void *data)
@@ -659,6 +668,21 @@ buttonpress(struct wl_listener *listener, void *data)
/* If you released any buttons, we exit interactive move/resize mode. */
/* TODO: should reset to the pointer focus's current setcursor */
if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) {
@@ -717,20 +719,14 @@ index 8101ffa..32a94c4 100644
+ selmon->root = create_client_node(c);
+
+ setfloating(c, 0);
+ arrange(selmon);
+
+ } else if (cursor_mode == CurResize && !c->isfloating) {
+ resizing_from_mouse = 0;
+ apply_layout(selmon, selmon->root, selmon->w, 1);
+ }
+ } else {
+ if (cursor_mode == CurResize && resizing_from_mouse)
+ resizing_from_mouse = 0;
+ }
+ /* Default behaviour */
wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
cursor_mode = CurNormal;
/* Drop the window off on its new monitor */
@@ -750,6 +780,7 @@ cleanupmon(struct wl_listener *listener, void *data)
@@ -750,6 +774,7 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_output_layout_remove(output_layout, m->wlr_output);
wlr_scene_output_destroy(m->scene_output);
@@ -738,7 +734,7 @@ index 8101ffa..32a94c4 100644
closemon(m);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
free(m);
@@ -1094,6 +1125,7 @@ createmon(struct wl_listener *listener, void *data)
@@ -1094,6 +1119,7 @@ createmon(struct wl_listener *listener, void *data)
wl_list_insert(&mons, &m->link);
printstatus();
@@ -746,14 +742,16 @@ index 8101ffa..32a94c4 100644
/* The xdg-protocol specifies:
*
@@ -1336,6 +1368,15 @@ destroynotify(struct wl_listener *listener, void *data)
@@ -1333,9 +1359,17 @@ destroynotify(struct wl_listener *listener, void *data)
{
/* Called when the xdg_toplevel is destroyed. */
Client *c = wl_container_of(listener, c, destroy);
+ Monitor *mon;
wl_list_remove(&c->destroy.link);
wl_list_remove(&c->set_title.link);
wl_list_remove(&c->fullscreen.link);
+ /* We check if the destroyed client was part of any tiled_list, to catch
+ * client removals even if they would not be currently managed by btrtile */
+ // btrtile remove clients for each monitor
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {
+ remove_client(mon, c);
@@ -762,7 +760,7 @@ index 8101ffa..32a94c4 100644
#ifdef XWAYLAND
if (c->type != XDGShell) {
wl_list_remove(&c->activate.link);
@@ -1866,7 +1907,8 @@ void
@@ -1866,7 +1900,8 @@ void
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
double dx_unaccel, double dy_unaccel)
{
@@ -772,13 +770,13 @@ index 8101ffa..32a94c4 100644
Client *c = NULL, *w = NULL;
LayerSurface *l = NULL;
struct wlr_surface *surface = NULL;
@@ -1920,18 +1962,56 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
@@ -1920,18 +1955,55 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
/* Update drag icon's position */
wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
- /* If we are currently grabbing the mouse, handle and return */
+ /* Skip if internal call or already resizing */
+ if (time == 0 && resizing_from_mouse)
+ /* Skip if internal call */
+ if (time == 0)
+ goto focus;
+
+ tiled = grabc && !grabc->isfloating && !grabc->isfullscreen;
@@ -800,7 +798,7 @@ index 8101ffa..32a94c4 100644
- resize(grabc, (struct wlr_box){.x = grabc->geom.x, .y = grabc->geom.y,
- .width = (int)round(cursor->x) - grabc->geom.x, .height = (int)round(cursor->y) - grabc->geom.y}, 1);
- return;
+ if (tiled && resizing_from_mouse) {
+ if (tiled) {
+ dx_total = cursor->x - resize_last_update_x;
+ dy_total = cursor->y - resize_last_update_y;
+
@@ -813,7 +811,6 @@ index 8101ffa..32a94c4 100644
+ a.f = (float)(dy_total * resize_factor);
+ setratio_v(&a);
+ }
+ arrange(selmon);
+
+ last_resize_time = time;
+ resize_last_update_x = cursor->x;
@@ -836,7 +833,7 @@ index 8101ffa..32a94c4 100644
/* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */
@@ -1965,22 +2045,41 @@ moveresize(const Arg *arg)
@@ -1965,22 +2037,40 @@ moveresize(const Arg *arg)
if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen)
return;
@@ -871,7 +868,6 @@ index 8101ffa..32a94c4 100644
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ resize_last_update_x = cursor->x;
+ resize_last_update_y = cursor->y;
+ resizing_from_mouse = 1;
+ break;
+ }
+ } else {
@@ -894,11 +890,11 @@ index 8101ffa..32a94c4 100644
}
}
@@ -2833,6 +2932,14 @@ unmapnotify(struct wl_listener *listener, void *data)
@@ -2833,6 +2923,14 @@ unmapnotify(struct wl_listener *listener, void *data)
focusclient(focustop(selmon), 1);
}
} else {
+ // btrtile remove clients for each monitor
+ /* btrtile remove clients for each monitor */
+ Monitor *mon;
+ wl_list_for_each(mon, &mons, link) {
+ if (mon->root) {