opt: optimize the scalability of the code for other window effect

This commit is contained in:
DreamMaoMao 2025-05-03 13:20:30 +08:00
parent 6479096b44
commit ec2e5d5019

View file

@ -146,6 +146,7 @@ struct vec2 {
struct uvec2 { struct uvec2 {
int x, y; int x, y;
}; };
typedef struct { typedef struct {
int i; int i;
float f; float f;
@ -191,7 +192,7 @@ typedef struct {
float height_scale; float height_scale;
int width; int width;
int height; int height;
Monitor *m; bool should_scale;
} animationScale; } animationScale;
typedef struct Client Client; typedef struct Client Client;
@ -603,21 +604,21 @@ static struct wlr_box setclient_coordinate_center(struct wlr_box geom,
int offsetx, int offsety); int offsetx, int offsety);
static unsigned int get_tags_first_tag(unsigned int tags); static unsigned int get_tags_first_tag(unsigned int tags);
void client_commit(Client *c); static void client_commit(Client *c);
void apply_border(Client *c, struct wlr_box clip_box, int offsetx, int offsety); static void apply_border(Client *c, struct wlr_box clip_box, int offsetx, int offsety);
void client_set_opacity(Client *c, double opacity); static void client_set_opacity(Client *c, double opacity);
void init_baked_points(void); static void init_baked_points(void);
void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer, int sx, int sy, static void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer, int sx, int sy,
void *data); void *data);
Client *direction_select(const Arg *arg); static Client *direction_select(const Arg *arg);
void view_in_mon(const Arg *arg, bool want_animation, Monitor *m); static void view_in_mon(const Arg *arg, bool want_animation, Monitor *m);
void buffer_set_size(Client *c, animationScale scale_data); static void buffer_set_effect(Client *c, animationScale scale_data);
void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, static void snap_scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx,
int sy, void *data); int sy, void *data);
void client_set_pending_state(Client *c); static void client_set_pending_state(Client *c);
void set_rect_size(struct wlr_scene_rect *rect, int width, int height); static void set_rect_size(struct wlr_scene_rect *rect, int width, int height);
#include "dispatch/dispatch.h" #include "dispatch/dispatch.h"
@ -944,7 +945,7 @@ void fadeout_client_animation_next_tick(Client *c) {
scale_data.height_scale = animation_passed; scale_data.height_scale = animation_passed;
wlr_scene_node_for_each_buffer(&c->scene->node, wlr_scene_node_for_each_buffer(&c->scene->node,
snap_scene_buffer_apply_size, &scale_data); snap_scene_buffer_apply_effect, &scale_data);
} }
if (animation_passed == 1.0) { if (animation_passed == 1.0) {
@ -1134,23 +1135,13 @@ struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) {
return offset; return offset;
} }
void apply_buffer_scale(Client *c, struct wlr_box clip_box,
struct wlr_box geom) {
animationScale scale_data;
scale_data.width = clip_box.width - 2 * c->bw;
scale_data.height = clip_box.height - 2 * c->bw;
scale_data.m = c->mon;
scale_data.width_scale = (float)scale_data.width / geom.width;
scale_data.height_scale = (float)scale_data.height / geom.height;
buffer_set_size(c, scale_data);
}
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;
if (!animations) { if (!animations) {
c->animation.running = false; c->animation.running = false;
@ -1161,7 +1152,7 @@ void client_apply_clip(Client *c) {
offset = clip_to_hide(c, &clip_box); offset = clip_to_hide(c, &clip_box);
apply_border(c, clip_box, offset.x, offset.y); apply_border(c, clip_box, offset.x, offset.y);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box);
/* apply_buffer_scale(c, clip_box); */ buffer_set_effect(c, (animationScale){0, 0, 0, 0, false});
return; return;
} }
@ -1186,7 +1177,13 @@ void client_apply_clip(Client *c) {
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box);
apply_border(c, clip_box, offset.x, offset.y); apply_border(c, clip_box, offset.x, offset.y);
apply_buffer_scale(c, clip_box, geometry);
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;
scale_data.height_scale = (float)scale_data.height / geometry.height;
buffer_set_effect(c, scale_data);
} }
bool client_draw_frame(Client *c) { bool client_draw_frame(Client *c) {
@ -4566,20 +4563,20 @@ void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer, int sx, int sy,
wlr_scene_buffer_set_opacity(buffer, *(double *)data); wlr_scene_buffer_set_opacity(buffer, *(double *)data);
} }
void scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy, void scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx, int sy,
void *data) { void *data) {
animationScale *scale_data = (animationScale *)data; animationScale *scale_data = (animationScale *)data;
if (scale_data->height_scale < 1 && scale_data->width_scale < 1) { if (scale_data->should_scale && scale_data->height_scale < 1 && scale_data->width_scale < 1) {
return; scale_data->should_scale = false;
} }
if (scale_data->height_scale == 1 && scale_data->width_scale < 1) { if (scale_data->should_scale && scale_data->height_scale == 1 && scale_data->width_scale < 1) {
return; scale_data->should_scale = false;
} }
if (scale_data->height_scale < 1 && scale_data->width_scale == 1) { if (scale_data->should_scale && scale_data->height_scale < 1 && scale_data->width_scale == 1) {
return; scale_data->should_scale = false;
} }
struct wlr_scene_surface *scene_surface = struct wlr_scene_surface *scene_surface =
@ -4590,6 +4587,8 @@ void scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy,
struct wlr_surface *surface = scene_surface->surface; struct wlr_surface *surface = scene_surface->surface;
if (scale_data->should_scale) {
uint32_t surface_width = surface->current.width; uint32_t surface_width = surface->current.width;
uint32_t surface_height = surface->current.height; uint32_t surface_height = surface->current.height;
@ -4614,29 +4613,32 @@ void scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy,
wlr_scene_buffer_set_dest_size(buffer, surface_width, surface_height); wlr_scene_buffer_set_dest_size(buffer, surface_width, surface_height);
} }
} }
// TODO: blur set, opacity set
void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, }
void snap_scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx,
int sy, void *data) { int sy, void *data) {
animationScale *scale_data = (animationScale *)data; animationScale *scale_data = (animationScale *)data;
wlr_scene_buffer_set_dest_size(buffer, scale_data->width, scale_data->height); wlr_scene_buffer_set_dest_size(buffer, scale_data->width, scale_data->height);
} }
void buffer_set_size(Client *c, animationScale data) { void buffer_set_effect(Client *c, animationScale data) {
if (c->iskilling || c->animation.tagouting || c->animation.tagouted || if (c->iskilling || c->animation.tagouting || c->animation.tagouted ||
c->animation.tagining) { c->animation.tagining) {
return; data.should_scale = false;
} }
if(client_is_x11(c) && c->current.height >= c->animation.current.height && c->current.width >= c->animation.current.width) { if(client_is_x11(c) && c->current.height >= c->animation.current.height && c->current.width >= c->animation.current.width) {
return; data.should_scale = false;
} }
if (c == grabc) if (c == grabc)
return; data.should_scale = false;
wlr_scene_node_for_each_buffer(&c->scene_surface->node, wlr_scene_node_for_each_buffer(&c->scene_surface->node,
scene_buffer_apply_size, &data); scene_buffer_apply_effect, &data);
} }
void client_set_opacity(Client *c, double opacity) { void client_set_opacity(Client *c, double opacity) {