From e429f5626e8b0a5e5f0019ae1e706a92743dfc02 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 17 Jul 2024 02:25:44 +0200 Subject: [PATCH 1/7] Replace `WindowId` `From/Into` `u64` with methods --- src/changelog/unreleased.md | 3 +++ src/platform_impl/android/mod.rs | 8 ++------ src/platform_impl/apple/appkit/window.rs | 12 ++++-------- src/platform_impl/apple/uikit/window.rs | 14 +++++--------- src/platform_impl/linux/mod.rs | 18 +++++++----------- src/platform_impl/orbital/mod.rs | 12 ++++-------- src/platform_impl/web/event_loop/runner.rs | 12 ++++++------ src/platform_impl/web/window.rs | 14 +++++--------- src/platform_impl/windows/mod.rs | 16 ++++++---------- src/window.rs | 18 +++++++----------- 10 files changed, 49 insertions(+), 78 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 5d797b034d..c6e24646c5 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -62,6 +62,7 @@ changelog entry. - Implement `Clone`, `Copy`, `Debug`, `Deserialize`, `Eq`, `Hash`, `Ord`, `PartialEq`, `PartialOrd` and `Serialize` on many types. - Add `MonitorHandle::current_video_mode()`. +- Add `WindowId::into_raw()` and `from_raw()`. ### Changed @@ -127,6 +128,8 @@ changelog entry. - Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of `MonitorHandle::current_video_mode()`. - On Android, remove all `MonitorHandle` support instead of emitting false data. +- Remove `impl From for WindowId` and `impl From for u64`. Replaced with + `WindowId::into_raw()` and `from_raw()`. ### Fixed diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index b3425ea339..d5cc4e9799 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -673,16 +673,12 @@ impl WindowId { pub const fn dummy() -> Self { WindowId } -} -impl From for u64 { - fn from(_: WindowId) -> Self { + pub const fn into_raw(self) -> u64 { 0 } -} -impl From for WindowId { - fn from(_: u64) -> Self { + pub const fn from_raw(_id: u64) -> Self { Self } } diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 06013051e0..96c7aa9434 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -76,17 +76,13 @@ impl WindowId { pub const fn dummy() -> Self { Self(0) } -} -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 as u64 + pub const fn into_raw(self) -> u64 { + self.0 as u64 } -} -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id as usize) + pub const fn from_raw(id: u64) -> Self { + Self(id as usize) } } diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index d60e79afe5..04eabc7f5a 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -100,7 +100,7 @@ impl WinitUIWindow { } pub(crate) fn id(&self) -> WindowId { - (self as *const Self as usize as u64).into() + WindowId { window: (self as *const Self as usize) as _ } } } @@ -679,17 +679,13 @@ impl WindowId { pub const fn dummy() -> Self { WindowId { window: std::ptr::null_mut() } } -} -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.window as u64 + pub fn into_raw(self) -> u64 { + self.window as u64 } -} -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self { window: raw_id as _ } + pub const fn from_raw(id: u64) -> Self { + Self { window: id as *mut WinitUIWindow } } } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 9fbc3e8912..8c44336ebe 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -143,21 +143,17 @@ pub(crate) enum Window { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct WindowId(u64); -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 +impl WindowId { + pub const fn dummy() -> Self { + Self(0) } -} -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id) + pub const fn into_raw(self) -> u64 { + self.0 } -} -impl WindowId { - pub const fn dummy() -> Self { - Self(0) + pub const fn from_raw(id: u64) -> Self { + Self(id) } } diff --git a/src/platform_impl/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index 4ba0923cc6..660eb778ed 100644 --- a/src/platform_impl/orbital/mod.rs +++ b/src/platform_impl/orbital/mod.rs @@ -105,17 +105,13 @@ impl WindowId { pub const fn dummy() -> Self { WindowId { fd: u64::MAX } } -} -impl From for u64 { - fn from(id: WindowId) -> Self { - id.fd + pub const fn into_raw(self) -> u64 { + self.fd } -} -impl From for WindowId { - fn from(fd: u64) -> Self { - Self { fd } + pub const fn from_raw(id: u64) -> Self { + Self { fd: id } } } diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index 64c65a34eb..daaae53d4c 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -49,7 +49,7 @@ struct Execution { suspended: Cell, event_loop_recreation: Cell, events: RefCell>, - id: RefCell, + id: Cell, window: web_sys::Window, navigator: Navigator, document: Document, @@ -171,7 +171,7 @@ impl Shared { window, navigator, document, - id: RefCell::new(0), + id: Cell::new(0), all_canvases: RefCell::new(Vec::new()), redraw_pending: RefCell::new(HashSet::new()), destroy_pending: RefCell::new(VecDeque::new()), @@ -438,11 +438,11 @@ impl Shared { // Generate a strictly increasing ID // This is used to differentiate windows when handling events - pub fn generate_id(&self) -> u32 { - let mut id = self.0.id.borrow_mut(); - *id += 1; + pub fn generate_id(&self) -> u64 { + let id = self.0.id.get(); + self.0.id.set(id.checked_add(1).expect("exhausted `WindowId`")); - *id + id } pub fn request_redraw(&self, id: WindowId) { diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 77931aa5b8..e4126583b5 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -429,23 +429,19 @@ impl Drop for Inner { } } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(pub(crate) u32); +pub struct WindowId(pub(crate) u64); impl WindowId { pub const fn dummy() -> Self { Self(0) } -} -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 as u64 + pub const fn into_raw(self) -> u64 { + self.0 } -} -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id as u32) + pub const fn from_raw(id: u64) -> Self { + Self(id) } } diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 93349f7f14..7c4ad16fac 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -120,11 +120,13 @@ impl WindowId { pub const fn dummy() -> Self { WindowId(0) } -} -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 as u64 + pub const fn into_raw(self) -> u64 { + self.0 as u64 + } + + pub const fn from_raw(id: u64) -> Self { + Self(id as HWND) } } @@ -134,12 +136,6 @@ impl From for HWND { } } -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id as HWND) - } -} - #[inline(always)] const fn get_xbutton_wparam(x: u32) -> u16 { hiword(x) diff --git a/src/window.rs b/src/window.rs index 7dd7807107..8274989663 100644 --- a/src/window.rs +++ b/src/window.rs @@ -92,23 +92,19 @@ impl WindowId { pub const fn dummy() -> Self { WindowId(platform_impl::WindowId::dummy()) } -} -impl fmt::Debug for WindowId { - fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(fmtr) + pub fn into_raw(self) -> u64 { + self.0.into_raw() } -} -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0.into() + pub const fn from_raw(id: u64) -> Self { + Self(platform_impl::WindowId::from_raw(id)) } } -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id.into()) +impl fmt::Debug for WindowId { + fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(fmtr) } } From 7cf6f7d0f9a689472f8d1b0e47f7d89bd22e1b97 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 15 Aug 2024 22:24:29 +0200 Subject: [PATCH 2/7] Use usize in WindowId on iOS to make `WindowId::into_raw` const --- src/platform_impl/apple/uikit/window.rs | 26 +++++++++---------------- src/window.rs | 2 +- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 04eabc7f5a..07c53ac409 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -3,10 +3,9 @@ use std::collections::VecDeque; use objc2::rc::Retained; -use objc2::runtime::{AnyObject, NSObject}; use objc2::{class, declare_class, msg_send, msg_send_id, mutability, ClassType, DeclaredClass}; use objc2_foundation::{ - CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker, NSObjectProtocol, + CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker, NSObject, NSObjectProtocol, }; use objc2_ui_kit::{ UIApplication, UICoordinateSpace, UIResponder, UIScreen, UIScreenOverscanCompensation, @@ -100,7 +99,7 @@ impl WinitUIWindow { } pub(crate) fn id(&self) -> WindowId { - WindowId { window: (self as *const Self as usize) as _ } + WindowId::from_window(self) } } @@ -671,30 +670,23 @@ impl Inner { } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId { - window: *mut WinitUIWindow, -} +pub struct WindowId(usize); impl WindowId { pub const fn dummy() -> Self { - WindowId { window: std::ptr::null_mut() } + WindowId(0) } - pub fn into_raw(self) -> u64 { - self.window as u64 + pub const fn into_raw(self) -> u64 { + self.0 as _ } pub const fn from_raw(id: u64) -> Self { - Self { window: id as *mut WinitUIWindow } + Self(id as _) } -} - -unsafe impl Send for WindowId {} -unsafe impl Sync for WindowId {} -impl From<&AnyObject> for WindowId { - fn from(window: &AnyObject) -> WindowId { - WindowId { window: window as *const _ as _ } + fn from_window(window: &UIWindow) -> Self { + Self(window as *const UIWindow as usize) } } diff --git a/src/window.rs b/src/window.rs index 8274989663..c756ba3a74 100644 --- a/src/window.rs +++ b/src/window.rs @@ -93,7 +93,7 @@ impl WindowId { WindowId(platform_impl::WindowId::dummy()) } - pub fn into_raw(self) -> u64 { + pub const fn into_raw(self) -> u64 { self.0.into_raw() } From 49f6ddf697186b6293c4d197be72d11bea652a94 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 8 Sep 2024 12:53:33 +0200 Subject: [PATCH 3/7] Document into_raw/from_raw --- src/window.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/window.rs b/src/window.rs index c756ba3a74..2368ce6061 100644 --- a/src/window.rs +++ b/src/window.rs @@ -93,10 +93,16 @@ impl WindowId { WindowId(platform_impl::WindowId::dummy()) } + /// Convert the `WindowId` into the underlying integer. + /// + /// This is useful if you need to pass the ID across an FFI boundary, or store it in an atomic. pub const fn into_raw(self) -> u64 { self.0.into_raw() } + /// Construct a `WindowId` from the underlying integer. + /// + /// This should only be called with integers returned from [`WindowId::into_raw`]. pub const fn from_raw(id: u64) -> Self { Self(platform_impl::WindowId::from_raw(id)) } From c59a46cebaf1158f54f456afd2d36f58b857131d Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 13 Aug 2024 23:25:12 +0200 Subject: [PATCH 4/7] Remove `dummy()` from `WindowId`, `DeviceId` and `FingerId` --- src/changelog/unreleased.md | 1 + src/event.rs | 28 ++++--------------- src/platform_impl/android/mod.rs | 6 ++-- src/platform_impl/apple/appkit/mod.rs | 2 ++ src/platform_impl/apple/appkit/window.rs | 4 --- src/platform_impl/apple/uikit/mod.rs | 2 ++ src/platform_impl/apple/uikit/window.rs | 4 --- src/platform_impl/linux/mod.rs | 6 ++-- src/platform_impl/linux/wayland/mod.rs | 2 ++ src/platform_impl/linux/x11/mod.rs | 2 ++ src/platform_impl/orbital/mod.rs | 6 ++-- src/platform_impl/web/event.rs | 14 +++++++--- src/platform_impl/web/event_loop/runner.rs | 6 ++-- .../web/event_loop/window_target.rs | 6 ++-- src/platform_impl/web/window.rs | 4 --- src/platform_impl/windows/mod.rs | 6 ++-- src/window.rs | 11 -------- 17 files changed, 38 insertions(+), 72 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 6cb5e5dd01..4e7f83e9ba 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -153,6 +153,7 @@ changelog entry. - On Android, remove all `MonitorHandle` support instead of emitting false data. - Remove `impl From for WindowId` and `impl From for u64`. Replaced with `WindowId::into_raw()` and `from_raw()`. +- Remove `dummy()` from `WindowId` and `DeviceId`. ### Fixed diff --git a/src/event.rs b/src/event.rs index 223992db8f..58e12f5421 100644 --- a/src/event.rs +++ b/src/event.rs @@ -439,21 +439,9 @@ pub enum WindowEvent { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(pub(crate) platform_impl::DeviceId); -impl Default for DeviceId { - fn default() -> Self { - Self::dummy() - } -} - impl DeviceId { - /// Returns a dummy id, useful for unit testing. - /// - /// # Notes - /// - /// The only guarantee made about the return value of this function is that - /// it will always be equal to itself and to future values returned by this function. - /// No other guarantees are made. This may be equal to a real `DeviceId`. - pub const fn dummy() -> Self { + #[cfg(test)] + pub(crate) const fn dummy() -> Self { DeviceId(platform_impl::DeviceId::dummy()) } } @@ -466,14 +454,8 @@ impl DeviceId { pub struct FingerId(pub(crate) platform_impl::FingerId); impl FingerId { - /// Returns a dummy id, useful for unit testing. - /// - /// # Notes - /// - /// The only guarantee made about the return value of this function is that - /// it will always be equal to itself and to future values returned by this function. - /// No other guarantees are made. This may be equal to a real `FingerId`. - pub const fn dummy() -> Self { + #[cfg(test)] + pub(crate) const fn dummy() -> Self { FingerId(platform_impl::FingerId::dummy()) } } @@ -1056,7 +1038,7 @@ mod tests { use crate::window::WindowId; // Mainline events. - let wid = WindowId::dummy(); + let wid = WindowId::from_raw(0); x(NewEvents(event::StartCause::Init)); x(AboutToWait); x(LoopExiting); diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 0503bf871e..63c64d9ed7 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -668,10 +668,6 @@ impl OwnedDisplayHandle { pub(crate) struct WindowId; impl WindowId { - pub const fn dummy() -> Self { - WindowId - } - pub const fn into_raw(self) -> u64 { 0 } @@ -685,6 +681,7 @@ impl WindowId { pub struct DeviceId(i32); impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { DeviceId(0) } @@ -694,6 +691,7 @@ impl DeviceId { pub struct FingerId(i32); impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId(0) } diff --git a/src/platform_impl/apple/appkit/mod.rs b/src/platform_impl/apple/appkit/mod.rs index 8724c24938..62ba7d9e3c 100644 --- a/src/platform_impl/apple/appkit/mod.rs +++ b/src/platform_impl/apple/appkit/mod.rs @@ -32,6 +32,7 @@ pub(crate) use crate::platform_impl::Fullscreen; pub struct DeviceId; impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { DeviceId } @@ -44,6 +45,7 @@ pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId); pub struct FingerId; impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId } diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index aaa5775c6a..1fcdb4c8f5 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -339,10 +339,6 @@ impl CoreWindow for Window { pub struct WindowId(pub usize); impl WindowId { - pub const fn dummy() -> Self { - Self(0) - } - pub const fn into_raw(self) -> u64 { self.0 as u64 } diff --git a/src/platform_impl/apple/uikit/mod.rs b/src/platform_impl/apple/uikit/mod.rs index d8347a75ee..57293a2410 100644 --- a/src/platform_impl/apple/uikit/mod.rs +++ b/src/platform_impl/apple/uikit/mod.rs @@ -30,6 +30,7 @@ pub(crate) use crate::platform_impl::Fullscreen; pub struct DeviceId; impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { DeviceId } @@ -41,6 +42,7 @@ pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId); pub struct FingerId(usize); impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId(0) } diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index b7603244ac..93f8b00aa4 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -944,10 +944,6 @@ impl Inner { pub struct WindowId(usize); impl WindowId { - pub const fn dummy() -> Self { - WindowId(0) - } - pub const fn into_raw(self) -> u64 { self.0 as _ } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 9ecc809bf3..3901b65ae8 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -111,10 +111,6 @@ pub(crate) static X11_BACKEND: Lazy, XNotSupported pub struct WindowId(u64); impl WindowId { - pub const fn dummy() -> Self { - Self(0) - } - pub const fn into_raw(self) -> u64 { self.0 } @@ -133,6 +129,7 @@ pub enum DeviceId { } impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { #[cfg(wayland_platform)] return DeviceId::Wayland(wayland::DeviceId::dummy()); @@ -150,6 +147,7 @@ pub enum FingerId { } impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { #[cfg(wayland_platform)] return FingerId::Wayland(wayland::FingerId::dummy()); diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 214b4a71d5..9f49100622 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -22,6 +22,7 @@ mod window; pub struct DeviceId; impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { DeviceId } @@ -31,6 +32,7 @@ impl DeviceId { pub struct FingerId(i32); impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId(0) } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index cada63f42e..c47aec727c 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -812,6 +812,7 @@ impl<'a> Deref for DeviceInfo<'a> { pub struct DeviceId(xinput::DeviceId); impl DeviceId { + #[cfg(test)] #[allow(unused)] pub const fn dummy() -> Self { DeviceId(0) @@ -822,6 +823,7 @@ impl DeviceId { pub struct FingerId(u32); impl FingerId { + #[cfg(test)] #[allow(unused)] pub const fn dummy() -> Self { FingerId(0) diff --git a/src/platform_impl/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index 22db646d69..56248e8163 100644 --- a/src/platform_impl/orbital/mod.rs +++ b/src/platform_impl/orbital/mod.rs @@ -105,10 +105,6 @@ pub struct WindowId { } impl WindowId { - pub const fn dummy() -> Self { - WindowId { fd: u64::MAX } - } - pub const fn into_raw(self) -> u64 { self.fd } @@ -122,6 +118,7 @@ impl WindowId { pub struct DeviceId; impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { DeviceId } @@ -131,6 +128,7 @@ impl DeviceId { pub struct FingerId; impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId } diff --git a/src/platform_impl/web/event.rs b/src/platform_impl/web/event.rs index 937702b118..a1f37a348f 100644 --- a/src/platform_impl/web/event.rs +++ b/src/platform_impl/web/event.rs @@ -1,13 +1,18 @@ -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct DeviceId(i32); +#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] +pub enum DeviceId { + Wheel, + Keyboard, + Id(i32), +} impl DeviceId { pub fn new(pointer_id: i32) -> Self { - Self(pointer_id) + Self::Id(pointer_id) } + #[cfg(test)] pub const fn dummy() -> Self { - Self(-1) + Self::Id(-1) } } @@ -22,6 +27,7 @@ impl FingerId { Self { pointer_id, primary } } + #[cfg(test)] pub const fn dummy() -> Self { Self { pointer_id: -1, primary: false } } diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index daaae53d4c..cf430fc9f5 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -327,7 +327,7 @@ impl Shared { if let Some(delta) = backend::event::mouse_scroll_delta(&window, &event) { runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::dummy()), + device_id: RootDeviceId(DeviceId::Wheel), event: DeviceEvent::MouseWheel { delta }, }); } @@ -381,7 +381,7 @@ impl Shared { } runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::dummy()), + device_id: RootDeviceId(DeviceId::Keyboard), event: DeviceEvent::Key(RawKeyEvent { physical_key: backend::event::key_code(&event), state: ElementState::Pressed, @@ -399,7 +399,7 @@ impl Shared { } runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::dummy()), + device_id: RootDeviceId(DeviceId::Keyboard), event: DeviceEvent::Key(RawKeyEvent { physical_key: backend::event::key_code(&event), state: ElementState::Released, diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 7b4f63da52..4251576b20 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -144,7 +144,7 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(DeviceId::dummy()); + let device_id = RootDeviceId(DeviceId::Keyboard); runner.send_events( iter::once(Event::WindowEvent { @@ -180,7 +180,7 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(DeviceId::dummy()); + let device_id = RootDeviceId(DeviceId::Keyboard); runner.send_events( iter::once(Event::WindowEvent { @@ -502,7 +502,7 @@ impl ActiveEventLoop { Event::WindowEvent { window_id: RootWindowId(id), event: WindowEvent::MouseWheel { - device_id: RootDeviceId(DeviceId::dummy()), + device_id: RootDeviceId(DeviceId::Keyboard), delta, phase: TouchPhase::Moved, }, diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 6d4943272b..c93b1e3bc4 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -433,10 +433,6 @@ impl Drop for Inner { pub struct WindowId(pub(crate) u64); impl WindowId { - pub const fn dummy() -> Self { - Self(0) - } - pub const fn into_raw(self) -> u64 { self.0 } diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index efdda2c57c..48c71eb538 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -63,6 +63,7 @@ unsafe impl Sync for PlatformSpecificWindowAttributes {} pub struct DeviceId(u32); impl DeviceId { + #[cfg(test)] pub const fn dummy() -> Self { DeviceId(0) } @@ -85,6 +86,7 @@ pub struct FingerId { } impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId { id: 0, primary: false } } @@ -115,10 +117,6 @@ unsafe impl Send for WindowId {} unsafe impl Sync for WindowId {} impl WindowId { - pub const fn dummy() -> Self { - WindowId(0) - } - pub const fn into_raw(self) -> u64 { self.0 as u64 } diff --git a/src/window.rs b/src/window.rs index 33238eb2ef..debb58a6a6 100644 --- a/src/window.rs +++ b/src/window.rs @@ -24,17 +24,6 @@ use crate::utils::AsAny; pub struct WindowId(pub(crate) platform_impl::WindowId); impl WindowId { - /// Returns a dummy id, useful for unit testing. - /// - /// # Notes - /// - /// The only guarantee made about the return value of this function is that - /// it will always be equal to itself and to future values returned by this function. - /// No other guarantees are made. This may be equal to a real [`WindowId`]. - pub const fn dummy() -> Self { - WindowId(platform_impl::WindowId::dummy()) - } - /// Convert the `WindowId` into the underlying integer. /// /// This is useful if you need to pass the ID across an FFI boundary, or store it in an atomic. From 5c99ba4f0f16b72d9a635424767790a8d83e4c45 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 14 Aug 2024 01:12:06 +0200 Subject: [PATCH 5/7] Change `DeviceId` to `Option` --- examples/window.rs | 2 +- src/application.rs | 6 +- src/changelog/unreleased.md | 2 + src/event.rs | 62 ++++++++++--------- src/platform_impl/android/mod.rs | 4 +- src/platform_impl/apple/appkit/app.rs | 7 +-- src/platform_impl/apple/appkit/mod.rs | 4 -- src/platform_impl/apple/appkit/view.rs | 37 +++++------ src/platform_impl/apple/uikit/mod.rs | 3 - src/platform_impl/apple/uikit/view.rs | 16 ++--- src/platform_impl/linux/mod.rs | 1 + .../linux/wayland/event_loop/mod.rs | 2 +- .../linux/wayland/event_loop/sink.rs | 12 ++-- .../linux/wayland/seat/keyboard/mod.rs | 5 +- .../linux/wayland/seat/pointer/mod.rs | 20 +++--- .../wayland/seat/pointer/relative_pointer.rs | 7 +-- .../linux/wayland/seat/touch/mod.rs | 18 ++---- .../linux/x11/event_processor.rs | 38 ++++++------ src/platform_impl/linux/x11/util/input.rs | 1 - src/platform_impl/orbital/event_loop.rs | 29 +++------ src/platform_impl/web/event.rs | 19 +++--- src/platform_impl/web/event_loop/mod.rs | 2 +- src/platform_impl/web/event_loop/runner.rs | 12 ++-- .../web/event_loop/window_target.rs | 31 ++++------ src/platform_impl/web/web_sys/canvas.rs | 28 ++++++--- src/platform_impl/web/web_sys/pointer.rs | 28 ++++++--- src/platform_impl/windows/event_loop.rs | 38 ++++++------ src/platform_impl/windows/mod.rs | 3 - 28 files changed, 209 insertions(+), 228 deletions(-) diff --git a/examples/window.rs b/examples/window.rs index 650b0a7cb2..99e87a57be 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -522,7 +522,7 @@ impl ApplicationHandler for Application { fn device_event( &mut self, _event_loop: &dyn ActiveEventLoop, - device_id: DeviceId, + device_id: Option, event: DeviceEvent, ) { info!("Device {device_id:?} event: {event:?}"); diff --git a/src/application.rs b/src/application.rs index 8b268b05d5..2dc224c941 100644 --- a/src/application.rs +++ b/src/application.rs @@ -196,7 +196,7 @@ pub trait ApplicationHandler { fn device_event( &mut self, event_loop: &dyn ActiveEventLoop, - device_id: DeviceId, + device_id: Option, event: DeviceEvent, ) { let _ = (event_loop, device_id, event); @@ -363,7 +363,7 @@ impl ApplicationHandler for &mut A { fn device_event( &mut self, event_loop: &dyn ActiveEventLoop, - device_id: DeviceId, + device_id: Option, event: DeviceEvent, ) { (**self).device_event(event_loop, device_id, event); @@ -431,7 +431,7 @@ impl ApplicationHandler for Box { fn device_event( &mut self, event_loop: &dyn ActiveEventLoop, - device_id: DeviceId, + device_id: Option, event: DeviceEvent, ) { (**self).device_event(event_loop, device_id, event); diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 4e7f83e9ba..9c36dc45e1 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -125,6 +125,8 @@ changelog entry. - `Window::set_max_inner_size` to `set_max_surface_size`. To migrate, you can probably just replace all instances of `inner_size` with `surface_size` in your codebase. +- Every event carrying a `DeviceId` now uses `Option` instead. A `None` value signifies that the + device can't be uniquely differentiated. ### Removed diff --git a/src/event.rs b/src/event.rs index 58e12f5421..82f9fd9d8e 100644 --- a/src/event.rs +++ b/src/event.rs @@ -78,7 +78,7 @@ pub(crate) enum Event { /// /// [`ApplicationHandler::device_event`]: crate::application::ApplicationHandler::device_event #[allow(clippy::enum_variant_names)] - DeviceEvent { device_id: DeviceId, event: DeviceEvent }, + DeviceEvent { device_id: Option, event: DeviceEvent }, /// See [`ApplicationHandler::suspended`] for details. /// @@ -199,7 +199,7 @@ pub enum WindowEvent { /// numpad keys act as if NumLock wasn't active. When this is used, the OS sends fake key /// events which are not marked as `is_synthetic`. KeyboardInput { - device_id: DeviceId, + device_id: Option, event: KeyEvent, /// If `true`, the event was generated synthetically by winit @@ -236,7 +236,7 @@ pub enum WindowEvent { /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform CursorMoved { - device_id: DeviceId, + device_id: Option, /// (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 @@ -254,7 +254,7 @@ pub enum WindowEvent { /// [`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 }, + CursorEntered { device_id: Option }, /// The cursor has left the window. /// @@ -265,13 +265,13 @@ pub enum WindowEvent { /// [`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 }, + CursorLeft { device_id: Option }, /// A mouse wheel movement or touchpad scroll occurred. - MouseWheel { device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase }, + MouseWheel { device_id: Option, delta: MouseScrollDelta, phase: TouchPhase }, /// An mouse button press has been received. - MouseInput { device_id: DeviceId, state: ElementState, button: MouseButton }, + MouseInput { device_id: Option, state: ElementState, button: MouseButton }, /// Two-finger pinch gesture, often used for magnification. /// @@ -280,7 +280,7 @@ pub enum WindowEvent { /// - Only available on **macOS** and **iOS**. /// - On iOS, not recognized by default. It must be enabled when needed. PinchGesture { - device_id: DeviceId, + device_id: Option, /// Positive values indicate magnification (zooming in) and negative /// values indicate shrinking (zooming out). /// @@ -296,7 +296,7 @@ pub enum WindowEvent { /// - Only available on **iOS**. /// - On iOS, not recognized by default. It must be enabled when needed. PanGesture { - device_id: DeviceId, + device_id: Option, /// Change in pixels of pan gesture from last update. delta: PhysicalPosition, phase: TouchPhase, @@ -320,7 +320,7 @@ pub enum WindowEvent { /// /// - Only available on **macOS 10.8** and later, and **iOS**. /// - On iOS, not recognized by default. It must be enabled when needed. - DoubleTapGesture { device_id: DeviceId }, + DoubleTapGesture { device_id: Option }, /// Two-finger rotation gesture. /// @@ -332,7 +332,7 @@ pub enum WindowEvent { /// - Only available on **macOS** and **iOS**. /// - On iOS, not recognized by default. It must be enabled when needed. RotationGesture { - device_id: DeviceId, + device_id: Option, /// change in rotation in degrees delta: f32, phase: TouchPhase, @@ -343,7 +343,7 @@ pub enum WindowEvent { /// At the moment, only supported on Apple forcetouch-capable macbooks. /// The parameters are: pressure level (value between 0 and 1 representing how hard the /// touchpad is being pressed) and stage (integer representing the click level). - TouchpadPressure { device_id: DeviceId, pressure: f32, stage: i64 }, + TouchpadPressure { device_id: Option, pressure: f32, stage: i64 }, /// Touch event has been received /// @@ -846,7 +846,7 @@ pub enum TouchPhase { /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform #[derive(Debug, Clone, Copy, PartialEq)] pub struct Touch { - pub device_id: DeviceId, + pub device_id: Option, pub phase: TouchPhase, pub location: PhysicalPosition, /// Describes how hard the screen was pressed. May be `None` if the platform @@ -1027,7 +1027,6 @@ mod tests { ($closure:expr) => {{ #[allow(unused_mut)] let mut x = $closure; - let did = event::DeviceId::dummy(); let fid = event::FingerId::dummy(); #[allow(deprecated)] @@ -1057,39 +1056,39 @@ mod tests { with_window_event(HoveredFile("x.txt".into())); with_window_event(HoveredFileCancelled); with_window_event(Ime(Enabled)); - with_window_event(CursorMoved { device_id: did, position: (0, 0).into() }); + with_window_event(CursorMoved { device_id: None, position: (0, 0).into() }); with_window_event(ModifiersChanged(event::Modifiers::default())); - with_window_event(CursorEntered { device_id: did }); - with_window_event(CursorLeft { device_id: did }); + with_window_event(CursorEntered { device_id: None }); + with_window_event(CursorLeft { device_id: None }); with_window_event(MouseWheel { - device_id: did, + device_id: None, delta: event::MouseScrollDelta::LineDelta(0.0, 0.0), phase: event::TouchPhase::Started, }); with_window_event(MouseInput { - device_id: did, + device_id: None, state: event::ElementState::Pressed, button: event::MouseButton::Other(0), }); with_window_event(PinchGesture { - device_id: did, + device_id: None, delta: 0.0, phase: event::TouchPhase::Started, }); - with_window_event(DoubleTapGesture { device_id: did }); + with_window_event(DoubleTapGesture { device_id: None }); with_window_event(RotationGesture { - device_id: did, + device_id: None, delta: 0.0, phase: event::TouchPhase::Started, }); with_window_event(PanGesture { - device_id: did, + device_id: None, delta: PhysicalPosition::::new(0.0, 0.0), phase: event::TouchPhase::Started, }); - with_window_event(TouchpadPressure { device_id: did, pressure: 0.0, stage: 0 }); + with_window_event(TouchpadPressure { device_id: None, pressure: 0.0, stage: 0 }); with_window_event(Touch(event::Touch { - device_id: did, + device_id: None, phase: event::TouchPhase::Started, location: (0.0, 0.0).into(), finger_id: fid, @@ -1104,7 +1103,7 @@ mod tests { use event::DeviceEvent::*; let with_device_event = - |dev_ev| x(event::Event::DeviceEvent { device_id: did, event: dev_ev }); + |dev_ev| x(event::Event::DeviceEvent { device_id: None, event: dev_ev }); with_device_event(MouseMotion { delta: (0.0, 0.0).into() }); with_device_event(MouseWheel { @@ -1150,7 +1149,6 @@ mod tests { let _ = event::StartCause::Init.clone(); let did = crate::event::DeviceId::dummy().clone(); - let fid = crate::event::FingerId::dummy().clone(); HashSet::new().insert(did); let mut set = [did, did, did]; set.sort_unstable(); @@ -1158,12 +1156,20 @@ mod tests { set2.insert(did); set2.insert(did); + let fid = crate::event::FingerId::dummy().clone(); + HashSet::new().insert(fid); + let mut set = [fid, fid, fid]; + set.sort_unstable(); + let mut set2 = BTreeSet::new(); + set2.insert(fid); + set2.insert(fid); + HashSet::new().insert(event::TouchPhase::Started.clone()); HashSet::new().insert(event::MouseButton::Left.clone()); HashSet::new().insert(event::Ime::Enabled); let _ = event::Touch { - device_id: did, + device_id: None, phase: event::TouchPhase::Started, location: (0.0, 0.0).into(), finger_id: fid, diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 63c64d9ed7..ef4a0825c1 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -316,7 +316,7 @@ impl EventLoop { match event { InputEvent::MotionEvent(motion_event) => { let window_id = window::WindowId(WindowId); - let device_id = event::DeviceId(DeviceId(motion_event.device_id())); + let device_id = Some(event::DeviceId(DeviceId(motion_event.device_id()))); let phase = match motion_event.action() { MotionAction::Down | MotionAction::PointerDown => { @@ -388,7 +388,7 @@ impl EventLoop { let window_id = window::WindowId(WindowId); let event = event::WindowEvent::KeyboardInput { - device_id: event::DeviceId(DeviceId(key.device_id())), + device_id: Some(event::DeviceId(DeviceId(key.device_id()))), event: event::KeyEvent { state, physical_key: keycodes::to_physical_key(keycode), diff --git a/src/platform_impl/apple/appkit/app.rs b/src/platform_impl/apple/appkit/app.rs index 5313640131..5292f92f41 100644 --- a/src/platform_impl/apple/appkit/app.rs +++ b/src/platform_impl/apple/appkit/app.rs @@ -7,7 +7,6 @@ use objc2_app_kit::{NSApplication, NSEvent, NSEventModifierFlags, NSEventType, N use objc2_foundation::{MainThreadMarker, NSObject}; use super::app_state::AppState; -use super::DEVICE_ID; use crate::event::{DeviceEvent, ElementState}; declare_class!( @@ -61,7 +60,7 @@ fn maybe_dispatch_device_event(app_state: &Rc, event: &NSEvent) { if delta_x != 0.0 || delta_y != 0.0 { app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event(event_loop, DEVICE_ID, DeviceEvent::MouseMotion { + app.device_event(event_loop, None, DeviceEvent::MouseMotion { delta: (delta_x, delta_y), }); }); @@ -70,7 +69,7 @@ fn maybe_dispatch_device_event(app_state: &Rc, event: &NSEvent) { NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => { let button = unsafe { event.buttonNumber() } as u32; app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event(event_loop, DEVICE_ID, DeviceEvent::Button { + app.device_event(event_loop, None, DeviceEvent::Button { button, state: ElementState::Pressed, }); @@ -79,7 +78,7 @@ fn maybe_dispatch_device_event(app_state: &Rc, event: &NSEvent) { NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => { let button = unsafe { event.buttonNumber() } as u32; app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event(event_loop, DEVICE_ID, DeviceEvent::Button { + app.device_event(event_loop, None, DeviceEvent::Button { button, state: ElementState::Released, }); diff --git a/src/platform_impl/apple/appkit/mod.rs b/src/platform_impl/apple/appkit/mod.rs index 62ba7d9e3c..9558ce481b 100644 --- a/src/platform_impl/apple/appkit/mod.rs +++ b/src/platform_impl/apple/appkit/mod.rs @@ -24,7 +24,6 @@ pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle}; pub(crate) use self::window::{Window, WindowId}; pub(crate) use self::window_delegate::PlatformSpecificWindowAttributes; pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; -use crate::event::DeviceId as RootDeviceId; pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::platform_impl::Fullscreen; @@ -38,9 +37,6 @@ impl DeviceId { } } -// Constant device ID; to be removed when if backend is updated to report real device IDs. -pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId); - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId; diff --git a/src/platform_impl/apple/appkit/view.rs b/src/platform_impl/apple/appkit/view.rs index 0ba46a6338..f7c3f9b1d8 100644 --- a/src/platform_impl/apple/appkit/view.rs +++ b/src/platform_impl/apple/appkit/view.rs @@ -24,7 +24,6 @@ use super::event::{ scancode_to_physicalkey, }; use super::window::WinitWindow; -use super::DEVICE_ID; use crate::dpi::{LogicalPosition, LogicalSize}; use crate::event::{ DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, TouchPhase, @@ -486,7 +485,7 @@ declare_class!( if !had_ime_input || self.ivars().forward_key_to_app.get() { let key_event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); self.queue_event(WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event: key_event, is_synthetic: false, }); @@ -506,7 +505,7 @@ declare_class!( ImeState::Ground | ImeState::Disabled ) { self.queue_event(WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event: create_key_event(&event, false, false, None), is_synthetic: false, }); @@ -557,7 +556,7 @@ declare_class!( let event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); self.queue_event(WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event, is_synthetic: false, }); @@ -642,7 +641,7 @@ declare_class!( fn mouse_entered(&self, _event: &NSEvent) { trace_scope!("mouseEntered:"); self.queue_event(WindowEvent::CursorEntered { - device_id: DEVICE_ID, + device_id: None, }); } @@ -651,7 +650,7 @@ declare_class!( trace_scope!("mouseExited:"); self.queue_event(WindowEvent::CursorLeft { - device_id: DEVICE_ID, + device_id: None, }); } @@ -689,10 +688,10 @@ declare_class!( self.update_modifiers(event, false); self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| - app.device_event(event_loop, DEVICE_ID, DeviceEvent::MouseWheel { delta }) + app.device_event(event_loop, None, DeviceEvent::MouseWheel { delta }) ); self.queue_event(WindowEvent::MouseWheel { - device_id: DEVICE_ID, + device_id: None, delta, phase, }); @@ -714,7 +713,7 @@ declare_class!( }; self.queue_event(WindowEvent::PinchGesture { - device_id: DEVICE_ID, + device_id: None, delta: unsafe { event.magnification() }, phase, }); @@ -727,7 +726,7 @@ declare_class!( self.mouse_motion(event); self.queue_event(WindowEvent::DoubleTapGesture { - device_id: DEVICE_ID, + device_id: None, }); } @@ -747,7 +746,7 @@ declare_class!( }; self.queue_event(WindowEvent::RotationGesture { - device_id: DEVICE_ID, + device_id: None, delta: unsafe { event.rotation() }, phase, }); @@ -758,7 +757,7 @@ declare_class!( trace_scope!("pressureChangeWithEvent:"); self.queue_event(WindowEvent::TouchpadPressure { - device_id: DEVICE_ID, + device_id: None, pressure: unsafe { event.pressure() }, stage: unsafe { event.stage() } as i64, }); @@ -972,7 +971,7 @@ impl WinitView { event.location = KeyLocation::Left; event.physical_key = get_left_modifier_code(&event.logical_key).into(); events.push_back(WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event, is_synthetic: false, }); @@ -981,7 +980,7 @@ impl WinitView { event.location = KeyLocation::Right; event.physical_key = get_right_modifier_code(&event.logical_key).into(); events.push_back(WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event, is_synthetic: false, }); @@ -1012,7 +1011,7 @@ impl WinitView { } events.push_back(WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event, is_synthetic: false, }); @@ -1038,11 +1037,7 @@ impl WinitView { self.update_modifiers(event, false); - self.queue_event(WindowEvent::MouseInput { - device_id: DEVICE_ID, - state: button_state, - button, - }); + self.queue_event(WindowEvent::MouseInput { device_id: None, state: button_state, button }); } fn mouse_motion(&self, event: &NSEvent) { @@ -1067,7 +1062,7 @@ impl WinitView { self.update_modifiers(event, false); self.queue_event(WindowEvent::CursorMoved { - device_id: DEVICE_ID, + device_id: None, position: view_point.to_physical(self.scale_factor()), }); } diff --git a/src/platform_impl/apple/uikit/mod.rs b/src/platform_impl/apple/uikit/mod.rs index 57293a2410..98af1bdaaa 100644 --- a/src/platform_impl/apple/uikit/mod.rs +++ b/src/platform_impl/apple/uikit/mod.rs @@ -18,7 +18,6 @@ pub(crate) use self::window::{PlatformSpecificWindowAttributes, Window, WindowId pub(crate) use crate::cursor::{ NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource, }; -use crate::event::DeviceId as RootDeviceId; pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::platform_impl::Fullscreen; @@ -36,8 +35,6 @@ impl DeviceId { } } -pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId); - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(usize); diff --git a/src/platform_impl/apple/uikit/view.rs b/src/platform_impl/apple/uikit/view.rs index 20a185b957..a258a8dae0 100644 --- a/src/platform_impl/apple/uikit/view.rs +++ b/src/platform_impl/apple/uikit/view.rs @@ -14,7 +14,7 @@ use objc2_ui_kit::{ use super::app_state::{self, EventWrapper}; use super::window::WinitUIWindow; -use super::{FingerId, DEVICE_ID}; +use super::FingerId; use crate::dpi::PhysicalPosition; use crate::event::{ ElementState, Event, FingerId as RootFingerId, Force, KeyEvent, Touch, TouchPhase, WindowEvent, @@ -198,7 +198,7 @@ declare_class!( let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.id()), event: WindowEvent::PinchGesture { - device_id: DEVICE_ID, + device_id: None, delta: delta as f64, phase, }, @@ -216,7 +216,7 @@ declare_class!( let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.id()), event: WindowEvent::DoubleTapGesture { - device_id: DEVICE_ID, + device_id: None, }, }); @@ -258,7 +258,7 @@ declare_class!( let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.id()), event: WindowEvent::RotationGesture { - device_id: DEVICE_ID, + device_id: None, delta: -delta.to_degrees() as _, phase, }, @@ -309,7 +309,7 @@ declare_class!( let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.id()), event: WindowEvent::PanGesture { - device_id: DEVICE_ID, + device_id: None, delta: PhysicalPosition::new(dx as _, dy as _), phase, }, @@ -530,7 +530,7 @@ impl WinitView { touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.id()), event: WindowEvent::Touch(Touch { - device_id: DEVICE_ID, + device_id: None, finger_id: RootFingerId(FingerId(touch_id)), location: physical_location, force, @@ -572,7 +572,7 @@ impl WinitView { platform_specific: KeyEventExtra {}, }, is_synthetic: false, - device_id: DEVICE_ID, + device_id: None, }, }) }) @@ -590,7 +590,7 @@ impl WinitView { EventWrapper::StaticEvent(Event::WindowEvent { window_id, event: WindowEvent::KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event: KeyEvent { state, logical_key: Key::Named(NamedKey::Backspace), diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 3901b65ae8..ddf628f196 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -125,6 +125,7 @@ pub enum DeviceId { #[cfg(x11_platform)] X(x11::DeviceId), #[cfg(wayland_platform)] + #[allow(unused)] Wayland(wayland::DeviceId), } diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 1ba1667e8c..6b12e20a5c 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -30,7 +30,7 @@ use sink::EventSink; use super::state::{WindowCompositorUpdate, WinitState}; use super::window::state::FrameCallbackState; -use super::{logical_to_physical_rounded, DeviceId, WindowId}; +use super::{logical_to_physical_rounded, WindowId}; type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource, WinitState>; diff --git a/src/platform_impl/linux/wayland/event_loop/sink.rs b/src/platform_impl/linux/wayland/event_loop/sink.rs index a313a621ce..ed33f8fd06 100644 --- a/src/platform_impl/linux/wayland/event_loop/sink.rs +++ b/src/platform_impl/linux/wayland/event_loop/sink.rs @@ -2,9 +2,8 @@ use std::vec::Drain; -use super::{DeviceId, WindowId}; -use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent}; -use crate::platform_impl::platform::DeviceId as PlatformDeviceId; +use super::WindowId; +use crate::event::{DeviceEvent, Event, WindowEvent}; use crate::window::WindowId as RootWindowId; /// An event loop's sink to deliver events from the Wayland event callbacks @@ -27,11 +26,8 @@ impl EventSink { /// Add new device event to a queue. #[inline] - pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) { - self.window_events.push(Event::DeviceEvent { - event, - device_id: RootDeviceId(PlatformDeviceId::Wayland(device_id)), - }); + pub fn push_device_event(&mut self, event: DeviceEvent) { + self.window_events.push(Event::DeviceEvent { event, device_id: None }); } /// Add new window event to a queue. diff --git a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs index 2ce88cd76b..871df785e3 100644 --- a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs +++ b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs @@ -17,7 +17,7 @@ use crate::keyboard::ModifiersState; use crate::platform_impl::common::xkb::Context; use crate::platform_impl::wayland::event_loop::sink::EventSink; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::wayland::{self, DeviceId, WindowId}; +use crate::platform_impl::wayland::{self, WindowId}; impl Dispatch for WinitState { fn event( @@ -369,10 +369,9 @@ fn key_input( None => return, }; - let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId)); if let Some(mut key_context) = keyboard_state.xkb_context.key_context() { let event = key_context.process_key_event(keycode, state, repeat); - let event = WindowEvent::KeyboardInput { device_id, event, is_synthetic: false }; + let event = WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: false }; event_sink.push_window_event(event, window_id); } } diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index fcca59343b..e99988fe28 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -30,7 +30,7 @@ use crate::dpi::{LogicalPosition, PhysicalPosition}; use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent}; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::wayland::{self, DeviceId, WindowId}; +use crate::platform_impl::wayland::{self, WindowId}; pub mod relative_pointer; @@ -59,8 +59,6 @@ impl PointerHandler for WinitState { }, }; - let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId)); - for event in events { let surface = &event.surface; @@ -124,8 +122,10 @@ 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::CursorEntered { device_id: None }, + window_id, + ); window.pointer_entered(Arc::downgrade(themed_pointer)); @@ -133,7 +133,7 @@ impl PointerHandler for WinitState { pointer.winit_data().inner.lock().unwrap().surface = Some(window_id); self.events_sink.push_window_event( - WindowEvent::CursorMoved { device_id, position }, + WindowEvent::CursorMoved { device_id: None, position }, window_id, ); }, @@ -144,11 +144,11 @@ impl PointerHandler for WinitState { pointer.winit_data().inner.lock().unwrap().surface = None; self.events_sink - .push_window_event(WindowEvent::CursorLeft { device_id }, window_id); + .push_window_event(WindowEvent::CursorLeft { device_id: None }, window_id); }, PointerEventKind::Motion { .. } => { self.events_sink.push_window_event( - WindowEvent::CursorMoved { device_id, position }, + WindowEvent::CursorMoved { device_id: None, position }, window_id, ); }, @@ -164,7 +164,7 @@ impl PointerHandler for WinitState { ElementState::Released }; self.events_sink.push_window_event( - WindowEvent::MouseInput { device_id, state, button }, + WindowEvent::MouseInput { device_id: None, state, button }, window_id, ); }, @@ -209,7 +209,7 @@ impl PointerHandler for WinitState { }; self.events_sink.push_window_event( - WindowEvent::MouseWheel { device_id, delta, phase }, + WindowEvent::MouseWheel { device_id: None, delta, phase }, window_id, ) }, diff --git a/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs b/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs index 33fc9e91e3..b71fc238d2 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs @@ -66,10 +66,9 @@ impl Dispatch for RelativePointerS }, _ => return, }; - state.events_sink.push_device_event( - DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) }, - super::DeviceId, - ); + state + .events_sink + .push_device_event(DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) }); } } diff --git a/src/platform_impl/linux/wayland/seat/touch/mod.rs b/src/platform_impl/linux/wayland/seat/touch/mod.rs index 665279f019..caaf77224d 100644 --- a/src/platform_impl/linux/wayland/seat/touch/mod.rs +++ b/src/platform_impl/linux/wayland/seat/touch/mod.rs @@ -10,7 +10,7 @@ use tracing::warn; use crate::dpi::LogicalPosition; use crate::event::{Touch, TouchPhase, WindowEvent}; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::wayland::{self, DeviceId, FingerId}; +use crate::platform_impl::wayland::{self, FingerId}; impl TouchHandler for WinitState { fn down( @@ -44,9 +44,7 @@ impl TouchHandler for WinitState { self.events_sink.push_window_event( WindowEvent::Touch(Touch { - device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( - DeviceId, - )), + device_id: None, phase: TouchPhase::Started, location: location.to_physical(scale_factor), force: None, @@ -89,9 +87,7 @@ impl TouchHandler for WinitState { self.events_sink.push_window_event( WindowEvent::Touch(Touch { - device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( - DeviceId, - )), + device_id: None, phase: TouchPhase::Ended, location: touch_point.location.to_physical(scale_factor), force: None, @@ -136,9 +132,7 @@ impl TouchHandler for WinitState { self.events_sink.push_window_event( WindowEvent::Touch(Touch { - device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( - DeviceId, - )), + device_id: None, phase: TouchPhase::Moved, location: touch_point.location.to_physical(scale_factor), force: None, @@ -170,9 +164,7 @@ impl TouchHandler for WinitState { self.events_sink.push_window_event( WindowEvent::Touch(Touch { - device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( - DeviceId, - )), + device_id: None, phase: TouchPhase::Cancelled, location, force: None, diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 032c417ae1..c92bbbb77f 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -878,7 +878,6 @@ impl EventProcessor { }; let window_id = mkwid(window); - let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD); let keycode = xev.keycode as _; @@ -942,7 +941,11 @@ impl EventProcessor { let event = key_processor.process_key_event(keycode, state, repeat); let event = Event::WindowEvent { window_id, - event: WindowEvent::KeyboardInput { device_id, event, is_synthetic: false }, + event: WindowEvent::KeyboardInput { + device_id: None, + event, + is_synthetic: false, + }, }; callback(&self.target, event); } @@ -1012,7 +1015,7 @@ impl EventProcessor { F: FnMut(&ActiveEventLoop, Event), { let window_id = mkwid(event.event as xproto::Window); - let device_id = mkdid(event.deviceid as xinput::DeviceId); + let device_id = Some(mkdid(event.deviceid as xinput::DeviceId)); // Set the timestamp. self.target.xconn.set_timestamp(event.time as xproto::Timestamp); @@ -1066,7 +1069,7 @@ impl EventProcessor { // Set the timestamp. self.target.xconn.set_timestamp(event.time as xproto::Timestamp); - let device_id = mkdid(event.deviceid as xinput::DeviceId); + let device_id = Some(mkdid(event.deviceid as xinput::DeviceId)); let window = event.event as xproto::Window; let window_id = mkwid(window); let new_cursor_pos = (event.event_x, event.event_y); @@ -1161,6 +1164,7 @@ impl EventProcessor { } if self.window_exists(window) { + let device_id = Some(device_id); let position = PhysicalPosition::new(event.event_x, event.event_y); let event = @@ -1190,7 +1194,7 @@ impl EventProcessor { let event = Event::WindowEvent { window_id: mkwid(window), event: WindowEvent::CursorLeft { - device_id: mkdid(event.deviceid as xinput::DeviceId), + device_id: Some(mkdid(event.deviceid as xinput::DeviceId)), }, }; callback(&self.target, event); @@ -1241,16 +1245,15 @@ impl EventProcessor { // The deviceid for this event is for a keyboard instead of a pointer, // so we have to do a little extra work. - let pointer_id = self + let device_id = self .devices .borrow() .get(&DeviceId(xev.deviceid as xinput::DeviceId)) - .map(|device| device.attachment) - .unwrap_or(2); + .map(|device| mkdid(device.attachment as _)); let event = Event::WindowEvent { window_id, - event: WindowEvent::CursorMoved { device_id: mkdid(pointer_id as _), position }, + event: WindowEvent::CursorMoved { device_id, position }, }; callback(&self.target, event); } @@ -1324,10 +1327,7 @@ impl EventProcessor { if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) { let event = Event::WindowEvent { window_id, - event: WindowEvent::CursorMoved { - device_id: mkdid(util::VIRTUAL_CORE_POINTER), - position: location.cast(), - }, + event: WindowEvent::CursorMoved { device_id: None, position: location.cast() }, }; callback(&self.target, event); } @@ -1335,7 +1335,7 @@ impl EventProcessor { let event = Event::WindowEvent { window_id, event: WindowEvent::Touch(Touch { - device_id: mkdid(xev.deviceid as xinput::DeviceId), + device_id: Some(mkdid(xev.deviceid as xinput::DeviceId)), phase, location, force: None, // TODO @@ -1355,7 +1355,7 @@ impl EventProcessor { if xev.flags & xinput2::XIPointerEmulated == 0 { let event = Event::DeviceEvent { - device_id: mkdid(xev.deviceid as xinput::DeviceId), + device_id: Some(mkdid(xev.deviceid as xinput::DeviceId)), event: DeviceEvent::Button { state, button: xev.detail as u32 }, }; callback(&self.target, event); @@ -1369,7 +1369,7 @@ impl EventProcessor { // Set the timestamp. self.target.xconn.set_timestamp(xev.time as xproto::Timestamp); - let did = mkdid(xev.deviceid as xinput::DeviceId); + let did = Some(mkdid(xev.deviceid as xinput::DeviceId)); let mask = unsafe { slice::from_raw_parts(xev.valuators.mask, xev.valuators.mask_len as usize) }; @@ -1421,7 +1421,7 @@ impl EventProcessor { // Set the timestamp. self.target.xconn.set_timestamp(xev.time as xproto::Timestamp); - let device_id = mkdid(xev.sourceid as xinput::DeviceId); + let device_id = Some(mkdid(xev.sourceid as xinput::DeviceId)); let keycode = xev.detail as u32; if keycode < KEYCODE_OFFSET as u32 { return; @@ -1695,8 +1695,6 @@ impl EventProcessor { ) where F: FnMut(&ActiveEventLoop, Event), { - let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD); - // Update modifiers state and emit key events based on which keys are currently pressed. let xcb = target.xconn.xcb_connection().get_raw_xcb_connection(); @@ -1719,7 +1717,7 @@ impl EventProcessor { let event = key_processor.process_key_event(keycode as u32, state, false); let event = Event::WindowEvent { window_id, - event: WindowEvent::KeyboardInput { device_id, event, is_synthetic: true }, + event: WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: true }, }; callback(target, event); } diff --git a/src/platform_impl/linux/x11/util/input.rs b/src/platform_impl/linux/x11/util/input.rs index 367e890154..12a69bd0c7 100644 --- a/src/platform_impl/linux/x11/util/input.rs +++ b/src/platform_impl/linux/x11/util/input.rs @@ -6,7 +6,6 @@ use x11rb::protocol::xkb; use super::*; pub const VIRTUAL_CORE_POINTER: u16 = 2; -pub const VIRTUAL_CORE_KEYBOARD: u16 = 3; // A base buffer size of 1kB uses a negligible amount of RAM while preventing us from having to // re-allocate (and make another round-trip) in the *vast* majority of cases. diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index c40914c906..01f868c69f 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -12,7 +12,7 @@ use orbclient::{ use smol_str::SmolStr; use super::{ - DeviceId, KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, + KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, WindowId, WindowProperties, }; use crate::application::ApplicationHandler; @@ -364,7 +364,7 @@ impl EventLoop { let window_id = RootWindowId(window_id); let event = event::WindowEvent::KeyboardInput { - device_id: event::DeviceId(DeviceId), + device_id: None, event: event::KeyEvent { logical_key, physical_key, @@ -407,29 +407,20 @@ impl EventLoop { app.window_event( window_target, RootWindowId(window_id), - event::WindowEvent::CursorMoved { - device_id: event::DeviceId(DeviceId), - position: (x, y).into(), - }, + event::WindowEvent::CursorMoved { device_id: None, position: (x, y).into() }, ); }, EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => { - app.device_event( - window_target, - event::DeviceId(DeviceId), - event::DeviceEvent::MouseMotion { delta: (dx as f64, dy as f64) }, - ); + app.device_event(window_target, None, event::DeviceEvent::MouseMotion { + delta: (dx as f64, dy as f64), + }); }, EventOption::Button(ButtonEvent { left, middle, right }) => { while let Some((button, state)) = event_state.mouse(left, middle, right) { app.window_event( window_target, RootWindowId(window_id), - event::WindowEvent::MouseInput { - device_id: event::DeviceId(DeviceId), - state, - button, - }, + event::WindowEvent::MouseInput { device_id: None, state, button }, ); } }, @@ -438,7 +429,7 @@ impl EventLoop { window_target, RootWindowId(window_id), event::WindowEvent::MouseWheel { - device_id: event::DeviceId(DeviceId), + device_id: None, delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), phase: event::TouchPhase::Moved, }, @@ -478,9 +469,9 @@ impl EventLoop { // TODO: Screen, Clipboard, Drop EventOption::Hover(HoverEvent { entered }) => { let event = if entered { - event::WindowEvent::CursorEntered { device_id: event::DeviceId(DeviceId) } + event::WindowEvent::CursorEntered { device_id: None } } else { - event::WindowEvent::CursorLeft { device_id: event::DeviceId(DeviceId) } + event::WindowEvent::CursorLeft { device_id: None } }; app.window_event(window_target, RootWindowId(window_id), event); diff --git a/src/platform_impl/web/event.rs b/src/platform_impl/web/event.rs index a1f37a348f..0b4557708a 100644 --- a/src/platform_impl/web/event.rs +++ b/src/platform_impl/web/event.rs @@ -1,18 +1,21 @@ #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] -pub enum DeviceId { - Wheel, - Keyboard, - Id(i32), -} +pub struct DeviceId(u32); impl DeviceId { - pub fn new(pointer_id: i32) -> Self { - Self::Id(pointer_id) + pub fn new(pointer_id: i32) -> Option { + if let Ok(pointer_id) = u32::try_from(pointer_id) { + Some(Self(pointer_id)) + } else if pointer_id == -1 { + None + } else { + tracing::error!("found unexpected negative `PointerEvent.pointerId`: {pointer_id}"); + None + } } #[cfg(test)] pub const fn dummy() -> Self { - Self::Id(-1) + Self(0) } } diff --git a/src/platform_impl/web/event_loop/mod.rs b/src/platform_impl/web/event_loop/mod.rs index 89721cac8d..eced29cdd9 100644 --- a/src/platform_impl/web/event_loop/mod.rs +++ b/src/platform_impl/web/event_loop/mod.rs @@ -1,4 +1,4 @@ -use super::{backend, event, window, HasMonitorPermissionFuture, MonitorPermissionFuture}; +use super::{backend, window, HasMonitorPermissionFuture, MonitorPermissionFuture}; use crate::application::ApplicationHandler; use crate::error::{EventLoopError, NotSupportedError}; use crate::event::Event; diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index cf430fc9f5..f6fedab0a0 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -286,7 +286,7 @@ impl Shared { } // chorded button event - let device_id = RootDeviceId(DeviceId::new(event.pointer_id())); + let device_id = DeviceId::new(event.pointer_id()).map(RootDeviceId); if let Some(button) = backend::event::mouse_button(&event) { let state = if backend::event::mouse_buttons(&event).contains(button.into()) { @@ -327,7 +327,7 @@ impl Shared { if let Some(delta) = backend::event::mouse_scroll_delta(&window, &event) { runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::Wheel), + device_id: None, event: DeviceEvent::MouseWheel { delta }, }); } @@ -344,7 +344,7 @@ impl Shared { let button = backend::event::mouse_button(&event).expect("no mouse button pressed"); runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::new(event.pointer_id())), + device_id: DeviceId::new(event.pointer_id()).map(RootDeviceId), event: DeviceEvent::Button { button: button.to_id(), state: ElementState::Pressed, @@ -363,7 +363,7 @@ impl Shared { let button = backend::event::mouse_button(&event).expect("no mouse button pressed"); runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::new(event.pointer_id())), + device_id: DeviceId::new(event.pointer_id()).map(RootDeviceId), event: DeviceEvent::Button { button: button.to_id(), state: ElementState::Released, @@ -381,7 +381,7 @@ impl Shared { } runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::Keyboard), + device_id: None, event: DeviceEvent::Key(RawKeyEvent { physical_key: backend::event::key_code(&event), state: ElementState::Pressed, @@ -399,7 +399,7 @@ impl Shared { } runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(DeviceId::Keyboard), + device_id: None, event: DeviceEvent::Key(RawKeyEvent { physical_key: backend::event::key_code(&event), state: ElementState::Released, diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 4251576b20..dbd3dd7217 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -7,7 +7,6 @@ use web_sys::Element; use super::super::monitor::MonitorPermissionFuture; use super::super::{lock, KeyEventExtra}; -use super::event::DeviceId; use super::runner::{EventWrapper, WeakShared}; use super::window::WindowId; use super::{backend, runner, EventLoopProxy}; @@ -144,13 +143,11 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(DeviceId::Keyboard); - runner.send_events( iter::once(Event::WindowEvent { window_id: RootWindowId(id), event: WindowEvent::KeyboardInput { - device_id, + device_id: None, event: KeyEvent { physical_key, logical_key, @@ -180,13 +177,11 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(DeviceId::Keyboard); - runner.send_events( iter::once(Event::WindowEvent { window_id: RootWindowId(id), event: WindowEvent::KeyboardInput { - device_id, + device_id: None, event: KeyEvent { physical_key, logical_key, @@ -221,7 +216,7 @@ impl ActiveEventLoop { let pointer = pointer_id.map(|device_id| Event::WindowEvent { window_id: RootWindowId(id), - event: WindowEvent::CursorLeft { device_id: RootDeviceId(device_id) }, + event: WindowEvent::CursorLeft { device_id: device_id.map(RootDeviceId) }, }); if focus.is_some() || pointer.is_some() { @@ -246,7 +241,7 @@ impl ActiveEventLoop { let pointer = pointer_id.map(|device_id| Event::WindowEvent { window_id: RootWindowId(id), - event: WindowEvent::CursorEntered { device_id: RootDeviceId(device_id) }, + event: WindowEvent::CursorEntered { device_id: device_id.map(RootDeviceId) }, }); if focus.is_some() || pointer.is_some() { @@ -272,7 +267,7 @@ impl ActiveEventLoop { }); runner.send_events(modifiers.into_iter().chain(events.flat_map(|position| { - let device_id = RootDeviceId(pointer_id); + let device_id = pointer_id.map(RootDeviceId); iter::once(Event::WindowEvent { window_id: RootWindowId(id), @@ -301,7 +296,7 @@ impl ActiveEventLoop { window_id: RootWindowId(id), event: WindowEvent::Touch(Touch { finger_id: RootFingerId(finger_id), - device_id: RootDeviceId(device_id), + device_id: device_id.map(RootDeviceId), phase: TouchPhase::Moved, force: Some(force), location, @@ -329,7 +324,7 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(device_id); + let device_id = device_id.map(RootDeviceId); let state = if buttons.contains(button.into()) { ElementState::Pressed @@ -368,7 +363,7 @@ impl ActiveEventLoop { } }); - let device_id: RootDeviceId = RootDeviceId(pointer_id); + let device_id = pointer_id.map(RootDeviceId); // A mouse down event may come in without any prior CursorMoved events, // therefore we should send a CursorMoved event to make sure that the @@ -407,7 +402,7 @@ impl ActiveEventLoop { window_id: RootWindowId(id), event: WindowEvent::Touch(Touch { finger_id: RootFingerId(finger_id), - device_id: RootDeviceId(device_id), + device_id: device_id.map(RootDeviceId), phase: TouchPhase::Started, force: Some(force), location, @@ -434,7 +429,7 @@ impl ActiveEventLoop { } }); - let device_id: RootDeviceId = RootDeviceId(pointer_id); + let device_id = pointer_id.map(RootDeviceId); // A mouse up event may come in without any prior CursorMoved events, // therefore we should send a CursorMoved event to make sure that the @@ -475,7 +470,7 @@ impl ActiveEventLoop { window_id: RootWindowId(id), event: WindowEvent::Touch(Touch { finger_id: RootFingerId(finger_id), - device_id: RootDeviceId(device_id), + device_id: device_id.map(RootDeviceId), phase: TouchPhase::Ended, force: Some(force), location, @@ -502,7 +497,7 @@ impl ActiveEventLoop { Event::WindowEvent { window_id: RootWindowId(id), event: WindowEvent::MouseWheel { - device_id: RootDeviceId(DeviceId::Keyboard), + device_id: None, delta, phase: TouchPhase::Moved, }, @@ -516,7 +511,7 @@ impl ActiveEventLoop { window_id: RootWindowId(id), event: WindowEvent::Touch(Touch { finger_id: RootFingerId(finger_id), - device_id: RootDeviceId(device_id), + device_id: device_id.map(RootDeviceId), phase: TouchPhase::Cancelled, force: Some(force), location, diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index a1e5096e00..41d26d9b6f 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -330,22 +330,23 @@ impl Canvas { pub fn on_cursor_leave(&self, handler: F) where - F: 'static + FnMut(ModifiersState, Option), + F: 'static + FnMut(ModifiersState, Option>), { self.handlers.borrow_mut().pointer_handler.on_cursor_leave(&self.common, handler) } pub fn on_cursor_enter(&self, handler: F) where - F: 'static + FnMut(ModifiersState, Option), + F: 'static + FnMut(ModifiersState, Option>), { self.handlers.borrow_mut().pointer_handler.on_cursor_enter(&self.common, handler) } pub fn on_mouse_release(&self, mouse_handler: M, touch_handler: T) where - M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition, MouseButton), - T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition, Force), + M: 'static + FnMut(ModifiersState, Option, PhysicalPosition, MouseButton), + T: 'static + + FnMut(ModifiersState, Option, FingerId, PhysicalPosition, Force), { self.handlers.borrow_mut().pointer_handler.on_mouse_release( &self.common, @@ -356,8 +357,9 @@ impl Canvas { pub fn on_mouse_press(&self, mouse_handler: M, touch_handler: T) where - M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition, MouseButton), - T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition, Force), + M: 'static + FnMut(ModifiersState, Option, PhysicalPosition, MouseButton), + T: 'static + + FnMut(ModifiersState, Option, FingerId, PhysicalPosition, Force), { self.handlers.borrow_mut().pointer_handler.on_mouse_press( &self.common, @@ -370,16 +372,22 @@ impl Canvas { pub fn on_cursor_move(&self, mouse_handler: M, touch_handler: T, button_handler: B) where M: 'static - + FnMut(ModifiersState, DeviceId, &mut dyn Iterator>), + + FnMut(ModifiersState, Option, &mut dyn Iterator>), T: 'static + FnMut( ModifiersState, - DeviceId, + Option, FingerId, &mut dyn Iterator, Force)>, ), B: 'static - + FnMut(ModifiersState, DeviceId, PhysicalPosition, ButtonsState, MouseButton), + + FnMut( + ModifiersState, + Option, + PhysicalPosition, + ButtonsState, + MouseButton, + ), { self.handlers.borrow_mut().pointer_handler.on_cursor_move( &self.common, @@ -392,7 +400,7 @@ impl Canvas { pub fn on_touch_cancel(&self, handler: F) where - F: 'static + FnMut(DeviceId, FingerId, PhysicalPosition, Force), + F: 'static + FnMut(Option, FingerId, PhysicalPosition, Force), { self.handlers.borrow_mut().pointer_handler.on_touch_cancel(&self.common, handler) } diff --git a/src/platform_impl/web/web_sys/pointer.rs b/src/platform_impl/web/web_sys/pointer.rs index 6679cbd2b0..11a37a3e7a 100644 --- a/src/platform_impl/web/web_sys/pointer.rs +++ b/src/platform_impl/web/web_sys/pointer.rs @@ -36,7 +36,7 @@ impl PointerHandler { pub fn on_cursor_leave(&mut self, canvas_common: &Common, mut handler: F) where - F: 'static + FnMut(ModifiersState, Option), + F: 'static + FnMut(ModifiersState, Option>), { self.on_cursor_leave = Some(canvas_common.add_event("pointerout", move |event: PointerEvent| { @@ -54,7 +54,7 @@ impl PointerHandler { pub fn on_cursor_enter(&mut self, canvas_common: &Common, mut handler: F) where - F: 'static + FnMut(ModifiersState, Option), + F: 'static + FnMut(ModifiersState, Option>), { self.on_cursor_enter = Some(canvas_common.add_event("pointerover", move |event: PointerEvent| { @@ -76,8 +76,9 @@ impl PointerHandler { mut mouse_handler: M, mut touch_handler: T, ) where - M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition, MouseButton), - T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition, Force), + M: 'static + FnMut(ModifiersState, Option, PhysicalPosition, MouseButton), + T: 'static + + FnMut(ModifiersState, Option, FingerId, PhysicalPosition, Force), { let window = canvas_common.window.clone(); self.on_pointer_release = @@ -112,8 +113,9 @@ impl PointerHandler { mut touch_handler: T, prevent_default: Rc>, ) where - M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition, MouseButton), - T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition, Force), + M: 'static + FnMut(ModifiersState, Option, PhysicalPosition, MouseButton), + T: 'static + + FnMut(ModifiersState, Option, FingerId, PhysicalPosition, Force), { let window = canvas_common.window.clone(); let canvas = canvas_common.raw().clone(); @@ -172,16 +174,22 @@ impl PointerHandler { prevent_default: Rc>, ) where M: 'static - + FnMut(ModifiersState, DeviceId, &mut dyn Iterator>), + + FnMut(ModifiersState, Option, &mut dyn Iterator>), T: 'static + FnMut( ModifiersState, - DeviceId, + Option, FingerId, &mut dyn Iterator, Force)>, ), B: 'static - + FnMut(ModifiersState, DeviceId, PhysicalPosition, ButtonsState, MouseButton), + + FnMut( + ModifiersState, + Option, + PhysicalPosition, + ButtonsState, + MouseButton, + ), { let window = canvas_common.window.clone(); let canvas = canvas_common.raw().clone(); @@ -237,7 +245,7 @@ impl PointerHandler { pub fn on_touch_cancel(&mut self, canvas_common: &Common, mut handler: F) where - F: 'static + FnMut(DeviceId, FingerId, PhysicalPosition, Force), + F: 'static + FnMut(Option, FingerId, PhysicalPosition, Force), { let window = canvas_common.window.clone(); self.on_touch_cancel = diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 5c7a3e1a49..0ed29a3be4 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -81,7 +81,7 @@ use crate::platform_impl::platform::window_state::{ CursorFlags, ImeState, WindowFlags, WindowState, }; use crate::platform_impl::platform::{ - raw_input, util, wrap_device_id, FingerId, Fullscreen, WindowId, DEVICE_ID, + raw_input, util, wrap_device_id, FingerId, Fullscreen, WindowId, }; use crate::platform_impl::Window; use crate::utils::Lazy; @@ -1047,7 +1047,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), event: KeyboardInput { - device_id: DEVICE_ID, + device_id: None, event: event.event, is_synthetic: event.is_synthetic, }, @@ -1541,7 +1541,7 @@ unsafe fn public_window_callback_inner( drop(w); userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: CursorEntered { device_id: DEVICE_ID }, + event: CursorEntered { device_id: None }, }); // Calling TrackMouseEvent in order to receive mouse leave events. @@ -1562,7 +1562,7 @@ unsafe fn public_window_callback_inner( drop(w); userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: CursorLeft { device_id: DEVICE_ID }, + event: CursorLeft { device_id: None }, }); }, PointerMoveKind::None => drop(w), @@ -1581,7 +1581,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: CursorMoved { device_id: DEVICE_ID, position }, + event: CursorMoved { device_id: None, position }, }); } @@ -1597,7 +1597,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: CursorLeft { device_id: DEVICE_ID }, + event: CursorLeft { device_id: None }, }); result = ProcResult::Value(0); @@ -1614,7 +1614,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), event: WindowEvent::MouseWheel { - device_id: DEVICE_ID, + device_id: None, delta: LineDelta(0.0, value), phase: TouchPhase::Moved, }, @@ -1634,7 +1634,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), event: WindowEvent::MouseWheel { - device_id: DEVICE_ID, + device_id: None, delta: LineDelta(value, 0.0), phase: TouchPhase::Moved, }, @@ -1668,7 +1668,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: MouseInput { device_id: DEVICE_ID, state: Pressed, button: Left }, + event: MouseInput { device_id: None, state: Pressed, button: Left }, }); result = ProcResult::Value(0); }, @@ -1684,7 +1684,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: MouseInput { device_id: DEVICE_ID, state: Released, button: Left }, + event: MouseInput { device_id: None, state: Released, button: Left }, }); result = ProcResult::Value(0); }, @@ -1700,7 +1700,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: MouseInput { device_id: DEVICE_ID, state: Pressed, button: Right }, + event: MouseInput { device_id: None, state: Pressed, button: Right }, }); result = ProcResult::Value(0); }, @@ -1716,7 +1716,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: MouseInput { device_id: DEVICE_ID, state: Released, button: Right }, + event: MouseInput { device_id: None, state: Released, button: Right }, }); result = ProcResult::Value(0); }, @@ -1732,7 +1732,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: MouseInput { device_id: DEVICE_ID, state: Pressed, button: Middle }, + event: MouseInput { device_id: None, state: Pressed, button: Middle }, }); result = ProcResult::Value(0); }, @@ -1748,7 +1748,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), - event: MouseInput { device_id: DEVICE_ID, state: Released, button: Middle }, + event: MouseInput { device_id: None, state: Released, button: Middle }, }); result = ProcResult::Value(0); }, @@ -1766,7 +1766,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), event: MouseInput { - device_id: DEVICE_ID, + device_id: None, state: Pressed, button: match xbutton { 1 => Back, @@ -1791,7 +1791,7 @@ unsafe fn public_window_callback_inner( userdata.send_event(Event::WindowEvent { window_id: CoreWindowId(WindowId(window)), event: MouseInput { - device_id: DEVICE_ID, + device_id: None, state: Released, button: match xbutton { 1 => Back, @@ -1855,7 +1855,7 @@ unsafe fn public_window_callback_inner( id: input.dwID, primary: util::has_flag(input.dwFlags, TOUCHEVENTF_PRIMARY), }), - device_id: DEVICE_ID, + device_id: None, }), }); } @@ -2007,7 +2007,7 @@ unsafe fn public_window_callback_inner( POINTER_FLAG_PRIMARY, ), }), - device_id: DEVICE_ID, + device_id: None, }), }); } @@ -2435,7 +2435,7 @@ unsafe fn handle_raw_input(userdata: &ThreadMsgTargetData, data: RAWINPUT) { use crate::event::ElementState::{Pressed, Released}; use crate::event::MouseScrollDelta::LineDelta; - let device_id = wrap_device_id(data.header.hDevice as _); + let device_id = Some(wrap_device_id(data.header.hDevice as _)); if data.header.dwType == RIM_TYPEMOUSE { let mouse = unsafe { data.data.mouse }; diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 48c71eb538..df45b1060e 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -98,9 +98,6 @@ impl FingerId { } } -// Constant device ID, to be removed when this backend is updated to report real device IDs. -const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId(0)); - fn wrap_device_id(id: u32) -> RootDeviceId { RootDeviceId(DeviceId(id)) } From 71faa9872794a2db630f2f219820b8bdbcf7389f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 8 Sep 2024 13:09:32 +0200 Subject: [PATCH 6/7] Fully remove `DeviceId::dummy` --- src/event.rs | 15 --------------- src/platform_impl/android/mod.rs | 7 ------- src/platform_impl/apple/appkit/mod.rs | 7 ------- src/platform_impl/apple/uikit/mod.rs | 7 ------- src/platform_impl/linux/mod.rs | 10 ---------- src/platform_impl/linux/wayland/mod.rs | 7 ------- src/platform_impl/linux/x11/mod.rs | 8 -------- src/platform_impl/orbital/mod.rs | 7 ------- src/platform_impl/web/event.rs | 5 ----- src/platform_impl/windows/mod.rs | 7 ------- 10 files changed, 80 deletions(-) diff --git a/src/event.rs b/src/event.rs index 82f9fd9d8e..e862c21833 100644 --- a/src/event.rs +++ b/src/event.rs @@ -439,13 +439,6 @@ pub enum WindowEvent { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(pub(crate) platform_impl::DeviceId); -impl DeviceId { - #[cfg(test)] - pub(crate) const fn dummy() -> Self { - DeviceId(platform_impl::DeviceId::dummy()) - } -} - /// Identifier of a finger in a touch event. /// /// Whenever a touch event is received it contains a `FingerId` which uniquely identifies the finger @@ -1148,14 +1141,6 @@ mod tests { }); let _ = event::StartCause::Init.clone(); - let did = crate::event::DeviceId::dummy().clone(); - HashSet::new().insert(did); - let mut set = [did, did, did]; - set.sort_unstable(); - let mut set2 = BTreeSet::new(); - set2.insert(did); - set2.insert(did); - let fid = crate::event::FingerId::dummy().clone(); HashSet::new().insert(fid); let mut set = [fid, fid, fid]; diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index ef4a0825c1..a93dc56dd5 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -680,13 +680,6 @@ impl WindowId { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DeviceId(i32); -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - DeviceId(0) - } -} - #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct FingerId(i32); diff --git a/src/platform_impl/apple/appkit/mod.rs b/src/platform_impl/apple/appkit/mod.rs index 9558ce481b..c34e3a9c24 100644 --- a/src/platform_impl/apple/appkit/mod.rs +++ b/src/platform_impl/apple/appkit/mod.rs @@ -30,13 +30,6 @@ pub(crate) use crate::platform_impl::Fullscreen; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - DeviceId - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId; diff --git a/src/platform_impl/apple/uikit/mod.rs b/src/platform_impl/apple/uikit/mod.rs index 98af1bdaaa..ee581aa9ef 100644 --- a/src/platform_impl/apple/uikit/mod.rs +++ b/src/platform_impl/apple/uikit/mod.rs @@ -28,13 +28,6 @@ pub(crate) use crate::platform_impl::Fullscreen; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - DeviceId - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(usize); diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index ddf628f196..701f1bdce0 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -129,16 +129,6 @@ pub enum DeviceId { Wayland(wayland::DeviceId), } -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - #[cfg(wayland_platform)] - return DeviceId::Wayland(wayland::DeviceId::dummy()); - #[cfg(all(not(wayland_platform), x11_platform))] - return DeviceId::X(x11::DeviceId::dummy()); - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum FingerId { #[cfg(x11_platform)] diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 9f49100622..bb700e2a2c 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -21,13 +21,6 @@ mod window; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - DeviceId - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(i32); diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index c47aec727c..d82d8b04a0 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -811,14 +811,6 @@ impl<'a> Deref for DeviceInfo<'a> { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(xinput::DeviceId); -impl DeviceId { - #[cfg(test)] - #[allow(unused)] - pub const fn dummy() -> Self { - DeviceId(0) - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(u32); diff --git a/src/platform_impl/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index 56248e8163..e29f9aea0e 100644 --- a/src/platform_impl/orbital/mod.rs +++ b/src/platform_impl/orbital/mod.rs @@ -117,13 +117,6 @@ impl WindowId { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DeviceId; -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - DeviceId - } -} - #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct FingerId; diff --git a/src/platform_impl/web/event.rs b/src/platform_impl/web/event.rs index 0b4557708a..6912bfc93a 100644 --- a/src/platform_impl/web/event.rs +++ b/src/platform_impl/web/event.rs @@ -12,11 +12,6 @@ impl DeviceId { None } } - - #[cfg(test)] - pub const fn dummy() -> Self { - Self(0) - } } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index df45b1060e..93fdb5c21d 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -62,13 +62,6 @@ unsafe impl Sync for PlatformSpecificWindowAttributes {} #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(u32); -impl DeviceId { - #[cfg(test)] - pub const fn dummy() -> Self { - DeviceId(0) - } -} - impl DeviceId { pub fn persistent_identifier(&self) -> Option { if self.0 != 0 { From 07f161b459d5da407b79447146d14595701d3f6d Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 8 Sep 2024 13:47:56 +0200 Subject: [PATCH 7/7] Fix formatting --- src/platform_impl/orbital/event_loop.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 01f868c69f..19a774c413 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -12,8 +12,8 @@ use orbclient::{ use smol_str::SmolStr; use super::{ - KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, - TimeSocket, WindowId, WindowProperties, + KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, + WindowId, WindowProperties, }; use crate::application::ApplicationHandler; use crate::error::{EventLoopError, NotSupportedError, RequestError};