mirror of
https://codeberg.org/dwl/dwl-patches.git
synced 2026-06-11 10:23:19 +00:00
btrtile: Refactored the tiled client resizing logic
Improved detection of the node to resize. btrtile now handles client resizing based on the nearest client edge in the resize direction. It also handles resizing of clientless split nodes, making the behavior feel more intuitive.
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
From f5d7fe287bd4405879a92d649243d3f646652617 Mon Sep 17 00:00:00 2001
|
||||
From ad32bb92157d5238340eb53322254dc8127477db Mon Sep 17 00:00:00 2001
|
||||
From: julmajustus <julmajustus@tutanota.com>
|
||||
Date: Thu, 19 Mar 2026 00:08:10 +0200
|
||||
Subject: [PATCH] Refactor btrtile-gaps to v0.8
|
||||
Date: Sun, 17 May 2026 22:49:07 +0300
|
||||
Subject: [PATCH] btrtile resizing refactor
|
||||
|
||||
- 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.
|
||||
---
|
||||
btrtile.c | 584 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
btrtile.c | 582 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
config.def.h | 12 ++
|
||||
dwl.c | 148 ++++++++++---
|
||||
3 files changed, 717 insertions(+), 27 deletions(-)
|
||||
dwl.c | 160 +++++++++++---
|
||||
3 files changed, 727 insertions(+), 27 deletions(-)
|
||||
create mode 100644 btrtile.c
|
||||
|
||||
diff --git a/btrtile.c b/btrtile.c
|
||||
new file mode 100644
|
||||
index 0000000..afe3c8f
|
||||
index 0000000..c63e59f
|
||||
--- /dev/null
|
||||
+++ b/btrtile.c
|
||||
@@ -0,0 +1,584 @@
|
||||
@@ -0,0 +1,582 @@
|
||||
+/* ************************************************************************** */
|
||||
+/* @@@ @@@@@@@@ */
|
||||
+/* @@@ @@@@@@@@@@ */
|
||||
@@ -26,7 +28,7 @@ index 0000000..afe3c8f
|
||||
+/* By: julmajustus <julmajustus@tutanota.com> !!: !!:! !!! */
|
||||
+/* ::! :!: !:! */
|
||||
+/* Created: 2024/12/15 00:26:07 by julmajustus :: ::::::: :: */
|
||||
+/* Updated: 2026/03/19 00:07:19 by julmajustus : : : : : : */
|
||||
+/* Updated: 2026/05/17 22:00:31 by julmajustus : : : : : : */
|
||||
+/* */
|
||||
+/* ************************************************************************** */
|
||||
+
|
||||
@@ -49,7 +51,8 @@ index 0000000..afe3c8f
|
||||
+static void destroy_node(LayoutNode *node);
|
||||
+static void destroy_tree(Monitor *m);
|
||||
+static LayoutNode *find_client_node(LayoutNode *node, Client *c);
|
||||
+static LayoutNode *find_suitable_split(LayoutNode *start, unsigned int need_vert);
|
||||
+static LayoutNode *find_suitable_split(Monitor *m, LayoutNode *start,
|
||||
+ unsigned int need_vertical, int focused_on_left);
|
||||
+static void init_tree(Monitor *m);
|
||||
+static void insert_client(Monitor *m, Client *focused_client, Client *new_client);
|
||||
+static LayoutNode *remove_client_node(LayoutNode *node, Client *c);
|
||||
@@ -76,7 +79,7 @@ index 0000000..afe3c8f
|
||||
+ if (!node)
|
||||
+ return;
|
||||
+
|
||||
+ if (is_root && e) {
|
||||
+ if (is_root && e) {
|
||||
+ area.x += gappx;
|
||||
+ area.y += gappx;
|
||||
+ area.width -= 2 * gappx;
|
||||
@@ -129,7 +132,7 @@ index 0000000..afe3c8f
|
||||
+ right_area.width = area.width - mid;
|
||||
+ right_area.height = area.height;
|
||||
+
|
||||
+ if (e) {
|
||||
+ if (e) {
|
||||
+ left_area.width -= gappx / 2;
|
||||
+ right_area.x += gappx / 2;
|
||||
+ right_area.width -= gappx / 2;
|
||||
@@ -147,7 +150,7 @@ index 0000000..afe3c8f
|
||||
+ right_area.width = area.width;
|
||||
+ right_area.height= area.height - mid;
|
||||
+
|
||||
+ if (e) {
|
||||
+ if (e) {
|
||||
+ left_area.height -= gappx / 2;
|
||||
+ right_area.y += gappx / 2;
|
||||
+ right_area.height -= gappx / 2;
|
||||
@@ -166,16 +169,16 @@ index 0000000..afe3c8f
|
||||
+ LayoutNode *found;
|
||||
+ struct wlr_box full_area;
|
||||
+
|
||||
+ if (!m || !m->root)
|
||||
+ return;
|
||||
+ if (!m)
|
||||
+ return;
|
||||
+
|
||||
+ /* Remove non tiled clients from tree. */
|
||||
+ wl_list_for_each(c, &clients, link) {
|
||||
+ if (c->mon == m && !c->isfloating && !c->isfullscreen) {
|
||||
+ } else {
|
||||
+ remove_client(m, c);
|
||||
+ }
|
||||
+ }
|
||||
+ /* Remove non tiled clients from tree. */
|
||||
+ wl_list_for_each(c, &clients, link) {
|
||||
+ if (c->mon == m && !c->isfloating && !c->isfullscreen) {
|
||||
+ } else {
|
||||
+ remove_client(m, c);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /* If no client is found under cursor, fallback to focustop(m) */
|
||||
+ if (!(focused = xytoclient(cursor->x, cursor->y)))
|
||||
@@ -268,30 +271,37 @@ index 0000000..afe3c8f
|
||||
+}
|
||||
+
|
||||
+LayoutNode *
|
||||
+find_suitable_split(LayoutNode *start_node, unsigned int need_vertical)
|
||||
+find_suitable_split(Monitor *m, LayoutNode *start_node,
|
||||
+ unsigned int need_vertical, int focused_on_left)
|
||||
+{
|
||||
+ LayoutNode *n = start_node;
|
||||
+ /* if we started from a client node, jump to its parent: */
|
||||
+ if (n && n->is_client_node)
|
||||
+ LayoutNode *n = start_node, *child = NULL;
|
||||
+
|
||||
+ if (!m)
|
||||
+ return NULL;
|
||||
+
|
||||
+ if (n && n->is_client_node) {
|
||||
+ child = n;
|
||||
+ n = n->split_node;
|
||||
+ }
|
||||
+
|
||||
+ while (n) {
|
||||
+ if (!n->is_client_node && n->is_split_vertically == need_vertical &&
|
||||
+ visible_count(n->left, selmon) > 0 && visible_count(n->right, selmon) > 0)
|
||||
+ return n;
|
||||
+ if (!n->is_client_node && n->is_split_vertically == need_vertical
|
||||
+ && visible_count(n->left, m) > 0
|
||||
+ && visible_count(n->right, m) > 0) {
|
||||
+ if ((focused_on_left && n->left == child) ||
|
||||
+ (!focused_on_left && n->right == child))
|
||||
+ return n;
|
||||
+ }
|
||||
+ child = n;
|
||||
+ n = n->split_node;
|
||||
+ }
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+init_tree(Monitor *m)
|
||||
+{
|
||||
+ if (!m)
|
||||
+ return;
|
||||
+ m->root = calloc(1, sizeof(LayoutNode));
|
||||
+ if (!m->root)
|
||||
+ m->root = NULL;
|
||||
+ if (m)
|
||||
+ m->root = NULL;
|
||||
+}
|
||||
+
|
||||
+void
|
||||
@@ -415,21 +425,31 @@ index 0000000..afe3c8f
|
||||
+ m->root = remove_client_node(m->root, c);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+setratio_h(const Arg *arg)
|
||||
+static void
|
||||
+setratio(unsigned int need_vertical, const Arg *arg)
|
||||
+{
|
||||
+ Client *sel = focustop(selmon);
|
||||
+ Client *sel;
|
||||
+ LayoutNode *client_node, *split_node;
|
||||
+ float new_ratio;
|
||||
+ int focused_on_left;
|
||||
+
|
||||
+ if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange)
|
||||
+ if (!selmon || !selmon->lt[selmon->sellt]->arrange)
|
||||
+ return;
|
||||
+
|
||||
+ sel = focustop(selmon);
|
||||
+ if (!sel)
|
||||
+ return;
|
||||
+
|
||||
+ client_node = find_client_node(selmon->root, sel);
|
||||
+ if (!client_node)
|
||||
+ return;
|
||||
+
|
||||
+ split_node = find_suitable_split(client_node, 1);
|
||||
+ focused_on_left = (arg->f >= 0.0f);
|
||||
+
|
||||
+ split_node = find_suitable_split(selmon, client_node, need_vertical, focused_on_left);
|
||||
+
|
||||
+ if (!split_node)
|
||||
+ split_node = find_suitable_split(selmon, client_node, need_vertical, !focused_on_left);
|
||||
+ if (!split_node)
|
||||
+ return;
|
||||
+
|
||||
@@ -440,43 +460,22 @@ index 0000000..afe3c8f
|
||||
+ new_ratio = 0.95f;
|
||||
+ split_node->split_ratio = new_ratio;
|
||||
+
|
||||
+ /* Skip the arrange if done resizing by mouse,
|
||||
+ * we call arrange from motionotify */
|
||||
+ if (!resizing_from_mouse) {
|
||||
+ /* Skip the arrange when called from motionnotify; that path calls
|
||||
+ * arrange itself after rate-limiting. */
|
||||
+ if (!resizing_from_mouse)
|
||||
+ arrange(selmon);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+setratio_h(const Arg *arg)
|
||||
+{
|
||||
+ setratio(1, arg);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+setratio_v(const Arg *arg)
|
||||
+{
|
||||
+ Client *sel = focustop(selmon);
|
||||
+ LayoutNode *client_node, *split_node;
|
||||
+ float new_ratio;
|
||||
+
|
||||
+ if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange)
|
||||
+ return;
|
||||
+
|
||||
+ client_node = find_client_node(selmon->root, sel);
|
||||
+ if (!client_node)
|
||||
+ return;
|
||||
+
|
||||
+ split_node = find_suitable_split(client_node, 0);
|
||||
+ if (!split_node)
|
||||
+ return;
|
||||
+
|
||||
+ new_ratio = (arg->f != 0.0f) ? (split_node->split_ratio + arg->f) : 0.5f;
|
||||
+ if (new_ratio < 0.05f)
|
||||
+ new_ratio = 0.05f;
|
||||
+ if (new_ratio > 0.95f)
|
||||
+ new_ratio = 0.95f;
|
||||
+ split_node->split_ratio = new_ratio;
|
||||
+
|
||||
+ /* Skip the arrange if done resizing by mouse,
|
||||
+ * we call arrange from motionotify */
|
||||
+ if (!resizing_from_mouse) {
|
||||
+ arrange(selmon);
|
||||
+ }
|
||||
+ setratio(0, arg);
|
||||
+}
|
||||
+
|
||||
+void swapclients(const Arg *arg) {
|
||||
@@ -565,11 +564,12 @@ index 0000000..afe3c8f
|
||||
+
|
||||
+Client *
|
||||
+xytoclient(double x, double y) {
|
||||
+ Monitor *m = xytomon(x, y);
|
||||
+ Client *c, *closest = NULL;
|
||||
+ double dist, mindist = INT_MAX, dx, dy;
|
||||
+
|
||||
+ wl_list_for_each_reverse(c, &clients, link) {
|
||||
+ if (VISIBLEON(c, selmon) && !c->isfloating && !c->isfullscreen &&
|
||||
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen &&
|
||||
+ x >= c->geom.x && x <= (c->geom.x + c->geom.width) &&
|
||||
+ y >= c->geom.y && y <= (c->geom.y + c->geom.height)){
|
||||
+ return c;
|
||||
@@ -578,7 +578,7 @@ index 0000000..afe3c8f
|
||||
+
|
||||
+ /* If no client was found at cursor position fallback to closest. */
|
||||
+ wl_list_for_each_reverse(c, &clients, link) {
|
||||
+ if (VISIBLEON(c, selmon) && !c->isfloating && !c->isfullscreen) {
|
||||
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) {
|
||||
+ dx = 0, dy = 0;
|
||||
+
|
||||
+ if (x < c->geom.x)
|
||||
@@ -591,7 +591,7 @@ index 0000000..afe3c8f
|
||||
+ else if (y > (c->geom.y + c->geom.height))
|
||||
+ dy = y - (c->geom.y + c->geom.height);
|
||||
+
|
||||
+ dist = sqrt(dx * dx + dy * dy);
|
||||
+ dist = dx * dx + dy * dy;
|
||||
+ if (dist < mindist) {
|
||||
+ mindist = dist;
|
||||
+ closest = c;
|
||||
@@ -639,7 +639,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..f74d9a1 100644
|
||||
index 44f3ad9..d37e235 100644
|
||||
--- a/dwl.c
|
||||
+++ b/dwl.c
|
||||
@@ -1,6 +1,7 @@
|
||||
@@ -765,18 +765,22 @@ index 44f3ad9..f74d9a1 100644
|
||||
|
||||
/* The xdg-protocol specifies:
|
||||
*
|
||||
@@ -1332,6 +1364,10 @@ destroynotify(struct wl_listener *listener, void *data)
|
||||
@@ -1332,6 +1364,14 @@ destroynotify(struct wl_listener *listener, void *data)
|
||||
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 */
|
||||
+ if (selmon && selmon->root)
|
||||
+ remove_client(selmon, c);
|
||||
+ Monitor *mon;
|
||||
+ wl_list_for_each(mon, &mons, link) {
|
||||
+ if (mon->root) {
|
||||
+ remove_client(mon, c);
|
||||
+ }
|
||||
+ }
|
||||
#ifdef XWAYLAND
|
||||
if (c->type != XDGShell) {
|
||||
wl_list_remove(&c->activate.link);
|
||||
@@ -1862,7 +1898,8 @@ void
|
||||
@@ -1862,7 +1902,8 @@ void
|
||||
motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
|
||||
double dx_unaccel, double dy_unaccel)
|
||||
{
|
||||
@@ -786,7 +790,7 @@ index 44f3ad9..f74d9a1 100644
|
||||
Client *c = NULL, *w = NULL;
|
||||
LayerSurface *l = NULL;
|
||||
struct wlr_surface *surface = NULL;
|
||||
@@ -1916,18 +1953,56 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
|
||||
@@ -1916,18 +1957,56 @@ 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));
|
||||
|
||||
@@ -850,7 +854,7 @@ index 44f3ad9..f74d9a1 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 +2036,41 @@ moveresize(const Arg *arg)
|
||||
@@ -1961,22 +2040,41 @@ moveresize(const Arg *arg)
|
||||
if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen)
|
||||
return;
|
||||
|
||||
@@ -908,6 +912,21 @@ index 44f3ad9..f74d9a1 100644
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2826,6 +2924,14 @@ unmapnotify(struct wl_listener *listener, void *data)
|
||||
focusclient(focustop(selmon), 1);
|
||||
}
|
||||
} else {
|
||||
+ // btrtile remove clients for each monitor
|
||||
+ Monitor *mon;
|
||||
+ wl_list_for_each(mon, &mons, link) {
|
||||
+ if (mon->root) {
|
||||
+ remove_client(mon, c);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
wl_list_remove(&c->link);
|
||||
setmon(c, NULL, 0);
|
||||
wl_list_remove(&c->flink);
|
||||
--
|
||||
2.52.0
|
||||
2.53.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user