From 3dd559cdf1fb9bc68e90827073467bc9a47da92d Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 22 Sep 2017 10:46:00 +0200 Subject: [PATCH] Move Rectangle to utils module. --- src/compositor/mod.rs | 14 +------------- src/lib.rs | 1 + src/shell/mod.rs | 3 ++- src/shell/wl_handlers.rs | 3 ++- src/shell/xdg_handlers.rs | 3 ++- src/utils/mod.rs | 5 +++++ src/utils/rectangle.rs | 21 +++++++++++++++++++++ 7 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 src/utils/mod.rs create mode 100644 src/utils/rectangle.rs diff --git a/src/compositor/mod.rs b/src/compositor/mod.rs index 68336c2..cc9dd9d 100644 --- a/src/compositor/mod.rs +++ b/src/compositor/mod.rs @@ -94,6 +94,7 @@ use self::region::RegionData; use self::roles::{Role, RoleType, WrongRole}; use self::tree::SurfaceData; pub use self::tree::TraversalAction; +use utils::Rectangle; use wayland_server::{resource_is_registered, EventLoop, EventLoopHandle, Global}; use wayland_server::protocol::{wl_buffer, wl_callback, wl_compositor, wl_output, wl_region, wl_subcompositor, wl_surface}; @@ -217,19 +218,6 @@ pub enum RectangleKind { Subtract, } -/// A rectangle defined by its top-left corner and dimensions -#[derive(Copy, Clone, Debug)] -pub struct Rectangle { - /// horizontal position of the top-leftcorner of the rectangle, in surface coordinates - pub x: i32, - /// vertical position of the top-leftcorner of the rectangle, in surface coordinates - pub y: i32, - /// width of the rectangle - pub width: i32, - /// height of the rectangle - pub height: i32, -} - /// Description of the contents of a region /// /// A region is defined as an union and difference of rectangle. diff --git a/src/lib.rs b/src/lib.rs index 0ab2e73..6f8f0a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub mod compositor; pub mod shm; pub mod seat; pub mod shell; +pub mod utils; fn slog_or_stdlog(logger: L) -> ::slog::Logger where diff --git a/src/shell/mod.rs b/src/shell/mod.rs index a8b7048..dce9124 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -105,10 +105,11 @@ //! access from the `state()` of the event loop and the token returned by the init //! function. -use compositor::{CompositorToken, Rectangle}; +use compositor::CompositorToken; use compositor::roles::Role; use std::cell::RefCell; use std::rc::Rc; +use utils::Rectangle; use wayland_protocols::unstable::xdg_shell::server::{zxdg_popup_v6, zxdg_positioner_v6 as xdg_positioner, zxdg_shell_v6, zxdg_surface_v6, zxdg_toplevel_v6}; use wayland_server::{EventLoop, EventLoopHandle, EventResult, Global, Liveness, Resource, StateToken}; diff --git a/src/shell/wl_handlers.rs b/src/shell/wl_handlers.rs index d97297e..53c3102 100644 --- a/src/shell/wl_handlers.rs +++ b/src/shell/wl_handlers.rs @@ -1,9 +1,10 @@ use super::{make_shell_client_data, PopupConfigure, PopupState, PositionerState, ShellClient, ShellClientData, ShellSurfaceIData, ShellSurfacePendingState, ShellSurfaceRole, ToplevelConfigure, ToplevelState}; -use compositor::{CompositorToken, Rectangle}; +use compositor::CompositorToken; use compositor::roles::*; use std::sync::Mutex; +use utils::Rectangle; use wayland_protocols::unstable::xdg_shell::server::{zxdg_positioner_v6 as xdg_positioner, zxdg_toplevel_v6}; use wayland_server::{Client, EventLoopHandle, Resource}; use wayland_server::protocol::{wl_output, wl_shell, wl_shell_surface, wl_surface}; diff --git a/src/shell/xdg_handlers.rs b/src/shell/xdg_handlers.rs index 7a568fe..15311b9 100644 --- a/src/shell/xdg_handlers.rs +++ b/src/shell/xdg_handlers.rs @@ -1,9 +1,10 @@ use super::{make_shell_client_data, PopupConfigure, PopupState, PositionerState, ShellClient, ShellClientData, ShellSurfaceIData, ShellSurfacePendingState, ShellSurfaceRole, ToplevelConfigure, ToplevelState}; -use compositor::{CompositorToken, Rectangle}; +use compositor::CompositorToken; use compositor::roles::*; use std::sync::Mutex; +use utils::Rectangle; use wayland_protocols::unstable::xdg_shell::server::{zxdg_popup_v6, zxdg_positioner_v6, zxdg_shell_v6, zxdg_surface_v6, zxdg_toplevel_v6}; use wayland_server::{Client, EventLoopHandle, Resource}; diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..5e1bc70 --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1,5 @@ +//! Various utilities functions and types + +mod rectangle; + +pub use self::rectangle::Rectangle; diff --git a/src/utils/rectangle.rs b/src/utils/rectangle.rs new file mode 100644 index 0000000..d643c01 --- /dev/null +++ b/src/utils/rectangle.rs @@ -0,0 +1,21 @@ +/// A rectangle defined by its top-left corner and dimensions +#[derive(Copy, Clone, Debug)] +pub struct Rectangle { + /// horizontal position of the top-leftcorner of the rectangle, in surface coordinates + pub x: i32, + /// vertical position of the top-leftcorner of the rectangle, in surface coordinates + pub y: i32, + /// width of the rectangle + pub width: i32, + /// height of the rectangle + pub height: i32, +} + +impl Rectangle { + /// Checks wether given point is inside a rectangle + pub fn contains(&self, point: (i32, i32)) -> bool { + let (x, y) = point; + (x >= self.x) && (x < self.x + self.width) + && (y >= self.y) && (y < self.y + self.height) + } +} \ No newline at end of file