From 32cd1ad9a741728ca6ccf4f8b3e63e6324a51392 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 29 Sep 2024 15:49:45 +0200 Subject: [PATCH] api: remove `::dummy` from `Id` types `::dummy` was used for testing purposes and became redundant after adding e.g. `from_raw` and `into_raw` methods on `Id` types. --- examples/window.rs | 2 +- src/application.rs | 6 +- src/changelog/unreleased.md | 3 + src/event.rs | 93 +++++++------------ src/platform_impl/android/mod.rs | 15 +-- src/platform_impl/apple/appkit/app.rs | 7 +- src/platform_impl/apple/appkit/mod.rs | 11 +-- src/platform_impl/apple/appkit/view.rs | 37 ++++---- src/platform_impl/apple/appkit/window.rs | 4 - src/platform_impl/apple/uikit/mod.rs | 10 +- src/platform_impl/apple/uikit/view.rs | 16 ++-- src/platform_impl/apple/uikit/window.rs | 4 - src/platform_impl/linux/mod.rs | 15 +-- .../linux/wayland/event_loop/mod.rs | 2 +- .../linux/wayland/event_loop/sink.rs | 12 +-- src/platform_impl/linux/wayland/mod.rs | 7 +- .../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/mod.rs | 8 +- src/platform_impl/linux/x11/util/input.rs | 1 - src/platform_impl/orbital/event_loop.rs | 31 +++---- src/platform_impl/orbital/mod.rs | 11 +-- src/platform_impl/web/event.rs | 20 ++-- 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/web/window.rs | 4 - src/platform_impl/windows/event_loop.rs | 38 ++++---- src/platform_impl/windows/mod.rs | 14 +-- src/window.rs | 11 --- 35 files changed, 219 insertions(+), 352 deletions(-) diff --git a/examples/window.rs b/examples/window.rs index 225fd53838..3b1a73802c 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 ee8b4e76ef..2a89a131cd 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 identified. ### Removed @@ -153,6 +155,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 709a2bf648..3742596d5d 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 @@ -255,7 +255,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. /// @@ -266,13 +266,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. /// @@ -281,7 +281,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). /// @@ -297,7 +297,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, @@ -321,7 +321,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. /// @@ -333,7 +333,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, @@ -344,7 +344,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 /// @@ -440,25 +440,6 @@ 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 { - 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 @@ -467,14 +448,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()) } } @@ -865,7 +840,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 @@ -1046,7 +1021,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,7 +1031,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); @@ -1076,39 +1050,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, @@ -1123,7 +1097,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 { @@ -1168,21 +1142,20 @@ 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]; + HashSet::new().insert(fid); + let mut set = [fid, fid, fid]; set.sort_unstable(); let mut set2 = BTreeSet::new(); - set2.insert(did); - set2.insert(did); + 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 0503bf871e..a93dc56dd5 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), @@ -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 } @@ -684,16 +680,11 @@ impl WindowId { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DeviceId(i32); -impl DeviceId { - pub const fn dummy() -> Self { - DeviceId(0) - } -} - #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct FingerId(i32); impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId(0) } 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 8724c24938..c34e3a9c24 100644 --- a/src/platform_impl/apple/appkit/mod.rs +++ b/src/platform_impl/apple/appkit/mod.rs @@ -24,26 +24,17 @@ 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; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; -impl DeviceId { - pub const fn dummy() -> Self { - 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; impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { 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/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..ee581aa9ef 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; @@ -29,18 +28,11 @@ pub(crate) use crate::platform_impl::Fullscreen; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; -impl DeviceId { - pub const fn dummy() -> Self { - DeviceId - } -} - -pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId); - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(usize); impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId(0) } 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/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 fe4e6ff885..5d4482481a 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 } @@ -129,18 +125,10 @@ pub enum DeviceId { #[cfg(x11_platform)] X(x11::DeviceId), #[cfg(wayland_platform)] + #[allow(unused)] Wayland(wayland::DeviceId), } -impl DeviceId { - 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)] @@ -150,6 +138,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/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/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 214b4a71d5..bb700e2a2c 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -21,16 +21,11 @@ mod window; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId; -impl DeviceId { - pub const fn dummy() -> Self { - DeviceId - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(i32); impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId(0) } 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/mod.rs b/src/platform_impl/linux/x11/mod.rs index cada63f42e..d82d8b04a0 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -811,17 +811,11 @@ impl<'a> Deref for DeviceInfo<'a> { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(xinput::DeviceId); -impl DeviceId { - #[allow(unused)] - pub const fn dummy() -> Self { - DeviceId(0) - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FingerId(u32); impl FingerId { + #[cfg(test)] #[allow(unused)] pub const fn dummy() -> Self { FingerId(0) 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..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::{ - DeviceId, KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, - TimeSocket, WindowId, WindowProperties, + KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, + WindowId, WindowProperties, }; use crate::application::ApplicationHandler; use crate::error::{EventLoopError, NotSupportedError, RequestError}; @@ -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/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index 22db646d69..e29f9aea0e 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 } @@ -121,16 +117,11 @@ impl WindowId { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DeviceId; -impl DeviceId { - pub const fn dummy() -> Self { - DeviceId - } -} - #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] 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..6912bfc93a 100644 --- a/src/platform_impl/web/event.rs +++ b/src/platform_impl/web/event.rs @@ -1,13 +1,16 @@ -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct DeviceId(i32); +#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] +pub struct DeviceId(u32); impl DeviceId { - pub fn new(pointer_id: i32) -> Self { - Self(pointer_id) - } - - pub const fn dummy() -> Self { - Self(-1) + 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 + } } } @@ -22,6 +25,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/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 daaae53d4c..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::dummy()), + 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::dummy()), + 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::dummy()), + 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 7b4f63da52..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::dummy()); - 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::dummy()); - 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::dummy()), + 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/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/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 efdda2c57c..93fdb5c21d 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -62,12 +62,6 @@ unsafe impl Sync for PlatformSpecificWindowAttributes {} #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(u32); -impl DeviceId { - pub const fn dummy() -> Self { - DeviceId(0) - } -} - impl DeviceId { pub fn persistent_identifier(&self) -> Option { if self.0 != 0 { @@ -85,6 +79,7 @@ pub struct FingerId { } impl FingerId { + #[cfg(test)] pub const fn dummy() -> Self { FingerId { id: 0, primary: false } } @@ -96,9 +91,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)) } @@ -115,10 +107,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.