fix: Avoid animation ghosting

This commit is contained in:
DreamMaoMao 2025-06-14 10:21:30 +08:00
parent d5c8a7bd91
commit 33947c30f2

View file

@ -1108,138 +1108,144 @@ bool check_hit_no_border(Client *c) {
return hit_no_border; return hit_no_border;
} }
void void client_draw_shadow(Client *c) {
client_draw_shadow(Client *c) {
if (c->iskilling || !client_surface(c)->mapped) if (c->iskilling || !client_surface(c)->mapped)
return; return;
if(!shadows || !c->isfloating) { if (!shadows || !c->isfloating) {
wlr_scene_shadow_set_size(c->shadow, 0, 0); wlr_scene_shadow_set_size(c->shadow, 0, 0);
return; return;
} }
uint32_t width, height; uint32_t width, height;
client_actual_size(c, &width, &height); client_actual_size(c, &width, &height);
uint32_t delta = shadows_size + c->bw; uint32_t delta = shadows_size + c->bw;
/* we calculate where to clip the shadow */ /* we calculate where to clip the shadow */
struct wlr_box client_box = { struct wlr_box client_box = {
.x = 0, .x = 0,
.y = 0, .y = 0,
.width = width, .width = width,
.height = height, .height = height,
}; };
struct wlr_box shadow_box = { struct wlr_box shadow_box = {
.x = shadows_position_x, .x = shadows_position_x,
.y = shadows_position_y, .y = shadows_position_y,
.width = width + 2 * delta, .width = width + 2 * delta,
.height = height + 2 * delta, .height = height + 2 * delta,
}; };
struct wlr_box intersection_box; struct wlr_box intersection_box;
wlr_box_intersection(&intersection_box, &client_box, &shadow_box); wlr_box_intersection(&intersection_box, &client_box, &shadow_box);
/* clipped region takes shadow relative coords, so we translate everything by its position */ /* clipped region takes shadow relative coords, so we translate everything
intersection_box.x -= shadows_position_x; * by its position */
intersection_box.y -= shadows_position_y; intersection_box.x -= shadows_position_x;
intersection_box.y -= shadows_position_y;
struct clipped_region clipped_region = { struct clipped_region clipped_region = {
.area = intersection_box, .area = intersection_box,
.corner_radius = border_radius, .corner_radius = border_radius,
.corners = border_radius_location_default, .corners = border_radius_location_default,
}; };
wlr_scene_node_set_position(&c->shadow->node, shadow_box.x, shadow_box.y); wlr_scene_node_set_position(&c->shadow->node, shadow_box.x, shadow_box.y);
wlr_scene_shadow_set_size(c->shadow, shadow_box.width, shadow_box.height); wlr_scene_shadow_set_size(c->shadow, shadow_box.width, shadow_box.height);
wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region); wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region);
} }
void apply_border(Client *c, struct wlr_box clip_box, int offsetx, void apply_border(Client *c, struct wlr_box clip_box, int offsetx, int offsety,
int offsety, enum corner_location border_radius_location) { enum corner_location border_radius_location) {
bool hit_no_border = false; bool hit_no_border = false;
if (c->iskilling || !client_surface(c)->mapped) if (c->iskilling || !client_surface(c)->mapped)
return; return;
if (clip_box.width > c->animation.current.width) { if (clip_box.width > c->animation.current.width) {
clip_box.width = c->animation.current.width; clip_box.width = c->animation.current.width;
} }
if (clip_box.height > c->animation.current.height) { if (clip_box.height > c->animation.current.height) {
clip_box.height = c->animation.current.height; clip_box.height = c->animation.current.height;
} }
hit_no_border = check_hit_no_border(c); hit_no_border = check_hit_no_border(c);
if (hit_no_border && smartgaps) { if (hit_no_border && smartgaps) {
c->bw = 0; c->bw = 0;
c->fake_no_border = true; c->fake_no_border = true;
} else if (hit_no_border && !smartgaps) { } else if (hit_no_border && !smartgaps) {
wlr_scene_rect_set_size(c->border, 0, 0); wlr_scene_rect_set_size(c->border, 0, 0);
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);
c->fake_no_border = true; c->fake_no_border = true;
return; return;
} else if (!c->isfullscreen && VISIBLEON(c, c->mon)) { } else if (!c->isfullscreen && VISIBLEON(c, c->mon)) {
c->bw = c->isnoborder ? 0 : borderpx; c->bw = c->isnoborder ? 0 : borderpx;
c->fake_no_border = false; c->fake_no_border = false;
} }
int clip_box_width = clip_box.width - 2 * c->bw; int clip_box_width = clip_box.width - 2 * c->bw;
int clip_box_height = clip_box.height - 2 * c->bw; int clip_box_height = clip_box.height - 2 * c->bw;
if(clip_box_width < 0) { if (clip_box_width < 0) {
clip_box_width = 0; clip_box_width = 0;
} }
if(clip_box_height < 0) { if (clip_box_height < 0) {
clip_box_height = 0; clip_box_height = 0;
} }
int clip_x = c->bw - offsetx; int clip_x = c->bw - offsetx;
int clip_y = c->bw - offsety; int clip_y = c->bw - offsety;
clip_x = clip_x < 0 ? 0 : clip_x; clip_x = clip_x < 0 ? 0 : clip_x;
clip_y = clip_y < 0 ? 0 : clip_y; clip_y = clip_y < 0 ? 0 : clip_y;
struct clipped_region clipped_region = { struct clipped_region clipped_region = {
.area = { clip_x, clip_y, clip_box_width, clip_box_height }, .area = {clip_x, clip_y, clip_box_width, clip_box_height},
.corner_radius = border_radius, .corner_radius = border_radius,
.corners = border_radius_location, .corners = border_radius_location,
}; };
int right_offset = GEZERO(c->animation.current.x + c->animation.current.width - c->mon->m.x - c->mon->m.width); int right_offset =
int bottom_offset = GEZERO(c->animation.current.y + c->animation.current.height - c->mon->m.y - c->mon->m.height); GEZERO(c->animation.current.x + c->animation.current.width -
int rect_width = clip_box.width; c->mon->m.x - c->mon->m.width);
int rect_height = clip_box.height; int bottom_offset =
GEZERO(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
int rect_width = clip_box.width;
int rect_height = clip_box.height;
if(right_offset > 0) { if (right_offset > 0) {
clipped_region.area.width = MIN(clip_box.width,clipped_region.area.width + right_offset); clipped_region.area.width =
} MIN(clip_box.width, clipped_region.area.width + right_offset);
}
if(bottom_offset > 0) { if (bottom_offset > 0) {
clipped_region.area.height = MIN(clip_box.height,clipped_region.area.height + bottom_offset); clipped_region.area.height =
} MIN(clip_box.height, clipped_region.area.height + bottom_offset);
}
if(rect_width < 0) { if (rect_width < 0) {
rect_width = 0; rect_width = 0;
} }
if(rect_height < 0) { if (rect_height < 0) {
rect_height = 0; rect_height = 0;
} }
int node_x = offsetx; int node_x = offsetx;
int node_y = offsety; int node_y = offsety;
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, node_x, node_y); wlr_scene_node_set_position(&c->border->node, node_x, node_y);
wlr_scene_rect_set_corner_radius(c->border, border_radius, border_radius_location); wlr_scene_rect_set_corner_radius(c->border, border_radius,
wlr_scene_rect_set_clipped_region(c->border, clipped_region); border_radius_location);
wlr_scene_rect_set_clipped_region(c->border, clipped_region);
} }
enum corner_location set_client_corner_location(Client *c) { enum corner_location set_client_corner_location(Client *c) {
@ -1263,143 +1269,166 @@ enum corner_location set_client_corner_location(Client *c) {
} }
struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) {
int offsetx = 0; int offsetx = 0;
int offsety = 0; int offsety = 0;
struct uvec2 offset; struct uvec2 offset;
offset.x = 0; offset.x = 0;
offset.y = 0; offset.y = 0;
if (!ISTILED(c) && !c->animation.tagining && !c->animation.tagouted && if (!ISTILED(c) && !c->animation.tagining && !c->animation.tagouted &&
!c->animation.tagouting) !c->animation.tagouting)
return offset; return offset;
// // make tagout tagin animations not visible in other monitors // // make tagout tagin animations not visible in other monitors
if (ISTILED(c) || c->animation.tagining || c->animation.tagouted || if (ISTILED(c) || c->animation.tagining || c->animation.tagouted ||
c->animation.tagouting) { c->animation.tagouting) {
if (c->animation.current.x < c->mon->m.x) { if (c->animation.current.x < c->mon->m.x) {
offsetx = c->mon->m.x - c->bw - c->animation.current.x; offsetx = c->mon->m.x - c->bw - c->animation.current.x;
offsetx = offsetx < 0 ? 0 : offsetx; offsetx = offsetx < 0 ? 0 : offsetx;
clip_box->x = clip_box->x + offsetx; clip_box->x = clip_box->x + offsetx;
clip_box->width = clip_box->width - offsetx; clip_box->width = clip_box->width - offsetx;
} else if (c->animation.current.x + c->animation.current.width > } else if (c->animation.current.x + c->animation.current.width >
c->mon->m.x + c->mon->m.width) { c->mon->m.x + c->mon->m.width) {
clip_box->width = clip_box->width - clip_box->width =
(c->animation.current.x + c->animation.current.width - clip_box->width -
c->mon->m.x - c->mon->m.width) + (c->animation.current.x + c->animation.current.width -
c->bw; c->mon->m.x - c->mon->m.width) +
} c->bw;
}
if (c->animation.current.y < c->mon->m.y) { if (c->animation.current.y < c->mon->m.y) {
offsety = c->mon->m.y - c->bw - c->animation.current.y; offsety = c->mon->m.y - c->bw - c->animation.current.y;
offsety = offsety < 0 ? 0 : offsety; offsety = offsety < 0 ? 0 : offsety;
clip_box->y = clip_box->y + offsety; clip_box->y = clip_box->y + offsety;
clip_box->height = clip_box->height - offsety; clip_box->height = clip_box->height - offsety;
} else if (c->animation.current.y + c->animation.current.height > } else if (c->animation.current.y + c->animation.current.height >
c->mon->m.y + c->mon->m.height) { c->mon->m.y + c->mon->m.height) {
clip_box->height = clip_box->height - clip_box->height =
(c->animation.current.y + c->animation.current.height - clip_box->height -
c->mon->m.y - c->mon->m.height) + (c->animation.current.y + c->animation.current.height -
c->bw; c->mon->m.y - c->mon->m.height) +
} c->bw;
} }
}
offset.x = offsetx; offset.x = offsetx;
offset.y = offsety; offset.y = offsety;
if ((clip_box->width < 0 || clip_box->height < 0) && if ((clip_box->width < 0 || clip_box->height < 0) &&
(ISTILED(c) || c->animation.tagouting || c->animation.tagining)) { (ISTILED(c) || c->animation.tagouting || c->animation.tagining)) {
c->is_clip_to_hide = true; c->is_clip_to_hide = true;
wlr_scene_node_set_enabled(&c->scene->node, false); wlr_scene_node_set_enabled(&c->scene->node, false);
} else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) { } else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) {
c->is_clip_to_hide = false; c->is_clip_to_hide = false;
wlr_scene_node_set_enabled(&c->scene->node, true); wlr_scene_node_set_enabled(&c->scene->node, true);
} }
if (clip_box->width > c->animation.current.width) { if (clip_box->width > c->animation.current.width) {
clip_box->width = c->animation.current.width; clip_box->width = c->animation.current.width;
} }
if (clip_box->height > c->animation.current.height) { if (clip_box->height > c->animation.current.height) {
clip_box->height = c->animation.current.height; clip_box->height = c->animation.current.height;
} }
return offset; return offset;
} }
void client_apply_clip(Client *c) { void client_apply_clip(Client *c) {
if (c->iskilling || !client_surface(c)->mapped) if (c->iskilling || !client_surface(c)->mapped)
return; return;
struct wlr_box clip_box; struct wlr_box clip_box;
struct uvec2 offset; struct uvec2 offset;
animationScale scale_data; bool should_render_client_surface = false;
struct wlr_box surface_clip; animationScale scale_data;
enum corner_location current_corner_location = set_client_corner_location(c); struct wlr_box surface_clip;
enum corner_location current_corner_location =
set_client_corner_location(c);
if (!animations) { if (!animations) {
c->animation.running = false; c->animation.running = false;
c->need_output_flush = false; c->need_output_flush = false;
c->animainit_geom = c->current = c->pending = c->animation.current = c->animainit_geom = c->current = c->pending = c->animation.current =
c->geom; c->geom;
client_get_clip(c, &clip_box); client_get_clip(c, &clip_box);
offset = clip_to_hide(c, &clip_box); offset = clip_to_hide(c, &clip_box);
apply_border(c, clip_box, offset.x, offset.y, current_corner_location); apply_border(c, clip_box, offset.x, offset.y, current_corner_location);
client_draw_shadow(c); client_draw_shadow(c);
surface_clip = clip_box; surface_clip = clip_box;
surface_clip.width = surface_clip.width - 2 * c->bw; surface_clip.width = surface_clip.width - 2 * c->bw;
surface_clip.height = surface_clip.height - 2 * c->bw; surface_clip.height = surface_clip.height - 2 * c->bw;
if(surface_clip.width <= 0 || surface_clip.height <= 0) { if (surface_clip.width <= 0 || surface_clip.height <= 0) {
return; return;
} }
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &surface_clip); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node,
buffer_set_effect(c, (animationScale){0, 0, 0, 0, current_corner_location,false}); &surface_clip);
return; buffer_set_effect(
} c, (animationScale){0, 0, 0, 0, current_corner_location, false});
return;
}
uint32_t width, height; uint32_t width, height;
client_actual_size(c, &width, &height); client_actual_size(c, &width, &height);
struct wlr_box geometry; struct wlr_box geometry;
client_get_geometry(c, &geometry); client_get_geometry(c, &geometry);
clip_box = (struct wlr_box){ clip_box = (struct wlr_box){
.x = geometry.x, .x = geometry.x,
.y = geometry.y, .y = geometry.y,
.width = width, .width = width,
.height = height, .height = height,
}; };
if (client_is_x11(c)) { if (client_is_x11(c)) {
clip_box.x = 0; clip_box.x = 0;
clip_box.y = 0; clip_box.y = 0;
} }
offset = clip_to_hide(c, &clip_box); offset = clip_to_hide(c, &clip_box);
apply_border(c, clip_box, offset.x, offset.y, current_corner_location);
client_draw_shadow(c);
surface_clip = clip_box; surface_clip = clip_box;
surface_clip.width = surface_clip.width - 2 * c->bw; surface_clip.width = surface_clip.width - 2 * c->bw;
surface_clip.height = surface_clip.height - 2 * c->bw; surface_clip.height = surface_clip.height - 2 * c->bw;
if(surface_clip.width <= 0 || surface_clip.height <= 0) { if (surface_clip.width <= 0 || surface_clip.height <= 0) {
return; should_render_client_surface = false;
} wlr_scene_node_set_enabled(&c->scene_surface->node, false);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &surface_clip); } else {
should_render_client_surface = true;
wlr_scene_node_set_enabled(&c->scene_surface->node, true);
}
scale_data.should_scale = true; apply_border(c, clip_box, offset.x, offset.y, current_corner_location);
scale_data.width = clip_box.width - 2 * c->bw; client_draw_shadow(c);
scale_data.height = clip_box.height - 2 * c->bw;
scale_data.width_scale = (float)scale_data.width / (geometry.width - offset.x); if (!should_render_client_surface) {
scale_data.height_scale = (float)scale_data.height / (geometry.height - offset.y); return;
scale_data.corner_location = current_corner_location; }
scale_data.percent = c->animation.action == OPEN && animation_fade_in && !c->nofadein ? (double)c->animation.passed_frames / c->animation.total_frames : 1.0;
scale_data.opacity = c->isfullscreen ? 1 : c == selmon->sel ? c->focused_opacity : c->unfocused_opacity; wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &surface_clip);
buffer_set_effect(c, scale_data);
scale_data.should_scale = true;
scale_data.width = clip_box.width - 2 * c->bw;
scale_data.height = clip_box.height - 2 * c->bw;
scale_data.width_scale =
(float)scale_data.width / (geometry.width - offset.x);
scale_data.height_scale =
(float)scale_data.height / (geometry.height - offset.y);
scale_data.corner_location = current_corner_location;
scale_data.percent =
c->animation.action == OPEN && animation_fade_in && !c->nofadein
? (double)c->animation.passed_frames / c->animation.total_frames
: 1.0;
scale_data.opacity = c->isfullscreen ? 1
: c == selmon->sel ? c->focused_opacity
: c->unfocused_opacity;
buffer_set_effect(c, scale_data);
} }
bool client_draw_frame(Client *c) { bool client_draw_frame(Client *c) {
@ -4713,22 +4742,24 @@ static void iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int sx,
int sy, void *user_data) { int sy, void *user_data) {
Client *c = user_data; Client *c = user_data;
struct wlr_scene_surface * scene_surface = wlr_scene_surface_try_from_buffer(buffer); struct wlr_scene_surface *scene_surface =
wlr_scene_surface_try_from_buffer(buffer);
if (!scene_surface) { if (!scene_surface) {
return; return;
} }
struct wlr_surface *surface = scene_surface->surface; struct wlr_surface *surface = scene_surface->surface;
/* we dont blur subsurfaces */ /* we dont blur subsurfaces */
if(wlr_subsurface_try_from_wlr_surface(surface) != NULL) return; if (wlr_subsurface_try_from_wlr_surface(surface) != NULL)
return;
if (blur && c) { if (blur && c) {
wlr_scene_buffer_set_backdrop_blur(buffer, true); wlr_scene_buffer_set_backdrop_blur(buffer, true);
wlr_scene_buffer_set_backdrop_blur_optimized(buffer, true); wlr_scene_buffer_set_backdrop_blur_optimized(buffer, true);
wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, true); wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, true);
} else { } else {
wlr_scene_buffer_set_backdrop_blur(buffer, false); wlr_scene_buffer_set_backdrop_blur(buffer, false);
} }
} }
void // old fix to 0.5 void // old fix to 0.5