use size for transformed functions

This commit is contained in:
Christian Meissl 2021-07-13 21:27:09 +02:00 committed by Victor Berger
parent 72e4d910fe
commit d09de13bfc
6 changed files with 55 additions and 57 deletions

View File

@ -217,7 +217,7 @@ impl AnvilState<WinitData> {
.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<UdevData> {
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<UdevData> {
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()));

View File

@ -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<B: InputBackend>: Event<B> {
/// Device position converted to the targets coordinate space.
/// E.g. the focused output's resolution.
fn position_transformed(&self, coordinate_space: Point<u32, Logical>) -> Point<f64, Logical> {
fn position_transformed(&self, coordinate_space: Size<i32, Logical>) -> Point<f64, Logical> {
(
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<B: InputBackend> PointerMotionAbsoluteEvent<B> for UnusedEvent {
@ -291,11 +291,11 @@ impl<B: InputBackend> PointerMotionAbsoluteEvent<B> 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<B: InputBackend>: Event<B> {
/// Touch position converted into the target coordinate space.
/// E.g. the focused output's resolution.
fn position_transformed(&self, coordinate_space: Point<u32, Logical>) -> Point<f64, Logical> {
fn position_transformed(&self, coordinate_space: Size<i32, Logical>) -> Point<f64, Logical> {
(
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<B: InputBackend>: Event<B> {
/// 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<B: InputBackend> TouchDownEvent<B> for UnusedEvent {
@ -371,11 +371,11 @@ impl<B: InputBackend> TouchDownEvent<B> 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<B: InputBackend>: Event<B> {
/// Touch position converted into the target coordinate space.
/// E.g. the focused output's resolution.
fn position_transformed(&self, coordinate_space: Point<u32, Logical>) -> Point<f64, Logical> {
fn position_transformed(&self, coordinate_space: Size<i32, Logical>) -> Point<f64, Logical> {
(
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<B: InputBackend>: Event<B> {
/// 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<B: InputBackend> TouchMotionEvent<B> for UnusedEvent {
@ -434,11 +434,11 @@ impl<B: InputBackend> TouchMotionEvent<B> 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 {}
}
}

View File

@ -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<B: InputBackend> {
}
/// Tool position converted into the target coordinate space.
fn position_transformed(&self, coordinate_space: Point<u32, Logical>) -> Point<f64, Logical> {
fn position_transformed(&self, coordinate_space: Size<i32, Logical>) -> Point<f64, Logical> {
(
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<B: InputBackend> {
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<B: InputBackend> TabletToolEvent<B> 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 {

View File

@ -242,12 +242,12 @@ impl backend::PointerMotionAbsoluteEvent<LibinputInputBackend>
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<LibinputInputBackend> 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<LibinputInputBackend> 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)
}
}

View File

@ -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 {

View File

@ -397,13 +397,13 @@ impl PointerMotionAbsoluteEvent<WinitInputBackend> 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<WinitInputBackend> 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<WinitInputBackend> 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)