mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
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:
36
winit-core/src/event.rs
Normal file
36
winit-core/src/event.rs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -54,6 +54,9 @@ use crate::{
|
||||
window::{ActivationToken, Theme, WindowId},
|
||||
};
|
||||
|
||||
#[doc(inline)]
|
||||
pub use winit_core::event::DeviceId;
|
||||
|
||||
/// Describes a generic event.
|
||||
///
|
||||
/// See the module-level docs for more information on the event loop manages each event.
|
||||
@@ -599,30 +602,6 @@ pub enum WindowEvent {
|
||||
RedrawRequested,
|
||||
}
|
||||
|
||||
/// 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(pub(crate) platform_impl::DeviceId);
|
||||
|
||||
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 {
|
||||
#[allow(unused_unsafe)]
|
||||
DeviceId(unsafe { platform_impl::DeviceId::dummy() })
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents raw hardware events that are not associated with any particular window.
|
||||
///
|
||||
/// Useful for interactions that diverge significantly from a conventional 2D GUI, such as 3D camera or first-person
|
||||
|
||||
@@ -504,7 +504,7 @@ pub trait DeviceIdExtWindows {
|
||||
impl DeviceIdExtWindows for DeviceId {
|
||||
#[inline]
|
||||
fn persistent_identifier(&self) -> Option<String> {
|
||||
self.0.persistent_identifier()
|
||||
crate::platform_impl::persistent_identifier(*self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -385,7 +385,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
match event {
|
||||
InputEvent::MotionEvent(motion_event) => {
|
||||
let window_id = WindowId::from(WINDOW_ID);
|
||||
let device_id = event::DeviceId(DeviceId(motion_event.device_id()));
|
||||
let device_id = event::DeviceId::from(motion_event.device_id() as u64);
|
||||
|
||||
let phase = match motion_event.action() {
|
||||
MotionAction::Down | MotionAction::PointerDown => {
|
||||
@@ -457,7 +457,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
let event = event::Event::WindowEvent {
|
||||
window_id: WindowId::from(WINDOW_ID),
|
||||
event: event::WindowEvent::KeyboardInput {
|
||||
device_id: event::DeviceId(DeviceId(key.device_id())),
|
||||
device_id: event::DeviceId::from(key.device_id() as u64),
|
||||
event: event::KeyEvent {
|
||||
state,
|
||||
physical_key: keycodes::to_physical_key(keycode),
|
||||
@@ -744,15 +744,6 @@ impl OwnedDisplayHandle {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct DeviceId(i32);
|
||||
|
||||
impl DeviceId {
|
||||
pub const fn dummy() -> Self {
|
||||
DeviceId(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ mod window;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
use crate::event::DeviceId;
|
||||
|
||||
pub(crate) use self::{
|
||||
event_loop::{
|
||||
@@ -83,20 +83,7 @@ pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursorBuilder;
|
||||
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
||||
pub(crate) use crate::platform_impl::Fullscreen;
|
||||
|
||||
/// There is no way to detect which device that performed a certain event in
|
||||
/// UIKit (i.e. you can't differentiate between different external keyboards,
|
||||
/// or wether it was the main touchscreen, assistive technologies, or some
|
||||
/// other pointer device that caused a touch event).
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId;
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
DeviceId
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);
|
||||
pub(crate) const DEVICE_ID: DeviceId = unsafe { DeviceId::dummy() };
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct KeyEventExtra {}
|
||||
|
||||
@@ -142,23 +142,6 @@ pub(crate) enum Window {
|
||||
Wayland(wayland::Window),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum DeviceId {
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::DeviceId),
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::DeviceId),
|
||||
}
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
#[cfg(wayland_platform)]
|
||||
return DeviceId::Wayland(unsafe { wayland::DeviceId::dummy() });
|
||||
#[cfg(all(not(wayland_platform), x11_platform))]
|
||||
return DeviceId::X(unsafe { x11::DeviceId::dummy() });
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum MonitorHandle {
|
||||
#[cfg(x11_platform)]
|
||||
|
||||
@@ -34,7 +34,7 @@ use sink::EventSink;
|
||||
|
||||
use super::state::{WindowCompositorUpdate, WinitState};
|
||||
use super::window::state::FrameCallbackState;
|
||||
use super::{logical_to_physical_rounded, DeviceId, WaylandError, WindowId};
|
||||
use super::{logical_to_physical_rounded, WaylandError, WindowId};
|
||||
|
||||
type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource<WinitState>, WinitState>;
|
||||
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
|
||||
use std::vec::Drain;
|
||||
|
||||
use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent};
|
||||
use crate::platform_impl::platform::DeviceId as PlatformDeviceId;
|
||||
use crate::event::{DeviceEvent, DeviceId, Event, WindowEvent};
|
||||
use crate::window::WindowId;
|
||||
|
||||
use super::DeviceId;
|
||||
|
||||
/// An event loop's sink to deliver events from the Wayland event callbacks
|
||||
/// to the winit's user.
|
||||
#[derive(Default)]
|
||||
@@ -31,7 +28,7 @@ impl EventSink {
|
||||
pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) {
|
||||
self.window_events.push(Event::DeviceEvent {
|
||||
event,
|
||||
device_id: RootDeviceId(PlatformDeviceId::Wayland(device_id)),
|
||||
device_id,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -65,16 +65,6 @@ impl From<WaylandError> for OsError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Dummy device id, since Wayland doesn't have device events.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId;
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
DeviceId
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the WindowId out of the surface.
|
||||
#[inline]
|
||||
fn make_wid(surface: &WlSurface) -> WindowId {
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::platform_impl::common::xkb_state::KbdState;
|
||||
use crate::platform_impl::wayland::event_loop::sink::EventSink;
|
||||
use crate::platform_impl::wayland::seat::WinitSeatState;
|
||||
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 {
|
||||
fn event(
|
||||
@@ -384,7 +384,7 @@ fn key_input(
|
||||
|
||||
let keyboard_state = seat_state.keyboard_state.as_mut().unwrap();
|
||||
|
||||
let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId));
|
||||
let device_id = crate::event::DeviceId::from(0);
|
||||
let event = keyboard_state
|
||||
.xkb_state
|
||||
.process_key_event(keycode, state, repeat);
|
||||
|
||||
@@ -22,12 +22,13 @@ use sctk::globals::GlobalData;
|
||||
use sctk::seat::pointer::{PointerData, PointerDataExt};
|
||||
use sctk::seat::pointer::{PointerEvent, PointerEventKind, PointerHandler};
|
||||
use sctk::seat::SeatState;
|
||||
use winit_core::event::DeviceId;
|
||||
|
||||
use crate::dpi::{LogicalPosition, PhysicalPosition};
|
||||
use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent};
|
||||
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId, WindowId};
|
||||
use crate::platform_impl::wayland::{self, WindowId};
|
||||
|
||||
pub mod relative_pointer;
|
||||
|
||||
@@ -42,7 +43,7 @@ impl PointerHandler for WinitState {
|
||||
let seat = pointer.winit_data().seat();
|
||||
let seat_state = self.seats.get(&seat.id()).unwrap();
|
||||
|
||||
let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId));
|
||||
let device_id = DeviceId::from(0);
|
||||
|
||||
for event in events {
|
||||
let surface = &event.surface;
|
||||
|
||||
@@ -70,7 +70,7 @@ impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerS
|
||||
DeviceEvent::MouseMotion {
|
||||
delta: (dx_unaccel, dy_unaccel),
|
||||
},
|
||||
super::DeviceId,
|
||||
crate::event::DeviceId::from(0),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ use sctk::reexports::client::protocol::wl_touch::WlTouch;
|
||||
use sctk::reexports::client::{Connection, Proxy, QueueHandle};
|
||||
|
||||
use sctk::seat::touch::{TouchData, TouchHandler};
|
||||
use winit_core::event::DeviceId;
|
||||
|
||||
use crate::dpi::LogicalPosition;
|
||||
use crate::event::{Touch, TouchPhase, WindowEvent};
|
||||
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId};
|
||||
use crate::platform_impl::wayland;
|
||||
|
||||
impl TouchHandler for WinitState {
|
||||
fn down(
|
||||
@@ -42,9 +43,7 @@ impl TouchHandler for WinitState {
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
device_id: DeviceId::from(0),
|
||||
phase: TouchPhase::Started,
|
||||
location: location.to_physical(scale_factor),
|
||||
force: None,
|
||||
@@ -79,9 +78,7 @@ impl TouchHandler for WinitState {
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
device_id: DeviceId::from(0),
|
||||
phase: TouchPhase::Ended,
|
||||
location: touch_point.location.to_physical(scale_factor),
|
||||
force: None,
|
||||
@@ -118,9 +115,7 @@ impl TouchHandler for WinitState {
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
device_id: DeviceId::from(0),
|
||||
phase: TouchPhase::Moved,
|
||||
location: touch_point.location.to_physical(scale_factor),
|
||||
force: None,
|
||||
@@ -144,9 +139,7 @@ impl TouchHandler for WinitState {
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
device_id: DeviceId::from(0),
|
||||
phase: TouchPhase::Cancelled,
|
||||
location,
|
||||
force: None,
|
||||
|
||||
@@ -17,13 +17,13 @@ use x11rb::{
|
||||
};
|
||||
|
||||
use super::{
|
||||
atoms::*, ffi, get_xtarget, mkdid, mkwid, util, CookieResultExt, Device, DeviceId, DeviceInfo,
|
||||
atoms::*, ffi, get_xtarget, mkdid, mkwid, util, CookieResultExt, Device, DeviceInfo,
|
||||
Dnd, DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
dpi::{PhysicalPosition, PhysicalSize},
|
||||
event::{DeviceEvent, ElementState, Event, Ime, RawKeyEvent, TouchPhase, WindowEvent},
|
||||
event::{DeviceEvent, ElementState, Event, Ime, RawKeyEvent, TouchPhase, WindowEvent, DeviceId},
|
||||
event_loop::EventLoopWindowTarget as RootELW,
|
||||
keyboard::ModifiersState,
|
||||
platform_impl::platform::common::{keymap, xkb_state::KbdState},
|
||||
@@ -67,7 +67,7 @@ impl EventProcessor {
|
||||
let mut devices = self.devices.borrow_mut();
|
||||
if let Some(info) = DeviceInfo::get(&wt.xconn, device as _) {
|
||||
for info in info.iter() {
|
||||
devices.insert(DeviceId(info.deviceid as _), Device::new(info));
|
||||
devices.insert(mkdid(info.deviceid as _), Device::new(info));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -859,7 +859,7 @@ impl EventProcessor {
|
||||
};
|
||||
let mut devices = self.devices.borrow_mut();
|
||||
let physical_device = match devices
|
||||
.get_mut(&DeviceId(xev.sourceid as xinput::DeviceId))
|
||||
.get_mut(&mkdid(xev.sourceid as xinput::DeviceId))
|
||||
{
|
||||
Some(device) => device,
|
||||
None => return,
|
||||
@@ -933,7 +933,7 @@ impl EventProcessor {
|
||||
// the virtual device.
|
||||
|| device_info.attachment == xev.sourceid
|
||||
{
|
||||
let device_id = DeviceId(device_info.deviceid as _);
|
||||
let device_id = mkdid(device_info.deviceid as _);
|
||||
if let Some(device) = devices.get_mut(&device_id) {
|
||||
device.reset_scroll_position(device_info);
|
||||
}
|
||||
@@ -1015,7 +1015,7 @@ impl EventProcessor {
|
||||
let pointer_id = self
|
||||
.devices
|
||||
.borrow()
|
||||
.get(&DeviceId(xev.deviceid as xinput::DeviceId))
|
||||
.get(&mkdid(xev.deviceid as xinput::DeviceId))
|
||||
.map(|device| device.attachment)
|
||||
.unwrap_or(2);
|
||||
|
||||
@@ -1252,7 +1252,7 @@ impl EventProcessor {
|
||||
event: DeviceEvent::Removed,
|
||||
});
|
||||
let mut devices = self.devices.borrow_mut();
|
||||
devices.remove(&DeviceId(info.deviceid as xinput::DeviceId));
|
||||
devices.remove(&mkdid(info.deviceid as xinput::DeviceId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -812,16 +812,6 @@ impl<'a> Deref for DeviceInfo<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId(xinput::DeviceId);
|
||||
|
||||
impl DeviceId {
|
||||
#[allow(unused)]
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
DeviceId(0)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Window(Arc<UnownedWindow>);
|
||||
|
||||
impl Deref for Window {
|
||||
@@ -1043,7 +1033,7 @@ fn mkwid(w: xproto::Window) -> crate::window::WindowId {
|
||||
WindowId::from(w as u64)
|
||||
}
|
||||
fn mkdid(w: xinput::DeviceId) -> crate::event::DeviceId {
|
||||
crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w)))
|
||||
crate::event::DeviceId::from(w as u64)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -25,7 +25,7 @@ pub(crate) use self::{
|
||||
monitor::{MonitorHandle, VideoModeHandle},
|
||||
window_delegate::PlatformSpecificWindowBuilderAttributes,
|
||||
};
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
use crate::event::DeviceId;
|
||||
|
||||
pub(crate) use self::cursor::CustomCursor as PlatformCustomCursor;
|
||||
pub(crate) use self::window::Window;
|
||||
@@ -33,17 +33,8 @@ pub(crate) use crate::cursor::OnlyCursorImageBuilder as PlatformCustomCursorBuil
|
||||
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
||||
pub(crate) use crate::platform_impl::Fullscreen;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId;
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe 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);
|
||||
pub(crate) const DEVICE_ID: DeviceId = unsafe { DeviceId::dummy() };
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum OsError {
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::{
|
||||
DeviceId, KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes,
|
||||
KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes,
|
||||
RedoxSocket, TimeSocket, WindowProperties,
|
||||
};
|
||||
|
||||
@@ -344,7 +344,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
event_handler(event::Event::WindowEvent {
|
||||
window_id,
|
||||
event: event::WindowEvent::KeyboardInput {
|
||||
device_id: event::DeviceId(DeviceId),
|
||||
device_id: event::DeviceId::from(0),
|
||||
event: event::KeyEvent {
|
||||
logical_key: Key::Unidentified(NativeKey::Unidentified),
|
||||
physical_key,
|
||||
@@ -382,7 +382,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
event_handler(event::Event::WindowEvent {
|
||||
window_id,
|
||||
event: event::WindowEvent::CursorMoved {
|
||||
device_id: event::DeviceId(DeviceId),
|
||||
device_id: event::DeviceId::from(0),
|
||||
position: (x, y).into(),
|
||||
},
|
||||
});
|
||||
@@ -396,7 +396,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
event_handler(event::Event::WindowEvent {
|
||||
window_id,
|
||||
event: event::WindowEvent::MouseInput {
|
||||
device_id: event::DeviceId(DeviceId),
|
||||
device_id: event::DeviceId::from(0),
|
||||
state,
|
||||
button,
|
||||
},
|
||||
@@ -407,7 +407,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
event_handler(event::Event::WindowEvent {
|
||||
window_id,
|
||||
event: event::WindowEvent::MouseWheel {
|
||||
device_id: event::DeviceId(DeviceId),
|
||||
device_id: event::DeviceId::from(0),
|
||||
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
|
||||
phase: event::TouchPhase::Moved,
|
||||
},
|
||||
@@ -446,14 +446,14 @@ impl<T: 'static> EventLoop<T> {
|
||||
event_handler(event::Event::WindowEvent {
|
||||
window_id,
|
||||
event: event::WindowEvent::CursorEntered {
|
||||
device_id: event::DeviceId(DeviceId),
|
||||
device_id: event::DeviceId::from(0),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
event_handler(event::Event::WindowEvent {
|
||||
window_id,
|
||||
event: event::WindowEvent::CursorLeft {
|
||||
device_id: event::DeviceId(DeviceId),
|
||||
device_id: event::DeviceId::from(0),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,15 +95,6 @@ impl TimeSocket {
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct PlatformSpecificEventLoopAttributes {}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct DeviceId;
|
||||
|
||||
impl DeviceId {
|
||||
pub const fn dummy() -> Self {
|
||||
DeviceId
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes;
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId(pub i32);
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use crate::error::EventLoopError;
|
||||
use crate::event::Event;
|
||||
use crate::event_loop::EventLoopWindowTarget as RootEventLoopWindowTarget;
|
||||
|
||||
use super::{backend, device};
|
||||
use super::backend;
|
||||
|
||||
mod proxy;
|
||||
pub(crate) mod runner;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use super::super::main_thread::MainThreadMarker;
|
||||
use super::super::DeviceId;
|
||||
use super::{backend, state::State};
|
||||
use crate::dpi::PhysicalSize;
|
||||
use crate::event::{
|
||||
DeviceEvent, DeviceId as RootDeviceId, ElementState, Event, RawKeyEvent, StartCause,
|
||||
DeviceEvent, DeviceId, ElementState, Event, RawKeyEvent, StartCause,
|
||||
WindowEvent,
|
||||
};
|
||||
use crate::event_loop::{ControlFlow, DeviceEvents};
|
||||
@@ -265,7 +264,7 @@ impl Shared {
|
||||
}
|
||||
|
||||
// chorded button event
|
||||
let device_id = RootDeviceId(DeviceId(event.pointer_id()));
|
||||
let device_id = DeviceId::from(event.pointer_id() as u64);
|
||||
|
||||
if let Some(button) = backend::event::mouse_button(&event) {
|
||||
debug_assert_eq!(
|
||||
@@ -337,7 +336,7 @@ impl Shared {
|
||||
|
||||
if let Some(delta) = backend::event::mouse_scroll_delta(&window, &event) {
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId(0)),
|
||||
device_id: DeviceId::from(0u64),
|
||||
event: DeviceEvent::MouseWheel { delta },
|
||||
});
|
||||
}
|
||||
@@ -358,7 +357,7 @@ impl Shared {
|
||||
|
||||
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId(event.pointer_id())),
|
||||
device_id: DeviceId::from(event.pointer_id() as u64),
|
||||
event: DeviceEvent::Button {
|
||||
button: button.to_id(),
|
||||
state: ElementState::Pressed,
|
||||
@@ -381,7 +380,7 @@ impl Shared {
|
||||
|
||||
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(DeviceId(event.pointer_id())),
|
||||
device_id: DeviceId::from(event.pointer_id() as u64),
|
||||
event: DeviceEvent::Button {
|
||||
button: button.to_id(),
|
||||
state: ElementState::Released,
|
||||
@@ -399,7 +398,7 @@ impl Shared {
|
||||
}
|
||||
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(unsafe { DeviceId::dummy() }),
|
||||
device_id: unsafe { DeviceId::dummy() },
|
||||
event: DeviceEvent::Key(RawKeyEvent {
|
||||
physical_key: backend::event::key_code(&event),
|
||||
state: ElementState::Pressed,
|
||||
@@ -417,7 +416,7 @@ impl Shared {
|
||||
}
|
||||
|
||||
runner.send_event(Event::DeviceEvent {
|
||||
device_id: RootDeviceId(unsafe { DeviceId::dummy() }),
|
||||
device_id: unsafe { DeviceId::dummy() },
|
||||
event: DeviceEvent::Key(RawKeyEvent {
|
||||
physical_key: backend::event::key_code(&event),
|
||||
state: ElementState::Released,
|
||||
|
||||
@@ -10,11 +10,10 @@ use super::runner::{EventWrapper, Execution};
|
||||
use super::{
|
||||
super::{monitor::MonitorHandle, KeyEventExtra},
|
||||
backend,
|
||||
device::DeviceId,
|
||||
runner,
|
||||
};
|
||||
use crate::event::{
|
||||
DeviceId as RootDeviceId, ElementState, Event, KeyEvent, Touch, TouchPhase, WindowEvent,
|
||||
DeviceId, ElementState, Event, KeyEvent, Touch, TouchPhase, WindowEvent,
|
||||
};
|
||||
use crate::event_loop::{ControlFlow, DeviceEvents};
|
||||
use crate::keyboard::ModifiersState;
|
||||
@@ -138,7 +137,7 @@ impl EventLoopWindowTarget {
|
||||
}
|
||||
});
|
||||
|
||||
let device_id = RootDeviceId(unsafe { DeviceId::dummy() });
|
||||
let device_id = unsafe { DeviceId::dummy() };
|
||||
|
||||
runner.send_events(
|
||||
iter::once(Event::WindowEvent {
|
||||
@@ -174,7 +173,7 @@ impl EventLoopWindowTarget {
|
||||
}
|
||||
});
|
||||
|
||||
let device_id = RootDeviceId(unsafe { DeviceId::dummy() });
|
||||
let device_id = unsafe { DeviceId::dummy() };
|
||||
|
||||
runner.send_events(
|
||||
iter::once(Event::WindowEvent {
|
||||
@@ -216,7 +215,7 @@ impl EventLoopWindowTarget {
|
||||
let pointer = pointer_id.map(|pointer_id| Event::WindowEvent {
|
||||
window_id: id,
|
||||
event: WindowEvent::CursorLeft {
|
||||
device_id: RootDeviceId(DeviceId(pointer_id)),
|
||||
device_id: DeviceId::from(pointer_id as u64),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -243,7 +242,7 @@ impl EventLoopWindowTarget {
|
||||
let pointer = pointer_id.map(|pointer_id| Event::WindowEvent {
|
||||
window_id: id,
|
||||
event: WindowEvent::CursorEntered {
|
||||
device_id: RootDeviceId(DeviceId(pointer_id)),
|
||||
device_id: DeviceId::from(pointer_id as u64),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -285,7 +284,7 @@ impl EventLoopWindowTarget {
|
||||
});
|
||||
|
||||
runner.send_events(modifiers.into_iter().chain(events.flat_map(|position| {
|
||||
let device_id = RootDeviceId(DeviceId(pointer_id));
|
||||
let device_id = DeviceId::from(pointer_id as u64);
|
||||
|
||||
iter::once(Event::WindowEvent {
|
||||
window_id: id,
|
||||
@@ -317,7 +316,7 @@ impl EventLoopWindowTarget {
|
||||
window_id: id,
|
||||
event: WindowEvent::Touch(Touch {
|
||||
id: device_id as u64,
|
||||
device_id: RootDeviceId(DeviceId(device_id)),
|
||||
device_id: DeviceId::from(device_id as u64),
|
||||
phase: TouchPhase::Moved,
|
||||
force: Some(force),
|
||||
location,
|
||||
@@ -345,7 +344,7 @@ impl EventLoopWindowTarget {
|
||||
}
|
||||
});
|
||||
|
||||
let device_id = RootDeviceId(DeviceId(pointer_id));
|
||||
let device_id = DeviceId::from(pointer_id as u64);
|
||||
|
||||
let state = if buttons.contains(button.into()) {
|
||||
ElementState::Pressed
|
||||
@@ -405,7 +404,7 @@ impl EventLoopWindowTarget {
|
||||
}
|
||||
});
|
||||
|
||||
let device_id: RootDeviceId = RootDeviceId(DeviceId(pointer_id));
|
||||
let device_id: DeviceId = DeviceId::from(pointer_id as u64);
|
||||
|
||||
// A mouse down event may come in without any prior CursorMoved events,
|
||||
// therefore we should send a CursorMoved event to make sure that the
|
||||
@@ -447,7 +446,7 @@ impl EventLoopWindowTarget {
|
||||
window_id: id,
|
||||
event: WindowEvent::Touch(Touch {
|
||||
id: device_id as u64,
|
||||
device_id: RootDeviceId(DeviceId(device_id)),
|
||||
device_id: DeviceId::from(device_id as u64),
|
||||
phase: TouchPhase::Started,
|
||||
force: Some(force),
|
||||
location,
|
||||
@@ -489,7 +488,7 @@ impl EventLoopWindowTarget {
|
||||
}
|
||||
});
|
||||
|
||||
let device_id: RootDeviceId = RootDeviceId(DeviceId(pointer_id));
|
||||
let device_id: DeviceId = DeviceId::from(pointer_id as u64);
|
||||
|
||||
// A mouse up event may come in without any prior CursorMoved events,
|
||||
// therefore we should send a CursorMoved event to make sure that the
|
||||
@@ -533,7 +532,7 @@ impl EventLoopWindowTarget {
|
||||
window_id: id,
|
||||
event: WindowEvent::Touch(Touch {
|
||||
id: device_id as u64,
|
||||
device_id: RootDeviceId(DeviceId(device_id)),
|
||||
device_id: DeviceId::from(device_id as u64),
|
||||
phase: TouchPhase::Ended,
|
||||
force: Some(force),
|
||||
location,
|
||||
@@ -560,7 +559,7 @@ impl EventLoopWindowTarget {
|
||||
Event::WindowEvent {
|
||||
window_id: id,
|
||||
event: WindowEvent::MouseWheel {
|
||||
device_id: RootDeviceId(DeviceId(pointer_id)),
|
||||
device_id: DeviceId::from(pointer_id as u64),
|
||||
delta,
|
||||
phase: TouchPhase::Moved,
|
||||
},
|
||||
@@ -574,7 +573,7 @@ impl EventLoopWindowTarget {
|
||||
window_id: id,
|
||||
event: WindowEvent::Touch(Touch {
|
||||
id: device_id as u64,
|
||||
device_id: RootDeviceId(DeviceId(device_id)),
|
||||
device_id: DeviceId::from(device_id as u64),
|
||||
phase: TouchPhase::Cancelled,
|
||||
force: Some(force),
|
||||
location,
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
mod r#async;
|
||||
mod cursor;
|
||||
mod device;
|
||||
mod error;
|
||||
mod event_loop;
|
||||
mod keyboard;
|
||||
@@ -30,7 +29,6 @@ mod window;
|
||||
#[path = "web_sys/mod.rs"]
|
||||
mod backend;
|
||||
|
||||
pub use self::device::DeviceId;
|
||||
pub use self::error::OsError;
|
||||
pub(crate) use self::event_loop::{
|
||||
EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle,
|
||||
|
||||
@@ -22,7 +22,7 @@ pub use self::icon::WinIcon as PlatformIcon;
|
||||
pub(crate) use crate::cursor::OnlyCursorImageBuilder as PlatformCustomCursorBuilder;
|
||||
use crate::platform_impl::Fullscreen;
|
||||
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
use crate::event::DeviceId;
|
||||
use crate::icon::Icon;
|
||||
use crate::keyboard::Key;
|
||||
use crate::platform::windows::{BackdropType, Color, CornerPreference};
|
||||
@@ -75,30 +75,20 @@ pub struct Cursor(pub *const u16);
|
||||
unsafe impl Send for Cursor {}
|
||||
unsafe impl Sync for Cursor {}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId(u32);
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
DeviceId(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl DeviceId {
|
||||
pub fn persistent_identifier(&self) -> Option<String> {
|
||||
if self.0 != 0 {
|
||||
raw_input::get_raw_input_device_name(self.0 as HANDLE)
|
||||
pub fn persistent_identifier(id: DeviceId) -> Option<String> {
|
||||
let val: u64 = id.into();
|
||||
if val != 0 {
|
||||
raw_input::get_raw_input_device_name(val as HANDLE)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Constant device ID, to be removed when this backend is updated to report real device IDs.
|
||||
const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId(0));
|
||||
const DEVICE_ID: DeviceId = unsafe { DeviceId::dummy() };
|
||||
|
||||
fn wrap_device_id(id: u32) -> RootDeviceId {
|
||||
RootDeviceId(DeviceId(id))
|
||||
fn wrap_device_id(id: u32) -> DeviceId {
|
||||
(id as u64).into()
|
||||
}
|
||||
|
||||
pub type OsError = std::io::Error;
|
||||
|
||||
Reference in New Issue
Block a user