diff --git a/anvil/src/input_handler.rs b/anvil/src/input_handler.rs index b6a4aa2..f145388 100644 --- a/anvil/src/input_handler.rs +++ b/anvil/src/input_handler.rs @@ -217,7 +217,7 @@ impl AnvilState { .output_map .borrow() .find_by_name(crate::winit::OUTPUT_NAME) - .map(|o| (o.size().w as u32, o.size().h as u32).into()) + .map(|o| o.size()) .unwrap(); let pos = evt.position_transformed(output_size); self.pointer_location = pos; @@ -365,8 +365,7 @@ impl AnvilState { let output_geometry = output_map.with_primary().map(|o| o.geometry()); if let Some(rect) = output_geometry { - let rect_size = (rect.size.w as u32, rect.size.h as u32).into(); - *pointer_location = evt.position_transformed(rect_size) + rect.loc.to_f64(); + *pointer_location = evt.position_transformed(rect.size) + rect.loc.to_f64(); let under = window_map.get_surface_under(*pointer_location); let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&evt.device())); @@ -415,8 +414,7 @@ impl AnvilState { let tool = evt.tool(); tablet_seat.add_tool(&tool); - let rect_size = (rect.size.h as u32, rect.size.w as u32).into(); - *pointer_location = evt.position_transformed(rect_size) + rect.loc.to_f64(); + *pointer_location = evt.position_transformed(rect.size) + rect.loc.to_f64(); let under = window_map.get_surface_under(*pointer_location); let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&evt.device())); diff --git a/src/backend/input/mod.rs b/src/backend/input/mod.rs index be58533..df13cac 100644 --- a/src/backend/input/mod.rs +++ b/src/backend/input/mod.rs @@ -9,7 +9,7 @@ pub use tablet::{ TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TabletToolType, }; -use crate::utils::{Logical, Point, Raw}; +use crate::utils::{Logical, Point, Raw, Size}; /// Trait for generic functions every input device does provide pub trait Device: PartialEq + Eq + std::hash::Hash { @@ -265,21 +265,21 @@ pub trait PointerMotionAbsoluteEvent: Event { /// Device position converted to the targets coordinate space. /// E.g. the focused output's resolution. - fn position_transformed(&self, coordinate_space: Point) -> Point { + fn position_transformed(&self, coordinate_space: Size) -> Point { ( - self.x_transformed(coordinate_space.x), - self.y_transformed(coordinate_space.y), + self.x_transformed(coordinate_space.w), + self.y_transformed(coordinate_space.h), ) .into() } /// Device x position converted to the targets coordinate space's width. /// E.g. the focused output's width. - fn x_transformed(&self, width: u32) -> f64; + fn x_transformed(&self, width: i32) -> f64; /// Device y position converted to the targets coordinate space's height. /// E.g. the focused output's height. - fn y_transformed(&self, height: u32) -> f64; + fn y_transformed(&self, height: i32) -> f64; } impl PointerMotionAbsoluteEvent for UnusedEvent { @@ -291,11 +291,11 @@ impl PointerMotionAbsoluteEvent for UnusedEvent { match *self {} } - fn x_transformed(&self, _width: u32) -> f64 { + fn x_transformed(&self, _width: i32) -> f64 { match *self {} } - fn y_transformed(&self, _height: u32) -> f64 { + fn y_transformed(&self, _height: i32) -> f64 { match *self {} } } @@ -331,10 +331,10 @@ pub trait TouchDownEvent: Event { /// Touch position converted into the target coordinate space. /// E.g. the focused output's resolution. - fn position_transformed(&self, coordinate_space: Point) -> Point { + fn position_transformed(&self, coordinate_space: Size) -> Point { ( - self.x_transformed(coordinate_space.x), - self.y_transformed(coordinate_space.y), + self.x_transformed(coordinate_space.w), + self.y_transformed(coordinate_space.h), ) .into() } @@ -351,11 +351,11 @@ pub trait TouchDownEvent: Event { /// Touch event's x position converted to the targets coordinate space's width. /// E.g. the focused output's width. - fn x_transformed(&self, width: u32) -> f64; + fn x_transformed(&self, width: i32) -> f64; /// Touch event's y position converted to the targets coordinate space's width. /// E.g. the focused output's width. - fn y_transformed(&self, height: u32) -> f64; + fn y_transformed(&self, height: i32) -> f64; } impl TouchDownEvent for UnusedEvent { @@ -371,11 +371,11 @@ impl TouchDownEvent for UnusedEvent { match *self {} } - fn x_transformed(&self, _width: u32) -> f64 { + fn x_transformed(&self, _width: i32) -> f64 { match *self {} } - fn y_transformed(&self, _height: u32) -> f64 { + fn y_transformed(&self, _height: i32) -> f64 { match *self {} } } @@ -394,10 +394,10 @@ pub trait TouchMotionEvent: Event { /// Touch position converted into the target coordinate space. /// E.g. the focused output's resolution. - fn position_transformed(&self, coordinate_space: Point) -> Point { + fn position_transformed(&self, coordinate_space: Size) -> Point { ( - self.x_transformed(coordinate_space.x), - self.y_transformed(coordinate_space.y), + self.x_transformed(coordinate_space.w), + self.y_transformed(coordinate_space.h), ) .into() } @@ -414,11 +414,11 @@ pub trait TouchMotionEvent: Event { /// Touch event's x position converted to the targets coordinate space's width. /// E.g. the focused output's width. - fn x_transformed(&self, width: u32) -> f64; + fn x_transformed(&self, width: i32) -> f64; /// Touch event's y position converted to the targets coordinate space's width. /// E.g. the focused output's width. - fn y_transformed(&self, height: u32) -> f64; + fn y_transformed(&self, height: i32) -> f64; } impl TouchMotionEvent for UnusedEvent { @@ -434,11 +434,11 @@ impl TouchMotionEvent for UnusedEvent { match *self {} } - fn x_transformed(&self, _width: u32) -> f64 { + fn x_transformed(&self, _width: i32) -> f64 { match *self {} } - fn y_transformed(&self, _height: u32) -> f64 { + fn y_transformed(&self, _height: i32) -> f64 { match *self {} } } diff --git a/src/backend/input/tablet.rs b/src/backend/input/tablet.rs index 85e2659..8583f59 100644 --- a/src/backend/input/tablet.rs +++ b/src/backend/input/tablet.rs @@ -1,5 +1,5 @@ use super::{ButtonState, Event, InputBackend, UnusedEvent}; -use crate::utils::{Logical, Point, Raw}; +use crate::utils::{Logical, Point, Raw, Size}; use bitflags::bitflags; /// Description of physical tablet tool @@ -73,10 +73,10 @@ pub trait TabletToolEvent { } /// Tool position converted into the target coordinate space. - fn position_transformed(&self, coordinate_space: Point) -> Point { + fn position_transformed(&self, coordinate_space: Size) -> Point { ( - self.x_transformed(coordinate_space.x), - self.y_transformed(coordinate_space.y), + self.x_transformed(coordinate_space.w), + self.y_transformed(coordinate_space.h), ) .into() } @@ -110,9 +110,9 @@ pub trait TabletToolEvent { fn y(&self) -> f64; /// Return the current absolute X coordinate of the tablet tool event, transformed to screen coordinates. - fn x_transformed(&self, width: u32) -> f64; + fn x_transformed(&self, width: i32) -> f64; /// Return the current absolute Y coordinate of the tablet tool event, transformed to screen coordinates. - fn y_transformed(&self, height: u32) -> f64; + fn y_transformed(&self, height: i32) -> f64; /// Returns the current distance from the tablet's sensor, normalized to the range [0, 1] /// @@ -205,10 +205,10 @@ impl TabletToolEvent for UnusedEvent { fn y(&self) -> f64 { match *self {} } - fn x_transformed(&self, _width: u32) -> f64 { + fn x_transformed(&self, _width: i32) -> f64 { match *self {} } - fn y_transformed(&self, _height: u32) -> f64 { + fn y_transformed(&self, _height: i32) -> f64 { match *self {} } fn distance(&self) -> f64 { diff --git a/src/backend/libinput/mod.rs b/src/backend/libinput/mod.rs index 8da6a29..2d9a76e 100644 --- a/src/backend/libinput/mod.rs +++ b/src/backend/libinput/mod.rs @@ -242,12 +242,12 @@ impl backend::PointerMotionAbsoluteEvent self.absolute_y() } - fn x_transformed(&self, width: u32) -> f64 { - self.absolute_x_transformed(width) + fn x_transformed(&self, width: i32) -> f64 { + self.absolute_x_transformed(width as u32) } - fn y_transformed(&self, height: u32) -> f64 { - self.absolute_y_transformed(height) + fn y_transformed(&self, height: i32) -> f64 { + self.absolute_y_transformed(height as u32) } } @@ -274,12 +274,12 @@ impl backend::TouchDownEvent for event::touch::TouchDownEv event::touch::TouchEventPosition::y(self) } - fn x_transformed(&self, width: u32) -> f64 { - event::touch::TouchEventPosition::x_transformed(self, width) + fn x_transformed(&self, width: i32) -> f64 { + event::touch::TouchEventPosition::x_transformed(self, width as u32) } - fn y_transformed(&self, height: u32) -> f64 { - event::touch::TouchEventPosition::y_transformed(self, height) + fn y_transformed(&self, height: i32) -> f64 { + event::touch::TouchEventPosition::y_transformed(self, height as u32) } } @@ -306,12 +306,12 @@ impl backend::TouchMotionEvent for event::touch::TouchMoti event::touch::TouchEventPosition::y(self) } - fn x_transformed(&self, width: u32) -> f64 { - event::touch::TouchEventPosition::x_transformed(self, width) + fn x_transformed(&self, width: i32) -> f64 { + event::touch::TouchEventPosition::x_transformed(self, width as u32) } - fn y_transformed(&self, height: u32) -> f64 { - event::touch::TouchEventPosition::y_transformed(self, height) + fn y_transformed(&self, height: i32) -> f64 { + event::touch::TouchEventPosition::y_transformed(self, height as u32) } } diff --git a/src/backend/libinput/tablet.rs b/src/backend/libinput/tablet.rs index f32eed8..463555d 100644 --- a/src/backend/libinput/tablet.rs +++ b/src/backend/libinput/tablet.rs @@ -103,12 +103,12 @@ where tablet_tool::TabletToolEventTrait::y(self) } - fn x_transformed(&self, width: u32) -> f64 { - tablet_tool::TabletToolEventTrait::x_transformed(self, width) + fn x_transformed(&self, width: i32) -> f64 { + tablet_tool::TabletToolEventTrait::x_transformed(self, width as u32) } - fn y_transformed(&self, height: u32) -> f64 { - tablet_tool::TabletToolEventTrait::y_transformed(self, height) + fn y_transformed(&self, height: i32) -> f64 { + tablet_tool::TabletToolEventTrait::y_transformed(self, height as u32) } fn distance(&self) -> f64 { diff --git a/src/backend/winit.rs b/src/backend/winit.rs index f71f092..5a4296a 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -397,13 +397,13 @@ impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent { self.logical_position.y * wsize.scale_factor } - fn x_transformed(&self, width: u32) -> f64 { + fn x_transformed(&self, width: i32) -> f64 { let wsize = self.size.borrow(); let w_width = wsize.logical_size().w; f64::max(self.logical_position.x * width as f64 / w_width, 0.0) } - fn y_transformed(&self, height: u32) -> f64 { + fn y_transformed(&self, height: i32) -> f64 { let wsize = self.size.borrow(); let w_height = wsize.logical_size().h; f64::max(self.logical_position.y * height as f64 / w_height, 0.0) @@ -514,13 +514,13 @@ impl TouchDownEvent for WinitTouchStartedEvent { self.location.y * wsize.scale_factor } - fn x_transformed(&self, width: u32) -> f64 { + fn x_transformed(&self, width: i32) -> f64 { let wsize = self.size.borrow(); let w_width = wsize.logical_size().w; f64::max(self.location.x * width as f64 / w_width, 0.0) } - fn y_transformed(&self, height: u32) -> f64 { + fn y_transformed(&self, height: i32) -> f64 { let wsize = self.size.borrow(); let w_height = wsize.logical_size().h; f64::max(self.location.y * height as f64 / w_height, 0.0) @@ -561,13 +561,13 @@ impl TouchMotionEvent for WinitTouchMovedEvent { self.location.y * wsize.scale_factor } - fn x_transformed(&self, width: u32) -> f64 { + fn x_transformed(&self, width: i32) -> f64 { let wsize = self.size.borrow(); let w_width = wsize.logical_size().w; f64::max(self.location.x * width as f64 / w_width, 0.0) } - fn y_transformed(&self, height: u32) -> f64 { + fn y_transformed(&self, height: i32) -> f64 { let wsize = self.size.borrow(); let w_height = wsize.logical_size().h; f64::max(self.location.y * height as f64 / w_height, 0.0)