From 0090122ffefc3aa4fdc5e0b833081734d5527c30 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 25 Jan 2023 14:09:44 +0100 Subject: [PATCH] shell: Don't use output-relative coords for windwo geometry --- src/shell/layout/floating/grabs/resize.rs | 13 ++++---- src/shell/layout/floating/mod.rs | 38 +++++++++++++++++++++-- src/shell/layout/tiling/mod.rs | 6 ++-- src/shell/workspace.rs | 9 +----- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index 7e11d9e6..d94cfa87 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -176,7 +176,7 @@ impl ResizeSurfaceGrab { } pub fn apply_resize_to_location(window: CosmicMapped, space: &mut Workspace) { - if let Some(mut location) = space.floating_layer.space.element_location(&window) { + if let Some(location) = space.floating_layer.space.element_location(&window) { let mut new_location = None; let mut resize_state = window.resize_state.lock().unwrap(); @@ -193,16 +193,15 @@ impl ResizeSurfaceGrab { if edges.intersects(ResizeEdge::TOP_LEFT) { let size = window.geometry().size; + let mut new = location.clone(); if edges.intersects(ResizeEdge::LEFT) { - location.x = - initial_window_location.x + (initial_window_size.w - size.w); + new.x = initial_window_location.x + (initial_window_size.w - size.w); } if edges.intersects(ResizeEdge::TOP) { - location.y = - initial_window_location.y + (initial_window_size.h - size.h); + new.y = initial_window_location.y + (initial_window_size.h - size.h); } - new_location = Some(location); + new_location = Some(new); } } _ => {} @@ -227,7 +226,7 @@ impl ResizeSurfaceGrab { } } let mut geometry = window.geometry(); - geometry.loc = new_location; + geometry.loc += location - new_location; let _ = window.set_geometry(geometry); space .floating_layer diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index fc3ec568..976e46cf 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -146,7 +146,16 @@ impl FloatingLayout { }); mapped.set_tiled(false); - mapped.set_geometry(Rectangle::from_loc_and_size(position, win_geo.size)); + let offset = output.geometry().loc + - self + .space + .output_geometry(output) + .map(|g| g.loc) + .unwrap_or_default(); + mapped.set_geometry(Rectangle::from_loc_and_size( + position + offset, + win_geo.size, + )); mapped.configure(); self.space.map_element(mapped, position, false); } @@ -199,7 +208,21 @@ impl FloatingLayout { let last_geometry = mapped.last_geometry.lock().unwrap().clone(); let last_size = last_geometry.map(|g| g.size).expect("No previous size?"); let last_location = last_geometry.map(|g| g.loc).expect("No previous location?"); - mapped.set_geometry(Rectangle::from_loc_and_size(last_location, last_size)); + let output = self + .space + .output_under(last_location.to_f64()) + .next() + .unwrap_or(self.space.outputs().next().unwrap()); + let offset = output.geometry().loc + - self + .space + .output_geometry(output) + .map(|g| g.loc) + .unwrap_or_default(); + mapped.set_geometry(Rectangle::from_loc_and_size( + last_location + offset, + last_size, + )); self.space.map_element(mapped, last_location, true); Some(last_size) } else { @@ -308,7 +331,16 @@ impl FloatingLayout { .get(&output) .copied() .unwrap_or_else(|| (0, 0).into()); - element.set_geometry(elem_geo); + let offset = output.geometry().loc + - self + .space + .output_geometry(&output) + .map(|g| g.loc) + .unwrap_or_default(); + element.set_geometry(Rectangle::from_loc_and_size( + elem_geo.loc + offset, + elem_geo.size, + )); self.space.map_element(element.clone(), elem_geo.loc, false); } self.refresh(); //fixup any out of bounds elements diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 91865b16..a192e120 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -1158,8 +1158,10 @@ impl TilingLayout { if !(mapped.is_fullscreen() || mapped.is_maximized()) { mapped.set_tiled(true); let size = (geo.size.w - inner * 2, geo.size.h - inner * 2); - let internal_geometry = - Rectangle::from_loc_and_size(geo.loc, size); + let internal_geometry = Rectangle::from_loc_and_size( + geo.loc + output.geometry().loc, + size, + ); if mapped.geometry() != internal_geometry { mapped.set_geometry(internal_geometry); mapped.configure(); diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 55e23dc1..f89f4c81 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -238,14 +238,7 @@ impl Workspace { mapped.set_active(window); } - let size = output - .current_mode() - .map(|m| m.size) - .unwrap_or((0, 0).into()) - .to_f64() - .to_logical(output.current_scale().fractional_scale()) - .to_i32_round(); - window.set_geometry(Rectangle::from_loc_and_size((0, 0), size)); + window.set_geometry(output.geometry()); window.send_configure(); self.fullscreen.insert(output.clone(), window.clone()); }