Skip to content

Commit

Permalink
Remove dummy() from WindowId and DeviceId
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Aug 13, 2024
1 parent efebea1 commit c69047e
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 72 deletions.
1 change: 1 addition & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ changelog entry.
- Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of
`MonitorHandle::current_video_mode()`.
- On Android, remove all `MonitorHandle` support instead of emitting false data.
- Remove `dummy()` from `WindowId` and `DeviceId`.

### Fixed

Expand Down
28 changes: 5 additions & 23 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,21 +434,9 @@ pub enum WindowEvent {
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(pub(crate) platform_impl::DeviceId);

impl Default for DeviceId {
fn default() -> Self {
Self::dummy()
}
}

impl DeviceId {
/// Returns a dummy id, useful for unit testing.
///
/// # Notes
///
/// The only guarantee made about the return value of this function is that
/// it will always be equal to itself and to future values returned by this function.
/// No other guarantees are made. This may be equal to a real `DeviceId`.
pub const fn dummy() -> Self {
#[cfg(test)]
pub(crate) const fn dummy() -> Self {
DeviceId(platform_impl::DeviceId::dummy())
}
}
Expand All @@ -461,14 +449,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())
}
}
Expand Down Expand Up @@ -1052,7 +1034,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);
Expand Down
6 changes: 2 additions & 4 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,6 @@ impl OwnedDisplayHandle {
pub(crate) struct WindowId;

impl WindowId {
pub const fn dummy() -> Self {
WindowId
}

pub fn into_raw(self) -> u64 {
0
}
Expand All @@ -687,6 +683,7 @@ impl WindowId {
pub struct DeviceId(i32);

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
DeviceId(0)
}
Expand All @@ -696,6 +693,7 @@ impl DeviceId {
pub struct FingerId(i32);

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId(0)
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/apple/appkit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) use crate::platform_impl::Fullscreen;
pub struct DeviceId;

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
DeviceId
}
Expand All @@ -47,6 +48,7 @@ pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);
pub struct FingerId;

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId
}
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/apple/appkit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ impl Window {
pub struct WindowId(pub usize);

impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}

pub fn into_raw(self) -> u64 {
self.0 as u64
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/apple/uikit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) use crate::platform_impl::Fullscreen;
pub struct DeviceId;

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
DeviceId
}
Expand All @@ -41,6 +42,7 @@ pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);
pub struct FingerId(usize);

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId(0)
}
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/apple/uikit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,6 @@ pub struct WindowId {
}

impl WindowId {
pub const fn dummy() -> Self {
WindowId { window: std::ptr::null_mut() }
}

pub fn into_raw(self) -> u64 {
self.window as u64
}
Expand Down
6 changes: 2 additions & 4 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ pub(crate) enum Window {
pub struct WindowId(u64);

impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}

pub const fn into_raw(self) -> u64 {
self.0
}
Expand All @@ -166,6 +162,7 @@ pub enum DeviceId {
}

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
#[cfg(wayland_platform)]
return DeviceId::Wayland(wayland::DeviceId::dummy());
Expand All @@ -183,6 +180,7 @@ pub enum FingerId {
}

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
#[cfg(wayland_platform)]
return FingerId::Wayland(wayland::FingerId::dummy());
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/linux/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl From<WaylandError> for OsError {
pub struct DeviceId;

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
DeviceId
}
Expand All @@ -75,6 +76,7 @@ impl DeviceId {
pub struct FingerId(i32);

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId(0)
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ impl<'a> Deref for DeviceInfo<'a> {
pub struct DeviceId(xinput::DeviceId);

impl DeviceId {
#[cfg(test)]
#[allow(unused)]
pub const fn dummy() -> Self {
DeviceId(0)
Expand All @@ -821,6 +822,7 @@ impl DeviceId {
pub struct FingerId(u32);

impl FingerId {
#[cfg(test)]
#[allow(unused)]
pub const fn dummy() -> Self {
FingerId(0)
Expand Down
6 changes: 2 additions & 4 deletions src/platform_impl/orbital/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ pub struct WindowId {
}

impl WindowId {
pub const fn dummy() -> Self {
WindowId { fd: u64::MAX }
}

pub const fn into_raw(self) -> u64 {
self.fd
}
Expand All @@ -119,6 +115,7 @@ impl WindowId {
pub struct DeviceId;

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
DeviceId
}
Expand All @@ -128,6 +125,7 @@ impl DeviceId {
pub struct FingerId;

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId
}
Expand Down
14 changes: 10 additions & 4 deletions src/platform_impl/web/event.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(i32);
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub enum DeviceId {
Wheel,
Keyboard,
Id(i32),
}

impl DeviceId {
pub fn new(pointer_id: i32) -> Self {
Self(pointer_id)
Self::Id(pointer_id)
}

#[cfg(test)]
pub const fn dummy() -> Self {
Self(-1)
Self::Id(-1)
}
}

Expand All @@ -22,6 +27,7 @@ impl FingerId {
Self { pointer_id, primary }
}

#[cfg(test)]
pub const fn dummy() -> Self {
Self { pointer_id: -1, primary: false }
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/web/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl Shared {

if let Some(delta) = backend::event::mouse_scroll_delta(&window, &event) {
runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId::dummy()),
device_id: RootDeviceId(DeviceId::Wheel),
event: DeviceEvent::MouseWheel { delta },
});
}
Expand Down Expand Up @@ -381,7 +381,7 @@ impl Shared {
}

runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId::dummy()),
device_id: RootDeviceId(DeviceId::Keyboard),
event: DeviceEvent::Key(RawKeyEvent {
physical_key: backend::event::key_code(&event),
state: ElementState::Pressed,
Expand All @@ -399,7 +399,7 @@ impl Shared {
}

runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId::dummy()),
device_id: RootDeviceId(DeviceId::Keyboard),
event: DeviceEvent::Key(RawKeyEvent {
physical_key: backend::event::key_code(&event),
state: ElementState::Released,
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/web/event_loop/window_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ActiveEventLoop {
}
});

let device_id = RootDeviceId(DeviceId::dummy());
let device_id = RootDeviceId(DeviceId::Keyboard);

runner.send_events(
iter::once(Event::WindowEvent {
Expand Down Expand Up @@ -181,7 +181,7 @@ impl ActiveEventLoop {
}
});

let device_id = RootDeviceId(DeviceId::dummy());
let device_id = RootDeviceId(DeviceId::Keyboard);

runner.send_events(
iter::once(Event::WindowEvent {
Expand Down Expand Up @@ -503,7 +503,7 @@ impl ActiveEventLoop {
Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::MouseWheel {
device_id: RootDeviceId(DeviceId::dummy()),
device_id: RootDeviceId(DeviceId::Keyboard),
delta,
phase: TouchPhase::Moved,
},
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,6 @@ impl Drop for Inner {
pub struct WindowId(pub(crate) u64);

impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}

pub fn into_raw(self) -> u64 {
self.0
}
Expand Down
6 changes: 2 additions & 4 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ unsafe impl Sync for PlatformSpecificWindowAttributes {}
pub struct DeviceId(u32);

impl DeviceId {
#[cfg(test)]
pub const fn dummy() -> Self {
DeviceId(0)
}
Expand All @@ -85,6 +86,7 @@ pub struct FingerId {
}

impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId { id: 0, primary: false }
}
Expand Down Expand Up @@ -117,10 +119,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
}
Expand Down
11 changes: 0 additions & 11 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ impl std::hash::Hash for Window {
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())
}

pub fn into_raw(self) -> u64 {
self.0.into_raw()
}
Expand Down

0 comments on commit c69047e

Please sign in to comment.