backend: consolidate rendering code

This commit is contained in:
Victoria Brekenfeld 2022-02-04 21:04:17 +01:00
parent 78cc1713ad
commit b0cf94047f
7 changed files with 236 additions and 171 deletions

View file

@ -3,7 +3,7 @@
pub use smithay::{
desktop::Space,
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::{Logical, Rectangle, Size},
utils::{Logical, Point, Rectangle, Size},
wayland::output::Output,
};
use std::{cell::Cell, mem::MaybeUninit};
@ -126,6 +126,26 @@ impl Workspaces {
.size
}
pub fn global_space(&self) -> Rectangle<i32, Logical> {
let size = self.outputs.iter().fold((0, 0), |(w, h), output| {
let size = self.output_size(output);
(w + size.w, std::cmp::max(h, size.h))
});
Rectangle::from_loc_and_size((0, 0), size)
}
pub fn space_relative_output_geometry(
&self,
global_loc: impl Into<Point<i32, Logical>>,
output: &Output,
) -> Point<i32, Logical> {
match self.mode {
Mode::Global { .. } => global_loc.into(),
Mode::OutputBound => global_loc.into() - self.output_geometry(output).loc,
}
}
pub fn output_geometry(&self, output: &Output) -> Rectangle<i32, Logical> {
// due to our different modes, we cannot just ask the space for the global output coordinates,
// because for `Mode::OutputBound` the origin will always be (0, 0)