1 Commits

Author SHA1 Message Date
43bf716e36 added bottomstack 2025-04-10 03:09:25 +02:00
4 changed files with 230 additions and 252 deletions

140
bottomstack.patch Normal file
View File

@@ -0,0 +1,140 @@
From b352fb08f40b1ee2d8c4748be4922df711e3aaa9 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Fri, 5 Jul 2024 10:44:29 -0500
Subject: [PATCH] implement bottomstack
---
config.def.h | 4 +++
dwl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+)
diff --git a/config.def.h b/config.def.h
index 22d2171..5aac3e9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -34,6 +34,8 @@ static const Layout layouts[] = {
{ "[]=", tile },
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
+ { "TTT", bstack },
+ { "===", bstackhoriz },
};
/* monitors */
@@ -139,6 +141,8 @@ 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_u, setlayout, {.v = &layouts[3]} },
+ { MODKEY, XKB_KEY_o, setlayout, {.v = &layouts[4]} },
{ 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 dc0437e..5648d5f 100644
--- a/dwl.c
+++ b/dwl.c
@@ -57,6 +57,7 @@
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
+#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <xkbcommon/xkbcommon.h>
@@ -351,6 +352,8 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
+static void bstack(Monitor *m);
+static void bstackhoriz(Monitor *m);
/* variables */
static const char broken[] = "broken";
@@ -3160,3 +3163,84 @@ main(int argc, char *argv[])
usage:
die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
}
+
+static void
+bstack(Monitor *m)
+{
+ int w, h, mh, mx, tx, ty, tw;
+ int i, n = 0;
+ Client *c;
+
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating)
+ n++;
+ if (n == 0)
+ return;
+
+ if (n > m->nmaster) {
+ mh = (int)round(m->nmaster ? m->mfact * m->w.height : 0);
+ tw = m->w.width / (n - m->nmaster);
+ ty = m->w.y + mh;
+ } else {
+ mh = m->w.height;
+ tw = m->w.width;
+ ty = m->w.y;
+ }
+
+ i = mx = 0;
+ tx = m-> w.x;
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating)
+ continue;
+ if (i < m->nmaster) {
+ w = (m->w.width - mx) / (MIN(n, m->nmaster) - i);
+ resize(c, (struct wlr_box) { .x = m->w.x + mx, .y = m->w.y, .width = w, .height = mh }, 0);
+ mx += c->geom.width;
+ } else {
+ h = m->w.height - mh;
+ resize(c, (struct wlr_box) { .x = tx, .y = ty, .width = tw, .height = h }, 0);
+ if (tw != m->w.width)
+ tx += c->geom.width;
+ }
+ i++;
+ }
+}
+
+static void
+bstackhoriz(Monitor *m) {
+ int w, mh, mx, tx, ty, th;
+ int i, n = 0;
+ Client *c;
+
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating)
+ n ++;
+ if (n == 0)
+ return;
+
+ if (n > m->nmaster) {
+ mh = (int)round(m->nmaster ? m->mfact * m->w.height : 0);
+ th = (m->w.height - mh) / (n - m->nmaster);
+ ty = m->w.y + mh;
+ } else {
+ th = mh = m->w.height;
+ ty = m->w.y;
+ }
+
+ i = mx = 0;
+ tx = m-> w.x;
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c,m) || c->isfloating)
+ continue;
+ if (i < m->nmaster) {
+ w = (m->w.width - mx) / (MIN(n, m->nmaster) - i);
+ resize(c, (struct wlr_box) { .x = m->w.x + mx, .y = m->w.y, .width = w, .height = mh }, 0);
+ mx += c->geom.width;
+ } else {
+ resize(c, (struct wlr_box) { .x = tx, .y = ty, .width = m->w.width, .height = th }, 0);
+ if (th != m->w.height)
+ ty += c->geom.height;
+ }
+ i++;
+ }
+}
--
2.45.1

View File

@@ -34,6 +34,8 @@ static const Layout layouts[] = {
{ "[]=", tile },
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
{ "TTT", bstack },
{ "===", bstackhoriz },
};
/* monitors */
@@ -60,18 +62,6 @@ static const struct xkb_rule_names xkb_rules = {
.options = NULL,
};
/* input devices */
static const InputRule inputrules[] = {
/* name kbcreate ptrcreate */
/* ignore bad device - like a touchpad ;) */
{ "BAD DEVICE", NULL, NULL },
/* ungroup ydotool device - fixes a bug */
{ "ydotoold virtual device", createungroupedkeyboard, createpointer },
/* put your touchpad name here to enable toggle touchpad */
{ "Elan Touchpad", createkeyboard, createtogglepointer },
{ NULL, createkeyboard, createpointer },
};
static const int repeat_rate = 25;
static const int repeat_delay = 600;
@@ -151,10 +141,11 @@ 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_u, setlayout, {.v = &layouts[3]} },
{ MODKEY, XKB_KEY_o, setlayout, {.v = &layouts[4]} },
{ MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
{ MODKEY, XKB_KEY_u, togglepointer, {0} },
{ MODKEY, XKB_KEY_0, view, {.ui = ~0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
{ MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },

152
dwl.c
View File

@@ -59,6 +59,7 @@
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include <xkbcommon/xkbcommon.h>
@@ -141,12 +142,6 @@ typedef struct {
uint32_t resize; /* configure serial of a pending resize */
} Client;
typedef struct {
const char *name;
void (*kbcreate)(struct wlr_keyboard *);
void (*ptrcreate)(struct wlr_pointer *);
} InputRule;
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
@@ -274,8 +269,6 @@ static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
static void createpointerconstraint(struct wl_listener *listener, void *data);
static void createpopup(struct wl_listener *listener, void *data);
static void createtogglepointer(struct wlr_pointer *pointer);
static void createungroupedkeyboard(struct wlr_keyboard *keyboard);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
@@ -344,7 +337,6 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void togglepointer(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -360,6 +352,8 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
static void bstack(Monitor *m);
static void bstackhoriz(Monitor *m);
/* variables */
static pid_t child_pid = -1;
@@ -445,8 +439,6 @@ static struct wl_listener request_start_drag = {.notify = requeststartdrag};
static struct wl_listener start_drag = {.notify = startdrag};
static struct wl_listener new_session_lock = {.notify = locksession};
static struct libinput_device *togglepointerdevice = NULL;
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
@@ -1207,33 +1199,6 @@ createpopup(struct wl_listener *listener, void *data)
LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup);
}
void
createtogglepointer(struct wlr_pointer *pointer)
{
struct libinput_device *device;
createpointer(pointer);
if (wlr_input_device_is_libinput(&pointer->base)
&& (device = wlr_libinput_get_device_handle(&pointer->base))) {
togglepointerdevice = device;
}
}
void
createungroupedkeyboard(struct wlr_keyboard *keyboard)
{
/* for keyboards that need their own keyboard group */
KeyboardGroup *group = createkeyboardgroup();
/* Set the keymap to match the group keymap */
wlr_keyboard_set_keymap(keyboard, group->wlr_group->keyboard.keymap);
LISTEN(&keyboard->base.events.destroy, &group->destroy, destroykeyboardgroup);
/* Add the new keyboard to the group */
wlr_keyboard_group_add_keyboard(group->wlr_group, keyboard);
}
void
cursorconstrain(struct wlr_pointer_constraint_v1 *constraint)
{
@@ -1617,27 +1582,13 @@ inputdevice(struct wl_listener *listener, void *data)
* available. */
struct wlr_input_device *device = data;
uint32_t caps;
const InputRule *r;
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
for (r = inputrules; r < END(inputrules); r++) {
if (!r->name || strstr(device->name, r->name)) {
if (r->kbcreate)
r->kbcreate(wlr_keyboard_from_input_device(device));
break;
}
}
createkeyboard(wlr_keyboard_from_input_device(device));
break;
case WLR_INPUT_DEVICE_POINTER:
for (r = inputrules; r < END(inputrules); r++) {
if (!r->name || strstr(device->name, r->name)) {
if (r->ptrcreate)
r->ptrcreate(wlr_pointer_from_input_device(device));
break;
}
}
createpointer(wlr_pointer_from_input_device(device));
break;
default:
/* TODO handle other input device types */
@@ -2807,18 +2758,6 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
void
togglepointer(const Arg *arg)
{
if (!togglepointerdevice)
return;
libinput_device_config_send_events_set_mode(
togglepointerdevice,
libinput_device_config_send_events_get_mode(togglepointerdevice) ^ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED
);
}
void
toggletag(const Arg *arg)
{
@@ -3272,3 +3211,84 @@ main(int argc, char *argv[])
usage:
die("Usage: %s [-v] [-d] [-s startup command]", argv[0]);
}
static void
bstack(Monitor *m)
{
int w, h, mh, mx, tx, ty, tw;
int i, n = 0;
Client *c;
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, m) && !c->isfloating)
n++;
if (n == 0)
return;
if (n > m->nmaster) {
mh = (int)round(m->nmaster ? m->mfact * m->w.height : 0);
tw = m->w.width / (n - m->nmaster);
ty = m->w.y + mh;
} else {
mh = m->w.height;
tw = m->w.width;
ty = m->w.y;
}
i = mx = 0;
tx = m-> w.x;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating)
continue;
if (i < m->nmaster) {
w = (m->w.width - mx) / (MIN(n, m->nmaster) - i);
resize(c, (struct wlr_box) { .x = m->w.x + mx, .y = m->w.y, .width = w, .height = mh }, 0);
mx += c->geom.width;
} else {
h = m->w.height - mh;
resize(c, (struct wlr_box) { .x = tx, .y = ty, .width = tw, .height = h }, 0);
if (tw != m->w.width)
tx += c->geom.width;
}
i++;
}
}
static void
bstackhoriz(Monitor *m) {
int w, mh, mx, tx, ty, th;
int i, n = 0;
Client *c;
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, m) && !c->isfloating)
n ++;
if (n == 0)
return;
if (n > m->nmaster) {
mh = (int)round(m->nmaster ? m->mfact * m->w.height : 0);
th = (m->w.height - mh) / (n - m->nmaster);
ty = m->w.y + mh;
} else {
th = mh = m->w.height;
ty = m->w.y;
}
i = mx = 0;
tx = m-> w.x;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c,m) || c->isfloating)
continue;
if (i < m->nmaster) {
w = (m->w.width - mx) / (MIN(n, m->nmaster) - i);
resize(c, (struct wlr_box) { .x = m->w.x + mx, .y = m->w.y, .width = w, .height = mh }, 0);
mx += c->geom.width;
} else {
resize(c, (struct wlr_box) { .x = tx, .y = ty, .width = m->w.width, .height = th }, 0);
if (th != m->w.height)
ty += c->geom.height;
}
i++;
}
}

View File

@@ -1,173 +0,0 @@
From 89f870a04f903681b0a7a0ac4eb1ae70c4984b46 Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Sat, 15 Jun 2024 12:34:01 +1000
Subject: [PATCH] input device rules
* customise input device handling
* ignore unwanted input devices
* configure a toggle for an input device
---
config.def.h | 13 ++++++++++
dwl.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 22d2171d..0b287ab5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -60,6 +60,18 @@ static const struct xkb_rule_names xkb_rules = {
.options = NULL,
};
+/* input devices */
+static const InputRule inputrules[] = {
+ /* name kbcreate ptrcreate */
+ /* ignore bad device - like a touchpad ;) */
+ { "BAD DEVICE", NULL, NULL },
+ /* ungroup ydotool device - fixes a bug */
+ { "ydotoold virtual device", createungroupedkeyboard, createpointer },
+ /* put your touchpad name here to enable toggle touchpad */
+ { "Elan Touchpad", createkeyboard, createtogglepointer },
+ { NULL, createkeyboard, createpointer },
+};
+
static const int repeat_rate = 25;
static const int repeat_delay = 600;
@@ -142,6 +154,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
+ { MODKEY, XKB_KEY_u, togglepointer, {0} },
{ MODKEY, XKB_KEY_0, view, {.ui = ~0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
{ MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },
diff --git a/dwl.c b/dwl.c
index a2711f67..f6f91938 100644
--- a/dwl.c
+++ b/dwl.c
@@ -143,6 +143,12 @@ typedef struct {
uint32_t resize; /* configure serial of a pending resize */
} Client;
+typedef struct {
+ const char *name;
+ void (*kbcreate)(struct wlr_keyboard *);
+ void (*ptrcreate)(struct wlr_pointer *);
+} InputRule;
+
typedef struct {
uint32_t mod;
xkb_keysym_t keysym;
@@ -270,6 +276,8 @@ static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer);
static void createpointerconstraint(struct wl_listener *listener, void *data);
static void createpopup(struct wl_listener *listener, void *data);
+static void createtogglepointer(struct wlr_pointer *pointer);
+static void createungroupedkeyboard(struct wlr_keyboard *keyboard);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
@@ -340,6 +348,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
+static void togglepointer(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -413,6 +422,8 @@ static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
+static struct libinput_device *togglepointerdevice = NULL;
+
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
@@ -1133,6 +1144,33 @@ createpopup(struct wl_listener *listener, void *data)
LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup);
}
+void
+createtogglepointer(struct wlr_pointer *pointer)
+{
+ struct libinput_device *device;
+
+ createpointer(pointer);
+
+ if (wlr_input_device_is_libinput(&pointer->base)
+ && (device = wlr_libinput_get_device_handle(&pointer->base))) {
+ togglepointerdevice = device;
+ }
+}
+
+void
+createungroupedkeyboard(struct wlr_keyboard *keyboard)
+{
+ /* for keyboards that need their own keyboard group */
+ KeyboardGroup *group = createkeyboardgroup();
+
+ /* Set the keymap to match the group keymap */
+ wlr_keyboard_set_keymap(keyboard, group->wlr_group->keyboard.keymap);
+ LISTEN(&keyboard->base.events.destroy, &group->destroy, destroykeyboardgroup);
+
+ /* Add the new keyboard to the group */
+ wlr_keyboard_group_add_keyboard(group->wlr_group, keyboard);
+}
+
void
cursorconstrain(struct wlr_pointer_constraint_v1 *constraint)
{
@@ -1531,13 +1569,27 @@ inputdevice(struct wl_listener *listener, void *data)
* available. */
struct wlr_input_device *device = data;
uint32_t caps;
+ const InputRule *r;
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
- createkeyboard(wlr_keyboard_from_input_device(device));
+ for (r = inputrules; r < END(inputrules); r++) {
+ if (!r->name || strstr(device->name, r->name)) {
+ if (r->kbcreate)
+ r->kbcreate(wlr_keyboard_from_input_device(device));
+ break;
+ }
+ }
+
break;
case WLR_INPUT_DEVICE_POINTER:
- createpointer(wlr_pointer_from_input_device(device));
+ for (r = inputrules; r < END(inputrules); r++) {
+ if (!r->name || strstr(device->name, r->name)) {
+ if (r->ptrcreate)
+ r->ptrcreate(wlr_pointer_from_input_device(device));
+ break;
+ }
+ }
break;
default:
/* TODO handle other input device types */
@@ -2739,6 +2791,18 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
+void
+togglepointer(const Arg *arg)
+{
+ if (!togglepointerdevice)
+ return;
+
+ libinput_device_config_send_events_set_mode(
+ togglepointerdevice,
+ libinput_device_config_send_events_get_mode(togglepointerdevice) ^ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED
+ );
+}
+
void
toggletag(const Arg *arg)
{
--
2.45.2