This commit is contained in:
DreamMaoMao 2026-03-23 10:13:38 +08:00 committed by GitHub
commit 7cc6a0c0b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 101 additions and 64 deletions

View file

@ -8,23 +8,27 @@ void set_rect_size(struct wlr_scene_rect *rect, int32_t width, int32_t height) {
wlr_scene_rect_set_size(rect, GEZERO(width), GEZERO(height)); wlr_scene_rect_set_size(rect, GEZERO(width), GEZERO(height));
} }
enum corner_location set_client_corner_location(Client *c) { struct fx_corner_radii set_client_corner_location(Client *c) {
enum corner_location current_corner_location = CORNER_LOCATION_ALL; struct fx_corner_radii current_corner_location =
struct wlr_box target_geom = corner_radii_all(config.border_radius);
config.animations ? c->animation.current : c->geom; struct wlr_box target_geom = config.animations ? c->animation.current : c->geom;
if (target_geom.x + config.border_radius <= c->mon->m.x) { if (target_geom.x + config.border_radius <= c->mon->m.x) {
current_corner_location &= ~CORNER_LOCATION_LEFT; current_corner_location.top_left = 0; // 清除左标志位
current_corner_location.bottom_left = 0; // 清除左标志位
} }
if (target_geom.x + target_geom.width - config.border_radius >= if (target_geom.x + target_geom.width - config.border_radius >=
c->mon->m.x + c->mon->m.width) { c->mon->m.x + c->mon->m.width) {
current_corner_location &= ~CORNER_LOCATION_RIGHT; current_corner_location.top_right = 0; // 清除右标志位
current_corner_location.bottom_right = 0; // 清除右标志位
} }
if (target_geom.y + config.border_radius <= c->mon->m.y) { if (target_geom.y + config.border_radius <= c->mon->m.y) {
current_corner_location &= ~CORNER_LOCATION_TOP; current_corner_location.top_left = 0; // 清除上标志位
current_corner_location.top_right = 0; // 清除上标志位
} }
if (target_geom.y + target_geom.height - config.border_radius >= if (target_geom.y + target_geom.height - config.border_radius >=
c->mon->m.y + c->mon->m.height) { c->mon->m.y + c->mon->m.height) {
current_corner_location &= ~CORNER_LOCATION_BOTTOM; current_corner_location.bottom_left = 0; // 清除下标志位
current_corner_location.bottom_right = 0; // 清除下标志位
} }
return current_corner_location; return current_corner_location;
} }
@ -226,8 +230,7 @@ void scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int32_t sx,
if (wlr_xdg_popup_try_from_wlr_surface(surface) != NULL) if (wlr_xdg_popup_try_from_wlr_surface(surface) != NULL)
return; return;
wlr_scene_buffer_set_corner_radius(buffer, config.border_radius, wlr_scene_buffer_set_corner_radii(buffer, buffer_data->corner_location);
buffer_data->corner_location);
} }
void buffer_set_effect(Client *c, BufferData data) { void buffer_set_effect(Client *c, BufferData data) {
@ -243,12 +246,14 @@ void buffer_set_effect(Client *c, BufferData data) {
if (c == grabc) if (c == grabc)
data.should_scale = false; data.should_scale = false;
if (c->isnoradius || c->isfullscreen || if (c->isfullscreen || (config.no_radius_when_single && c->mon &&
(config.no_radius_when_single && c->mon && c->mon->visible_tiling_clients == 1)) {
c->mon->visible_tiling_clients == 1)) { data.corner_location = corner_radii_none();
data.corner_location = CORNER_LOCATION_NONE;
} }
if (config.blur && !c->noblur) {
wlr_scene_blur_set_corner_radii(c->blur, data.corner_location);
}
wlr_scene_node_for_each_buffer(&c->scene_surface->node, wlr_scene_node_for_each_buffer(&c->scene_surface->node,
scene_buffer_apply_effect, &data); scene_buffer_apply_effect, &data);
} }
@ -268,11 +273,11 @@ void client_draw_shadow(Client *c) {
} }
bool hit_no_border = check_hit_no_border(c); bool hit_no_border = check_hit_no_border(c);
enum corner_location current_corner_location = struct fx_corner_radii current_corner_location =
c->isfullscreen || (config.no_radius_when_single && c->mon && c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1) c->mon->visible_tiling_clients == 1)
? CORNER_LOCATION_NONE ? corner_radii_none()
: CORNER_LOCATION_ALL; : set_client_corner_location(c);
int32_t bwoffset = c->bw != 0 && hit_no_border ? (int32_t)c->bw : 0; int32_t bwoffset = c->bw != 0 && hit_no_border ? (int32_t)c->bw : 0;
@ -302,7 +307,6 @@ void client_draw_shadow(Client *c) {
struct clipped_region clipped_region = { struct clipped_region clipped_region = {
.area = intersection_box, .area = intersection_box,
.corner_radius = config.border_radius,
.corners = current_corner_location, .corners = current_corner_location,
}; };
@ -350,18 +354,24 @@ void client_draw_shadow(Client *c) {
wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region); 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 (config.blur && !c->noblur && c->blur) {
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) { void apply_border(Client *c) {
if (!c || c->iskilling || !client_surface(c)->mapped) if (!c || c->iskilling || !client_surface(c)->mapped)
return; return;
bool hit_no_border = check_hit_no_border(c); bool hit_no_border = check_hit_no_border(c);
enum corner_location current_corner_location; struct fx_corner_radii current_corner_location =
if (c->isfullscreen || (config.no_radius_when_single && c->mon && c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)) { c->mon->visible_tiling_clients == 1)
current_corner_location = CORNER_LOCATION_NONE; ? corner_radii_none()
} else { : set_client_corner_location(c);
current_corner_location = set_client_corner_location(c);
}
if (hit_no_border && config.smartgaps) { if (hit_no_border && config.smartgaps) {
c->bw = 0; c->bw = 0;
@ -434,15 +444,13 @@ void apply_border(Client *c) {
struct clipped_region clipped_region = { struct clipped_region clipped_region = {
.area = {inner_surface_x, inner_surface_y, inner_surface_width, .area = {inner_surface_x, inner_surface_y, inner_surface_width,
inner_surface_height}, inner_surface_height},
.corner_radius = config.border_radius,
.corners = current_corner_location, .corners = current_corner_location,
}; };
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw); wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
wlr_scene_rect_set_size(c->border, rect_width, rect_height); wlr_scene_rect_set_size(c->border, rect_width, rect_height);
wlr_scene_node_set_position(&c->border->node, rect_x, rect_y); wlr_scene_node_set_position(&c->border->node, rect_x, rect_y);
wlr_scene_rect_set_corner_radius(c->border, config.border_radius, wlr_scene_rect_set_corner_radii(c->border, current_corner_location);
current_corner_location);
wlr_scene_rect_set_clipped_region(c->border, clipped_region); wlr_scene_rect_set_clipped_region(c->border, clipped_region);
} }
@ -520,7 +528,7 @@ void client_apply_clip(Client *c, float factor) {
struct ivec2 offset; struct ivec2 offset;
BufferData buffer_data; BufferData buffer_data;
enum corner_location current_corner_location = struct fx_corner_radii current_corner_location =
set_client_corner_location(c); set_client_corner_location(c);
if (!config.animations) { if (!config.animations) {
@ -535,12 +543,14 @@ void client_apply_clip(Client *c, float factor) {
apply_border(c); apply_border(c);
client_draw_shadow(c); client_draw_shadow(c);
client_draw_blur(c, clip_box, offset);
if (clip_box.width <= 0 || clip_box.height <= 0) { if (clip_box.width <= 0 || clip_box.height <= 0) {
return; return;
} }
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box);
buffer_set_effect(c, (BufferData){1.0f, 1.0f, clip_box.width, buffer_set_effect(c, (BufferData){1.0f, 1.0f, clip_box.width,
clip_box.height, clip_box.height,
current_corner_location, true}); current_corner_location, true});
@ -572,6 +582,7 @@ void client_apply_clip(Client *c, float factor) {
// 应用窗口装饰 // 应用窗口装饰
apply_border(c); apply_border(c);
client_draw_shadow(c); client_draw_shadow(c);
client_draw_blur(c, clip_box, offset);
// 如果窗口剪切区域已经剪切到0则不渲染窗口表面 // 如果窗口剪切区域已经剪切到0则不渲染窗口表面
if (clip_box.width <= 0 || clip_box.height <= 0) { if (clip_box.width <= 0 || clip_box.height <= 0) {
@ -1005,6 +1016,10 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) {
apply_border(c); apply_border(c);
client_get_clip(c, &clip); client_get_clip(c, &clip);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
if (config.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; return;
} }
// 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小 // 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小
@ -1124,6 +1139,16 @@ bool client_apply_focus_opacity(Client *c) {
sizeof(c->opacity_animation.current_border_color)); sizeof(c->opacity_animation.current_border_color));
c->opacity_animation.current_opacity = target_opacity; c->opacity_animation.current_opacity = target_opacity;
client_set_opacity(c, target_opacity); client_set_opacity(c, target_opacity);
if (config.blur && !c->noblur && !config.blur_optimized) {
wlr_scene_blur_set_strength(
c->blur, MIN(percent * (1.0 - config.fadein_begin_opacity) +
config.fadein_begin_opacity,
1.0));
wlr_scene_blur_set_alpha(
c->blur, MIN(percent * (1.0 - config.fadein_begin_opacity) +
config.fadein_begin_opacity,
1.0));
}
client_set_border_color(c, c->opacity_animation.target_border_color); client_set_border_color(c, c->opacity_animation.target_border_color);
} else if (config.animations && c->opacity_animation.running) { } else if (config.animations && c->opacity_animation.running) {

View file

@ -175,15 +175,8 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int32_t lx,
// Effects // Effects
wlr_scene_buffer_set_opacity(snapshot_buffer, scene_buffer->opacity); wlr_scene_buffer_set_opacity(snapshot_buffer, scene_buffer->opacity);
wlr_scene_buffer_set_corner_radius(snapshot_buffer, wlr_scene_buffer_set_corner_radii(snapshot_buffer,
scene_buffer->corner_radius, scene_buffer->corners);
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; snapshot_buffer->node.data = scene_buffer->node.data;
@ -219,6 +212,8 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int32_t lx,
break; break;
} }
case WLR_SCENE_NODE_BLUR:
break;
case WLR_SCENE_NODE_OPTIMIZED_BLUR: case WLR_SCENE_NODE_OPTIMIZED_BLUR:
return true; return true;
} }

View file

@ -187,8 +187,7 @@ void layer_draw_shadow(LayerSurface *l) {
struct clipped_region clipped_region = { struct clipped_region clipped_region = {
.area = intersection_box, .area = intersection_box,
.corner_radius = config.border_radius, .corners = corner_radii_all(config.border_radius),
.corners = config.border_radius_location_default,
}; };
wlr_scene_node_set_position(&l->shadow->node, shadow_box.x, shadow_box.y); wlr_scene_node_set_position(&l->shadow->node, shadow_box.x, shadow_box.y);
@ -328,9 +327,14 @@ void layer_animation_next_tick(LayerSurface *l) {
opacity_eased_progress * (1.0 - config.fadein_begin_opacity), opacity_eased_progress * (1.0 - config.fadein_begin_opacity),
1.0f); 1.0f);
if (config.animation_fade_in) if (config.animation_fade_in) {
if (config.blur && !l->noblur && !config.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, wlr_scene_node_for_each_buffer(&l->scene->node,
scene_buffer_apply_opacity, &opacity); scene_buffer_apply_opacity, &opacity);
}
wlr_scene_node_set_position(&l->scene->node, x, y); wlr_scene_node_set_position(&l->scene->node, x, y);
@ -358,6 +362,10 @@ void layer_animation_next_tick(LayerSurface *l) {
.height = height, .height = height,
}; };
if (config.blur && config.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) { if (animation_passed >= 1.0) {
l->animation.running = false; l->animation.running = false;
l->need_output_flush = false; l->need_output_flush = false;

View file

@ -3363,7 +3363,6 @@ void set_value_default() {
config.blur_layer = 0; config.blur_layer = 0;
config.blur_optimized = 1; config.blur_optimized = 1;
config.border_radius = 0; config.border_radius = 0;
config.border_radius_location_default = CORNER_LOCATION_ALL;
config.blur_params.num_passes = 1; config.blur_params.num_passes = 1;
config.blur_params.radius = 5; config.blur_params.radius = 5;
config.blur_params.noise = 0.02f; config.blur_params.noise = 0.02f;

View file

@ -11,7 +11,6 @@
#include <scenefx/render/fx_renderer/fx_renderer.h> #include <scenefx/render/fx_renderer/fx_renderer.h>
#include <scenefx/types/fx/blur_data.h> #include <scenefx/types/fx/blur_data.h>
#include <scenefx/types/fx/clipped_region.h> #include <scenefx/types/fx/clipped_region.h>
#include <scenefx/types/fx/corner_location.h>
#include <scenefx/types/wlr_scene.h> #include <scenefx/types/wlr_scene.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
@ -301,7 +300,7 @@ typedef struct {
float height_scale; float height_scale;
int32_t width; int32_t width;
int32_t height; int32_t height;
enum corner_location corner_location; struct fx_corner_radii corner_location;
bool should_scale; bool should_scale;
} BufferData; } BufferData;
@ -315,6 +314,7 @@ struct Client {
struct wlr_scene_tree *scene; struct wlr_scene_tree *scene;
struct wlr_scene_rect *border; /* top, bottom, left, right */ struct wlr_scene_rect *border; /* top, bottom, left, right */
struct wlr_scene_shadow *shadow; struct wlr_scene_shadow *shadow;
struct wlr_scene_blur *blur;
struct wlr_scene_tree *scene_surface; struct wlr_scene_tree *scene_surface;
struct wl_list link; struct wl_list link;
struct wl_list flink; struct wl_list flink;
@ -465,6 +465,7 @@ typedef struct {
struct wlr_scene_tree *scene; struct wlr_scene_tree *scene;
struct wlr_scene_tree *popups; struct wlr_scene_tree *popups;
struct wlr_scene_shadow *shadow; struct wlr_scene_shadow *shadow;
struct wlr_scene_blur *blur;
struct wlr_scene_layer_surface_v1 *scene_layer; struct wlr_scene_layer_surface_v1 *scene_layer;
struct wl_list link; struct wl_list link;
struct wl_list fadeout_link; struct wl_list fadeout_link;
@ -763,7 +764,7 @@ static double find_animation_curve_at(double t, int32_t type);
static void apply_opacity_to_rect_nodes(Client *c, struct wlr_scene_node *node, static void apply_opacity_to_rect_nodes(Client *c, struct wlr_scene_node *node,
double animation_passed); double animation_passed);
static enum corner_location set_client_corner_location(Client *c); static struct fx_corner_radii set_client_corner_location(Client *c);
static double all_output_frame_duration_ms(); static double all_output_frame_duration_ms();
static struct wlr_scene_tree * static struct wlr_scene_tree *
wlr_scene_tree_snapshot(struct wlr_scene_node *node, wlr_scene_tree_snapshot(struct wlr_scene_node *node,
@ -2377,12 +2378,16 @@ static void iter_layer_scene_buffers(struct wlr_scene_buffer *buffer,
return; return;
} }
wlr_scene_buffer_set_backdrop_blur(buffer, true); LayerSurface *l = (LayerSurface *)user_data;
wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, true);
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 (config.blur_optimized) { if (config.blur_optimized) {
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, true); wlr_scene_blur_set_should_only_blur_bottom_layer(l->blur, true);
} else { } else {
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, false); wlr_scene_blur_set_should_only_blur_bottom_layer(l->blur, false);
} }
} }
@ -2440,14 +2445,17 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) {
} }
// 初始化阴影 // 初始化阴影
if (layer_surface->current.exclusive_zone == 0 && if (layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM &&
layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM &&
layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) { layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
l->shadow = if (layer_surface->current.exclusive_zone == 0) {
wlr_scene_shadow_create(l->scene, 0, 0, config.border_radius, l->shadow = wlr_scene_shadow_create(l->scene, 0, 0, config.border_radius,
config.shadows_blur, config.shadowscolor); config.shadows_blur, config.shadowscolor);
wlr_scene_node_lower_to_bottom(&l->shadow->node); wlr_scene_node_lower_to_bottom(&l->shadow->node);
wlr_scene_node_set_enabled(&l->shadow->node, true); 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);
} }
// 初始化动画 // 初始化动画
@ -2519,7 +2527,8 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) {
if (!l->noblur && if (!l->noblur &&
layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer_surface->current.layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM &&
layer_surface->current.layer != 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, wlr_scene_node_for_each_buffer(&l->scene->node,
iter_layer_scene_buffers, l); iter_layer_scene_buffers, l);
@ -3997,15 +4006,14 @@ static void iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int32_t sx,
return; return;
if (config.blur && c && !c->noblur) { if (config.blur && c && !c->noblur) {
wlr_scene_buffer_set_backdrop_blur(buffer, true); wlr_scene_node_set_enabled(&c->blur->node, true);
wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, false);
if (config.blur_optimized) { if (config.blur_optimized) {
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, true); wlr_scene_blur_set_should_only_blur_bottom_layer(c->blur, true);
} else { } else {
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, false); wlr_scene_blur_set_should_only_blur_bottom_layer(c->blur, false);
} }
} else { } else {
wlr_scene_buffer_set_backdrop_blur(buffer, false); wlr_scene_node_set_enabled(&c->blur->node, false);
} }
} }
@ -4155,14 +4163,16 @@ mapnotify(struct wl_listener *listener, void *data) {
c->scene, 0, 0, c->isurgent ? config.urgentcolor : config.bordercolor); c->scene, 0, 0, c->isurgent ? config.urgentcolor : config.bordercolor);
wlr_scene_node_lower_to_bottom(&c->border->node); wlr_scene_node_lower_to_bottom(&c->border->node);
wlr_scene_node_set_position(&c->border->node, 0, 0); wlr_scene_node_set_position(&c->border->node, 0, 0);
wlr_scene_rect_set_corner_radius(c->border, config.border_radius, wlr_scene_rect_set_corner_radii(c->border, corner_radii_all(config.border_radius));
config.border_radius_location_default);
wlr_scene_node_set_enabled(&c->border->node, true); wlr_scene_node_set_enabled(&c->border->node, true);
c->shadow = c->shadow =
wlr_scene_shadow_create(c->scene, 0, 0, config.border_radius, wlr_scene_shadow_create(c->scene, 0, 0, config.border_radius,
config.shadows_blur, config.shadowscolor); config.shadows_blur, config.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_lower_to_bottom(&c->shadow->node);
wlr_scene_node_set_enabled(&c->shadow->node, true); wlr_scene_node_set_enabled(&c->shadow->node, true);