From b1e66b853eba7aa1772f8b09c21136d3a7d0faad Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 18 Jan 2026 12:58:47 +0800 Subject: [PATCH] opt: optimize scroller stack logic --- src/dispatch/bind_define.h | 38 +++++++++++++++++++++++++++++++------- src/mango.c | 5 ++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index cffe359..de58927 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -1592,6 +1592,8 @@ int32_t toggle_monitor(const Arg *arg) { int32_t scroller_stack(const Arg *arg) { Client *c = selmon->sel; + Client *stack_head = NULL; + Client *source_stack_head = NULL; if (!c || c->isfloating || !is_scroller_layout(selmon)) return 0; @@ -1604,6 +1606,23 @@ int32_t scroller_stack(const Arg *arg) { target_client->isglobal || target_client->isunglobal)) return 0; + if (target_client && c) { + stack_head = get_scroll_stack_head(target_client); + source_stack_head = get_scroll_stack_head(c); + + if (stack_head == source_stack_head) { + return 0; + } + } + + if (c->isfullscreen) { + setfullscreen(c, 0); + } + + if (c->ismaximizescreen) { + setmaximizescreen(c, 0); + } + if (!target_client || target_client->mon != c->mon) { if (arg->i == LEFT || arg->i == UP) { exit_scroller_stack(c); @@ -1618,12 +1637,18 @@ int32_t scroller_stack(const Arg *arg) { return 0; } - if (c->isfullscreen) { - setfullscreen(c, 0); - } - - if (c->ismaximizescreen) { - setmaximizescreen(c, 0); + if (target_client && (c->next_in_stack || c->prev_in_stack)) { + if (arg->i == LEFT || arg->i == UP) { + exit_scroller_stack(c); + wl_list_remove(&c->link); + wl_list_insert(&target_client->link, &c->link); + } else { + exit_scroller_stack(c); + wl_list_remove(&c->link); + wl_list_insert(target_client->link.prev, &c->link); + } + arrange(selmon, false, false); + return 0; } exit_scroller_stack(c); @@ -1634,7 +1659,6 @@ int32_t scroller_stack(const Arg *arg) { stack_tail = stack_tail->next_in_stack; } - Client *stack_head = get_scroll_stack_head(target_client); c->scroller_proportion = stack_head->scroller_proportion; // Add c to the stack diff --git a/src/mango.c b/src/mango.c index a7b5bd2..4c0d4ef 100644 --- a/src/mango.c +++ b/src/mango.c @@ -1065,9 +1065,9 @@ void swallow(Client *c, Client *w) { c->scroller_proportion = w->scroller_proportion; c->next_in_stack = w->next_in_stack; c->prev_in_stack = w->prev_in_stack; - if(w->next_in_stack) + if (w->next_in_stack) w->next_in_stack->prev_in_stack = c; - if(w->prev_in_stack) + if (w->prev_in_stack) w->prev_in_stack->next_in_stack = c; c->stack_proportion = w->stack_proportion; wl_list_insert(&w->link, &c->link); @@ -5493,7 +5493,6 @@ void unmapnotify(struct wl_listener *listener, void *data) { init_fadeout_client(c); // If the client is in a stack, remove it from the stack - if (c->swallowedby) { c->swallowedby->mon = c->mon;