opt: optimzie border offset caculate

This commit is contained in:
DreamMaoMao 2025-06-14 20:41:26 +08:00
parent e0c3101c0c
commit ed2595d9ad

View file

@ -1105,31 +1105,19 @@ bool check_hit_no_border(Client *c) {
return hit_no_border; return hit_no_border;
} }
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) {
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) { bool hit_no_border = check_hit_no_border(c);
clip_box.width = c->animation.current.width;
}
if (clip_box.height > c->animation.current.height) {
clip_box.height = c->animation.current.height;
}
hit_no_border = check_hit_no_border(c);
// Handle no-border cases
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) {
set_rect_size(c->border[0], 0, 0); for (int i = 0; i < 4; i++)
set_rect_size(c->border[1], 0, 0); set_rect_size(c->border[i], 0, 0);
set_rect_size(c->border[2], 0, 0);
set_rect_size(c->border[3], 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;
@ -1138,63 +1126,94 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx,
c->fake_no_border = false; c->fake_no_border = false;
} }
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw); struct wlr_box geom = c->animation.current;
set_rect_size(c->border[0], clip_box.width, c->bw); int bw = c->bw;
set_rect_size(c->border[1], clip_box.width, c->bw);
set_rect_size(c->border[2], c->bw, clip_box.height - 2 * c->bw);
set_rect_size(c->border[3], c->bw, clip_box.height - 2 * c->bw);
wlr_scene_node_set_position(&c->border[0]->node, 0, 0);
wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw);
wlr_scene_node_set_position(&c->border[1]->node, 0,
clip_box.height - c->bw);
wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw,
c->bw);
if (ISTILED(c) || c->animation.tagining || c->animation.tagouted || // Calculate how much the window is outside the monitor
c->animation.tagouting) { // These values will be positive when window is outside the monitor
if (c->animation.current.x < c->mon->m.x) { int outside_left = GEZERO(c->mon->m.x - c->animation.current.x);
set_rect_size(c->border[2], GEZERO(c->bw - offsetx), int outside_top = GEZERO(c->mon->m.y - c->animation.current.y);
clip_box.height - 2 * c->bw); int outside_right = GEZERO((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) { int outside_bottom = GEZERO((c->animation.current.y + c->animation.current.height) -
set_rect_size(c->border[3], (c->mon->m.y + c->mon->m.height));
GEZERO(c->bw - GEZERO(c->animation.current.x +
c->animation.current.width - // Initialize border dimensions
c->mon->m.x - c->mon->m.width)), int top_width = geom.width;
clip_box.height - 2 * c->bw); int top_height = bw;
set_rect_size(c->border[0], clip_box.width + c->bw, int bottom_width = geom.width;
GEZERO(c->bw - offsety)); int bottom_height = bw;
set_rect_size( int left_width = bw;
c->border[1], clip_box.width + c->bw, int left_height = geom.height - 2 * bw;
GEZERO(c->bw - GEZERO(c->animation.current.y + int right_width = bw;
c->animation.current.height - int right_height = geom.height - 2 * bw;
c->mon->m.y - c->mon->m.height)));
} else if (c->animation.current.y < c->mon->m.y) { // Initialize border positions
set_rect_size(c->border[0], clip_box.width, int top_x = 0;
GEZERO(c->bw - offsety)); int top_y = 0;
} else if (c->animation.current.y + c->animation.current.height > int bottom_x = 0;
c->mon->m.y + c->mon->m.height) { int bottom_y = geom.height - bottom_height;
set_rect_size( int left_x = 0;
c->border[1], clip_box.width, int left_y = bw;
GEZERO(c->bw - GEZERO(c->animation.current.y + int right_x = geom.width - right_width;
c->animation.current.height - int right_y = bw;
c->mon->m.y - c->mon->m.height)));
set_rect_size(c->border[2], GEZERO(c->bw - offsetx), // Adjust borders when window is outside monitor
clip_box.height - c->bw); if (ISTILED(c) || c->animation.tagining || c->animation.tagouted || c->animation.tagouting) {
set_rect_size(c->border[3], // Top border - reduce height when window goes above monitor
GEZERO(c->bw - GEZERO(c->animation.current.x + if (outside_top > 0) {
c->animation.current.width - top_height = GEZERO(bw - outside_top);
c->mon->m.x - c->mon->m.width)), top_y = top_y + outside_top;
clip_box.height - c->bw); left_height = left_height - outside_top;
} right_height = right_height - outside_top;
left_y = left_y + outside_top;
right_y = right_y + outside_top;
} }
wlr_scene_node_set_position(&c->border[0]->node, offsetx, offsety); // Bottom border - reduce height when window goes below monitor
wlr_scene_node_set_position(&c->border[2]->node, offsetx, c->bw + offsety); if (outside_bottom > 0) {
wlr_scene_node_set_position(&c->border[1]->node, offsetx, bottom_height = GEZERO(bw - outside_bottom);
clip_box.height - c->bw + offsety); left_height = left_height - outside_bottom;
wlr_scene_node_set_position( right_height = right_height - outside_bottom;
&c->border[3]->node, clip_box.width - c->bw + offsetx, c->bw + offsety); }
// Left border - reduce width when window goes left of monitor
if (outside_left > 0) {
left_width = GEZERO(bw - outside_left);
left_x = left_x + outside_left;
top_width = top_width - outside_left;
bottom_width = bottom_width - outside_left;
top_x = top_x + outside_left;
bottom_x = bottom_x + outside_left;
}
// Right border - reduce width when window goes right of monitor
if (outside_right > 0) {
right_width = GEZERO(bw - outside_right);
top_width = top_width - outside_right;
bottom_width = bottom_width - outside_right;
}
}
// Position the surface within the borders
wlr_scene_node_set_position(&c->scene_surface->node,
bw,
bw);
// Set border sizes
set_rect_size(c->border[0], top_width, top_height); // Top
set_rect_size(c->border[1], bottom_width, bottom_height); // Bottom
set_rect_size(c->border[2], left_width, left_height); // Left
set_rect_size(c->border[3], right_width, right_height); // Right
// Position borders with offsets
wlr_scene_node_set_position(&c->border[0]->node, top_x, top_y );
wlr_scene_node_set_position(&c->border[1]->node, bottom_x, bottom_y);
wlr_scene_node_set_position(&c->border[2]->node, left_x , left_y);
wlr_scene_node_set_position(&c->border[3]->node, right_x, right_y);
} }
struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) {