1
0
Fork 0
forked from wry/wry

zwlr_layer_surface_v1: center along unanchored axis

Per the wlr-layer-shell spec, if a surface is not anchored to either
edge on an axis, it should be centered along that axis. The previous
code left x1/y1 at 0 (top-left) in those cases.
This commit is contained in:
kossLAN 2026-04-04 01:48:00 -04:00
parent ba047d3a94
commit e80a328381
No known key found for this signature in database

View file

@ -498,22 +498,24 @@ impl ZwlrLayerSurfaceV1 {
_ => opos,
};
let (owidth, oheight) = rect.size();
let mut x1 = 0;
let mut y1 = 0;
if anchor.contains(LEFT | RIGHT) {
x1 = ml + (owidth - width - ml - mr) / 2;
let x1 = if anchor.contains(LEFT | RIGHT) {
ml + (owidth - width - ml - mr) / 2
} else if anchor.contains(LEFT) {
x1 = ml;
ml
} else if anchor.contains(RIGHT) {
x1 = owidth - width - mr;
}
if anchor.contains(TOP | BOTTOM) {
y1 = mt + (oheight - height - mt - mb) / 2;
owidth - width - mr
} else {
(owidth - width) / 2
};
let y1 = if anchor.contains(TOP | BOTTOM) {
mt + (oheight - height - mt - mb) / 2
} else if anchor.contains(TOP) {
y1 = mt;
mt
} else if anchor.contains(BOTTOM) {
y1 = oheight - height - mb;
}
oheight - height - mb
} else {
(oheight - height) / 2
};
let a_rect = Rect::new_sized_saturating(x1 + rect.x1(), y1 + rect.y1(), width, height);
let o_rect = a_rect.move_(-opos.x1(), -opos.y1());
self.output_extents.set(o_rect);