feat: Move DeviceId to winit-core

This requires a similar restructuring as with WindowId.

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley
2024-02-04 12:01:40 -08:00
parent a232f7bc77
commit 859a6f109c
25 changed files with 107 additions and 199 deletions

36
winit-core/src/event.rs Normal file
View File

@@ -0,0 +1,36 @@
//! Incoming notifications from the GUI system.
/// Identifier of an input device.
///
/// Whenever you receive an event arising from a particular input device, this event contains a `DeviceId` which
/// identifies its origin. Note that devices may be virtual (representing an on-screen cursor and keyboard focus) or
/// physical. Virtual devices typically aggregate inputs from multiple physical devices.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(u64);
impl DeviceId {
/// Returns a dummy id, useful for unit testing.
///
/// # Safety
///
/// 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`.
///
/// **Passing this into a winit function will result in undefined behavior.**
pub const unsafe fn dummy() -> Self {
DeviceId(0)
}
}
impl From<u64> for DeviceId {
fn from(value: u64) -> Self {
Self(value)
}
}
impl From<DeviceId> for u64 {
fn from(value: DeviceId) -> Self {
value.0
}
}

View File

@@ -12,5 +12,6 @@ compile_error! { "no-std and no-alloc usage are not yet supported" }
pub mod dpi;
pub mod error;
pub mod event;
pub mod keyboard;
pub mod window;