use smithay::{ output::Output, utils::{Coordinate, Logical, Point, Rectangle, Size}, }; use super::prelude::OutputExt; /// Marker type for coordinates in global space #[derive(Debug)] pub struct Global; /// Marker type for coordinates in workspace local space #[derive(Debug)] pub struct Local; pub trait PointExt { fn as_global(self) -> Point; fn as_local(self) -> Point; } pub trait PointGlobalExt { fn to_local(self, output: &Output) -> Point; fn as_logical(self) -> Point; } pub trait PointLocalExt { fn to_global(self, output: &Output) -> Point; fn as_logical(self) -> Point; } pub trait SizeExt { fn as_logical(self) -> Size; fn as_local(self) -> Size; fn as_global(self) -> Size; } pub trait RectExt { fn as_global(self) -> Rectangle; fn as_local(self) -> Rectangle; } pub trait RectGlobalExt { fn to_local(self, output: &Output) -> Rectangle; fn as_logical(self) -> Rectangle; } pub trait RectLocalExt { fn to_global(self, output: &Output) -> Rectangle; fn as_logical(self) -> Rectangle; } impl PointExt for Point { fn as_global(self) -> Point { (self.x, self.y).into() } fn as_local(self) -> Point { (self.x, self.y).into() } } impl PointGlobalExt for Point { fn to_local(self, output: &Output) -> Point { let point = (self.to_f64() - output.geometry().loc.to_f64()).as_logical(); (C::from_f64(point.x), C::from_f64(point.y)).into() } fn as_logical(self) -> Point { (self.x, self.y).into() } } impl PointLocalExt for Point { fn to_global(self, output: &Output) -> Point { let point = (self.to_f64().as_logical() + output.geometry().loc.to_f64().as_logical()).as_global(); (C::from_f64(point.x), C::from_f64(point.y)).into() } fn as_logical(self) -> Point { (self.x, self.y).into() } } impl SizeExt for Size { fn as_logical(self) -> Size { (self.w, self.h).into() } fn as_global(self) -> Size { self } fn as_local(self) -> Size { (self.w, self.h).into() } } impl SizeExt for Size { fn as_logical(self) -> Size { (self.w, self.h).into() } fn as_global(self) -> Size { (self.w, self.h).into() } fn as_local(self) -> Size { self } } impl SizeExt for Size { fn as_logical(self) -> Size { self } fn as_global(self) -> Size { (self.w, self.h).into() } fn as_local(self) -> Size { (self.w, self.h).into() } } impl RectExt for Rectangle { fn as_global(self) -> Rectangle { Rectangle::from_loc_and_size(self.loc.as_global(), (self.size.w, self.size.h)) } fn as_local(self) -> Rectangle { Rectangle::from_loc_and_size(self.loc.as_local(), (self.size.w, self.size.h)) } } impl RectGlobalExt for Rectangle { fn to_local(self, output: &Output) -> Rectangle { Rectangle::from_loc_and_size(self.loc.to_local(output), (self.size.w, self.size.h)) } fn as_logical(self) -> Rectangle { Rectangle::from_loc_and_size(self.loc.as_logical(), self.size.as_logical()) } } impl RectLocalExt for Rectangle { fn to_global(self, output: &Output) -> Rectangle { Rectangle::from_loc_and_size(self.loc.to_global(output), (self.size.w, self.size.h)) } fn as_logical(self) -> Rectangle { Rectangle::from_loc_and_size(self.loc.as_logical(), self.size.as_logical()) } }