mirror of
https://codeberg.org/dwl/dwl-patches.git
synced 2025-09-10 13:14:57 +00:00
247 lines
10 KiB
Diff
247 lines
10 KiB
Diff
From ad717ddd80ec86b2c1f87b88c673bd272332790a Mon Sep 17 00:00:00 2001
|
|
From: Dima Krasner <dima@dimakrasner.com>
|
|
Date: Sat, 15 Jul 2023 15:45:58 +0300
|
|
Subject: [PATCH] add the snail layout
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
This layout is a scalable alternative to the "tile" and "spiral" layouts, optimized for wide monitors. Both the master area and the stack are "spirals", but windows in the master area are split horizontally as long as the master area has enough horizontal space, and the first window in the stack is split vertically unless the stack is wide.
|
|
|
|
With one window in the master area and mfact = 0.5, it behaves like the spiral layout:
|
|
|
|
┌───────────────┬────────────────┐
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
│ ├───┬───┬────────┤
|
|
│ │ │ │ │
|
|
│ ├───┴───┤ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
└───────────────┴───────┴────────┘
|
|
|
|
With 2 windows in the master area and 2 in the stack:
|
|
|
|
┌───────────────┬────────────────┐
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
├───────────────┼────────────────┤
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
└───────────────┴────────────────┘
|
|
|
|
With 3 windows in the master area and 2 in the stack:
|
|
|
|
┌───────────────┬────────────────┐
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
├───────┬───────┼────────────────┤
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
└───────┴───────┴────────────────┘
|
|
|
|
With many windows in both areas:
|
|
|
|
┌───────────────┬────────────────┐
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
│ │ │
|
|
├───┬───┬───────┼───┬───┬────────┤
|
|
│ │ │ │ │ │ │
|
|
├───┴───┤ ├───┴───┤ │
|
|
│ │ │ │ │
|
|
│ │ │ │ │
|
|
└───────┴───────┴───────┴────────┘
|
|
|
|
With 2 windows in the master area, many windows in the stack and high mfact:
|
|
|
|
┌──────────┬──────────┬──────────┐
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ master ├──┬stack──┤
|
|
│ │ │ │ │ │
|
|
│ │ ├──┴──┤ │
|
|
│ │ │ │ │
|
|
│ │ │ │ │
|
|
└──────────┴──────────┴─────┴────┘
|
|
|
|
With 2 windows in the master area, many windows in the stack and low mfact:
|
|
|
|
┌──────────┬──────────┬──────────┐
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
│ │ │ │
|
|
├──master──┤ stack┬──┬────┤
|
|
│ │ │ │ │ │
|
|
│ │ ├──┴──┤ │
|
|
│ │ │ │ │
|
|
│ │ │ │ │
|
|
└──────────┴──────────┴─────┴────┘
|
|
---
|
|
config.def.h | 4 +-
|
|
dwl.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 104 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/config.def.h b/config.def.h
|
|
index db0babc..fae7887 100644
|
|
--- a/config.def.h
|
|
+++ b/config.def.h
|
|
@@ -33,6 +33,7 @@ static const Layout layouts[] = {
|
|
{ "[]=", tile },
|
|
{ "><>", NULL }, /* no layout function means floating behavior */
|
|
{ "[M]", monocle },
|
|
+ { "@|@", snail },
|
|
};
|
|
|
|
/* monitors */
|
|
@@ -42,7 +43,7 @@ static const MonitorRule monrules[] = {
|
|
{ "eDP-1", 0.5, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
|
|
*/
|
|
/* defaults */
|
|
- { NULL, 0.55, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
|
|
+ { NULL, 0.64, 1, 1, &layouts[3], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
|
|
};
|
|
|
|
/* keyboard */
|
|
@@ -132,6 +133,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]} },
|
|
+ { MODKEY, XKB_KEY_s, setlayout, {.v = &layouts[3]} },
|
|
{ MODKEY, XKB_KEY_space, setlayout, {0} },
|
|
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
|
|
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
|
|
diff --git a/dwl.c b/dwl.c
|
|
index 6a96179..25e0137 100644
|
|
--- a/dwl.c
|
|
+++ b/dwl.c
|
|
@@ -306,6 +306,7 @@ static void setmon(Client *c, Monitor *m, uint32_t newtags);
|
|
static void setpsel(struct wl_listener *listener, void *data);
|
|
static void setsel(struct wl_listener *listener, void *data);
|
|
static void setup(void);
|
|
+static void snail(Monitor *m);
|
|
static void spawn(const Arg *arg);
|
|
static void startdrag(struct wl_listener *listener, void *data);
|
|
static void tag(const Arg *arg);
|
|
@@ -2361,6 +2362,106 @@ setup(void)
|
|
#endif
|
|
}
|
|
|
|
+void
|
|
+snail(Monitor *m)
|
|
+{
|
|
+ unsigned int i = 0, n = 0, mw = m->w.width;
|
|
+ Client *c, *prev;
|
|
+ enum wlr_direction dir = WLR_DIRECTION_RIGHT;
|
|
+
|
|
+ wl_list_for_each(c, &clients, link)
|
|
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
|
|
+ n++;
|
|
+ if (n == 0)
|
|
+ return;
|
|
+
|
|
+ if (n > m->nmaster)
|
|
+ mw = m->nmaster ? m->w.width * m->mfact : 0;
|
|
+
|
|
+ wl_list_for_each(c, &clients, link) {
|
|
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
|
|
+ continue;
|
|
+
|
|
+ /*
|
|
+ * If the master area exists and this is the first window, fill the
|
|
+ * master area with this window
|
|
+ */
|
|
+ if (mw > 0 && i == 0) {
|
|
+ c->geom = (struct wlr_box){.x = m->w.x, .y = m->w.y,
|
|
+ .width = mw, .height = m->w.height};
|
|
+ /*
|
|
+ * If the first window in the master area is wide, split it
|
|
+ * horizontally and put next one on its right; otherwise, split it
|
|
+ * vertically and put the next one below it
|
|
+ */
|
|
+ dir = c->geom.width > m->w.height ? WLR_DIRECTION_RIGHT : WLR_DIRECTION_DOWN;
|
|
+ /*
|
|
+ * If the master area is full or doesn't exist, fill the stack with the
|
|
+ * m->nmaster-th window
|
|
+ */
|
|
+ } else if (i == m->nmaster) {
|
|
+ c->geom = (struct wlr_box){.x = m->w.x + mw, .y = m->w.y,
|
|
+ .width = m->w.width - mw, .height = m->w.height};
|
|
+ /*
|
|
+ * If the first window in the stack is wide, split it horizontally
|
|
+ * and put next one on its right; otherwise, split it vertically and
|
|
+ * put the next one below it
|
|
+ */
|
|
+ dir = c->geom.width > m->w.height ? WLR_DIRECTION_RIGHT : WLR_DIRECTION_DOWN;
|
|
+ /*
|
|
+ * Split the previous horizontally and put the current window on the right
|
|
+ */
|
|
+ } else if (dir == WLR_DIRECTION_RIGHT) {
|
|
+ c->geom = (struct wlr_box){.x = prev->geom.x + prev->geom.width / 2, .y = prev->geom.y,
|
|
+ .width = prev->geom.width / 2, .height = prev->geom.height};
|
|
+ prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
|
|
+ .width = prev->geom.width / 2, .height = prev->geom.height};
|
|
+ /*
|
|
+ * If it's a stack window or the first narrow window in the master
|
|
+ * area, put the next one below it
|
|
+ */
|
|
+ if (i >= m->nmaster || c->geom.width < m->w.height)
|
|
+ dir = WLR_DIRECTION_DOWN;
|
|
+ /*
|
|
+ * Split the previous vertically and put the current window below it
|
|
+ */
|
|
+ } else if (dir == WLR_DIRECTION_DOWN) {
|
|
+ c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y + prev->geom.height / 2,
|
|
+ .width = prev->geom.width, .height = prev->geom.height / 2};
|
|
+ prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
|
|
+ .width = prev->geom.width, .height = prev->geom.height / 2};
|
|
+ dir = WLR_DIRECTION_LEFT;
|
|
+ /*
|
|
+ * Split the previous horizontally and put the current window on the left
|
|
+ */
|
|
+ } else if (dir == WLR_DIRECTION_LEFT) {
|
|
+ c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
|
|
+ .width = prev->geom.width / 2, .height = prev->geom.height};
|
|
+ prev->geom = (struct wlr_box){.x = prev->geom.x + prev->geom.width / 2, .y = prev->geom.y,
|
|
+ .width = prev->geom.width / 2, .height = prev->geom.height};
|
|
+ dir = WLR_DIRECTION_UP;
|
|
+ /*
|
|
+ * Split the previous vertically and put the current window above it
|
|
+ */
|
|
+ } else {
|
|
+ c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
|
|
+ .width = prev->geom.width, .height = prev->geom.height / 2};
|
|
+ prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y + prev->geom.height / 2,
|
|
+ .width = prev->geom.width, .height = prev->geom.height / 2};
|
|
+ dir = WLR_DIRECTION_RIGHT;
|
|
+ }
|
|
+ i++;
|
|
+ prev = c;
|
|
+ }
|
|
+
|
|
+ wl_list_for_each(c, &clients, link) {
|
|
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
|
|
+ continue;
|
|
+
|
|
+ resize(c, c->geom, 0);
|
|
+ }
|
|
+}
|
|
+
|
|
void
|
|
spawn(const Arg *arg)
|
|
{
|