feat: rotate clients on current monitor

This commit is contained in:
Florian Olk 2025-04-19 13:48:50 +02:00 committed by A Frederick Christensen
parent 7f227a0fac
commit 3b4043eb14
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,14 @@
### Description
Rotate clients on current monitor.
Example Configuration:
```c
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, rotate_clients, {.i = +1} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, rotate_clients, {.i = -1} },
```
### Download
- [0.7](/dwl/dwl-patches/raw/branch/main/patches/rotate-clients/rotate-clients.patch)
### Authors
- [folk](https://codeberg.org/folk)

View File

@ -0,0 +1,56 @@
diff --git a/config.def.h b/config.def.h
index 22d2171..6029666 100644
--- a/config.def.h
+++ b/config.def.h
@@ -129,6 +129,8 @@ static const Key keys[] = {
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
{ MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, rotate_clients, {.i = +1} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, rotate_clients, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
{ MODKEY, XKB_KEY_h, setmfact, {.f = -0.05f} },
diff --git a/dwl.c b/dwl.c
index a2711f6..6dfd87d 100644
--- a/dwl.c
+++ b/dwl.c
@@ -355,6 +355,7 @@ 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 rotate_clients(const Arg *arg);
/* variables */
static const char broken[] = "broken";
@@ -3054,6 +3055,30 @@ zoom(const Arg *arg)
arrange(selmon);
}
+static void rotate_clients(const Arg *arg) {
+ Monitor* m = selmon;
+ Client *c;
+ Client *first = NULL;
+ Client *last = NULL;
+
+ if (arg->i == 0)
+ return;
+
+ wl_list_for_each(c, &clients, link) {
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) {
+ if (first == NULL) first = c;
+ last = c;
+ }
+ }
+ if (first != last) {
+ struct wl_list *append_to = (arg->i > 0) ? &last->link : first->link.prev;
+ struct wl_list *elem = (arg->i > 0) ? &first->link : &last->link;
+ wl_list_remove(elem);
+ wl_list_insert(append_to, elem);
+ arrange(selmon);
+ }
+}
+
#ifdef XWAYLAND
void
activatex11(struct wl_listener *listener, void *data)