opt: reduce Repetitive calculation

This commit is contained in:
DreamMaoMao 2026-02-17 17:26:55 +08:00
parent c3dcee2c8e
commit b1c957dcc5
3 changed files with 351 additions and 410 deletions

View file

@ -250,369 +250,299 @@ void buffer_set_effect(Client *c, BufferData data) {
scene_buffer_apply_effect, &data); scene_buffer_apply_effect, &data);
} }
void client_draw_shadow(Client *c) { void client_draw_shadow(Client *c, int32_t left_offset, int32_t top_offset,
int32_t right_offset, int32_t bottom_offset,
enum corner_location current_corner_location) {
if (c->iskilling || !client_surface(c)->mapped || c->isnoshadow)
return;
if (c->iskilling || !client_surface(c)->mapped || c->isnoshadow) if (!shadows || (!c->isfloating && shadow_only_floating)) {
return; if (c->shadow->node.enabled)
wlr_scene_node_set_enabled(&c->shadow->node, false);
return;
} else {
if (c->scene_surface->node.enabled && !c->shadow->node.enabled)
wlr_scene_node_set_enabled(&c->shadow->node, true);
}
if (!shadows || (!c->isfloating && shadow_only_floating)) { bool hit_no_border = check_hit_no_border(c);
if (c->shadow->node.enabled) if (c->isfullscreen || (no_radius_when_single && c->mon &&
wlr_scene_node_set_enabled(&c->shadow->node, false); c->mon->visible_tiling_clients == 1)) {
return; current_corner_location = CORNER_LOCATION_NONE;
} else { }
if (c->scene_surface->node.enabled && !c->shadow->node.enabled)
wlr_scene_node_set_enabled(&c->shadow->node, true);
}
bool hit_no_border = check_hit_no_border(c); int32_t bwoffset = c->bw != 0 && hit_no_border ? (int32_t)c->bw : 0;
enum corner_location current_corner_location =
c->isfullscreen || (no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)
? CORNER_LOCATION_NONE
: CORNER_LOCATION_ALL;
int32_t bwoffset = c->bw != 0 && hit_no_border ? (int32_t)c->bw : 0; int32_t width, height;
client_actual_size(c, &width, &height);
int32_t width, height; int32_t delta = shadows_size + (int32_t)c->bw - bwoffset;
client_actual_size(c, &width, &height);
int32_t delta = shadows_size + (int32_t)c->bw - bwoffset; struct wlr_box client_box = {
.x = bwoffset,
.y = bwoffset,
.width = width + (int32_t)c->bw - bwoffset,
.height = height + (int32_t)c->bw - bwoffset,
};
/* we calculate where to clip the shadow */ struct wlr_box shadow_box = {
struct wlr_box client_box = { .x = shadows_position_x + bwoffset,
.x = bwoffset, .y = shadows_position_y + bwoffset,
.y = bwoffset, .width = width + 2 * delta,
.width = width + (int32_t)c->bw - bwoffset, .height = height + 2 * delta,
.height = height + (int32_t)c->bw - bwoffset, };
};
struct wlr_box shadow_box = { struct wlr_box intersection_box;
.x = shadows_position_x + bwoffset, wlr_box_intersection(&intersection_box, &client_box, &shadow_box);
.y = shadows_position_y + bwoffset, intersection_box.x -= shadows_position_x + bwoffset;
.width = width + 2 * delta, intersection_box.y -= shadows_position_y + bwoffset;
.height = height + 2 * delta,
};
struct wlr_box intersection_box; struct clipped_region clipped_region = {
wlr_box_intersection(&intersection_box, &client_box, &shadow_box); .area = intersection_box,
/* clipped region takes shadow relative coords, so we translate everything .corner_radius = border_radius,
* by its position */ .corners = current_corner_location,
intersection_box.x -= shadows_position_x + bwoffset; };
intersection_box.y -= shadows_position_y + bwoffset;
struct clipped_region clipped_region = { struct wlr_box absolute_shadow_box = {
.area = intersection_box, .x = shadow_box.x + c->animation.current.x,
.corner_radius = border_radius, .y = shadow_box.y + c->animation.current.y,
.corners = current_corner_location, .width = shadow_box.width,
}; .height = shadow_box.height,
};
struct wlr_box absolute_shadow_box = { int32_t right_out, bottom_out, left_out, top_out;
.x = shadow_box.x + c->animation.current.x, if (c == grabc) {
.y = shadow_box.y + c->animation.current.y, right_out = 0; bottom_out = 0; left_out = 0; top_out = 0;
.width = shadow_box.width, } else {
.height = shadow_box.height, right_out = GEZERO(absolute_shadow_box.x + absolute_shadow_box.width -
}; c->mon->m.x - c->mon->m.width);
bottom_out = GEZERO(absolute_shadow_box.y + absolute_shadow_box.height -
c->mon->m.y - c->mon->m.height);
left_out = GEZERO(c->mon->m.x - absolute_shadow_box.x);
top_out = GEZERO(c->mon->m.y - absolute_shadow_box.y);
}
int32_t right_offset, bottom_offset, left_offset, top_offset; left_out = MIN(left_out, shadow_box.width);
right_out = MIN(right_out, shadow_box.width);
top_out = MIN(top_out, shadow_box.height);
bottom_out = MIN(bottom_out, shadow_box.height);
if (c == grabc) { wlr_scene_node_set_position(&c->shadow->node, shadow_box.x + left_out,
right_offset = 0; shadow_box.y + top_out);
bottom_offset = 0;
left_offset = 0;
top_offset = 0;
} else {
right_offset =
GEZERO(absolute_shadow_box.x + absolute_shadow_box.width -
c->mon->m.x - c->mon->m.width);
bottom_offset =
GEZERO(absolute_shadow_box.y + absolute_shadow_box.height -
c->mon->m.y - c->mon->m.height);
left_offset = GEZERO(c->mon->m.x - absolute_shadow_box.x); wlr_scene_shadow_set_size(c->shadow,
top_offset = GEZERO(c->mon->m.y - absolute_shadow_box.y); GEZERO(shadow_box.width - left_out - right_out),
} GEZERO(shadow_box.height - top_out - bottom_out));
left_offset = MIN(left_offset, shadow_box.width); clipped_region.area.x -= left_out;
right_offset = MIN(right_offset, shadow_box.width); clipped_region.area.y -= top_out;
top_offset = MIN(top_offset, shadow_box.height); wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region);
bottom_offset = MIN(bottom_offset, shadow_box.height);
wlr_scene_node_set_position(&c->shadow->node, shadow_box.x + left_offset,
shadow_box.y + top_offset);
wlr_scene_shadow_set_size(
c->shadow, GEZERO(shadow_box.width - left_offset - right_offset),
GEZERO(shadow_box.height - top_offset - bottom_offset));
clipped_region.area.x = clipped_region.area.x - left_offset;
clipped_region.area.y = clipped_region.area.y - top_offset;
wlr_scene_shadow_set_clipped_region(c->shadow, clipped_region);
} }
void apply_border(Client *c) { void apply_border(Client *c, int32_t left_offset, int32_t top_offset,
if (!c || c->iskilling || !client_surface(c)->mapped) int32_t right_offset, int32_t bottom_offset,
return; enum corner_location current_corner_location) {
if (!c || c->iskilling || !client_surface(c)->mapped)
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; if (c->isfullscreen || (no_radius_when_single && c->mon &&
if (c->isfullscreen || (no_radius_when_single && c->mon && c->mon->visible_tiling_clients == 1)) {
c->mon->visible_tiling_clients == 1)) { current_corner_location = CORNER_LOCATION_NONE;
current_corner_location = CORNER_LOCATION_NONE; }
} else {
current_corner_location = set_client_corner_location(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;
} }
struct wlr_box clip_box = c->animation.current; struct wlr_box clip_box = c->animation.current;
// 一但在GEZERO如果使用无符号那么其他数据也会转换为无符号导致没有负数出错 int32_t bw = (int32_t)c->bw;
int32_t bw = (int32_t)c->bw;
int32_t right_offset, bottom_offset, left_offset, top_offset; int32_t inner_surface_width = GEZERO(clip_box.width - 2 * bw);
int32_t inner_surface_height = GEZERO(clip_box.height - 2 * bw);
if (c == grabc) { int32_t inner_surface_x = GEZERO(bw - left_offset);
right_offset = 0; int32_t inner_surface_y = GEZERO(bw - top_offset);
bottom_offset = 0;
left_offset = 0;
top_offset = 0;
} else {
right_offset =
GEZERO(c->animation.current.x + c->animation.current.width -
c->mon->m.x - c->mon->m.width);
bottom_offset =
GEZERO(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
left_offset = GEZERO(c->mon->m.x - c->animation.current.x); int32_t rect_x = left_offset;
top_offset = GEZERO(c->mon->m.y - c->animation.current.y); int32_t rect_y = top_offset;
}
int32_t inner_surface_width = GEZERO(clip_box.width - 2 * bw); int32_t rect_width = GEZERO(c->animation.current.width - left_offset - right_offset);
int32_t inner_surface_height = GEZERO(clip_box.height - 2 * bw); int32_t rect_height = GEZERO(c->animation.current.height - top_offset - bottom_offset);
int32_t inner_surface_x = GEZERO(bw - left_offset); if (left_offset > c->bw)
int32_t inner_surface_y = GEZERO(bw - top_offset); inner_surface_width = inner_surface_width - left_offset + (int32_t)c->bw;
if (top_offset > c->bw)
inner_surface_height = inner_surface_height - top_offset + (int32_t)c->bw;
if (right_offset > 0)
inner_surface_width = MIN(clip_box.width, inner_surface_width + right_offset);
if (bottom_offset > 0)
inner_surface_height = MIN(clip_box.height, inner_surface_height + bottom_offset);
int32_t rect_x = left_offset; struct clipped_region clipped_region = {
int32_t rect_y = top_offset; .area = {inner_surface_x, inner_surface_y, inner_surface_width,
inner_surface_height},
.corner_radius = border_radius,
.corners = current_corner_location,
};
int32_t rect_width = wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
GEZERO(c->animation.current.width - left_offset - right_offset); wlr_scene_node_set_position(&c->border->node, rect_x, rect_y);
int32_t rect_height = wlr_scene_rect_set_size(c->border, rect_width, rect_height);
GEZERO(c->animation.current.height - top_offset - bottom_offset); wlr_scene_rect_set_corner_radius(c->border, border_radius,
current_corner_location);
if (left_offset > c->bw) wlr_scene_rect_set_clipped_region(c->border, clipped_region);
inner_surface_width =
inner_surface_width - left_offset + (int32_t)c->bw;
if (top_offset > c->bw)
inner_surface_height =
inner_surface_height - top_offset + (int32_t)c->bw;
if (right_offset > 0) {
inner_surface_width =
MIN(clip_box.width, inner_surface_width + right_offset);
}
if (bottom_offset > 0) {
inner_surface_height =
MIN(clip_box.height, inner_surface_height + bottom_offset);
}
struct clipped_region clipped_region = {
.area = {inner_surface_x, inner_surface_y, inner_surface_width,
inner_surface_height},
.corner_radius = 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, border_radius,
current_corner_location);
wlr_scene_rect_set_clipped_region(c->border, clipped_region);
} }
struct ivec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { struct ivec2 clip_to_hide(Client *c, struct wlr_box *clip_box,
int32_t offsetx = 0, offsety = 0, offsetw = 0, offseth = 0; int32_t left_offset, int32_t top_offset,
struct ivec2 offset = {0, 0, 0, 0}; int32_t right_offset, int32_t bottom_offset) {
int32_t offsetx = 0, offsety = 0, offsetw = 0, offseth = 0;
struct ivec2 offset = {0, 0, 0, 0};
if (!ISSCROLLTILED(c) && !c->animation.tagining && !c->animation.tagouted && if (!ISSCROLLTILED(c) && !c->animation.tagining && !c->animation.tagouted &&
!c->animation.tagouting) !c->animation.tagouting)
return offset; return offset;
int32_t bottom_out_offset = int32_t bw = (int32_t)c->bw;
GEZERO(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
int32_t right_out_offset =
GEZERO(c->animation.current.x + c->animation.current.width -
c->mon->m.x - c->mon->m.width);
int32_t left_out_offset = GEZERO(c->mon->m.x - c->animation.current.x);
int32_t top_out_offset = GEZERO(c->mon->m.y - c->animation.current.y);
// 必须转换为int否计算会没有负数导致判断错误 if (ISSCROLLTILED(c) || c->animation.tagining || c->animation.tagouted ||
int32_t bw = (int32_t)c->bw; c->animation.tagouting) {
if (left_offset > 0) {
offsetx = GEZERO(left_offset - bw);
clip_box->x = clip_box->x + offsetx;
clip_box->width = clip_box->width - offsetx;
} else if (right_offset > 0) {
offsetw = GEZERO(right_offset - bw);
clip_box->width = clip_box->width - offsetw;
}
/* if (top_offset > 0) {
offsety = GEZERO(top_offset - bw);
border超出屏幕的时候不计算如偏差之内而是 clip_box->y = clip_box->y + offsety;
clip_box->height = clip_box->height - offsety;
*/ } else if (bottom_offset > 0) {
if (ISSCROLLTILED(c) || c->animation.tagining || c->animation.tagouted || offseth = GEZERO(bottom_offset - bw);
c->animation.tagouting) { clip_box->height = clip_box->height - offseth;
if (left_out_offset > 0) { }
offsetx = GEZERO(left_out_offset - bw); }
clip_box->x = clip_box->x + offsetx;
clip_box->width = clip_box->width - offsetx;
} else if (right_out_offset > 0) {
offsetw = GEZERO(right_out_offset - bw);
clip_box->width = clip_box->width - offsetw;
}
if (top_out_offset > 0) { offset.x = offsetx;
offsety = GEZERO(top_out_offset - bw); offset.y = offsety;
clip_box->y = clip_box->y + offsety; offset.width = offsetw;
clip_box->height = clip_box->height - offsety; offset.height = offseth;
} else if (bottom_out_offset > 0) {
offseth = GEZERO(bottom_out_offset - bw);
clip_box->height = clip_box->height - offseth;
}
}
// 窗口表面超出屏幕四个方向的偏差 if ((clip_box->width + bw <= 0 || clip_box->height + bw <= 0) &&
offset.x = offsetx; (ISSCROLLTILED(c) || c->animation.tagouting || c->animation.tagining)) {
offset.y = offsety; c->is_clip_to_hide = true;
offset.width = offsetw; wlr_scene_node_set_enabled(&c->scene->node, false);
offset.height = offseth; } else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) {
c->is_clip_to_hide = false;
wlr_scene_node_set_enabled(&c->scene->node, true);
}
if ((clip_box->width + bw <= 0 || clip_box->height + bw <= 0) && return offset;
(ISSCROLLTILED(c) || c->animation.tagouting || c->animation.tagining)) {
c->is_clip_to_hide = true;
wlr_scene_node_set_enabled(&c->scene->node, false);
} else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) {
c->is_clip_to_hide = false;
wlr_scene_node_set_enabled(&c->scene->node, true);
}
return offset;
} }
void client_apply_clip(Client *c, float factor) { void client_apply_clip(Client *c, float factor) {
if (c->iskilling || !client_surface(c)->mapped)
return;
if (c->iskilling || !client_surface(c)->mapped) struct wlr_box clip_box;
return; bool should_render_client_surface = false;
struct ivec2 offset;
BufferData buffer_data;
struct wlr_box clip_box; // 一次性计算四个方向的溢出偏移量
bool should_render_client_surface = false; int32_t left_offset = GEZERO(c->mon->m.x - c->animation.current.x);
struct ivec2 offset; int32_t top_offset = GEZERO(c->mon->m.y - c->animation.current.y);
BufferData buffer_data; int32_t right_offset = GEZERO(c->animation.current.x + c->animation.current.width -
c->mon->m.x - c->mon->m.width);
int32_t bottom_offset = GEZERO(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
enum corner_location current_corner_location = // 计算圆角位置(只一次)
set_client_corner_location(c); 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, left_offset, top_offset, right_offset, bottom_offset);
offset = clip_to_hide(c, &clip_box); apply_border(c, left_offset, top_offset, right_offset, bottom_offset, current_corner_location);
client_draw_shadow(c, left_offset, top_offset, right_offset, bottom_offset, current_corner_location);
apply_border(c); if (clip_box.width <= 0 || clip_box.height <= 0) return;
client_draw_shadow(c);
if (clip_box.width <= 0 || clip_box.height <= 0) { wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box);
return; buffer_set_effect(c, (BufferData){1.0f, 1.0f, clip_box.width,
} clip_box.height,
current_corner_location, true});
return;
}
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); int32_t width, height;
buffer_set_effect(c, (BufferData){1.0f, 1.0f, clip_box.width, client_actual_size(c, &width, &height);
clip_box.height, struct wlr_box geometry;
current_corner_location, true}); client_get_geometry(c, &geometry);
return; clip_box = (struct wlr_box){
} .x = geometry.x,
.y = geometry.y,
.width = width,
.height = height,
};
if (client_is_x11(c)) {
clip_box.x = 0;
clip_box.y = 0;
}
// 获取窗口动画实时位置矩形 offset = clip_to_hide(c, &clip_box, left_offset, top_offset, right_offset, bottom_offset);
int32_t width, height;
client_actual_size(c, &width, &height);
// 计算出除了边框的窗口实际剪切大小 apply_border(c, left_offset, top_offset, right_offset, bottom_offset, current_corner_location);
struct wlr_box geometry; client_draw_shadow(c, left_offset, top_offset, right_offset, bottom_offset, current_corner_location);
client_get_geometry(c, &geometry);
clip_box = (struct wlr_box){
.x = geometry.x,
.y = geometry.y,
.width = width,
.height = height,
};
if (client_is_x11(c)) { if (clip_box.width <= 0 || clip_box.height <= 0) {
clip_box.x = 0; should_render_client_surface = false;
clip_box.y = 0; wlr_scene_node_set_enabled(&c->scene_surface->node, false);
} } else {
should_render_client_surface = true;
wlr_scene_node_set_enabled(&c->scene_surface->node, true);
}
// 检测窗口是否需要剪切超出屏幕部分,如果需要就调整实际要剪切的矩形 if (!should_render_client_surface) return;
offset = clip_to_hide(c, &clip_box);
// 应用窗口装饰 wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box);
apply_border(c);
client_draw_shadow(c);
// 如果窗口剪切区域已经剪切到0则不渲染窗口表面 int32_t acutal_surface_width = geometry.width - offset.x - offset.width;
if (clip_box.width <= 0 || clip_box.height <= 0) { int32_t acutal_surface_height = geometry.height - offset.y - offset.height;
should_render_client_surface = false; if (acutal_surface_width <= 0 || acutal_surface_height <= 0) return;
wlr_scene_node_set_enabled(&c->scene_surface->node, false);
} else {
should_render_client_surface = true;
wlr_scene_node_set_enabled(&c->scene_surface->node, true);
}
// 不用在执行下面的窗口表面剪切和缩放等效果操作 buffer_data.should_scale = true;
if (!should_render_client_surface) { buffer_data.width = clip_box.width;
return; buffer_data.height = clip_box.height;
} buffer_data.corner_location = current_corner_location;
// 应用窗口表面剪切 if (factor == 1.0) {
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); buffer_data.width_scale = 1.0;
buffer_data.height_scale = 1.0;
} else {
buffer_data.width_scale = (float)buffer_data.width / acutal_surface_width;
buffer_data.height_scale = (float)buffer_data.height / acutal_surface_height;
}
// 获取剪切后的表面的实际大小用于计算缩放 buffer_set_effect(c, buffer_data);
int32_t acutal_surface_width = geometry.width - offset.x - offset.width;
int32_t acutal_surface_height = geometry.height - offset.y - offset.height;
if (acutal_surface_width <= 0 || acutal_surface_height <= 0)
return;
buffer_data.should_scale = true;
buffer_data.width = clip_box.width;
buffer_data.height = clip_box.height;
buffer_data.corner_location = current_corner_location;
if (factor == 1.0) {
buffer_data.width_scale = 1.0;
buffer_data.height_scale = 1.0;
} else {
buffer_data.width_scale =
(float)buffer_data.width / acutal_surface_width;
buffer_data.height_scale =
(float)buffer_data.height / acutal_surface_height;
}
buffer_set_effect(c, buffer_data);
} }
void fadeout_client_animation_next_tick(Client *c) { void fadeout_client_animation_next_tick(Client *c) {
@ -908,129 +838,138 @@ void client_set_pending_state(Client *c) {
} }
void resize(Client *c, struct wlr_box geo, int32_t interact) { void resize(Client *c, struct wlr_box geo, int32_t interact) {
// 动画设置的起始函数,这里用来计算一些动画的起始值
// 动画起始位置大小是由于c->animainit_geom确定的
// 动画设置的起始函数,这里用来计算一些动画的起始值 if (!c || !c->mon || !client_surface(c)->mapped)
// 动画起始位置大小是由于c->animainit_geom确定的 return;
if (!c || !c->mon || !client_surface(c)->mapped) struct wlr_box *bbox;
return; struct wlr_box clip;
struct wlr_box *bbox; if (!c->mon)
struct wlr_box clip; return;
if (!c->mon) c->need_output_flush = true;
return; c->dirty = true;
c->need_output_flush = true; // float_geom = c->geom;
c->dirty = true; bbox = (interact || c->isfloating || c->isfullscreen) ? &sgeom : &c->mon->w;
// float_geom = c->geom; if (is_scroller_layout(c->mon) && (!c->isfloating || c == grabc)) {
bbox = (interact || c->isfloating || c->isfullscreen) ? &sgeom : &c->mon->w; c->geom = geo;
c->geom.width = MAX(1 + 2 * (int32_t)c->bw, c->geom.width);
c->geom.height = MAX(1 + 2 * (int32_t)c->bw, c->geom.height);
} else { // 这里会限制不允许窗口划出屏幕
c->geom = geo;
applybounds(c, bbox);
}
if (is_scroller_layout(c->mon) && (!c->isfloating || c == grabc)) { if (!c->isnosizehint && !c->ismaximizescreen && !c->isfullscreen &&
c->geom = geo; c->isfloating) {
c->geom.width = MAX(1 + 2 * (int32_t)c->bw, c->geom.width); client_set_size_bound(c);
c->geom.height = MAX(1 + 2 * (int32_t)c->bw, c->geom.height); }
} else { // 这里会限制不允许窗口划出屏幕
c->geom = geo;
applybounds(
c,
bbox); // 去掉这个推荐的窗口大小,因为有时推荐的窗口特别大导致平铺异常
}
if (!c->isnosizehint && !c->ismaximizescreen && !c->isfullscreen && if (!c->is_pending_open_animation) {
c->isfloating) { c->animation.begin_fade_in = false;
client_set_size_bound(c); }
}
if (!c->is_pending_open_animation) { if (c->animation.action == OPEN && !c->animation.tagining &&
c->animation.begin_fade_in = false; !c->animation.tagouting && wlr_box_equal(&c->geom, &c->current)) {
} c->animation.action = c->animation.action;
} else if (c->animation.tagouting) {
c->animation.duration = animation_duration_tag;
c->animation.action = TAG;
} else if (c->animation.tagining) {
c->animation.duration = animation_duration_tag;
c->animation.action = TAG;
} else if (c->is_pending_open_animation) {
c->animation.duration = animation_duration_open;
c->animation.action = OPEN;
} else {
c->animation.duration = animation_duration_move;
c->animation.action = MOVE;
}
if (c->animation.action == OPEN && !c->animation.tagining && // 动画起始位置大小设置
!c->animation.tagouting && wlr_box_equal(&c->geom, &c->current)) { if (c->animation.tagouting) {
c->animation.action = c->animation.action; c->animainit_geom = c->animation.current;
} else if (c->animation.tagouting) { } else if (c->animation.tagining) {
c->animation.duration = animation_duration_tag; c->animainit_geom.height = c->animation.current.height;
c->animation.action = TAG; c->animainit_geom.width = c->animation.current.width;
} else if (c->animation.tagining) { } else if (c->is_pending_open_animation) {
c->animation.duration = animation_duration_tag; set_client_open_animation(c, c->geom);
c->animation.action = TAG; } else {
} else if (c->is_pending_open_animation) { c->animainit_geom = c->animation.current;
c->animation.duration = animation_duration_open; }
c->animation.action = OPEN;
} else {
c->animation.duration = animation_duration_move;
c->animation.action = MOVE;
}
// 动画起始位置大小设置 if (c->isnoborder || c->iskilling) {
if (c->animation.tagouting) { c->bw = 0;
c->animainit_geom = c->animation.current; }
} else if (c->animation.tagining) {
c->animainit_geom.height = c->animation.current.height;
c->animainit_geom.width = c->animation.current.width;
} else if (c->is_pending_open_animation) {
set_client_open_animation(c, c->geom);
} else {
c->animainit_geom = c->animation.current;
}
if (c->isnoborder || c->iskilling) { bool hit_no_border = check_hit_no_border(c);
c->bw = 0; if (hit_no_border && smartgaps) {
} c->bw = 0;
c->fake_no_border = true;
}
bool hit_no_border = check_hit_no_border(c); // c->geom 是真实的窗口大小和位置,跟过度的动画无关,用于计算布局
if (hit_no_border && smartgaps) { c->configure_serial = client_set_size(c, c->geom.width - 2 * c->bw,
c->bw = 0; c->geom.height - 2 * c->bw);
c->fake_no_border = true;
}
// c->geom 是真实的窗口大小和位置,跟过度的动画无关,用于计算布局 if (c == grabc) {
c->configure_serial = client_set_size(c, c->geom.width - 2 * c->bw, c->animation.running = false;
c->geom.height - 2 * c->bw); c->need_output_flush = false;
if (c == grabc) { c->animainit_geom = c->current = c->pending = c->animation.current = c->geom;
c->animation.running = false; wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
c->need_output_flush = false;
c->animainit_geom = c->current = c->pending = c->animation.current = // 计算当前窗口相对于显示器的偏移量(用于边框和阴影)
c->geom; int32_t left_offset = GEZERO(c->mon->m.x - c->geom.x);
wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y); int32_t top_offset = GEZERO(c->mon->m.y - c->geom.y);
int32_t right_offset = GEZERO(c->geom.x + c->geom.width -
c->mon->m.x - c->mon->m.width);
int32_t bottom_offset = GEZERO(c->geom.y + c->geom.height -
c->mon->m.y - c->mon->m.height);
enum corner_location current_corner_location = set_client_corner_location(c);
client_draw_shadow(c); // 传入偏移量和圆角位置
apply_border(c); client_draw_shadow(c, left_offset, top_offset, right_offset, bottom_offset,
client_get_clip(c, &clip); current_corner_location);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip); apply_border(c, left_offset, top_offset, right_offset, bottom_offset,
return; current_corner_location);
} client_get_clip(c, &clip);
// 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小 wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
// c->pending 决定动画的终点一般在其他调用resize的函数的附近设置了 return;
if (!c->animation.tagouting && !c->iskilling) { }
c->pending = c->geom;
}
if (c->swallowedby && c->animation.action == OPEN) { // 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小
c->animainit_geom = c->swallowedby->animation.current; // c->pending 决定动画的终点一般在其他调用resize的函数的附近设置了
} if (!c->animation.tagouting && !c->iskilling) {
c->pending = c->geom;
}
if (c->swallowing) { if (c->swallowedby && c->animation.action == OPEN) {
c->animainit_geom = c->geom; c->animainit_geom = c->swallowedby->animation.current;
} }
if ((c->isglobal || c->isunglobal) && c->isfloating && if (c->swallowing) {
c->animation.action == TAG) { c->animainit_geom = c->geom;
c->animainit_geom = c->geom; }
}
if (c->scratchpad_switching_mon && c->isfloating) { if ((c->isglobal || c->isunglobal) && c->isfloating &&
c->animainit_geom = c->geom; c->animation.action == TAG) {
} c->animainit_geom = c->geom;
}
// 开始应用动画设置 if (c->scratchpad_switching_mon && c->isfloating) {
client_set_pending_state(c); c->animainit_geom = c->geom;
}
setborder_color(c); // 开始应用动画设置
client_set_pending_state(c);
setborder_color(c);
} }
bool client_draw_fadeout_frame(Client *c) { bool client_draw_fadeout_frame(Client *c) {

View file

@ -72,10 +72,10 @@ void init_baked_points(void) {
} }
double find_animation_curve_at(double t, int32_t type) { double find_animation_curve_at(double t, int32_t type) {
int32_t down = 0; uint32_t down = 0;
int32_t up = BAKED_POINTS_COUNT - 1; uint32_t up = BAKED_POINTS_COUNT - 1;
int32_t middle = (up + down) / 2; uint32_t middle = (up + down) / 2;
struct dvec2 *baked_points; struct dvec2 *baked_points;
if (type == MOVE) { if (type == MOVE) {
baked_points = baked_points_move; baked_points = baked_points_move;

View file

@ -717,7 +717,9 @@ get_nearest_output_mode(struct wlr_output *output, int32_t width,
static void client_commit(Client *c); static void client_commit(Client *c);
static void layer_commit(LayerSurface *l); static void layer_commit(LayerSurface *l);
static void apply_border(Client *c); static void apply_border(Client *c, int32_t left_offset, int32_t top_offset,
int32_t right_offset, int32_t bottom_offset,
enum corner_location current_corner_location);
static void client_set_opacity(Client *c, double opacity); static void client_set_opacity(Client *c, double opacity);
static void init_baked_points(void); static void init_baked_points(void);
static void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer, static void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer,