From d7286b0d8462bdff20c65b1dcec5ab0fad704928 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Fri, 7 Nov 2025 10:02:51 +0800 Subject: [PATCH 1/4] fix: adjust scenefx blur node feature --- src/animation/client.h | 12 +++++++++++ src/animation/common.h | 8 ++------ src/animation/layer.h | 4 ++++ src/mango.c | 46 +++++++++++++++++++++++++++--------------- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/animation/client.h b/src/animation/client.h index 90b664b..e9459d5 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -245,6 +245,13 @@ void buffer_set_effect(Client *c, BufferData data) { data.corner_location = CORNER_LOCATION_NONE; } + if (blur && !c->noblur) { + wlr_scene_blur_set_size(c->blur, c->animation.current.width - 2 * c->bw, + c->animation.current.height - 2 * c->bw); + + wlr_scene_blur_set_corner_radius(c->blur, border_radius, + data.corner_location); + } wlr_scene_node_for_each_buffer(&c->scene_surface->node, scene_buffer_apply_effect, &data); } @@ -535,6 +542,7 @@ void client_apply_clip(Client *c, float factor) { } wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); + buffer_set_effect(c, (BufferData){1.0f, 1.0f, clip_box.width, clip_box.height, current_corner_location, true}); @@ -987,6 +995,10 @@ void resize(Client *c, struct wlr_box geo, int interact) { apply_border(c); client_get_clip(c, &clip); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip); + if (blur && !c->noblur) + wlr_scene_blur_set_size(c->blur, + c->animation.current.width - 2 * c->bw, + c->animation.current.height - 2 * c->bw); return; } // 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小 diff --git a/src/animation/common.h b/src/animation/common.h index 06ffe1a..7079df8 100644 --- a/src/animation/common.h +++ b/src/animation/common.h @@ -158,12 +158,6 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly, scene_buffer->corner_radius, scene_buffer->corners); - // wlr_scene_buffer_set_backdrop_blur_optimized( - // snapshot_buffer, scene_buffer->backdrop_blur_optimized); - // wlr_scene_buffer_set_backdrop_blur_ignore_transparent( - // snapshot_buffer, scene_buffer->backdrop_blur_ignore_transparent); - wlr_scene_buffer_set_backdrop_blur(snapshot_buffer, false); - snapshot_buffer->node.data = scene_buffer->node.data; struct wlr_scene_surface *scene_surface = @@ -198,6 +192,8 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly, break; } + case WLR_SCENE_NODE_BLUR: + break; case WLR_SCENE_NODE_OPTIMIZED_BLUR: return true; } diff --git a/src/animation/layer.h b/src/animation/layer.h index 48ceb21..80caec5 100644 --- a/src/animation/layer.h +++ b/src/animation/layer.h @@ -356,6 +356,10 @@ void layer_animation_next_tick(LayerSurface *l) { .height = height, }; + if (blur && blur_layer && !l->noblur && l->blur) + wlr_scene_blur_set_size(l->blur, l->animation.current.width, + l->animation.current.height); + if (animation_passed >= 1.0) { l->animation.running = false; l->need_output_flush = false; diff --git a/src/mango.c b/src/mango.c index 36cbbbf..69208d6 100644 --- a/src/mango.c +++ b/src/mango.c @@ -276,6 +276,7 @@ struct Client { struct wlr_scene_tree *scene; struct wlr_scene_rect *border; /* top, bottom, left, right */ struct wlr_scene_shadow *shadow; + struct wlr_scene_blur *blur; struct wlr_scene_tree *scene_surface; struct wl_list link; struct wl_list flink; @@ -405,6 +406,7 @@ typedef struct { struct wlr_scene_tree *scene; struct wlr_scene_tree *popups; struct wlr_scene_shadow *shadow; + struct wlr_scene_blur *blur; struct wlr_scene_layer_surface_v1 *scene_layer; struct wl_list link; struct wl_list fadeout_link; @@ -2081,12 +2083,16 @@ static void iter_layer_scene_buffers(struct wlr_scene_buffer *buffer, int sx, return; } - wlr_scene_buffer_set_backdrop_blur(buffer, true); - wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, true); + LayerSurface *l = (LayerSurface *)user_data; + + wlr_scene_node_set_enabled(&l->blur->node, true); + wlr_scene_blur_set_transparency_mask_source(l->blur, buffer); + wlr_scene_blur_set_size(l->blur, l->geom.width, l->geom.height); + if (blur_optimized) { - wlr_scene_buffer_set_backdrop_blur_optimized(buffer, true); + wlr_scene_blur_set_should_only_blur_bottom_layer(l->blur, true); } else { - wlr_scene_buffer_set_backdrop_blur_optimized(buffer, false); + wlr_scene_blur_set_should_only_blur_bottom_layer(l->blur, false); } } @@ -2131,13 +2137,17 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) { } // 初始化阴影 - if (layer_surface->current.exclusive_zone == 0 && - layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && + if (layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) { - l->shadow = wlr_scene_shadow_create(l->scene, 0, 0, border_radius, - shadows_blur, shadowscolor); - wlr_scene_node_lower_to_bottom(&l->shadow->node); - wlr_scene_node_set_enabled(&l->shadow->node, true); + if (layer_surface->current.exclusive_zone == 0) { + l->shadow = wlr_scene_shadow_create(l->scene, 0, 0, border_radius, + shadows_blur, shadowscolor); + wlr_scene_node_lower_to_bottom(&l->shadow->node); + wlr_scene_node_set_enabled(&l->shadow->node, true); + } + + l->blur = wlr_scene_blur_create(l->scene, 0, 0); + wlr_scene_node_lower_to_bottom(&l->blur->node); } // 初始化动画 @@ -2194,7 +2204,8 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) { if (!l->noblur && layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer_surface->current.layer != - ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) { + ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND && + l->blur) { wlr_scene_node_for_each_buffer(&l->scene->node, iter_layer_scene_buffers, l); @@ -3521,15 +3532,15 @@ static void iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int sx, return; if (blur && c && !c->noblur) { - wlr_scene_buffer_set_backdrop_blur(buffer, true); - wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, false); + wlr_scene_node_set_enabled(&c->blur->node, true); + // wlr_scene_blur_set_transparency_mask_source(c->blur, buffer); if (blur_optimized) { - wlr_scene_buffer_set_backdrop_blur_optimized(buffer, true); + wlr_scene_blur_set_should_only_blur_bottom_layer(c->blur, true); } else { - wlr_scene_buffer_set_backdrop_blur_optimized(buffer, false); + wlr_scene_blur_set_should_only_blur_bottom_layer(c->blur, false); } } else { - wlr_scene_buffer_set_backdrop_blur(buffer, false); + wlr_scene_node_set_enabled(&c->blur->node, false); } } @@ -3642,6 +3653,9 @@ mapnotify(struct wl_listener *listener, void *data) { c->shadow = wlr_scene_shadow_create(c->scene, 0, 0, border_radius, shadows_blur, shadowscolor); + c->blur = wlr_scene_blur_create(c->scene_surface, 0, 0); + wlr_scene_node_lower_to_bottom(&c->blur->node); + wlr_scene_node_lower_to_bottom(&c->shadow->node); wlr_scene_node_set_enabled(&c->shadow->node, true); From 358591f16a876a5b6d252d2e44b6faa09f703e47 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 8 Nov 2025 19:59:05 +0800 Subject: [PATCH 2/4] fix: blur node size and position are wrong --- src/animation/client.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/animation/client.h b/src/animation/client.h index e9459d5..3792358 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -246,9 +246,6 @@ void buffer_set_effect(Client *c, BufferData data) { } if (blur && !c->noblur) { - wlr_scene_blur_set_size(c->blur, c->animation.current.width - 2 * c->bw, - c->animation.current.height - 2 * c->bw); - wlr_scene_blur_set_corner_radius(c->blur, border_radius, data.corner_location); } @@ -352,6 +349,14 @@ void client_draw_shadow(Client *c) { wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region); } +void client_draw_blur(Client *c, struct wlr_box clip_box, struct ivec2 offset) { + if (blur && !c->noblur) { + wlr_scene_node_set_position(&c->blur->node, offset.x, offset.y); + wlr_scene_blur_set_size(c->blur, clip_box.width - c->bw, + clip_box.height - c->bw); + } +} + void apply_border(Client *c) { if (!c || c->iskilling || !client_surface(c)->mapped) return; @@ -536,6 +541,7 @@ void client_apply_clip(Client *c, float factor) { apply_border(c); client_draw_shadow(c); + client_draw_blur(c, clip_box, offset); if (clip_box.width <= 0 || clip_box.height <= 0) { return; @@ -574,6 +580,7 @@ void client_apply_clip(Client *c, float factor) { // 应用窗口装饰 apply_border(c); client_draw_shadow(c); + client_draw_blur(c, clip_box, offset); // 如果窗口剪切区域已经剪切到0,则不渲染窗口表面 if (clip_box.width <= 0 || clip_box.height <= 0) { From d8583b1224a7fbb7f6b5a97839683c54985917b4 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Wed, 19 Nov 2025 11:10:05 +0800 Subject: [PATCH 3/4] fix: Fix blur lag --- src/mango.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mango.c b/src/mango.c index 69208d6..80ad241 100644 --- a/src/mango.c +++ b/src/mango.c @@ -2086,7 +2086,8 @@ static void iter_layer_scene_buffers(struct wlr_scene_buffer *buffer, int sx, LayerSurface *l = (LayerSurface *)user_data; wlr_scene_node_set_enabled(&l->blur->node, true); - wlr_scene_blur_set_transparency_mask_source(l->blur, buffer); + wlr_scene_blur_set_mask_source(l->blur, &buffer->node, + BLUR_MASK_IGNORE_TRANSPARENCY); wlr_scene_blur_set_size(l->blur, l->geom.width, l->geom.height); if (blur_optimized) { @@ -3533,7 +3534,6 @@ static void iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int sx, if (blur && c && !c->noblur) { wlr_scene_node_set_enabled(&c->blur->node, true); - // wlr_scene_blur_set_transparency_mask_source(c->blur, buffer); if (blur_optimized) { wlr_scene_blur_set_should_only_blur_bottom_layer(c->blur, true); } else { From fc677558f88a51d55e37f2805e291ccb30729209 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Wed, 19 Nov 2025 11:36:38 +0800 Subject: [PATCH 4/4] opt: set fadein blur to no blur_optimize --- src/animation/client.h | 10 ++++++++++ src/animation/layer.h | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/animation/client.h b/src/animation/client.h index 3792358..56bf432 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -1137,6 +1137,16 @@ bool client_apply_focus_opacity(Client *c) { target_opacity = opacity; } client_set_opacity(c, target_opacity); + if (blur && !c->noblur && !blur_optimized) { + wlr_scene_blur_set_strength( + c->blur, MIN(percent * (1.0 - fadein_begin_opacity) + + fadein_begin_opacity, + 1.0)); + wlr_scene_blur_set_alpha( + c->blur, MIN(percent * (1.0 - fadein_begin_opacity) + + fadein_begin_opacity, + 1.0)); + } } else if (animations && c->opacity_animation.running) { struct timespec now; diff --git a/src/animation/layer.h b/src/animation/layer.h index 80caec5..aa9f047 100644 --- a/src/animation/layer.h +++ b/src/animation/layer.h @@ -326,9 +326,14 @@ void layer_animation_next_tick(LayerSurface *l) { animation_passed * (1.0 - fadein_begin_opacity), 1.0f); - if (animation_fade_in) + if (animation_fade_in) { + if (blur && !l->noblur && !blur_optimized) { + wlr_scene_blur_set_strength(l->blur, opacity); + wlr_scene_blur_set_alpha(l->blur, opacity); + } wlr_scene_node_for_each_buffer(&l->scene->node, scene_buffer_apply_opacity, &opacity); + } wlr_scene_node_set_position(&l->scene->node, x, y);