Skip to content
83 changes: 54 additions & 29 deletions src/animation/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

enum corner_location set_client_corner_location(Client *c) {
enum corner_location current_corner_location = CORNER_LOCATION_ALL;
struct wlr_box target_geom =
config.animations ? c->animation.current : c->geom;
struct fx_corner_radii set_client_corner_location(Client *c) {
struct fx_corner_radii current_corner_location =
corner_radii_all(config.border_radius);
struct wlr_box target_geom = config.animations ? c->animation.current : c->geom;
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 >=
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) {
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 >=
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;
}
Expand Down Expand Up @@ -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)
return;

wlr_scene_buffer_set_corner_radius(buffer, config.border_radius,
buffer_data->corner_location);
wlr_scene_buffer_set_corner_radii(buffer, buffer_data->corner_location);
}

void buffer_set_effect(Client *c, BufferData data) {
Expand All @@ -243,12 +246,14 @@ void buffer_set_effect(Client *c, BufferData data) {
if (c == grabc)
data.should_scale = false;

if (c->isnoradius || c->isfullscreen ||
(config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)) {
data.corner_location = CORNER_LOCATION_NONE;
if (c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)) {
data.corner_location = corner_radii_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,
scene_buffer_apply_effect, &data);
}
Expand All @@ -268,11 +273,11 @@ void client_draw_shadow(Client *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->mon->visible_tiling_clients == 1)
? CORNER_LOCATION_NONE
: CORNER_LOCATION_ALL;
? corner_radii_none()
: set_client_corner_location(c);

int32_t bwoffset = c->bw != 0 && hit_no_border ? (int32_t)c->bw : 0;

Expand Down Expand Up @@ -302,7 +307,6 @@ void client_draw_shadow(Client *c) {

struct clipped_region clipped_region = {
.area = intersection_box,
.corner_radius = config.border_radius,
.corners = current_corner_location,
};

Expand Down Expand Up @@ -350,18 +354,24 @@ 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 (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) {
if (!c || c->iskilling || !client_surface(c)->mapped)
return;

bool hit_no_border = check_hit_no_border(c);
enum corner_location current_corner_location;
if (c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)) {
current_corner_location = CORNER_LOCATION_NONE;
} else {
current_corner_location = set_client_corner_location(c);
}
struct fx_corner_radii current_corner_location =
c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)
? corner_radii_none()
: set_client_corner_location(c);

if (hit_no_border && config.smartgaps) {
c->bw = 0;
Expand Down Expand Up @@ -434,15 +444,13 @@ void apply_border(Client *c) {
struct clipped_region clipped_region = {
.area = {inner_surface_x, inner_surface_y, inner_surface_width,
inner_surface_height},
.corner_radius = config.border_radius,
.corners = current_corner_location,
};

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_node_set_position(&c->border->node, rect_x, rect_y);
wlr_scene_rect_set_corner_radius(c->border, config.border_radius,
current_corner_location);
wlr_scene_rect_set_corner_radii(c->border, current_corner_location);
wlr_scene_rect_set_clipped_region(c->border, clipped_region);
}

Expand Down Expand Up @@ -520,7 +528,7 @@ void client_apply_clip(Client *c, float factor) {
struct ivec2 offset;
BufferData buffer_data;

enum corner_location current_corner_location =
struct fx_corner_radii current_corner_location =
set_client_corner_location(c);

if (!config.animations) {
Expand All @@ -535,12 +543,14 @@ 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;
}

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});
Expand Down Expand Up @@ -572,6 +582,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) {
Expand Down Expand Up @@ -1005,6 +1016,10 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) {
apply_border(c);
client_get_clip(c, &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;
}
// 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小
Expand Down Expand Up @@ -1124,6 +1139,16 @@ bool client_apply_focus_opacity(Client *c) {
sizeof(c->opacity_animation.current_border_color));
c->opacity_animation.current_opacity = 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);
} else if (config.animations && c->opacity_animation.running) {

Expand Down
13 changes: 4 additions & 9 deletions src/animation/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,8 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int32_t lx,

// Effects
wlr_scene_buffer_set_opacity(snapshot_buffer, scene_buffer->opacity);
wlr_scene_buffer_set_corner_radius(snapshot_buffer,
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);
wlr_scene_buffer_set_corner_radii(snapshot_buffer,
scene_buffer->corners);

snapshot_buffer->node.data = scene_buffer->node.data;

Expand Down Expand Up @@ -219,6 +212,8 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int32_t lx,

break;
}
case WLR_SCENE_NODE_BLUR:
break;
case WLR_SCENE_NODE_OPTIMIZED_BLUR:
return true;
}
Expand Down
14 changes: 11 additions & 3 deletions src/animation/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ void layer_draw_shadow(LayerSurface *l) {

struct clipped_region clipped_region = {
.area = intersection_box,
.corner_radius = config.border_radius,
.corners = config.border_radius_location_default,
.corners = corner_radii_all(config.border_radius),
};

wlr_scene_node_set_position(&l->shadow->node, shadow_box.x, shadow_box.y);
Expand Down Expand Up @@ -328,9 +327,14 @@ void layer_animation_next_tick(LayerSurface *l) {
opacity_eased_progress * (1.0 - config.fadein_begin_opacity),
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,
scene_buffer_apply_opacity, &opacity);
}

wlr_scene_node_set_position(&l->scene->node, x, y);

Expand Down Expand Up @@ -358,6 +362,10 @@ void layer_animation_next_tick(LayerSurface *l) {
.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) {
l->animation.running = false;
l->need_output_flush = false;
Expand Down
1 change: 0 additions & 1 deletion src/config/parse_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3352,7 +3352,6 @@ void set_value_default() {
config.blur_layer = 0;
config.blur_optimized = 1;
config.border_radius = 0;
config.border_radius_location_default = CORNER_LOCATION_ALL;
config.blur_params.num_passes = 1;
config.blur_params.radius = 5;
config.blur_params.noise = 0.02f;
Expand Down
Loading