From e67193d9b10627b010cd35790962915c4327d845 Mon Sep 17 00:00:00 2001 From: 0scar Date: Sun, 12 Mar 2023 16:26:36 +0100 Subject: Patch: movestack Source: https://github.com/djpohly/dwl/wiki/movestack Author: sam-barr (ss7m) Patch: extend movestack to move clients to first or last --- config.def.h | 6 ++++++ dwl.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/config.def.h b/config.def.h index 8fe9511..f3e0fbc 100644 --- a/config.def.h +++ b/config.def.h @@ -156,6 +156,12 @@ static const Key keys[] = { { MODKEY, XKB_KEY_apostrophe, togglescratch, {.v = scratchpadcalc} }, { MODKEY, XKB_KEY_j, focusstack, {.i = +1} }, { MODKEY, XKB_KEY_k, focusstack, {.i = -1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_J, movestack, {.i = +1} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_K, movestack, {.i = -1} }, + { MODKEY, XKB_KEY_v, focusstack, {.i = 0} }, + { MODKEY, XKB_KEY_b, focusstack, {.i = INT_MAX} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_V, movestack, {.i = 0} }, + { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_B, movestack, {.i = INT_MAX} }, { 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 a1be8bf..663ef9f 100644 --- a/dwl.c +++ b/dwl.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include #include @@ -317,6 +318,7 @@ static void locksession(struct wl_listener *listener, void *data); static void mapnotify(struct wl_listener *listener, void *data); static void maximizenotify(struct wl_listener *listener, void *data); static void monocle(Monitor *m); +static void movestack(const Arg *arg); static void motionabsolute(struct wl_listener *listener, void *data); static void motionnotify(uint32_t time, struct wlr_input_device *device, double sx, double sy, double sx_unaccel, double sy_unaccel); @@ -2035,6 +2037,49 @@ monocle(Monitor *m) wlr_scene_node_raise_to_top(&c->scene->node); } +void +movestack(const Arg *arg) +{ + Client *c, *sel = focustop(selmon); + + if (wl_list_length(&clients) <= 1) { + return; + } + + if (arg->i == 0) { + /* Put the selected client on top */ + wl_list_remove(&sel->link); + wl_list_insert(&clients, &sel->link); + arrange(selmon); + return; + } else if (arg->i == INT_MAX) { + /* Get the last element */ + wl_list_for_each_reverse(c, &clients, link) { + if (!VISIBLEON(c, selmon) || c->isfloating || c->isfullscreen) + continue; + break; + } + } else if (arg->i > 0) { + wl_list_for_each(c, &sel->link, link) { + if (VISIBLEON(c, selmon) || &c->link == &clients) { + break; /* found it */ + } + } + } else { + wl_list_for_each_reverse(c, &sel->link, link) { + if (VISIBLEON(c, selmon) || &c->link == &clients) { + break; /* found it */ + } + } + /* backup one client */ + c = wl_container_of(c->link.prev, c, link); + } + + wl_list_remove(&sel->link); + wl_list_insert(&c->link, &sel->link); + arrange(selmon); +} + void motionabsolute(struct wl_listener *listener, void *data) { -- cgit v1.3