Skip to content

Commit

Permalink
floating/resize: Fix local/global coordinate conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Nov 22, 2023
1 parent 8834fc3 commit e3a547d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/shell/layout/floating/grabs/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32, Logical>,
pub initial_window_location: Point<i32, Local>,
/// The initial window size (geometry width and height).
pub initial_window_size: Size<i32, Logical>,
}
Expand Down Expand Up @@ -277,7 +277,7 @@ impl ResizeSurfaceGrab {
start_data: PointerGrabStartData<State>,
mapped: CosmicMapped,
edges: ResizeEdge,
initial_window_location: Point<i32, Logical>,
initial_window_location: Point<i32, Local>,
initial_window_size: Size<i32, Logical>,
seat: &Seat<State>,
) -> ResizeSurfaceGrab {
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 9 additions & 18 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl FloatingLayout {
edges: ResizeEdge,
) -> Option<ResizeSurfaceGrab> {
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);

Expand Down Expand Up @@ -502,46 +502,37 @@ 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;
}
if edge.contains(ResizeEdge::LEFT) {
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;
}
if edge.contains(ResizeEdge::TOP) {
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);
Expand All @@ -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,
}));

Expand Down

0 comments on commit e3a547d

Please sign in to comment.