From 598731f5736933d5c06ddef43d4583a7098d58bc Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 17 Jan 2026 12:34:35 +0800 Subject: [PATCH] opt: remove useless code --- src/dispatch/bind_define.h | 18 +++--------------- src/layout/horizontal.h | 4 +--- src/mango.c | 12 ++---------- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 2c542be..d55b998 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -429,9 +429,7 @@ int32_t resizewin(const Arg *arg) { Client *target_client = c; if (is_scroller_layout(c->mon) && (c->prev_in_stack || c->next_in_stack)) { - while (target_client->prev_in_stack) { - target_client = target_client->prev_in_stack; - } + target_client = get_scroll_stack_head(target_client); } switch (arg->ui) { case NUM_TYPE_MINUS: @@ -1636,20 +1634,10 @@ int32_t scroller_unstack(const Arg *arg) { } Client *scroller_stack_head = c; - while (scroller_stack_head->prev_in_stack) { - scroller_stack_head = scroller_stack_head->prev_in_stack; - } + scroller_stack_head = get_scroll_stack_head(scroller_stack_head); // Remove c from its current stack - if (c->prev_in_stack) { - c->prev_in_stack->next_in_stack = c->next_in_stack; - } - if (c->next_in_stack) { - c->next_in_stack->prev_in_stack = c->prev_in_stack; - } - - c->next_in_stack = NULL; - c->prev_in_stack = NULL; + exit_scroller_stack(c); // Insert c after the stack it was in wl_list_remove(&c->link); diff --git a/src/layout/horizontal.h b/src/layout/horizontal.h index c17484e..0dc77d4 100644 --- a/src/layout/horizontal.h +++ b/src/layout/horizontal.h @@ -314,9 +314,7 @@ void scroller(Monitor *m) { // root_client might be in a stack, find the stack head if (root_client) { - while (root_client->prev_in_stack) { - root_client = root_client->prev_in_stack; - } + root_client = get_scroll_stack_head(root_client); } if (!root_client) { diff --git a/src/mango.c b/src/mango.c index 6da5fd2..c3ff10b 100644 --- a/src/mango.c +++ b/src/mango.c @@ -767,6 +767,7 @@ static void request_fresh_all_monitors(void); static Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, bool ignore_align); static void exit_scroller_stack(Client *c); +static Client *get_scroll_stack_head(Client *c); #include "data/static_keymap.h" #include "dispatch/bind_declare.h" @@ -5470,16 +5471,7 @@ 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->prev_in_stack || c->next_in_stack) { - if (c->prev_in_stack) { - c->prev_in_stack->next_in_stack = c->next_in_stack; - } - if (c->next_in_stack) { - c->next_in_stack->prev_in_stack = c->prev_in_stack; - } - c->prev_in_stack = NULL; - c->next_in_stack = NULL; - } + exit_scroller_stack(c); if (c->swallowedby) { c->swallowedby->mon = c->mon;