From 71125f948c47cf5f23d47c21d641bbf68d908d35 Mon Sep 17 00:00:00 2001 From: Ian Wood Date: Fri, 4 Aug 2023 11:46:14 +0100 Subject: [PATCH 1/4] use sketch of pointer api --- src/event.rs | 172 ++++++++---------- .../linux/wayland/seat/pointer/mod.rs | 42 +++-- .../linux/wayland/seat/touch/mod.rs | 58 +++--- 3 files changed, 138 insertions(+), 134 deletions(-) diff --git a/src/event.rs b/src/event.rs index e24b0a9c91..b8fd633ec1 100644 --- a/src/event.rs +++ b/src/event.rs @@ -378,46 +378,43 @@ pub enum WindowEvent { /// - **iOS / Android / Web / Orbital:** Unsupported. Ime(Ime), - /// The cursor has moved on the window. - /// - /// ## Platform-specific - /// - /// - **Web:** Doesn't take into account CSS [`border`], [`padding`], or [`transform`]. - /// - /// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border - /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding - /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform - CursorMoved { + PointerMoved { device_id: DeviceId, - - /// (x,y) coords in pixels relative to the top-left corner of the window. Because the range of this data is - /// limited by the display area and it may have been transformed by the OS to implement effects such as cursor - /// acceleration, it should not be used to implement non-cursor-like interactions such as 3D camera control. position: PhysicalPosition, + source: PointerMoved, }, - /// The cursor has entered the window. - /// - /// ## Platform-specific - /// - /// - **Web:** Doesn't take into account CSS [`border`], [`padding`], or [`transform`]. - /// - /// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border - /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding - /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform - CursorEntered { device_id: DeviceId }, + PointerDown { + device_id: DeviceId, + source: PointerDown, + }, - /// The cursor has left the window. - /// - /// ## Platform-specific - /// - /// - **Web:** Doesn't take into account CSS [`border`], [`padding`], or [`transform`]. - /// - /// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border - /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding - /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform - CursorLeft { device_id: DeviceId }, + PointerUp { + device_id: DeviceId, + source: PointerUp, + }, + + PointerEntered { + device_id: DeviceId, + source: PointerEntered, + }, + + PointerLeft { + device_id: DeviceId, + source: PointerLeft, + }, + + PointerCancelled { + device_id: DeviceId, + source: PointerCancelled, + }, + // /// An mouse button press has been received. + // MouseInput { + // device_id: DeviceId, + // state: ElementState, + // button: MouseButton, + // }, /// A mouse wheel movement or touchpad scroll occurred. MouseWheel { device_id: DeviceId, @@ -425,13 +422,6 @@ pub enum WindowEvent { phase: TouchPhase, }, - /// An mouse button press has been received. - MouseInput { - device_id: DeviceId, - state: ElementState, - button: MouseButton, - }, - /// Touchpad magnification event with two-finger pinch gesture. /// /// Positive delta values indicate magnification (zooming in) and @@ -497,18 +487,6 @@ pub enum WindowEvent { value: f64, }, - /// Touch event has been received - /// - /// ## Platform-specific - /// - /// - **Web:** Doesn't take into account CSS [`border`], [`padding`], or [`transform`]. - /// - **macOS:** Unsupported. - /// - /// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border - /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding - /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform - Touch(Touch), - /// The window's scale factor has changed. /// /// The following user actions can cause DPI changes: @@ -594,7 +572,7 @@ pub enum DeviceEvent { /// Change in physical position of a pointing device. /// - /// This represents raw, unfiltered physical motion. Not to be confused with [`WindowEvent::CursorMoved`]. + /// This represents raw, unfiltered physical motion. Not to be confused with cursor motion. MouseMotion { /// (x, y) change in position in unspecified units. /// @@ -897,6 +875,51 @@ pub enum Ime { Disabled, } +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerEntered { + Cursor, +} + +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerLeft { + Cursor, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerMoved { + Cursor, + Touch { finger: u64, force: Option }, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerDown { + Cursor { + button: MouseButton, + }, + Touch { + finger: u64, + force: Option, + location: PhysicalPosition, + }, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerUp { + Cursor { button: MouseButton }, + Touch { finger: u64, force: Option }, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerCancelled { + Touch { finger: u64, force: Option }, +} + /// Describes touch-screen input state. #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -907,47 +930,6 @@ pub enum TouchPhase { Cancelled, } -/// Represents a touch event -/// -/// Every time the user touches the screen, a new [`TouchPhase::Started`] event with an unique -/// identifier for the finger is generated. When the finger is lifted, an [`TouchPhase::Ended`] -/// event is generated with the same finger id. -/// -/// After a `Started` event has been emitted, there may be zero or more `Move` -/// events when the finger is moved or the touch pressure changes. -/// -/// The finger id may be reused by the system after an `Ended` event. The user -/// should assume that a new `Started` event received with the same id has nothing -/// to do with the old finger and is a new finger. -/// -/// A [`TouchPhase::Cancelled`] event is emitted when the system has canceled tracking this -/// touch, such as when the window loses focus, or on iOS if the user moves the -/// device against their face. -/// -/// ## Platform-specific -/// -/// - **Web:** Doesn't take into account CSS [`border`], [`padding`], or [`transform`]. -/// - **macOS:** Unsupported. -/// -/// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border -/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding -/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Touch { - pub device_id: DeviceId, - pub phase: TouchPhase, - pub location: PhysicalPosition, - /// Describes how hard the screen was pressed. May be `None` if the platform - /// does not support pressure sensitivity. - /// - /// ## Platform-specific - /// - /// - Only available on **iOS** 9.0+, **Windows** 8+, and **Web**. - pub force: Option, - /// Unique identifier of a finger. - pub id: u64, -} - /// Describes the force of a touch event #[derive(Debug, Clone, Copy, PartialEq)] pub enum Force { diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index 4d65e1fa0e..2af4212930 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -21,7 +21,10 @@ use sctk::seat::SeatState; use sctk::shell::xdg::frame::FrameClick; use crate::dpi::{LogicalPosition, PhysicalPosition}; -use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent}; +use crate::event::{ + ElementState, MouseButton, MouseScrollDelta, PointerDown, PointerEntered, PointerLeft, + PointerMoved, PointerUp, TouchPhase, WindowEvent, +}; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, DeviceId, WindowId}; @@ -115,8 +118,13 @@ impl PointerHandler for WinitState { } // Regular events on the main surface. PointerEventKind::Enter { .. } => { - self.events_sink - .push_window_event(WindowEvent::CursorEntered { device_id }, window_id); + self.events_sink.push_window_event( + WindowEvent::PointerEntered { + device_id, + source: PointerEntered::Cursor, + }, + window_id, + ); if let Some(pointer) = seat_state.pointer.as_ref().map(Arc::downgrade) { window.pointer_entered(pointer); @@ -126,9 +134,10 @@ impl PointerHandler for WinitState { pointer.winit_data().inner.lock().unwrap().surface = Some(window_id); self.events_sink.push_window_event( - WindowEvent::CursorMoved { + WindowEvent::PointerMoved { device_id, position, + source: PointerMoved::Cursor, }, window_id, ); @@ -141,14 +150,20 @@ impl PointerHandler for WinitState { // Remove the active surface. pointer.winit_data().inner.lock().unwrap().surface = None; - self.events_sink - .push_window_event(WindowEvent::CursorLeft { device_id }, window_id); + self.events_sink.push_window_event( + WindowEvent::PointerLeft { + device_id, + source: PointerLeft::Cursor, + }, + window_id, + ); } PointerEventKind::Motion { .. } => { self.events_sink.push_window_event( - WindowEvent::CursorMoved { + WindowEvent::PointerMoved { device_id, position, + source: PointerMoved::Cursor, }, window_id, ); @@ -170,10 +185,15 @@ impl PointerHandler for WinitState { ElementState::Released }; self.events_sink.push_window_event( - WindowEvent::MouseInput { - device_id, - state, - button, + match state { + ElementState::Pressed => WindowEvent::PointerDown { + device_id, + source: PointerDown::Cursor { button }, + }, + ElementState::Released => WindowEvent::PointerUp { + device_id, + source: PointerUp::Cursor { button }, + }, }, window_id, ); diff --git a/src/platform_impl/linux/wayland/seat/touch/mod.rs b/src/platform_impl/linux/wayland/seat/touch/mod.rs index e5b838689a..a72d289a9c 100644 --- a/src/platform_impl/linux/wayland/seat/touch/mod.rs +++ b/src/platform_impl/linux/wayland/seat/touch/mod.rs @@ -7,8 +7,8 @@ use sctk::reexports::client::{Connection, Proxy, QueueHandle}; use sctk::seat::touch::{TouchData, TouchHandler}; -use crate::dpi::LogicalPosition; -use crate::event::{Touch, TouchPhase, WindowEvent}; +use crate::dpi::{LogicalPosition, PhysicalPosition}; +use crate::event::{PointerCancelled, PointerDown, PointerMoved, PointerUp, WindowEvent}; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, DeviceId}; @@ -41,15 +41,16 @@ impl TouchHandler for WinitState { .insert(id, TouchPoint { surface, location }); self.events_sink.push_window_event( - WindowEvent::Touch(Touch { + WindowEvent::PointerDown { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - phase: TouchPhase::Started, - location: location.to_physical(scale_factor), - force: None, - id: id as u64, - }), + source: PointerDown::Touch { + finger: id as u64, + force: None, + location: location.to_physical(scale_factor), + }, + }, window_id, ); } @@ -78,15 +79,15 @@ impl TouchHandler for WinitState { }; self.events_sink.push_window_event( - WindowEvent::Touch(Touch { + WindowEvent::PointerUp { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - phase: TouchPhase::Ended, - location: touch_point.location.to_physical(scale_factor), - force: None, - id: id as u64, - }), + source: PointerUp::Touch { + finger: id as u64, + force: None, + }, + }, window_id, ); } @@ -117,15 +118,16 @@ impl TouchHandler for WinitState { touch_point.location = LogicalPosition::::from(position); self.events_sink.push_window_event( - WindowEvent::Touch(Touch { + WindowEvent::PointerMoved { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - phase: TouchPhase::Cancelled, - location: touch_point.location.to_physical(scale_factor), - force: None, - id: id as u64, - }), + position: touch_point.location.to_physical(scale_factor), + source: PointerMoved::Touch { + finger: id as u64, + force: None, + }, + }, window_id, ); } @@ -140,20 +142,20 @@ impl TouchHandler for WinitState { None => return, }; - let location = touch_point.location.to_physical(scale_factor); + let location: PhysicalPosition = touch_point.location.to_physical(scale_factor); self.events_sink.push_window_event( - WindowEvent::Touch(Touch { + WindowEvent::PointerCancelled { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - phase: TouchPhase::Cancelled, - location, - force: None, - id: id as u64, - }), + source: PointerCancelled::Touch { + finger: id as u64, + force: None, + }, + }, window_id, - ); + ) } } From 483ec02fef6959b062c290e5c80f480965792af6 Mon Sep 17 00:00:00 2001 From: Ian Wood Date: Fri, 4 Aug 2023 13:15:57 +0100 Subject: [PATCH 2/4] remove extra types --- src/event.rs | 66 ++++--------------- .../linux/wayland/seat/pointer/mod.rs | 33 +++++----- .../linux/wayland/seat/touch/mod.rs | 38 +++++------ 3 files changed, 47 insertions(+), 90 deletions(-) diff --git a/src/event.rs b/src/event.rs index b8fd633ec1..b5541cbe75 100644 --- a/src/event.rs +++ b/src/event.rs @@ -380,33 +380,33 @@ pub enum WindowEvent { PointerMoved { device_id: DeviceId, - position: PhysicalPosition, - source: PointerMoved, - }, - - PointerDown { - device_id: DeviceId, - source: PointerDown, + source: PointerSource, + location: PhysicalPosition, + force: Option, }, - PointerUp { + PointerInput { device_id: DeviceId, - source: PointerUp, + source: PointerSource, + state: ElementState, + button: Option, + location: Option>, + force: Option, }, PointerEntered { device_id: DeviceId, - source: PointerEntered, + source: PointerSource, }, PointerLeft { device_id: DeviceId, - source: PointerLeft, + source: PointerSource, }, PointerCancelled { device_id: DeviceId, - source: PointerCancelled, + source: PointerSource, }, // /// An mouse button press has been received. @@ -877,47 +877,9 @@ pub enum Ime { #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerEntered { +pub enum PointerSource { Cursor, -} - -#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerLeft { - Cursor, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerMoved { - Cursor, - Touch { finger: u64, force: Option }, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerDown { - Cursor { - button: MouseButton, - }, - Touch { - finger: u64, - force: Option, - location: PhysicalPosition, - }, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerUp { - Cursor { button: MouseButton }, - Touch { finger: u64, force: Option }, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerCancelled { - Touch { finger: u64, force: Option }, + Touch { finger: u64 }, } /// Describes touch-screen input state. diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index 2af4212930..853b76b537 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -22,8 +22,7 @@ use sctk::shell::xdg::frame::FrameClick; use crate::dpi::{LogicalPosition, PhysicalPosition}; use crate::event::{ - ElementState, MouseButton, MouseScrollDelta, PointerDown, PointerEntered, PointerLeft, - PointerMoved, PointerUp, TouchPhase, WindowEvent, + ElementState, MouseButton, MouseScrollDelta, PointerSource, TouchPhase, WindowEvent, }; use crate::platform_impl::wayland::state::WinitState; @@ -121,7 +120,7 @@ impl PointerHandler for WinitState { self.events_sink.push_window_event( WindowEvent::PointerEntered { device_id, - source: PointerEntered::Cursor, + source: PointerSource::Cursor, }, window_id, ); @@ -136,8 +135,9 @@ impl PointerHandler for WinitState { self.events_sink.push_window_event( WindowEvent::PointerMoved { device_id, - position, - source: PointerMoved::Cursor, + location: position, + source: PointerSource::Cursor, + force: None, }, window_id, ); @@ -153,7 +153,7 @@ impl PointerHandler for WinitState { self.events_sink.push_window_event( WindowEvent::PointerLeft { device_id, - source: PointerLeft::Cursor, + source: PointerSource::Cursor, }, window_id, ); @@ -162,8 +162,9 @@ impl PointerHandler for WinitState { self.events_sink.push_window_event( WindowEvent::PointerMoved { device_id, - position, - source: PointerMoved::Cursor, + location: position, + source: PointerSource::Cursor, + force: None, }, window_id, ); @@ -185,15 +186,13 @@ impl PointerHandler for WinitState { ElementState::Released }; self.events_sink.push_window_event( - match state { - ElementState::Pressed => WindowEvent::PointerDown { - device_id, - source: PointerDown::Cursor { button }, - }, - ElementState::Released => WindowEvent::PointerUp { - device_id, - source: PointerUp::Cursor { button }, - }, + WindowEvent::PointerInput { + device_id, + source: PointerSource::Cursor, + state, + button: Some(button), + location: None, + force: None, }, window_id, ); diff --git a/src/platform_impl/linux/wayland/seat/touch/mod.rs b/src/platform_impl/linux/wayland/seat/touch/mod.rs index a72d289a9c..8ed4c275f5 100644 --- a/src/platform_impl/linux/wayland/seat/touch/mod.rs +++ b/src/platform_impl/linux/wayland/seat/touch/mod.rs @@ -8,7 +8,7 @@ use sctk::reexports::client::{Connection, Proxy, QueueHandle}; use sctk::seat::touch::{TouchData, TouchHandler}; use crate::dpi::{LogicalPosition, PhysicalPosition}; -use crate::event::{PointerCancelled, PointerDown, PointerMoved, PointerUp, WindowEvent}; +use crate::event::{ElementState, PointerSource, WindowEvent}; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, DeviceId}; @@ -41,15 +41,15 @@ impl TouchHandler for WinitState { .insert(id, TouchPoint { surface, location }); self.events_sink.push_window_event( - WindowEvent::PointerDown { + WindowEvent::PointerInput { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerDown::Touch { - finger: id as u64, - force: None, - location: location.to_physical(scale_factor), - }, + source: PointerSource::Touch { finger: id as u64 }, + force: None, + location: Some(location.to_physical(scale_factor)), + state: ElementState::Pressed, + button: None, }, window_id, ); @@ -79,14 +79,15 @@ impl TouchHandler for WinitState { }; self.events_sink.push_window_event( - WindowEvent::PointerUp { + WindowEvent::PointerInput { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerUp::Touch { - finger: id as u64, - force: None, - }, + source: PointerSource::Touch { finger: id as u64 }, + state: ElementState::Released, + button: None, + location: None, + force: None, }, window_id, ); @@ -122,11 +123,9 @@ impl TouchHandler for WinitState { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - position: touch_point.location.to_physical(scale_factor), - source: PointerMoved::Touch { - finger: id as u64, - force: None, - }, + source: PointerSource::Touch { finger: id as u64 }, + location: touch_point.location.to_physical(scale_factor), + force: None, }, window_id, ); @@ -149,10 +148,7 @@ impl TouchHandler for WinitState { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerCancelled::Touch { - finger: id as u64, - force: None, - }, + source: PointerSource::Touch { finger: id as u64 }, }, window_id, ) From cc8de41956f2fce39de23169cea004a0bb170b04 Mon Sep 17 00:00:00 2001 From: Ian Wood Date: Sat, 5 Aug 2023 00:44:14 +0100 Subject: [PATCH 3/4] detach info from event --- src/event.rs | 82 ++++++++++--------- .../linux/wayland/seat/pointer/mod.rs | 14 ++-- .../linux/wayland/seat/touch/mod.rs | 14 ++-- 3 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/event.rs b/src/event.rs index b5541cbe75..3c3eb5c26b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -378,35 +378,10 @@ pub enum WindowEvent { /// - **iOS / Android / Web / Orbital:** Unsupported. Ime(Ime), - PointerMoved { + Pointer { device_id: DeviceId, - source: PointerSource, - location: PhysicalPosition, - force: Option, - }, - - PointerInput { - device_id: DeviceId, - source: PointerSource, - state: ElementState, - button: Option, - location: Option>, - force: Option, - }, - - PointerEntered { - device_id: DeviceId, - source: PointerSource, - }, - - PointerLeft { - device_id: DeviceId, - source: PointerSource, - }, - - PointerCancelled { - device_id: DeviceId, - source: PointerSource, + pointer_id: PointerId, + event: PointerEvent, }, // /// An mouse button press has been received. @@ -417,7 +392,7 @@ pub enum WindowEvent { // }, /// A mouse wheel movement or touchpad scroll occurred. MouseWheel { - device_id: DeviceId, + device_id: DeviceId,g delta: MouseScrollDelta, phase: TouchPhase, }, @@ -875,21 +850,45 @@ pub enum Ime { Disabled, } +#[derive(Debug, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum TouchPhase { + Started, + Moved, + Ended, + Cancelled, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerEvent { + Created, + Destroyed, + Entered, + Left, + UpdateForce(Force), + UpdateTilt(Tilt), + UpdateAngle(f64), + Moved(PhysicalPosition), + Button { + button: PointerButton, + state: ElementState, + }, + MotionCancelled, +} + #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum PointerSource { +pub enum PointerId { Cursor, Touch { finger: u64 }, } -/// Describes touch-screen input state. -#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone, Copy)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum TouchPhase { - Started, - Moved, - Ended, - Cancelled, +pub struct Tilt { + angle_x: f64, + angle_y: f64, } /// Describes the force of a touch event @@ -987,6 +986,15 @@ pub enum MouseButton { Other(u16), } +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PointerButton { + Mouse(MouseButton), + // Touch (probably) doesn't have any variations, different fingers + // are different pointers. + Touch, +} + /// Describes a difference in the mouse scroll wheel state. #[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index 853b76b537..6f2874e183 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -22,7 +22,7 @@ use sctk::shell::xdg::frame::FrameClick; use crate::dpi::{LogicalPosition, PhysicalPosition}; use crate::event::{ - ElementState, MouseButton, MouseScrollDelta, PointerSource, TouchPhase, WindowEvent, + ElementState, MouseButton, MouseScrollDelta, PointerId, TouchPhase, WindowEvent, }; use crate::platform_impl::wayland::state::WinitState; @@ -120,7 +120,7 @@ impl PointerHandler for WinitState { self.events_sink.push_window_event( WindowEvent::PointerEntered { device_id, - source: PointerSource::Cursor, + source: PointerId::Cursor, }, window_id, ); @@ -136,7 +136,7 @@ impl PointerHandler for WinitState { WindowEvent::PointerMoved { device_id, location: position, - source: PointerSource::Cursor, + source: PointerId::Cursor, force: None, }, window_id, @@ -153,7 +153,7 @@ impl PointerHandler for WinitState { self.events_sink.push_window_event( WindowEvent::PointerLeft { device_id, - source: PointerSource::Cursor, + source: PointerId::Cursor, }, window_id, ); @@ -163,7 +163,7 @@ impl PointerHandler for WinitState { WindowEvent::PointerMoved { device_id, location: position, - source: PointerSource::Cursor, + source: PointerId::Cursor, force: None, }, window_id, @@ -186,9 +186,9 @@ impl PointerHandler for WinitState { ElementState::Released }; self.events_sink.push_window_event( - WindowEvent::PointerInput { + WindowEvent::PointerButton { device_id, - source: PointerSource::Cursor, + source: PointerId::Cursor, state, button: Some(button), location: None, diff --git a/src/platform_impl/linux/wayland/seat/touch/mod.rs b/src/platform_impl/linux/wayland/seat/touch/mod.rs index 8ed4c275f5..8b2dc6f71c 100644 --- a/src/platform_impl/linux/wayland/seat/touch/mod.rs +++ b/src/platform_impl/linux/wayland/seat/touch/mod.rs @@ -8,7 +8,7 @@ use sctk::reexports::client::{Connection, Proxy, QueueHandle}; use sctk::seat::touch::{TouchData, TouchHandler}; use crate::dpi::{LogicalPosition, PhysicalPosition}; -use crate::event::{ElementState, PointerSource, WindowEvent}; +use crate::event::{ElementState, PointerId, WindowEvent}; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, DeviceId}; @@ -41,11 +41,11 @@ impl TouchHandler for WinitState { .insert(id, TouchPoint { surface, location }); self.events_sink.push_window_event( - WindowEvent::PointerInput { + WindowEvent::PointerButton { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerSource::Touch { finger: id as u64 }, + source: PointerId::Touch { finger: id as u64 }, force: None, location: Some(location.to_physical(scale_factor)), state: ElementState::Pressed, @@ -79,11 +79,11 @@ impl TouchHandler for WinitState { }; self.events_sink.push_window_event( - WindowEvent::PointerInput { + WindowEvent::PointerButton { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerSource::Touch { finger: id as u64 }, + source: PointerId::Touch { finger: id as u64 }, state: ElementState::Released, button: None, location: None, @@ -123,7 +123,7 @@ impl TouchHandler for WinitState { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerSource::Touch { finger: id as u64 }, + source: PointerId::Touch { finger: id as u64 }, location: touch_point.location.to_physical(scale_factor), force: None, }, @@ -148,7 +148,7 @@ impl TouchHandler for WinitState { device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( DeviceId, )), - source: PointerSource::Touch { finger: id as u64 }, + source: PointerId::Touch { finger: id as u64 }, }, window_id, ) From 6c047bd07bbd158709086457f6c2ff7c5b92d530 Mon Sep 17 00:00:00 2001 From: Ian Wood Date: Sat, 5 Aug 2023 00:57:27 +0100 Subject: [PATCH 4/4] remove spurious g --- src/event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event.rs b/src/event.rs index 3c3eb5c26b..4b14119d28 100644 --- a/src/event.rs +++ b/src/event.rs @@ -392,7 +392,7 @@ pub enum WindowEvent { // }, /// A mouse wheel movement or touchpad scroll occurred. MouseWheel { - device_id: DeviceId,g + device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase, },