From 00051994b63ab66c1913bbe034d3d7bf545b5963 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Fri, 27 Feb 2026 09:36:10 +0800 Subject: [PATCH] opt: use a unified node layer setting function --- src/animation/client.h | 9 +++-- src/animation/tag.h | 7 ++-- src/dispatch/bind_define.h | 17 ++-------- src/mango.c | 68 +++++++++++++++++++------------------- 4 files changed, 44 insertions(+), 57 deletions(-) diff --git a/src/animation/client.h b/src/animation/client.h index 957f3c5b..84ea80f8 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -268,7 +268,7 @@ void apply_border(Client *c) { } struct wlr_box fullgeom = c->animation.current; - int32_t bw = (int32_t)c->bw; // 使用有符号类型避免负数问题 + int32_t bw = (int32_t)c->bw; // 使用有符号类型避免负数问题 // 设置场景表面的位置(缩进边框宽度) wlr_scene_node_set_position(&c->scene_surface->node, bw, bw); @@ -290,7 +290,6 @@ void apply_border(Client *c) { wlr_scene_node_set_position(&c->border[3]->node, fullgeom.width - bw, 0); } - void client_apply_clip(Client *c, float factor) { if (c->iskilling || !client_surface(c)->mapped) return; @@ -504,6 +503,8 @@ void client_animation_next_tick(Client *c) { wlr_seat_pointer_notify_enter(seat, surface, sx, sy); } + client_apply_node_layer(c); + // end flush in next frame, not the current frame c->need_output_flush = false; } @@ -760,7 +761,7 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) { c->animainit_geom = c->current = c->pending = c->animation.current = c->geom; wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y); - + client_get_clip(c, &clip); apply_border(c); apply_shield(c); @@ -790,6 +791,8 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) { c->animainit_geom = c->geom; } + client_apply_node_layer(c); + // 开始应用动画设置 client_set_pending_state(c); diff --git a/src/animation/tag.h b/src/animation/tag.h index 8e65a93a..9a23b8cd 100644 --- a/src/animation/tag.h +++ b/src/animation/tag.h @@ -31,11 +31,8 @@ void set_tagin_animation(Monitor *m, Client *c) { void set_arrange_visible(Monitor *m, Client *c, bool want_animation) { - if (!c->is_clip_to_hide || !ISTILED(c) || !is_scroller_layout(c->mon)) { - c->is_clip_to_hide = false; - wlr_scene_node_set_enabled(&c->scene->node, true); - wlr_scene_node_set_enabled(&c->scene_surface->node, true); - } + wlr_scene_node_set_enabled(&c->scene->node, true); + wlr_scene_node_set_enabled(&c->scene_surface->node, true); client_set_suspended(c, false); if (!c->animation.tag_from_rule && want_animation && diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index bd745cb5..607e812c 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -1374,21 +1374,8 @@ int32_t toggleoverlay(const Arg *arg) { selmon->sel->isoverlay ^= 1; - if (selmon->sel->isoverlay) { - wlr_scene_node_reparent( - &selmon->sel->scene->node, - selmon->sel->mon->layers_scene_tree[LyrOverlay]); - wlr_scene_node_raise_to_top(&selmon->sel->scene->node); - } else if (client_should_overtop(selmon->sel) && selmon->sel->isfloating) { - wlr_scene_node_reparent(&selmon->sel->scene->node, - selmon->sel->mon->layers_scene_tree[LyrTop]); - } else { - wlr_scene_node_reparent( - &selmon->sel->scene->node, - selmon->sel->mon - ->layers_scene_tree[selmon->sel->isfloating ? LyrTop - : LyrTile]); - } + client_apply_node_layer(selmon->sel); + setborder_color(selmon->sel); return 0; } diff --git a/src/mango.c b/src/mango.c index 937dfad6..1df886ed 100644 --- a/src/mango.c +++ b/src/mango.c @@ -397,7 +397,6 @@ struct Client { int32_t force_tiled_state; pid_t pid; Client *swallowing, *swallowedby; - bool is_clip_to_hide; bool drag_to_tile; bool scratchpad_switching_mon; bool fake_no_border; @@ -816,6 +815,7 @@ static void handle_iamge_copy_capture_new_session(struct wl_listener *listener, void *data); static Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly); static bool match_monitor_spec(char *spec, Monitor *m); +static void client_apply_node_layer(Client *c); #include "data/static_keymap.h" #include "dispatch/bind_declare.h" @@ -1541,8 +1541,7 @@ void applyrules(Client *c) { newtags & mon->tagset[mon->seltags])); if (c->mon) { - wlr_scene_node_reparent(&c->scene->node, - c->mon->layers_scene_tree[LyrTile]); + client_apply_node_layer(c); } if (c->mon && @@ -1583,8 +1582,7 @@ void applyrules(Client *c) { // apply overlay rule if (c->isoverlay && c->scene) { - wlr_scene_node_reparent(&c->scene->node, - c->mon->layers_scene_tree[LyrOverlay]); + client_apply_node_layer(c); wlr_scene_node_raise_to_top(&c->scene->node); } } @@ -3912,7 +3910,6 @@ void init_client_properties(Client *c) { c->isnamedscratchpad = 0; c->is_scratchpad_show = 0; c->need_float_size_reduce = 0; - c->is_clip_to_hide = 0; c->is_restoring_from_ov = 0; c->isurgent = 0; c->need_output_flush = 0; @@ -4677,6 +4674,33 @@ void requeststartdrag(struct wl_listener *listener, void *data) { wlr_data_source_destroy(event->drag->source); } +void client_apply_node_layer(Client *c) { + if (c->animation.tagining || c->animation.tagouting) { + if (c->isoverlay) { + wlr_scene_node_reparent(&c->scene->node, + c->mon->layers_scene_tree[LyrOverlay]); + } else if (c->isfloating || c->isfullscreen) { + wlr_scene_node_reparent(&c->scene->node, + c->mon->layers_scene_tree[LyrTop]); + } else { + wlr_scene_node_reparent(&c->scene->node, + c->mon->layers_scene_tree[LyrTile]); + } + } else { + if (c->isfloating) { + wlr_scene_node_reparent(&c->scene->node, + layers[c->isoverlay ? LyrOverlay : LyrTop]); + } else if (c->isfullscreen) { + wlr_scene_node_reparent(&c->scene->node, + c->mon->layers_scene_tree[LyrTop]); + } else { + wlr_scene_node_reparent( + &c->scene->node, + c->mon->layers_scene_tree[c->isoverlay ? LyrOverlay : LyrTile]); + } + } +} + void setborder_color(Client *c) { if (!c || !c->mon) return; @@ -5011,17 +5035,7 @@ setfloating(Client *c, int32_t floating) { } } - if (c->isoverlay) { - wlr_scene_node_reparent(&c->scene->node, - c->mon->layers_scene_tree[LyrOverlay]); - } else if (client_should_overtop(c) && c->isfloating) { - wlr_scene_node_reparent(&c->scene->node, - c->mon->layers_scene_tree[LyrTop]); - } else { - wlr_scene_node_reparent( - &c->scene->node, - c->mon->layers_scene_tree[c->isfloating ? LyrTop : LyrTile]); - } + client_apply_node_layer(c); if (!c->isfloating && old_floating_state) { restore_size_per(c->mon, c); @@ -5107,9 +5121,7 @@ void setmaximizescreen(Client *c, int32_t maximizescreen) { setfloating(c, 1); } - wlr_scene_node_reparent( - &c->scene->node, - c->mon->layers_scene_tree[c->isfloating ? LyrTop : LyrTile]); + client_apply_node_layer(c); if (!c->ismaximizescreen && old_maximizescreen_state) { restore_size_per(c->mon, c); } @@ -5171,18 +5183,7 @@ void setfullscreen(Client *c, int32_t fullscreen) // 用自定义全屏代理自 setfloating(c, 1); } - if (c->isoverlay) { - wlr_scene_node_reparent(&c->scene->node, - c->mon->layers_scene_tree[LyrOverlay]); - } else if (client_should_overtop(c) && c->isfloating) { - wlr_scene_node_reparent(&c->scene->node, - c->mon->layers_scene_tree[LyrTop]); - } else { - wlr_scene_node_reparent( - &c->scene->node, - c->mon->layers_scene_tree[fullscreen || c->isfloating ? LyrTop - : LyrTile]); - } + client_apply_node_layer(c); if (!c->isfullscreen && old_fullscreen_state) { restore_size_per(c->mon, c); @@ -5896,8 +5897,7 @@ void unmapnotify(struct wl_listener *listener, void *data) { Client *prev_in_stack = c->prev_in_stack; c->iskilling = 1; - if (animations && !c->is_clip_to_hide && !c->isminimized && - (!c->mon || VISIBLEON(c, c->mon))) + if (animations && !c->isminimized && (!c->mon || VISIBLEON(c, c->mon))) init_fadeout_client(c); // If the client is in a stack, remove it from the stack