From e3a547d03d125be03e5c37a675d68afe1a70ea1a Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 22 Nov 2023 13:58:03 +0100 Subject: [PATCH] floating/resize: Fix local/global coordinate conversions --- src/shell/layout/floating/grabs/resize.rs | 5 +++-- src/shell/layout/floating/mod.rs | 27 ++++++++--------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index d245ef223..0bf281ccd 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -29,7 +29,7 @@ pub struct ResizeData { /// The edges the surface is being resized with. pub edges: ResizeEdge, /// The initial window location. - pub initial_window_location: Point, + pub initial_window_location: Point, /// The initial window size (geometry width and height). pub initial_window_size: Size, } @@ -277,7 +277,7 @@ impl ResizeSurfaceGrab { start_data: PointerGrabStartData, mapped: CosmicMapped, edges: ResizeEdge, - initial_window_location: Point, + initial_window_location: Point, initial_window_size: Size, seat: &Seat, ) -> ResizeSurfaceGrab { @@ -324,6 +324,7 @@ impl ResizeSurfaceGrab { initial_window_location, initial_window_size, } = resize_data; + let initial_window_location = initial_window_location.to_global(space.output()); if edges.intersects(ResizeEdge::TOP_LEFT) { let size = window.geometry().size; diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index dd2d83b93..4a1d0dedc 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -457,7 +457,7 @@ impl FloatingLayout { edges: ResizeEdge, ) -> Option { if seat.get_pointer().is_some() { - let location = self.space.element_location(&mapped).unwrap(); + let location = self.space.element_location(&mapped).unwrap().as_local(); let size = mapped.geometry().size; mapped.moved_since_mapped.store(true, Ordering::SeqCst); @@ -502,7 +502,7 @@ impl FloatingLayout { if edge.contains(ResizeEdge::RIGHT) || edge.contains(ResizeEdge::LEFT) { if direction == ResizeDirection::Inwards { - geo.size.w -= amount; + geo.size.w = (geo.size.w as u32).saturating_sub(amount as u32) as i32; } else { geo.size.w += amount; } @@ -510,13 +510,13 @@ impl FloatingLayout { if direction == ResizeDirection::Inwards { geo.loc.x += amount; } else { - geo.loc.x -= amount; + geo.loc.x = (geo.loc.x as u32).saturating_sub(amount as u32) as i32; } } } if edge.contains(ResizeEdge::BOTTOM) || edge.contains(ResizeEdge::TOP) { if direction == ResizeDirection::Inwards { - geo.size.h -= amount; + geo.size.h = (geo.size.h as u32).saturating_sub(amount as u32) as i32; } else { geo.size.h += amount; } @@ -524,24 +524,15 @@ impl FloatingLayout { if direction == ResizeDirection::Inwards { geo.loc.y += amount; } else { - geo.loc.y -= amount; + geo.loc.y = (geo.loc.y as u32).saturating_sub(amount as u32) as i32; } } } - let Some(bounding_box) = self + let bounding_box = self .space - .outputs() - .map(|o| self.space.output_geometry(o).unwrap()) - .filter(|output_geo| output_geo.overlaps(geo)) - .fold(None, |res, output_geo| match res { - None => Some(output_geo), - Some(other) => Some(other.merge(output_geo)), - }) - else { - return true; - }; - + .output_geometry(self.space.outputs().next().unwrap()) + .unwrap(); let (min_size, max_size) = (mapped.min_size(), mapped.max_size()); let min_width = min_size.map(|s| s.w).unwrap_or(360); let min_height = min_size.map(|s| s.h).unwrap_or(240); @@ -554,7 +545,7 @@ impl FloatingLayout { *mapped.resize_state.lock().unwrap() = Some(ResizeState::Resizing(ResizeData { edges: edge, - initial_window_location: original_geo.loc, + initial_window_location: original_geo.loc.as_local(), initial_window_size: original_geo.size, }));