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.
This commit is contained in:
daxpedda 2024-09-29 15:49:45 +02:00 committed by GitHub
parent 6e1b9fa24d
commit 32cd1ad9a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 219 additions and 352 deletions

View file

@ -522,7 +522,7 @@ impl ApplicationHandler for Application {
fn device_event( fn device_event(
&mut self, &mut self,
_event_loop: &dyn ActiveEventLoop, _event_loop: &dyn ActiveEventLoop,
device_id: DeviceId, device_id: Option<DeviceId>,
event: DeviceEvent, event: DeviceEvent,
) { ) {
info!("Device {device_id:?} event: {event:?}"); info!("Device {device_id:?} event: {event:?}");

View file

@ -196,7 +196,7 @@ pub trait ApplicationHandler {
fn device_event( fn device_event(
&mut self, &mut self,
event_loop: &dyn ActiveEventLoop, event_loop: &dyn ActiveEventLoop,
device_id: DeviceId, device_id: Option<DeviceId>,
event: DeviceEvent, event: DeviceEvent,
) { ) {
let _ = (event_loop, device_id, event); let _ = (event_loop, device_id, event);
@ -363,7 +363,7 @@ impl<A: ?Sized + ApplicationHandler> ApplicationHandler for &mut A {
fn device_event( fn device_event(
&mut self, &mut self,
event_loop: &dyn ActiveEventLoop, event_loop: &dyn ActiveEventLoop,
device_id: DeviceId, device_id: Option<DeviceId>,
event: DeviceEvent, event: DeviceEvent,
) { ) {
(**self).device_event(event_loop, device_id, event); (**self).device_event(event_loop, device_id, event);
@ -431,7 +431,7 @@ impl<A: ?Sized + ApplicationHandler> ApplicationHandler for Box<A> {
fn device_event( fn device_event(
&mut self, &mut self,
event_loop: &dyn ActiveEventLoop, event_loop: &dyn ActiveEventLoop,
device_id: DeviceId, device_id: Option<DeviceId>,
event: DeviceEvent, event: DeviceEvent,
) { ) {
(**self).device_event(event_loop, device_id, event); (**self).device_event(event_loop, device_id, event);

View file

@ -125,6 +125,8 @@ changelog entry.
- `Window::set_max_inner_size` to `set_max_surface_size`. - `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. 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<DeviceId>` instead. A `None` value signifies that the
device can't be uniquely identified.
### Removed ### Removed
@ -153,6 +155,7 @@ changelog entry.
- On Android, remove all `MonitorHandle` support instead of emitting false data. - On Android, remove all `MonitorHandle` support instead of emitting false data.
- Remove `impl From<u64> for WindowId` and `impl From<WindowId> for u64`. Replaced with - Remove `impl From<u64> for WindowId` and `impl From<WindowId> for u64`. Replaced with
`WindowId::into_raw()` and `from_raw()`. `WindowId::into_raw()` and `from_raw()`.
- Remove `dummy()` from `WindowId` and `DeviceId`.
### Fixed ### Fixed

View file

@ -78,7 +78,7 @@ pub(crate) enum Event {
/// ///
/// [`ApplicationHandler::device_event`]: crate::application::ApplicationHandler::device_event /// [`ApplicationHandler::device_event`]: crate::application::ApplicationHandler::device_event
#[allow(clippy::enum_variant_names)] #[allow(clippy::enum_variant_names)]
DeviceEvent { device_id: DeviceId, event: DeviceEvent }, DeviceEvent { device_id: Option<DeviceId>, event: DeviceEvent },
/// See [`ApplicationHandler::suspended`] for details. /// 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 /// 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`. /// events which are not marked as `is_synthetic`.
KeyboardInput { KeyboardInput {
device_id: DeviceId, device_id: Option<DeviceId>,
event: KeyEvent, event: KeyEvent,
/// If `true`, the event was generated synthetically by winit /// 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 /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
CursorMoved { CursorMoved {
device_id: DeviceId, device_id: Option<DeviceId>,
/// (x,y) coords in pixels relative to the top-left corner of the window. Because the range /// (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 /// 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 /// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
CursorEntered { device_id: DeviceId }, CursorEntered { device_id: Option<DeviceId> },
/// The cursor has left the window. /// The cursor has left the window.
/// ///
@ -266,13 +266,13 @@ pub enum WindowEvent {
/// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border /// [`border`]: https://developer.mozilla.org/en-US/docs/Web/CSS/border
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding /// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
CursorLeft { device_id: DeviceId }, CursorLeft { device_id: Option<DeviceId> },
/// A mouse wheel movement or touchpad scroll occurred. /// A mouse wheel movement or touchpad scroll occurred.
MouseWheel { device_id: DeviceId, delta: MouseScrollDelta, phase: TouchPhase }, MouseWheel { device_id: Option<DeviceId>, delta: MouseScrollDelta, phase: TouchPhase },
/// An mouse button press has been received. /// An mouse button press has been received.
MouseInput { device_id: DeviceId, state: ElementState, button: MouseButton }, MouseInput { device_id: Option<DeviceId>, state: ElementState, button: MouseButton },
/// Two-finger pinch gesture, often used for magnification. /// Two-finger pinch gesture, often used for magnification.
/// ///
@ -281,7 +281,7 @@ pub enum WindowEvent {
/// - Only available on **macOS** and **iOS**. /// - Only available on **macOS** and **iOS**.
/// - On iOS, not recognized by default. It must be enabled when needed. /// - On iOS, not recognized by default. It must be enabled when needed.
PinchGesture { PinchGesture {
device_id: DeviceId, device_id: Option<DeviceId>,
/// Positive values indicate magnification (zooming in) and negative /// Positive values indicate magnification (zooming in) and negative
/// values indicate shrinking (zooming out). /// values indicate shrinking (zooming out).
/// ///
@ -297,7 +297,7 @@ pub enum WindowEvent {
/// - Only available on **iOS**. /// - Only available on **iOS**.
/// - On iOS, not recognized by default. It must be enabled when needed. /// - On iOS, not recognized by default. It must be enabled when needed.
PanGesture { PanGesture {
device_id: DeviceId, device_id: Option<DeviceId>,
/// Change in pixels of pan gesture from last update. /// Change in pixels of pan gesture from last update.
delta: PhysicalPosition<f32>, delta: PhysicalPosition<f32>,
phase: TouchPhase, phase: TouchPhase,
@ -321,7 +321,7 @@ pub enum WindowEvent {
/// ///
/// - Only available on **macOS 10.8** and later, and **iOS**. /// - Only available on **macOS 10.8** and later, and **iOS**.
/// - On iOS, not recognized by default. It must be enabled when needed. /// - On iOS, not recognized by default. It must be enabled when needed.
DoubleTapGesture { device_id: DeviceId }, DoubleTapGesture { device_id: Option<DeviceId> },
/// Two-finger rotation gesture. /// Two-finger rotation gesture.
/// ///
@ -333,7 +333,7 @@ pub enum WindowEvent {
/// - Only available on **macOS** and **iOS**. /// - Only available on **macOS** and **iOS**.
/// - On iOS, not recognized by default. It must be enabled when needed. /// - On iOS, not recognized by default. It must be enabled when needed.
RotationGesture { RotationGesture {
device_id: DeviceId, device_id: Option<DeviceId>,
/// change in rotation in degrees /// change in rotation in degrees
delta: f32, delta: f32,
phase: TouchPhase, phase: TouchPhase,
@ -344,7 +344,7 @@ pub enum WindowEvent {
/// At the moment, only supported on Apple forcetouch-capable macbooks. /// At the moment, only supported on Apple forcetouch-capable macbooks.
/// The parameters are: pressure level (value between 0 and 1 representing how hard the /// 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). /// touchpad is being pressed) and stage (integer representing the click level).
TouchpadPressure { device_id: DeviceId, pressure: f32, stage: i64 }, TouchpadPressure { device_id: Option<DeviceId>, pressure: f32, stage: i64 },
/// Touch event has been received /// Touch event has been received
/// ///
@ -440,25 +440,6 @@ pub enum WindowEvent {
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(pub(crate) platform_impl::DeviceId); 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. /// Identifier of a finger in a touch event.
/// ///
/// Whenever a touch event is received it contains a `FingerId` which uniquely identifies the finger /// 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); pub struct FingerId(pub(crate) platform_impl::FingerId);
impl FingerId { impl FingerId {
/// Returns a dummy id, useful for unit testing. #[cfg(test)]
/// pub(crate) const fn dummy() -> Self {
/// # 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 {
FingerId(platform_impl::FingerId::dummy()) FingerId(platform_impl::FingerId::dummy())
} }
} }
@ -865,7 +840,7 @@ pub enum TouchPhase {
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct Touch { pub struct Touch {
pub device_id: DeviceId, pub device_id: Option<DeviceId>,
pub phase: TouchPhase, pub phase: TouchPhase,
pub location: PhysicalPosition<f64>, pub location: PhysicalPosition<f64>,
/// Describes how hard the screen was pressed. May be `None` if the platform /// Describes how hard the screen was pressed. May be `None` if the platform
@ -1046,7 +1021,6 @@ mod tests {
($closure:expr) => {{ ($closure:expr) => {{
#[allow(unused_mut)] #[allow(unused_mut)]
let mut x = $closure; let mut x = $closure;
let did = event::DeviceId::dummy();
let fid = event::FingerId::dummy(); let fid = event::FingerId::dummy();
#[allow(deprecated)] #[allow(deprecated)]
@ -1057,7 +1031,7 @@ mod tests {
use crate::window::WindowId; use crate::window::WindowId;
// Mainline events. // Mainline events.
let wid = WindowId::dummy(); let wid = WindowId::from_raw(0);
x(NewEvents(event::StartCause::Init)); x(NewEvents(event::StartCause::Init));
x(AboutToWait); x(AboutToWait);
x(LoopExiting); x(LoopExiting);
@ -1076,39 +1050,39 @@ mod tests {
with_window_event(HoveredFile("x.txt".into())); with_window_event(HoveredFile("x.txt".into()));
with_window_event(HoveredFileCancelled); with_window_event(HoveredFileCancelled);
with_window_event(Ime(Enabled)); 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(ModifiersChanged(event::Modifiers::default()));
with_window_event(CursorEntered { device_id: did }); with_window_event(CursorEntered { device_id: None });
with_window_event(CursorLeft { device_id: did }); with_window_event(CursorLeft { device_id: None });
with_window_event(MouseWheel { with_window_event(MouseWheel {
device_id: did, device_id: None,
delta: event::MouseScrollDelta::LineDelta(0.0, 0.0), delta: event::MouseScrollDelta::LineDelta(0.0, 0.0),
phase: event::TouchPhase::Started, phase: event::TouchPhase::Started,
}); });
with_window_event(MouseInput { with_window_event(MouseInput {
device_id: did, device_id: None,
state: event::ElementState::Pressed, state: event::ElementState::Pressed,
button: event::MouseButton::Other(0), button: event::MouseButton::Other(0),
}); });
with_window_event(PinchGesture { with_window_event(PinchGesture {
device_id: did, device_id: None,
delta: 0.0, delta: 0.0,
phase: event::TouchPhase::Started, phase: event::TouchPhase::Started,
}); });
with_window_event(DoubleTapGesture { device_id: did }); with_window_event(DoubleTapGesture { device_id: None });
with_window_event(RotationGesture { with_window_event(RotationGesture {
device_id: did, device_id: None,
delta: 0.0, delta: 0.0,
phase: event::TouchPhase::Started, phase: event::TouchPhase::Started,
}); });
with_window_event(PanGesture { with_window_event(PanGesture {
device_id: did, device_id: None,
delta: PhysicalPosition::<f32>::new(0.0, 0.0), delta: PhysicalPosition::<f32>::new(0.0, 0.0),
phase: event::TouchPhase::Started, 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 { with_window_event(Touch(event::Touch {
device_id: did, device_id: None,
phase: event::TouchPhase::Started, phase: event::TouchPhase::Started,
location: (0.0, 0.0).into(), location: (0.0, 0.0).into(),
finger_id: fid, finger_id: fid,
@ -1123,7 +1097,7 @@ mod tests {
use event::DeviceEvent::*; use event::DeviceEvent::*;
let with_device_event = 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(MouseMotion { delta: (0.0, 0.0).into() });
with_device_event(MouseWheel { with_device_event(MouseWheel {
@ -1168,21 +1142,20 @@ mod tests {
}); });
let _ = event::StartCause::Init.clone(); let _ = event::StartCause::Init.clone();
let did = crate::event::DeviceId::dummy().clone();
let fid = crate::event::FingerId::dummy().clone(); let fid = crate::event::FingerId::dummy().clone();
HashSet::new().insert(did); HashSet::new().insert(fid);
let mut set = [did, did, did]; let mut set = [fid, fid, fid];
set.sort_unstable(); set.sort_unstable();
let mut set2 = BTreeSet::new(); let mut set2 = BTreeSet::new();
set2.insert(did); set2.insert(fid);
set2.insert(did); set2.insert(fid);
HashSet::new().insert(event::TouchPhase::Started.clone()); HashSet::new().insert(event::TouchPhase::Started.clone());
HashSet::new().insert(event::MouseButton::Left.clone()); HashSet::new().insert(event::MouseButton::Left.clone());
HashSet::new().insert(event::Ime::Enabled); HashSet::new().insert(event::Ime::Enabled);
let _ = event::Touch { let _ = event::Touch {
device_id: did, device_id: None,
phase: event::TouchPhase::Started, phase: event::TouchPhase::Started,
location: (0.0, 0.0).into(), location: (0.0, 0.0).into(),
finger_id: fid, finger_id: fid,

View file

@ -316,7 +316,7 @@ impl EventLoop {
match event { match event {
InputEvent::MotionEvent(motion_event) => { InputEvent::MotionEvent(motion_event) => {
let window_id = window::WindowId(WindowId); 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() { let phase = match motion_event.action() {
MotionAction::Down | MotionAction::PointerDown => { MotionAction::Down | MotionAction::PointerDown => {
@ -388,7 +388,7 @@ impl EventLoop {
let window_id = window::WindowId(WindowId); let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::KeyboardInput { 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 { event: event::KeyEvent {
state, state,
physical_key: keycodes::to_physical_key(keycode), physical_key: keycodes::to_physical_key(keycode),
@ -668,10 +668,6 @@ impl OwnedDisplayHandle {
pub(crate) struct WindowId; pub(crate) struct WindowId;
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
WindowId
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
0 0
} }
@ -684,16 +680,11 @@ impl WindowId {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct DeviceId(i32); pub struct DeviceId(i32);
impl DeviceId {
pub const fn dummy() -> Self {
DeviceId(0)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct FingerId(i32); pub struct FingerId(i32);
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId(0) FingerId(0)
} }

View file

@ -7,7 +7,6 @@ use objc2_app_kit::{NSApplication, NSEvent, NSEventModifierFlags, NSEventType, N
use objc2_foundation::{MainThreadMarker, NSObject}; use objc2_foundation::{MainThreadMarker, NSObject};
use super::app_state::AppState; use super::app_state::AppState;
use super::DEVICE_ID;
use crate::event::{DeviceEvent, ElementState}; use crate::event::{DeviceEvent, ElementState};
declare_class!( declare_class!(
@ -61,7 +60,7 @@ fn maybe_dispatch_device_event(app_state: &Rc<AppState>, event: &NSEvent) {
if delta_x != 0.0 || delta_y != 0.0 { if delta_x != 0.0 || delta_y != 0.0 {
app_state.maybe_queue_with_handler(move |app, event_loop| { 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), delta: (delta_x, delta_y),
}); });
}); });
@ -70,7 +69,7 @@ fn maybe_dispatch_device_event(app_state: &Rc<AppState>, event: &NSEvent) {
NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => { NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => {
let button = unsafe { event.buttonNumber() } as u32; let button = unsafe { event.buttonNumber() } as u32;
app_state.maybe_queue_with_handler(move |app, event_loop| { 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, button,
state: ElementState::Pressed, state: ElementState::Pressed,
}); });
@ -79,7 +78,7 @@ fn maybe_dispatch_device_event(app_state: &Rc<AppState>, event: &NSEvent) {
NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => { NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => {
let button = unsafe { event.buttonNumber() } as u32; let button = unsafe { event.buttonNumber() } as u32;
app_state.maybe_queue_with_handler(move |app, event_loop| { 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, button,
state: ElementState::Released, state: ElementState::Released,
}); });

View file

@ -24,26 +24,17 @@ pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle};
pub(crate) use self::window::{Window, WindowId}; pub(crate) use self::window::{Window, WindowId};
pub(crate) use self::window_delegate::PlatformSpecificWindowAttributes; pub(crate) use self::window_delegate::PlatformSpecificWindowAttributes;
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; 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::icon::NoIcon as PlatformIcon;
pub(crate) use crate::platform_impl::Fullscreen; pub(crate) use crate::platform_impl::Fullscreen;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId; pub struct FingerId;
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId FingerId
} }

View file

@ -24,7 +24,6 @@ use super::event::{
scancode_to_physicalkey, scancode_to_physicalkey,
}; };
use super::window::WinitWindow; use super::window::WinitWindow;
use super::DEVICE_ID;
use crate::dpi::{LogicalPosition, LogicalSize}; use crate::dpi::{LogicalPosition, LogicalSize};
use crate::event::{ use crate::event::{
DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, TouchPhase, DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, TouchPhase,
@ -486,7 +485,7 @@ declare_class!(
if !had_ime_input || self.ivars().forward_key_to_app.get() { if !had_ime_input || self.ivars().forward_key_to_app.get() {
let key_event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); let key_event = create_key_event(&event, true, unsafe { event.isARepeat() }, None);
self.queue_event(WindowEvent::KeyboardInput { self.queue_event(WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event: key_event, event: key_event,
is_synthetic: false, is_synthetic: false,
}); });
@ -506,7 +505,7 @@ declare_class!(
ImeState::Ground | ImeState::Disabled ImeState::Ground | ImeState::Disabled
) { ) {
self.queue_event(WindowEvent::KeyboardInput { self.queue_event(WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event: create_key_event(&event, false, false, None), event: create_key_event(&event, false, false, None),
is_synthetic: false, is_synthetic: false,
}); });
@ -557,7 +556,7 @@ declare_class!(
let event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); let event = create_key_event(&event, true, unsafe { event.isARepeat() }, None);
self.queue_event(WindowEvent::KeyboardInput { self.queue_event(WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event, event,
is_synthetic: false, is_synthetic: false,
}); });
@ -642,7 +641,7 @@ declare_class!(
fn mouse_entered(&self, _event: &NSEvent) { fn mouse_entered(&self, _event: &NSEvent) {
trace_scope!("mouseEntered:"); trace_scope!("mouseEntered:");
self.queue_event(WindowEvent::CursorEntered { self.queue_event(WindowEvent::CursorEntered {
device_id: DEVICE_ID, device_id: None,
}); });
} }
@ -651,7 +650,7 @@ declare_class!(
trace_scope!("mouseExited:"); trace_scope!("mouseExited:");
self.queue_event(WindowEvent::CursorLeft { self.queue_event(WindowEvent::CursorLeft {
device_id: DEVICE_ID, device_id: None,
}); });
} }
@ -689,10 +688,10 @@ declare_class!(
self.update_modifiers(event, false); self.update_modifiers(event, false);
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| 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 { self.queue_event(WindowEvent::MouseWheel {
device_id: DEVICE_ID, device_id: None,
delta, delta,
phase, phase,
}); });
@ -714,7 +713,7 @@ declare_class!(
}; };
self.queue_event(WindowEvent::PinchGesture { self.queue_event(WindowEvent::PinchGesture {
device_id: DEVICE_ID, device_id: None,
delta: unsafe { event.magnification() }, delta: unsafe { event.magnification() },
phase, phase,
}); });
@ -727,7 +726,7 @@ declare_class!(
self.mouse_motion(event); self.mouse_motion(event);
self.queue_event(WindowEvent::DoubleTapGesture { self.queue_event(WindowEvent::DoubleTapGesture {
device_id: DEVICE_ID, device_id: None,
}); });
} }
@ -747,7 +746,7 @@ declare_class!(
}; };
self.queue_event(WindowEvent::RotationGesture { self.queue_event(WindowEvent::RotationGesture {
device_id: DEVICE_ID, device_id: None,
delta: unsafe { event.rotation() }, delta: unsafe { event.rotation() },
phase, phase,
}); });
@ -758,7 +757,7 @@ declare_class!(
trace_scope!("pressureChangeWithEvent:"); trace_scope!("pressureChangeWithEvent:");
self.queue_event(WindowEvent::TouchpadPressure { self.queue_event(WindowEvent::TouchpadPressure {
device_id: DEVICE_ID, device_id: None,
pressure: unsafe { event.pressure() }, pressure: unsafe { event.pressure() },
stage: unsafe { event.stage() } as i64, stage: unsafe { event.stage() } as i64,
}); });
@ -972,7 +971,7 @@ impl WinitView {
event.location = KeyLocation::Left; event.location = KeyLocation::Left;
event.physical_key = get_left_modifier_code(&event.logical_key).into(); event.physical_key = get_left_modifier_code(&event.logical_key).into();
events.push_back(WindowEvent::KeyboardInput { events.push_back(WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event, event,
is_synthetic: false, is_synthetic: false,
}); });
@ -981,7 +980,7 @@ impl WinitView {
event.location = KeyLocation::Right; event.location = KeyLocation::Right;
event.physical_key = get_right_modifier_code(&event.logical_key).into(); event.physical_key = get_right_modifier_code(&event.logical_key).into();
events.push_back(WindowEvent::KeyboardInput { events.push_back(WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event, event,
is_synthetic: false, is_synthetic: false,
}); });
@ -1012,7 +1011,7 @@ impl WinitView {
} }
events.push_back(WindowEvent::KeyboardInput { events.push_back(WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event, event,
is_synthetic: false, is_synthetic: false,
}); });
@ -1038,11 +1037,7 @@ impl WinitView {
self.update_modifiers(event, false); self.update_modifiers(event, false);
self.queue_event(WindowEvent::MouseInput { self.queue_event(WindowEvent::MouseInput { device_id: None, state: button_state, button });
device_id: DEVICE_ID,
state: button_state,
button,
});
} }
fn mouse_motion(&self, event: &NSEvent) { fn mouse_motion(&self, event: &NSEvent) {
@ -1067,7 +1062,7 @@ impl WinitView {
self.update_modifiers(event, false); self.update_modifiers(event, false);
self.queue_event(WindowEvent::CursorMoved { self.queue_event(WindowEvent::CursorMoved {
device_id: DEVICE_ID, device_id: None,
position: view_point.to_physical(self.scale_factor()), position: view_point.to_physical(self.scale_factor()),
}); });
} }

View file

@ -339,10 +339,6 @@ impl CoreWindow for Window {
pub struct WindowId(pub usize); pub struct WindowId(pub usize);
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
self.0 as u64 self.0 as u64
} }

View file

@ -18,7 +18,6 @@ pub(crate) use self::window::{PlatformSpecificWindowAttributes, Window, WindowId
pub(crate) use crate::cursor::{ pub(crate) use crate::cursor::{
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource, NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
}; };
use crate::event::DeviceId as RootDeviceId;
pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub(crate) use crate::platform_impl::Fullscreen; 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId(usize); pub struct FingerId(usize);
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId(0) FingerId(0)
} }

View file

@ -14,7 +14,7 @@ use objc2_ui_kit::{
use super::app_state::{self, EventWrapper}; use super::app_state::{self, EventWrapper};
use super::window::WinitUIWindow; use super::window::WinitUIWindow;
use super::{FingerId, DEVICE_ID}; use super::FingerId;
use crate::dpi::PhysicalPosition; use crate::dpi::PhysicalPosition;
use crate::event::{ use crate::event::{
ElementState, Event, FingerId as RootFingerId, Force, KeyEvent, Touch, TouchPhase, WindowEvent, ElementState, Event, FingerId as RootFingerId, Force, KeyEvent, Touch, TouchPhase, WindowEvent,
@ -198,7 +198,7 @@ declare_class!(
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::PinchGesture { event: WindowEvent::PinchGesture {
device_id: DEVICE_ID, device_id: None,
delta: delta as f64, delta: delta as f64,
phase, phase,
}, },
@ -216,7 +216,7 @@ declare_class!(
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::DoubleTapGesture { event: WindowEvent::DoubleTapGesture {
device_id: DEVICE_ID, device_id: None,
}, },
}); });
@ -258,7 +258,7 @@ declare_class!(
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::RotationGesture { event: WindowEvent::RotationGesture {
device_id: DEVICE_ID, device_id: None,
delta: -delta.to_degrees() as _, delta: -delta.to_degrees() as _,
phase, phase,
}, },
@ -309,7 +309,7 @@ declare_class!(
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::PanGesture { event: WindowEvent::PanGesture {
device_id: DEVICE_ID, device_id: None,
delta: PhysicalPosition::new(dx as _, dy as _), delta: PhysicalPosition::new(dx as _, dy as _),
phase, phase,
}, },
@ -530,7 +530,7 @@ impl WinitView {
touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()), window_id: RootWindowId(window.id()),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
device_id: DEVICE_ID, device_id: None,
finger_id: RootFingerId(FingerId(touch_id)), finger_id: RootFingerId(FingerId(touch_id)),
location: physical_location, location: physical_location,
force, force,
@ -572,7 +572,7 @@ impl WinitView {
platform_specific: KeyEventExtra {}, platform_specific: KeyEventExtra {},
}, },
is_synthetic: false, is_synthetic: false,
device_id: DEVICE_ID, device_id: None,
}, },
}) })
}) })
@ -590,7 +590,7 @@ impl WinitView {
EventWrapper::StaticEvent(Event::WindowEvent { EventWrapper::StaticEvent(Event::WindowEvent {
window_id, window_id,
event: WindowEvent::KeyboardInput { event: WindowEvent::KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event: KeyEvent { event: KeyEvent {
state, state,
logical_key: Key::Named(NamedKey::Backspace), logical_key: Key::Named(NamedKey::Backspace),

View file

@ -944,10 +944,6 @@ impl Inner {
pub struct WindowId(usize); pub struct WindowId(usize);
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
WindowId(0)
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
self.0 as _ self.0 as _
} }

View file

@ -111,10 +111,6 @@ pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported
pub struct WindowId(u64); pub struct WindowId(u64);
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
self.0 self.0
} }
@ -129,18 +125,10 @@ pub enum DeviceId {
#[cfg(x11_platform)] #[cfg(x11_platform)]
X(x11::DeviceId), X(x11::DeviceId),
#[cfg(wayland_platform)] #[cfg(wayland_platform)]
#[allow(unused)]
Wayland(wayland::DeviceId), 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum FingerId { pub enum FingerId {
#[cfg(x11_platform)] #[cfg(x11_platform)]
@ -150,6 +138,7 @@ pub enum FingerId {
} }
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
#[cfg(wayland_platform)] #[cfg(wayland_platform)]
return FingerId::Wayland(wayland::FingerId::dummy()); return FingerId::Wayland(wayland::FingerId::dummy());

View file

@ -30,7 +30,7 @@ use sink::EventSink;
use super::state::{WindowCompositorUpdate, WinitState}; use super::state::{WindowCompositorUpdate, WinitState};
use super::window::state::FrameCallbackState; 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>, WinitState>; type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource<WinitState>, WinitState>;

View file

@ -2,9 +2,8 @@
use std::vec::Drain; use std::vec::Drain;
use super::{DeviceId, WindowId}; use super::WindowId;
use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent}; use crate::event::{DeviceEvent, Event, WindowEvent};
use crate::platform_impl::platform::DeviceId as PlatformDeviceId;
use crate::window::WindowId as RootWindowId; use crate::window::WindowId as RootWindowId;
/// An event loop's sink to deliver events from the Wayland event callbacks /// 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. /// Add new device event to a queue.
#[inline] #[inline]
pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) { pub fn push_device_event(&mut self, event: DeviceEvent) {
self.window_events.push(Event::DeviceEvent { self.window_events.push(Event::DeviceEvent { event, device_id: None });
event,
device_id: RootDeviceId(PlatformDeviceId::Wayland(device_id)),
});
} }
/// Add new window event to a queue. /// Add new window event to a queue.

View file

@ -21,16 +21,11 @@ mod window;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; pub struct DeviceId;
impl DeviceId {
pub const fn dummy() -> Self {
DeviceId
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId(i32); pub struct FingerId(i32);
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId(0) FingerId(0)
} }

View file

@ -17,7 +17,7 @@ use crate::keyboard::ModifiersState;
use crate::platform_impl::common::xkb::Context; use crate::platform_impl::common::xkb::Context;
use crate::platform_impl::wayland::event_loop::sink::EventSink; use crate::platform_impl::wayland::event_loop::sink::EventSink;
use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, DeviceId, WindowId}; use crate::platform_impl::wayland::{self, WindowId};
impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState { impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
fn event( fn event(
@ -369,10 +369,9 @@ fn key_input(
None => return, 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() { if let Some(mut key_context) = keyboard_state.xkb_context.key_context() {
let event = key_context.process_key_event(keycode, state, repeat); 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); event_sink.push_window_event(event, window_id);
} }
} }

View file

@ -30,7 +30,7 @@ use crate::dpi::{LogicalPosition, PhysicalPosition};
use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent}; use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent};
use crate::platform_impl::wayland::state::WinitState; 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; 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 { for event in events {
let surface = &event.surface; let surface = &event.surface;
@ -124,8 +122,10 @@ impl PointerHandler for WinitState {
}, },
// Regular events on the main surface. // Regular events on the main surface.
PointerEventKind::Enter { .. } => { PointerEventKind::Enter { .. } => {
self.events_sink self.events_sink.push_window_event(
.push_window_event(WindowEvent::CursorEntered { device_id }, window_id); WindowEvent::CursorEntered { device_id: None },
window_id,
);
window.pointer_entered(Arc::downgrade(themed_pointer)); 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); pointer.winit_data().inner.lock().unwrap().surface = Some(window_id);
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::CursorMoved { device_id, position }, WindowEvent::CursorMoved { device_id: None, position },
window_id, window_id,
); );
}, },
@ -144,11 +144,11 @@ impl PointerHandler for WinitState {
pointer.winit_data().inner.lock().unwrap().surface = None; pointer.winit_data().inner.lock().unwrap().surface = None;
self.events_sink self.events_sink
.push_window_event(WindowEvent::CursorLeft { device_id }, window_id); .push_window_event(WindowEvent::CursorLeft { device_id: None }, window_id);
}, },
PointerEventKind::Motion { .. } => { PointerEventKind::Motion { .. } => {
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::CursorMoved { device_id, position }, WindowEvent::CursorMoved { device_id: None, position },
window_id, window_id,
); );
}, },
@ -164,7 +164,7 @@ impl PointerHandler for WinitState {
ElementState::Released ElementState::Released
}; };
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::MouseInput { device_id, state, button }, WindowEvent::MouseInput { device_id: None, state, button },
window_id, window_id,
); );
}, },
@ -209,7 +209,7 @@ impl PointerHandler for WinitState {
}; };
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::MouseWheel { device_id, delta, phase }, WindowEvent::MouseWheel { device_id: None, delta, phase },
window_id, window_id,
) )
}, },

View file

@ -66,10 +66,9 @@ impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerS
}, },
_ => return, _ => return,
}; };
state.events_sink.push_device_event( state
DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) }, .events_sink
super::DeviceId, .push_device_event(DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) });
);
} }
} }

View file

@ -10,7 +10,7 @@ use tracing::warn;
use crate::dpi::LogicalPosition; use crate::dpi::LogicalPosition;
use crate::event::{Touch, TouchPhase, WindowEvent}; use crate::event::{Touch, TouchPhase, WindowEvent};
use crate::platform_impl::wayland::state::WinitState; 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 { impl TouchHandler for WinitState {
fn down( fn down(
@ -44,9 +44,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::Touch(Touch { WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( device_id: None,
DeviceId,
)),
phase: TouchPhase::Started, phase: TouchPhase::Started,
location: location.to_physical(scale_factor), location: location.to_physical(scale_factor),
force: None, force: None,
@ -89,9 +87,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::Touch(Touch { WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( device_id: None,
DeviceId,
)),
phase: TouchPhase::Ended, phase: TouchPhase::Ended,
location: touch_point.location.to_physical(scale_factor), location: touch_point.location.to_physical(scale_factor),
force: None, force: None,
@ -136,9 +132,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::Touch(Touch { WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( device_id: None,
DeviceId,
)),
phase: TouchPhase::Moved, phase: TouchPhase::Moved,
location: touch_point.location.to_physical(scale_factor), location: touch_point.location.to_physical(scale_factor),
force: None, force: None,
@ -170,9 +164,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event( self.events_sink.push_window_event(
WindowEvent::Touch(Touch { WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland( device_id: None,
DeviceId,
)),
phase: TouchPhase::Cancelled, phase: TouchPhase::Cancelled,
location, location,
force: None, force: None,

View file

@ -878,7 +878,6 @@ impl EventProcessor {
}; };
let window_id = mkwid(window); let window_id = mkwid(window);
let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD);
let keycode = xev.keycode as _; let keycode = xev.keycode as _;
@ -942,7 +941,11 @@ impl EventProcessor {
let event = key_processor.process_key_event(keycode, state, repeat); let event = key_processor.process_key_event(keycode, state, repeat);
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id, 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); callback(&self.target, event);
} }
@ -1012,7 +1015,7 @@ impl EventProcessor {
F: FnMut(&ActiveEventLoop, Event), F: FnMut(&ActiveEventLoop, Event),
{ {
let window_id = mkwid(event.event as xproto::Window); 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. // Set the timestamp.
self.target.xconn.set_timestamp(event.time as xproto::Timestamp); self.target.xconn.set_timestamp(event.time as xproto::Timestamp);
@ -1066,7 +1069,7 @@ impl EventProcessor {
// Set the timestamp. // Set the timestamp.
self.target.xconn.set_timestamp(event.time as xproto::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 = event.event as xproto::Window;
let window_id = mkwid(window); let window_id = mkwid(window);
let new_cursor_pos = (event.event_x, event.event_y); let new_cursor_pos = (event.event_x, event.event_y);
@ -1161,6 +1164,7 @@ impl EventProcessor {
} }
if self.window_exists(window) { if self.window_exists(window) {
let device_id = Some(device_id);
let position = PhysicalPosition::new(event.event_x, event.event_y); let position = PhysicalPosition::new(event.event_x, event.event_y);
let event = let event =
@ -1190,7 +1194,7 @@ impl EventProcessor {
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id: mkwid(window), window_id: mkwid(window),
event: WindowEvent::CursorLeft { event: WindowEvent::CursorLeft {
device_id: mkdid(event.deviceid as xinput::DeviceId), device_id: Some(mkdid(event.deviceid as xinput::DeviceId)),
}, },
}; };
callback(&self.target, event); callback(&self.target, event);
@ -1241,16 +1245,15 @@ impl EventProcessor {
// The deviceid for this event is for a keyboard instead of a pointer, // The deviceid for this event is for a keyboard instead of a pointer,
// so we have to do a little extra work. // so we have to do a little extra work.
let pointer_id = self let device_id = self
.devices .devices
.borrow() .borrow()
.get(&DeviceId(xev.deviceid as xinput::DeviceId)) .get(&DeviceId(xev.deviceid as xinput::DeviceId))
.map(|device| device.attachment) .map(|device| mkdid(device.attachment as _));
.unwrap_or(2);
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id, window_id,
event: WindowEvent::CursorMoved { device_id: mkdid(pointer_id as _), position }, event: WindowEvent::CursorMoved { device_id, position },
}; };
callback(&self.target, event); callback(&self.target, event);
} }
@ -1324,10 +1327,7 @@ impl EventProcessor {
if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) { if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) {
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id, window_id,
event: WindowEvent::CursorMoved { event: WindowEvent::CursorMoved { device_id: None, position: location.cast() },
device_id: mkdid(util::VIRTUAL_CORE_POINTER),
position: location.cast(),
},
}; };
callback(&self.target, event); callback(&self.target, event);
} }
@ -1335,7 +1335,7 @@ impl EventProcessor {
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id, window_id,
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
device_id: mkdid(xev.deviceid as xinput::DeviceId), device_id: Some(mkdid(xev.deviceid as xinput::DeviceId)),
phase, phase,
location, location,
force: None, // TODO force: None, // TODO
@ -1355,7 +1355,7 @@ impl EventProcessor {
if xev.flags & xinput2::XIPointerEmulated == 0 { if xev.flags & xinput2::XIPointerEmulated == 0 {
let event = Event::DeviceEvent { 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 }, event: DeviceEvent::Button { state, button: xev.detail as u32 },
}; };
callback(&self.target, event); callback(&self.target, event);
@ -1369,7 +1369,7 @@ impl EventProcessor {
// Set the timestamp. // Set the timestamp.
self.target.xconn.set_timestamp(xev.time as xproto::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 = let mask =
unsafe { slice::from_raw_parts(xev.valuators.mask, xev.valuators.mask_len as usize) }; unsafe { slice::from_raw_parts(xev.valuators.mask, xev.valuators.mask_len as usize) };
@ -1421,7 +1421,7 @@ impl EventProcessor {
// Set the timestamp. // Set the timestamp.
self.target.xconn.set_timestamp(xev.time as xproto::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; let keycode = xev.detail as u32;
if keycode < KEYCODE_OFFSET as u32 { if keycode < KEYCODE_OFFSET as u32 {
return; return;
@ -1695,8 +1695,6 @@ impl EventProcessor {
) where ) where
F: FnMut(&ActiveEventLoop, Event), 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. // Update modifiers state and emit key events based on which keys are currently pressed.
let xcb = target.xconn.xcb_connection().get_raw_xcb_connection(); 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 = key_processor.process_key_event(keycode as u32, state, false);
let event = Event::WindowEvent { let event = Event::WindowEvent {
window_id, window_id,
event: WindowEvent::KeyboardInput { device_id, event, is_synthetic: true }, event: WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: true },
}; };
callback(target, event); callback(target, event);
} }

View file

@ -811,17 +811,11 @@ impl<'a> Deref for DeviceInfo<'a> {
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(xinput::DeviceId); 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId(u32); pub struct FingerId(u32);
impl FingerId { impl FingerId {
#[cfg(test)]
#[allow(unused)] #[allow(unused)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId(0) FingerId(0)

View file

@ -6,7 +6,6 @@ use x11rb::protocol::xkb;
use super::*; use super::*;
pub const VIRTUAL_CORE_POINTER: u16 = 2; 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 // 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. // re-allocate (and make another round-trip) in the *vast* majority of cases.

View file

@ -12,8 +12,8 @@ use orbclient::{
use smol_str::SmolStr; use smol_str::SmolStr;
use super::{ use super::{
DeviceId, KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket,
TimeSocket, WindowId, WindowProperties, WindowId, WindowProperties,
}; };
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, NotSupportedError, RequestError}; use crate::error::{EventLoopError, NotSupportedError, RequestError};
@ -364,7 +364,7 @@ impl EventLoop {
let window_id = RootWindowId(window_id); let window_id = RootWindowId(window_id);
let event = event::WindowEvent::KeyboardInput { let event = event::WindowEvent::KeyboardInput {
device_id: event::DeviceId(DeviceId), device_id: None,
event: event::KeyEvent { event: event::KeyEvent {
logical_key, logical_key,
physical_key, physical_key,
@ -407,29 +407,20 @@ impl EventLoop {
app.window_event( app.window_event(
window_target, window_target,
RootWindowId(window_id), RootWindowId(window_id),
event::WindowEvent::CursorMoved { event::WindowEvent::CursorMoved { device_id: None, position: (x, y).into() },
device_id: event::DeviceId(DeviceId),
position: (x, y).into(),
},
); );
}, },
EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => { EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => {
app.device_event( app.device_event(window_target, None, event::DeviceEvent::MouseMotion {
window_target, delta: (dx as f64, dy as f64),
event::DeviceId(DeviceId), });
event::DeviceEvent::MouseMotion { delta: (dx as f64, dy as f64) },
);
}, },
EventOption::Button(ButtonEvent { left, middle, right }) => { EventOption::Button(ButtonEvent { left, middle, right }) => {
while let Some((button, state)) = event_state.mouse(left, middle, right) { while let Some((button, state)) = event_state.mouse(left, middle, right) {
app.window_event( app.window_event(
window_target, window_target,
RootWindowId(window_id), RootWindowId(window_id),
event::WindowEvent::MouseInput { event::WindowEvent::MouseInput { device_id: None, state, button },
device_id: event::DeviceId(DeviceId),
state,
button,
},
); );
} }
}, },
@ -438,7 +429,7 @@ impl EventLoop {
window_target, window_target,
RootWindowId(window_id), RootWindowId(window_id),
event::WindowEvent::MouseWheel { event::WindowEvent::MouseWheel {
device_id: event::DeviceId(DeviceId), device_id: None,
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
phase: event::TouchPhase::Moved, phase: event::TouchPhase::Moved,
}, },
@ -478,9 +469,9 @@ impl EventLoop {
// TODO: Screen, Clipboard, Drop // TODO: Screen, Clipboard, Drop
EventOption::Hover(HoverEvent { entered }) => { EventOption::Hover(HoverEvent { entered }) => {
let event = if entered { let event = if entered {
event::WindowEvent::CursorEntered { device_id: event::DeviceId(DeviceId) } event::WindowEvent::CursorEntered { device_id: None }
} else { } else {
event::WindowEvent::CursorLeft { device_id: event::DeviceId(DeviceId) } event::WindowEvent::CursorLeft { device_id: None }
}; };
app.window_event(window_target, RootWindowId(window_id), event); app.window_event(window_target, RootWindowId(window_id), event);

View file

@ -105,10 +105,6 @@ pub struct WindowId {
} }
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
WindowId { fd: u64::MAX }
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
self.fd self.fd
} }
@ -121,16 +117,11 @@ impl WindowId {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct DeviceId; pub struct DeviceId;
impl DeviceId {
pub const fn dummy() -> Self {
DeviceId
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct FingerId; pub struct FingerId;
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId FingerId
} }

View file

@ -1,13 +1,16 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct DeviceId(i32); pub struct DeviceId(u32);
impl DeviceId { impl DeviceId {
pub fn new(pointer_id: i32) -> Self { pub fn new(pointer_id: i32) -> Option<Self> {
Self(pointer_id) if let Ok(pointer_id) = u32::try_from(pointer_id) {
} Some(Self(pointer_id))
} else if pointer_id == -1 {
pub const fn dummy() -> Self { None
Self(-1) } else {
tracing::error!("found unexpected negative `PointerEvent.pointerId`: {pointer_id}");
None
}
} }
} }
@ -22,6 +25,7 @@ impl FingerId {
Self { pointer_id, primary } Self { pointer_id, primary }
} }
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
Self { pointer_id: -1, primary: false } Self { pointer_id: -1, primary: false }
} }

View file

@ -1,4 +1,4 @@
use super::{backend, event, window, HasMonitorPermissionFuture, MonitorPermissionFuture}; use super::{backend, window, HasMonitorPermissionFuture, MonitorPermissionFuture};
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, NotSupportedError}; use crate::error::{EventLoopError, NotSupportedError};
use crate::event::Event; use crate::event::Event;

View file

@ -286,7 +286,7 @@ impl Shared {
} }
// chorded button event // 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) { if let Some(button) = backend::event::mouse_button(&event) {
let state = if backend::event::mouse_buttons(&event).contains(button.into()) { 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) { if let Some(delta) = backend::event::mouse_scroll_delta(&window, &event) {
runner.send_event(Event::DeviceEvent { runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId::dummy()), device_id: None,
event: DeviceEvent::MouseWheel { delta }, event: DeviceEvent::MouseWheel { delta },
}); });
} }
@ -344,7 +344,7 @@ impl Shared {
let button = backend::event::mouse_button(&event).expect("no mouse button pressed"); let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
runner.send_event(Event::DeviceEvent { 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 { event: DeviceEvent::Button {
button: button.to_id(), button: button.to_id(),
state: ElementState::Pressed, state: ElementState::Pressed,
@ -363,7 +363,7 @@ impl Shared {
let button = backend::event::mouse_button(&event).expect("no mouse button pressed"); let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
runner.send_event(Event::DeviceEvent { 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 { event: DeviceEvent::Button {
button: button.to_id(), button: button.to_id(),
state: ElementState::Released, state: ElementState::Released,
@ -381,7 +381,7 @@ impl Shared {
} }
runner.send_event(Event::DeviceEvent { runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId::dummy()), device_id: None,
event: DeviceEvent::Key(RawKeyEvent { event: DeviceEvent::Key(RawKeyEvent {
physical_key: backend::event::key_code(&event), physical_key: backend::event::key_code(&event),
state: ElementState::Pressed, state: ElementState::Pressed,
@ -399,7 +399,7 @@ impl Shared {
} }
runner.send_event(Event::DeviceEvent { runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId::dummy()), device_id: None,
event: DeviceEvent::Key(RawKeyEvent { event: DeviceEvent::Key(RawKeyEvent {
physical_key: backend::event::key_code(&event), physical_key: backend::event::key_code(&event),
state: ElementState::Released, state: ElementState::Released,

View file

@ -7,7 +7,6 @@ use web_sys::Element;
use super::super::monitor::MonitorPermissionFuture; use super::super::monitor::MonitorPermissionFuture;
use super::super::{lock, KeyEventExtra}; use super::super::{lock, KeyEventExtra};
use super::event::DeviceId;
use super::runner::{EventWrapper, WeakShared}; use super::runner::{EventWrapper, WeakShared};
use super::window::WindowId; use super::window::WindowId;
use super::{backend, runner, EventLoopProxy}; use super::{backend, runner, EventLoopProxy};
@ -144,13 +143,11 @@ impl ActiveEventLoop {
} }
}); });
let device_id = RootDeviceId(DeviceId::dummy());
runner.send_events( runner.send_events(
iter::once(Event::WindowEvent { iter::once(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::KeyboardInput { event: WindowEvent::KeyboardInput {
device_id, device_id: None,
event: KeyEvent { event: KeyEvent {
physical_key, physical_key,
logical_key, logical_key,
@ -180,13 +177,11 @@ impl ActiveEventLoop {
} }
}); });
let device_id = RootDeviceId(DeviceId::dummy());
runner.send_events( runner.send_events(
iter::once(Event::WindowEvent { iter::once(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::KeyboardInput { event: WindowEvent::KeyboardInput {
device_id, device_id: None,
event: KeyEvent { event: KeyEvent {
physical_key, physical_key,
logical_key, logical_key,
@ -221,7 +216,7 @@ impl ActiveEventLoop {
let pointer = pointer_id.map(|device_id| Event::WindowEvent { let pointer = pointer_id.map(|device_id| Event::WindowEvent {
window_id: RootWindowId(id), 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() { if focus.is_some() || pointer.is_some() {
@ -246,7 +241,7 @@ impl ActiveEventLoop {
let pointer = pointer_id.map(|device_id| Event::WindowEvent { let pointer = pointer_id.map(|device_id| Event::WindowEvent {
window_id: RootWindowId(id), 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() { if focus.is_some() || pointer.is_some() {
@ -272,7 +267,7 @@ impl ActiveEventLoop {
}); });
runner.send_events(modifiers.into_iter().chain(events.flat_map(|position| { 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 { iter::once(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
@ -301,7 +296,7 @@ impl ActiveEventLoop {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
finger_id: RootFingerId(finger_id), finger_id: RootFingerId(finger_id),
device_id: RootDeviceId(device_id), device_id: device_id.map(RootDeviceId),
phase: TouchPhase::Moved, phase: TouchPhase::Moved,
force: Some(force), force: Some(force),
location, 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()) { let state = if buttons.contains(button.into()) {
ElementState::Pressed 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, // A mouse down event may come in without any prior CursorMoved events,
// therefore we should send a CursorMoved event to make sure that the // therefore we should send a CursorMoved event to make sure that the
@ -407,7 +402,7 @@ impl ActiveEventLoop {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
finger_id: RootFingerId(finger_id), finger_id: RootFingerId(finger_id),
device_id: RootDeviceId(device_id), device_id: device_id.map(RootDeviceId),
phase: TouchPhase::Started, phase: TouchPhase::Started,
force: Some(force), force: Some(force),
location, 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, // A mouse up event may come in without any prior CursorMoved events,
// therefore we should send a CursorMoved event to make sure that the // therefore we should send a CursorMoved event to make sure that the
@ -475,7 +470,7 @@ impl ActiveEventLoop {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
finger_id: RootFingerId(finger_id), finger_id: RootFingerId(finger_id),
device_id: RootDeviceId(device_id), device_id: device_id.map(RootDeviceId),
phase: TouchPhase::Ended, phase: TouchPhase::Ended,
force: Some(force), force: Some(force),
location, location,
@ -502,7 +497,7 @@ impl ActiveEventLoop {
Event::WindowEvent { Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::MouseWheel { event: WindowEvent::MouseWheel {
device_id: RootDeviceId(DeviceId::dummy()), device_id: None,
delta, delta,
phase: TouchPhase::Moved, phase: TouchPhase::Moved,
}, },
@ -516,7 +511,7 @@ impl ActiveEventLoop {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
finger_id: RootFingerId(finger_id), finger_id: RootFingerId(finger_id),
device_id: RootDeviceId(device_id), device_id: device_id.map(RootDeviceId),
phase: TouchPhase::Cancelled, phase: TouchPhase::Cancelled,
force: Some(force), force: Some(force),
location, location,

View file

@ -330,22 +330,23 @@ impl Canvas {
pub fn on_cursor_leave<F>(&self, handler: F) pub fn on_cursor_leave<F>(&self, handler: F)
where where
F: 'static + FnMut(ModifiersState, Option<DeviceId>), F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
{ {
self.handlers.borrow_mut().pointer_handler.on_cursor_leave(&self.common, handler) self.handlers.borrow_mut().pointer_handler.on_cursor_leave(&self.common, handler)
} }
pub fn on_cursor_enter<F>(&self, handler: F) pub fn on_cursor_enter<F>(&self, handler: F)
where where
F: 'static + FnMut(ModifiersState, Option<DeviceId>), F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
{ {
self.handlers.borrow_mut().pointer_handler.on_cursor_enter(&self.common, handler) self.handlers.borrow_mut().pointer_handler.on_cursor_enter(&self.common, handler)
} }
pub fn on_mouse_release<M, T>(&self, mouse_handler: M, touch_handler: T) pub fn on_mouse_release<M, T>(&self, mouse_handler: M, touch_handler: T)
where where
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton), M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force), T: 'static
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
{ {
self.handlers.borrow_mut().pointer_handler.on_mouse_release( self.handlers.borrow_mut().pointer_handler.on_mouse_release(
&self.common, &self.common,
@ -356,8 +357,9 @@ impl Canvas {
pub fn on_mouse_press<M, T>(&self, mouse_handler: M, touch_handler: T) pub fn on_mouse_press<M, T>(&self, mouse_handler: M, touch_handler: T)
where where
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton), M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force), T: 'static
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
{ {
self.handlers.borrow_mut().pointer_handler.on_mouse_press( self.handlers.borrow_mut().pointer_handler.on_mouse_press(
&self.common, &self.common,
@ -370,16 +372,22 @@ impl Canvas {
pub fn on_cursor_move<M, T, B>(&self, mouse_handler: M, touch_handler: T, button_handler: B) pub fn on_cursor_move<M, T, B>(&self, mouse_handler: M, touch_handler: T, button_handler: B)
where where
M: 'static M: 'static
+ FnMut(ModifiersState, DeviceId, &mut dyn Iterator<Item = PhysicalPosition<f64>>), + FnMut(ModifiersState, Option<DeviceId>, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
T: 'static T: 'static
+ FnMut( + FnMut(
ModifiersState, ModifiersState,
DeviceId, Option<DeviceId>,
FingerId, FingerId,
&mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>, &mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>,
), ),
B: 'static B: 'static
+ FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, ButtonsState, MouseButton), + FnMut(
ModifiersState,
Option<DeviceId>,
PhysicalPosition<f64>,
ButtonsState,
MouseButton,
),
{ {
self.handlers.borrow_mut().pointer_handler.on_cursor_move( self.handlers.borrow_mut().pointer_handler.on_cursor_move(
&self.common, &self.common,
@ -392,7 +400,7 @@ impl Canvas {
pub fn on_touch_cancel<F>(&self, handler: F) pub fn on_touch_cancel<F>(&self, handler: F)
where where
F: 'static + FnMut(DeviceId, FingerId, PhysicalPosition<f64>, Force), F: 'static + FnMut(Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
{ {
self.handlers.borrow_mut().pointer_handler.on_touch_cancel(&self.common, handler) self.handlers.borrow_mut().pointer_handler.on_touch_cancel(&self.common, handler)
} }

View file

@ -36,7 +36,7 @@ impl PointerHandler {
pub fn on_cursor_leave<F>(&mut self, canvas_common: &Common, mut handler: F) pub fn on_cursor_leave<F>(&mut self, canvas_common: &Common, mut handler: F)
where where
F: 'static + FnMut(ModifiersState, Option<DeviceId>), F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
{ {
self.on_cursor_leave = self.on_cursor_leave =
Some(canvas_common.add_event("pointerout", move |event: PointerEvent| { Some(canvas_common.add_event("pointerout", move |event: PointerEvent| {
@ -54,7 +54,7 @@ impl PointerHandler {
pub fn on_cursor_enter<F>(&mut self, canvas_common: &Common, mut handler: F) pub fn on_cursor_enter<F>(&mut self, canvas_common: &Common, mut handler: F)
where where
F: 'static + FnMut(ModifiersState, Option<DeviceId>), F: 'static + FnMut(ModifiersState, Option<Option<DeviceId>>),
{ {
self.on_cursor_enter = self.on_cursor_enter =
Some(canvas_common.add_event("pointerover", move |event: PointerEvent| { Some(canvas_common.add_event("pointerover", move |event: PointerEvent| {
@ -76,8 +76,9 @@ impl PointerHandler {
mut mouse_handler: M, mut mouse_handler: M,
mut touch_handler: T, mut touch_handler: T,
) where ) where
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton), M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force), T: 'static
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
{ {
let window = canvas_common.window.clone(); let window = canvas_common.window.clone();
self.on_pointer_release = self.on_pointer_release =
@ -112,8 +113,9 @@ impl PointerHandler {
mut touch_handler: T, mut touch_handler: T,
prevent_default: Rc<Cell<bool>>, prevent_default: Rc<Cell<bool>>,
) where ) where
M: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, MouseButton), M: 'static + FnMut(ModifiersState, Option<DeviceId>, PhysicalPosition<f64>, MouseButton),
T: 'static + FnMut(ModifiersState, DeviceId, FingerId, PhysicalPosition<f64>, Force), T: 'static
+ FnMut(ModifiersState, Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
{ {
let window = canvas_common.window.clone(); let window = canvas_common.window.clone();
let canvas = canvas_common.raw().clone(); let canvas = canvas_common.raw().clone();
@ -172,16 +174,22 @@ impl PointerHandler {
prevent_default: Rc<Cell<bool>>, prevent_default: Rc<Cell<bool>>,
) where ) where
M: 'static M: 'static
+ FnMut(ModifiersState, DeviceId, &mut dyn Iterator<Item = PhysicalPosition<f64>>), + FnMut(ModifiersState, Option<DeviceId>, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
T: 'static T: 'static
+ FnMut( + FnMut(
ModifiersState, ModifiersState,
DeviceId, Option<DeviceId>,
FingerId, FingerId,
&mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>, &mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>,
), ),
B: 'static B: 'static
+ FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, ButtonsState, MouseButton), + FnMut(
ModifiersState,
Option<DeviceId>,
PhysicalPosition<f64>,
ButtonsState,
MouseButton,
),
{ {
let window = canvas_common.window.clone(); let window = canvas_common.window.clone();
let canvas = canvas_common.raw().clone(); let canvas = canvas_common.raw().clone();
@ -237,7 +245,7 @@ impl PointerHandler {
pub fn on_touch_cancel<F>(&mut self, canvas_common: &Common, mut handler: F) pub fn on_touch_cancel<F>(&mut self, canvas_common: &Common, mut handler: F)
where where
F: 'static + FnMut(DeviceId, FingerId, PhysicalPosition<f64>, Force), F: 'static + FnMut(Option<DeviceId>, FingerId, PhysicalPosition<f64>, Force),
{ {
let window = canvas_common.window.clone(); let window = canvas_common.window.clone();
self.on_touch_cancel = self.on_touch_cancel =

View file

@ -433,10 +433,6 @@ impl Drop for Inner {
pub struct WindowId(pub(crate) u64); pub struct WindowId(pub(crate) u64);
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
self.0 self.0
} }

View file

@ -81,7 +81,7 @@ use crate::platform_impl::platform::window_state::{
CursorFlags, ImeState, WindowFlags, WindowState, CursorFlags, ImeState, WindowFlags, WindowState,
}; };
use crate::platform_impl::platform::{ 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::platform_impl::Window;
use crate::utils::Lazy; use crate::utils::Lazy;
@ -1047,7 +1047,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: KeyboardInput { event: KeyboardInput {
device_id: DEVICE_ID, device_id: None,
event: event.event, event: event.event,
is_synthetic: event.is_synthetic, is_synthetic: event.is_synthetic,
}, },
@ -1541,7 +1541,7 @@ unsafe fn public_window_callback_inner(
drop(w); drop(w);
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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. // Calling TrackMouseEvent in order to receive mouse leave events.
@ -1562,7 +1562,7 @@ unsafe fn public_window_callback_inner(
drop(w); drop(w);
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: CursorLeft { device_id: DEVICE_ID }, event: CursorLeft { device_id: None },
}); });
}, },
PointerMoveKind::None => drop(w), PointerMoveKind::None => drop(w),
@ -1581,7 +1581,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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 { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: CursorLeft { device_id: DEVICE_ID }, event: CursorLeft { device_id: None },
}); });
result = ProcResult::Value(0); result = ProcResult::Value(0);
@ -1614,7 +1614,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: WindowEvent::MouseWheel { event: WindowEvent::MouseWheel {
device_id: DEVICE_ID, device_id: None,
delta: LineDelta(0.0, value), delta: LineDelta(0.0, value),
phase: TouchPhase::Moved, phase: TouchPhase::Moved,
}, },
@ -1634,7 +1634,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: WindowEvent::MouseWheel { event: WindowEvent::MouseWheel {
device_id: DEVICE_ID, device_id: None,
delta: LineDelta(value, 0.0), delta: LineDelta(value, 0.0),
phase: TouchPhase::Moved, phase: TouchPhase::Moved,
}, },
@ -1668,7 +1668,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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); result = ProcResult::Value(0);
}, },
@ -1684,7 +1684,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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); result = ProcResult::Value(0);
}, },
@ -1700,7 +1700,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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); result = ProcResult::Value(0);
}, },
@ -1716,7 +1716,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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); result = ProcResult::Value(0);
}, },
@ -1732,7 +1732,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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); result = ProcResult::Value(0);
}, },
@ -1748,7 +1748,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), 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); result = ProcResult::Value(0);
}, },
@ -1766,7 +1766,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: MouseInput { event: MouseInput {
device_id: DEVICE_ID, device_id: None,
state: Pressed, state: Pressed,
button: match xbutton { button: match xbutton {
1 => Back, 1 => Back,
@ -1791,7 +1791,7 @@ unsafe fn public_window_callback_inner(
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)), window_id: CoreWindowId(WindowId(window)),
event: MouseInput { event: MouseInput {
device_id: DEVICE_ID, device_id: None,
state: Released, state: Released,
button: match xbutton { button: match xbutton {
1 => Back, 1 => Back,
@ -1855,7 +1855,7 @@ unsafe fn public_window_callback_inner(
id: input.dwID, id: input.dwID,
primary: util::has_flag(input.dwFlags, TOUCHEVENTF_PRIMARY), 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, 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::ElementState::{Pressed, Released};
use crate::event::MouseScrollDelta::LineDelta; 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 { if data.header.dwType == RIM_TYPEMOUSE {
let mouse = unsafe { data.data.mouse }; let mouse = unsafe { data.data.mouse };

View file

@ -62,12 +62,6 @@ unsafe impl Sync for PlatformSpecificWindowAttributes {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(u32); pub struct DeviceId(u32);
impl DeviceId {
pub const fn dummy() -> Self {
DeviceId(0)
}
}
impl DeviceId { impl DeviceId {
pub fn persistent_identifier(&self) -> Option<String> { pub fn persistent_identifier(&self) -> Option<String> {
if self.0 != 0 { if self.0 != 0 {
@ -85,6 +79,7 @@ pub struct FingerId {
} }
impl FingerId { impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self { pub const fn dummy() -> Self {
FingerId { id: 0, primary: false } 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 { fn wrap_device_id(id: u32) -> RootDeviceId {
RootDeviceId(DeviceId(id)) RootDeviceId(DeviceId(id))
} }
@ -115,10 +107,6 @@ unsafe impl Send for WindowId {}
unsafe impl Sync for WindowId {} unsafe impl Sync for WindowId {}
impl WindowId { impl WindowId {
pub const fn dummy() -> Self {
WindowId(0)
}
pub const fn into_raw(self) -> u64 { pub const fn into_raw(self) -> u64 {
self.0 as u64 self.0 as u64
} }

View file

@ -24,17 +24,6 @@ use crate::utils::AsAny;
pub struct WindowId(pub(crate) platform_impl::WindowId); pub struct WindowId(pub(crate) platform_impl::WindowId);
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. /// 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. /// This is useful if you need to pass the ID across an FFI boundary, or store it in an atomic.