1
0
Fork 0
forked from wry/wry

rect: safer construction

This commit is contained in:
Stipe Kotarac 2025-12-29 10:42:17 +01:00 committed by Julian Orth
parent 411af0ea18
commit a1dfc473a2
33 changed files with 245 additions and 159 deletions

View file

@ -123,13 +123,12 @@ impl Cursor for CursorSurface {
return rect;
}
let scale = scale.to_f64();
Rect::new(
Rect::new_saturating(
(rect.x1() as f64 * scale).ceil() as _,
(rect.y1() as f64 * scale).ceil() as _,
(rect.x2() as f64 * scale).ceil() as _,
(rect.y2() as f64 * scale).ceil() as _,
)
.unwrap()
}
fn set_output(&self, output: &Rc<OutputNode>) {

View file

@ -142,7 +142,7 @@ impl XwindowData {
let mut width = event.width as i32;
let mut height = event.height as i32;
client_wire_scale_to_logical!(client, x, y, width, height);
let extents = Rect::new_sized(x, y, width, height).unwrap();
let extents = Rect::new_sized_saturating(x, y, width, height);
// log::info!("xwin {} new {:?} or {}", event.window, extents, event.override_redirect);
Self {
state: state.clone(),

View file

@ -536,7 +536,7 @@ impl XdgSurfaceRequestHandler for XdgSurface {
if req.height <= 0 || req.width <= 0 {
return Err(XdgSurfaceError::NonPositiveWidthHeight);
}
let extents = Rect::new_sized(req.x, req.y, req.width, req.height).unwrap();
let extents = Rect::new_sized_saturating(req.x, req.y, req.width, req.height);
self.pending().geometry = Some(extents);
Ok(())
}

View file

@ -207,13 +207,12 @@ impl XdgPopup {
// use its position as is.
if let Some(maybe_abs_pos) = maybe_abs_pos {
abs_pos = maybe_abs_pos;
rel_pos = Rect::new_sized(
rel_pos = Rect::new_sized_saturating(
abs_pos.x1() - parent_abs.x1(),
abs_pos.y1() - parent_abs.y1(),
abs_pos.width(),
abs_pos.height(),
)
.unwrap();
);
}
}
}

View file

@ -514,7 +514,7 @@ impl ZwlrLayerSurfaceV1 {
} else if anchor.contains(BOTTOM) {
y1 = oheight - height - mb;
}
let a_rect = Rect::new_sized(x1 + rect.x1(), y1 + rect.y1(), width, height).unwrap();
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);
let a_rect_old = self.pos.replace(a_rect);