mirror of
https://github.com/Smithay/smithay.git
synced 2024-09-28 03:21:14 +02:00
geometry: Add new private Client
coordinate space
This commit is contained in:
parent
dd23282222
commit
81ef4d5ddd
2 changed files with 77 additions and 0 deletions
|
@ -8,6 +8,11 @@ use wayland_server::protocol::wl_output::Transform as WlTransform;
|
|||
#[derive(Debug)]
|
||||
pub struct Logical;
|
||||
|
||||
/// Type-level marker for the client logical coordinate space
|
||||
#[derive(Debug)]
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
pub(crate) struct Client;
|
||||
|
||||
/// Type-level marker for the physical coordinate space
|
||||
#[derive(Debug)]
|
||||
pub struct Physical;
|
||||
|
@ -453,6 +458,17 @@ impl<N: fmt::Debug, S> fmt::Debug for Point<N, S> {
|
|||
}
|
||||
|
||||
impl<N: Coordinate> Point<N, Logical> {
|
||||
#[inline]
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
pub(crate) fn to_client(self, scale: impl Into<Scale<N>>) -> Point<N, Client> {
|
||||
let scale: Scale<N> = scale.into();
|
||||
Point {
|
||||
x: self.x.upscale(scale.x),
|
||||
y: self.y.upscale(scale.y),
|
||||
_kind: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Convert this logical point to physical coordinate space according to given scale factor
|
||||
pub fn to_physical(self, scale: impl Into<Scale<N>>) -> Point<N, Physical> {
|
||||
|
@ -512,6 +528,19 @@ impl<N: Coordinate> Point<N, Logical> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
impl<N: Coordinate> Point<N, Client> {
|
||||
#[inline]
|
||||
pub(crate) fn to_logical(self, scale: impl Into<Scale<N>>) -> Point<N, Logical> {
|
||||
let scale = scale.into();
|
||||
Point {
|
||||
x: self.x.downscale(scale.x),
|
||||
y: self.y.downscale(scale.y),
|
||||
_kind: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate> Point<N, Physical> {
|
||||
#[inline]
|
||||
/// Convert this physical point to logical coordinate space according to given scale factor
|
||||
|
@ -768,6 +797,17 @@ impl<N: fmt::Debug, S> fmt::Debug for Size<N, S> {
|
|||
}
|
||||
|
||||
impl<N: Coordinate> Size<N, Logical> {
|
||||
#[inline]
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
pub(crate) fn to_client(self, scale: impl Into<Scale<N>>) -> Size<N, Client> {
|
||||
let scale = scale.into();
|
||||
Size {
|
||||
w: self.w.upscale(scale.x),
|
||||
h: self.h.upscale(scale.y),
|
||||
_kind: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Convert this logical size to physical coordinate space according to given scale factor
|
||||
pub fn to_physical(self, scale: impl Into<Scale<N>>) -> Size<N, Physical> {
|
||||
|
@ -821,6 +861,19 @@ impl<N: Coordinate> Size<N, Logical> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
impl<N: Coordinate> Size<N, Client> {
|
||||
#[inline]
|
||||
pub(crate) fn to_logical(self, scale: impl Into<Scale<N>>) -> Size<N, Logical> {
|
||||
let scale = scale.into();
|
||||
Size {
|
||||
w: self.w.downscale(scale.x),
|
||||
h: self.h.downscale(scale.y),
|
||||
_kind: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate> Size<N, Physical> {
|
||||
#[inline]
|
||||
/// Convert this physical point to logical coordinate space according to given scale factor
|
||||
|
@ -1273,6 +1326,16 @@ impl<N: Coordinate, Kind> Rectangle<N, Kind> {
|
|||
}
|
||||
|
||||
impl<N: Coordinate> Rectangle<N, Logical> {
|
||||
#[inline]
|
||||
#[cfg(feature = "xwayland")]
|
||||
pub(crate) fn to_client(self, scale: impl Into<Scale<N>>) -> Rectangle<N, Client> {
|
||||
let scale = scale.into();
|
||||
Rectangle {
|
||||
loc: self.loc.to_client(scale),
|
||||
size: self.size.to_client(scale),
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert this logical rectangle to physical coordinate space according to given scale factor
|
||||
#[inline]
|
||||
pub fn to_physical(self, scale: impl Into<Scale<N>>) -> Rectangle<N, Physical> {
|
||||
|
@ -1342,6 +1405,18 @@ impl<N: Coordinate> Rectangle<N, Logical> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
impl<N: Coordinate> Rectangle<N, Client> {
|
||||
#[inline]
|
||||
pub(crate) fn to_logical(self, scale: impl Into<Scale<N>>) -> Rectangle<N, Logical> {
|
||||
let scale = scale.into();
|
||||
Rectangle {
|
||||
loc: self.loc.to_logical(scale),
|
||||
size: self.size.to_logical(scale),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate> Rectangle<N, Physical> {
|
||||
/// Convert this physical rectangle to logical coordinate space according to given scale factor
|
||||
#[inline]
|
||||
|
|
|
@ -18,6 +18,8 @@ pub use fd::*;
|
|||
#[cfg(feature = "wayland_frontend")]
|
||||
pub(crate) mod sealed_file;
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
pub(crate) use self::geometry::Client;
|
||||
pub use self::geometry::{
|
||||
Buffer, Coordinate, Logical, Physical, Point, Raw, Rectangle, Scale, Size, Transform,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue