From a232f7bc77eea30f956fc7aed9d0a48d2949cc55 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sun, 4 Feb 2024 11:16:49 -0800 Subject: [PATCH] feat: Move WindowId to winit-core This commit moves WindowId to winit-core and replaces its inner type with a platform-agnostic `u64`. This required some changes to many of the backend in order to accommodate this new system. Signed-off-by: John Nunley --- winit-core/src/window.rs | 36 + winit/src/platform_impl/android/mod.rs | 41 +- winit/src/platform_impl/ios/app_state.rs | 5 +- winit/src/platform_impl/ios/mod.rs | 2 +- winit/src/platform_impl/ios/view.rs | 25 +- winit/src/platform_impl/ios/window.rs | 43 +- winit/src/platform_impl/linux/mod.rs | 23 +- .../linux/wayland/event_loop/mod.rs | 14 +- .../linux/wayland/event_loop/sink.rs | 10 +- winit/src/platform_impl/linux/wayland/mod.rs | 6 +- .../linux/wayland/seat/text_input/mod.rs | 2 +- .../linux/wayland/types/xdg_activation.rs | 3 +- .../linux/wayland/window/state.rs | 4 +- .../linux/x11/event_processor.rs | 6 +- winit/src/platform_impl/linux/x11/mod.rs | 15 +- winit/src/platform_impl/linux/x11/window.rs | 11 +- winit/src/platform_impl/macos/app_delegate.rs | 17 +- winit/src/platform_impl/macos/mod.rs | 1 - winit/src/platform_impl/macos/window.rs | 25 +- .../platform_impl/macos/window_delegate.rs | 4 +- winit/src/platform_impl/orbital/event_loop.rs | 48 +- winit/src/platform_impl/orbital/mod.rs | 25 - winit/src/platform_impl/orbital/window.rs | 10 +- winit/src/platform_impl/web/event_loop/mod.rs | 2 +- .../web/event_loop/window_target.rs | 87 +- winit/src/platform_impl/web/keyboard.rs | 1020 ++++++++--------- winit/src/platform_impl/web/mod.rs | 2 +- winit/src/platform_impl/web/web_sys/canvas.rs | 7 +- winit/src/platform_impl/web/web_sys/event.rs | 6 +- winit/src/platform_impl/web/window.rs | 28 +- .../src/platform_impl/windows/drop_handler.rs | 13 +- winit/src/platform_impl/windows/event_loop.rs | 76 +- .../windows/event_loop/runner.rs | 2 +- winit/src/platform_impl/windows/mod.rs | 29 - winit/src/platform_impl/windows/window.rs | 6 +- winit/src/window.rs | 39 +- 36 files changed, 744 insertions(+), 949 deletions(-) diff --git a/winit-core/src/window.rs b/winit-core/src/window.rs index e1a334b83..1a26b883f 100644 --- a/winit-core/src/window.rs +++ b/winit-core/src/window.rs @@ -3,6 +3,42 @@ #[doc(inline)] pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError}; +/// Identifier of a window. Unique for each window. +/// +/// Can be obtained with [`window.id()`](`Window::id`). +/// +/// Whenever you receive an event specific to a window, this event contains a `WindowId` which you +/// can then compare to the ids of your windows. +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct WindowId(u64); + +impl WindowId { + /// 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 [`WindowId`]. + /// + /// **Passing this into a winit function will result in undefined behavior.** + pub const unsafe fn dummy() -> Self { + WindowId(0) + } +} + +impl From for u64 { + fn from(window_id: WindowId) -> Self { + window_id.0 + } +} + +impl From for WindowId { + fn from(raw_id: u64) -> Self { + Self(raw_id) + } +} + /// The behavior of cursor grabbing. /// /// Use this enum with [`Window::set_cursor_grab`] to grab the cursor. diff --git a/winit/src/platform_impl/android/mod.rs b/winit/src/platform_impl/android/mod.rs index ad5643855..1ff195328 100644 --- a/winit/src/platform_impl/android/mod.rs +++ b/winit/src/platform_impl/android/mod.rs @@ -27,7 +27,8 @@ use crate::{ event_loop::{self, ControlFlow, DeviceEvents, EventLoopWindowTarget as RootELW}, platform::pump_events::PumpStatus, window::{ - self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel, + self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowId, + WindowLevel, }, }; use crate::{error::EventLoopError, platform_impl::Fullscreen}; @@ -35,6 +36,7 @@ use crate::{error::EventLoopError, platform_impl::Fullscreen}; mod keycodes; static HAS_FOCUS: Lazy> = Lazy::new(|| RwLock::new(true)); +const WINDOW_ID: u64 = 0; /// Returns the minimum `Option`, taking into account that `None` /// equates to an infinite timeout, not a zero timeout (so can't just use @@ -234,7 +236,7 @@ impl EventLoop { *HAS_FOCUS.write().unwrap() = true; callback( event::Event::WindowEvent { - window_id: window::WindowId(WindowId), + window_id: WindowId::from(WINDOW_ID), event: event::WindowEvent::Focused(true), }, self.window_target(), @@ -244,7 +246,7 @@ impl EventLoop { *HAS_FOCUS.write().unwrap() = false; callback( event::Event::WindowEvent { - window_id: window::WindowId(WindowId), + window_id: WindowId::from(WINDOW_ID), event: event::WindowEvent::Focused(false), }, self.window_target(), @@ -259,7 +261,7 @@ impl EventLoop { MonitorHandle::new(self.android_app.clone()).size(), )); let event = event::Event::WindowEvent { - window_id: window::WindowId(WindowId), + window_id: WindowId::from(WINDOW_ID), event: event::WindowEvent::ScaleFactorChanged { inner_size_writer: InnerSizeWriter::new(Arc::downgrade( &new_inner_size, @@ -347,7 +349,7 @@ impl EventLoop { PhysicalSize::new(0, 0) }; let event = event::Event::WindowEvent { - window_id: window::WindowId(WindowId), + window_id: WindowId::from(WINDOW_ID), event: event::WindowEvent::Resized(size), }; callback(event, self.window_target()); @@ -357,7 +359,7 @@ impl EventLoop { if pending_redraw { pending_redraw = false; let event = event::Event::WindowEvent { - window_id: window::WindowId(WindowId), + window_id: WindowId::from(WINDOW_ID), event: event::WindowEvent::RedrawRequested, }; callback(event, self.window_target()); @@ -382,7 +384,7 @@ impl EventLoop { let mut input_status = InputStatus::Handled; match event { InputEvent::MotionEvent(motion_event) => { - let window_id = window::WindowId(WindowId); + let window_id = WindowId::from(WINDOW_ID); let device_id = event::DeviceId(DeviceId(motion_event.device_id())); let phase = match motion_event.action() { @@ -453,7 +455,7 @@ impl EventLoop { ); let event = event::Event::WindowEvent { - window_id: window::WindowId(WindowId), + window_id: WindowId::from(WINDOW_ID), event: event::WindowEvent::KeyboardInput { device_id: event::DeviceId(DeviceId(key.device_id())), event: event::KeyEvent { @@ -742,27 +744,6 @@ impl OwnedDisplayHandle { } } -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub(crate) struct WindowId; - -impl WindowId { - pub const fn dummy() -> Self { - WindowId - } -} - -impl From for u64 { - fn from(_: WindowId) -> Self { - 0 - } -} - -impl From for WindowId { - fn from(_: u64) -> Self { - Self - } -} - #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DeviceId(i32); @@ -802,7 +783,7 @@ impl Window { } pub fn id(&self) -> WindowId { - WindowId + WindowId::from(WINDOW_ID) } pub fn primary_monitor(&self) -> Option { diff --git a/winit/src/platform_impl/ios/app_state.rs b/winit/src/platform_impl/ios/app_state.rs index eac89365f..26bbf85d5 100644 --- a/winit/src/platform_impl/ios/app_state.rs +++ b/winit/src/platform_impl/ios/app_state.rs @@ -30,7 +30,6 @@ use crate::{ dpi::PhysicalSize, event::{Event, InnerSizeWriter, StartCause, WindowEvent}, event_loop::{ControlFlow, EventLoopWindowTarget as RootEventLoopWindowTarget}, - window::WindowId as RootWindowId, }; macro_rules! bug { @@ -768,7 +767,7 @@ pub fn handle_main_events_cleared(mtm: MainThreadMarker) { .into_iter() .map(|window| { EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::RedrawRequested, }) }) @@ -799,7 +798,7 @@ fn handle_hidpi_proxy(handler: &mut EventLoopHandler, event: ScaleFactorChanged) } = event; let new_inner_size = Arc::new(Mutex::new(suggested_size)); let event = Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::ScaleFactorChanged { scale_factor, inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), diff --git a/winit/src/platform_impl/ios/mod.rs b/winit/src/platform_impl/ios/mod.rs index 7f8c23fc2..854df7c49 100644 --- a/winit/src/platform_impl/ios/mod.rs +++ b/winit/src/platform_impl/ios/mod.rs @@ -76,7 +76,7 @@ pub(crate) use self::{ PlatformSpecificEventLoopAttributes, }, monitor::{MonitorHandle, VideoModeHandle}, - window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}, + window::{PlatformSpecificWindowBuilderAttributes, Window}, }; pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursor; pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursorBuilder; diff --git a/winit/src/platform_impl/ios/view.rs b/winit/src/platform_impl/ios/view.rs index 0f6a67779..d6a266e1b 100644 --- a/winit/src/platform_impl/ios/view.rs +++ b/winit/src/platform_impl/ios/view.rs @@ -15,7 +15,6 @@ use super::uikit::{ UIStatusBarStyle, UITapGestureRecognizer, UITouch, UITouchPhase, UITouchType, UITraitCollection, UIView, UIViewController, UIWindow, }; -use super::window::WindowId; use crate::{ dpi::PhysicalPosition, event::{Event, Force, Touch, TouchPhase, WindowEvent}, @@ -24,7 +23,7 @@ use crate::{ ffi::{UIRectEdge, UIUserInterfaceIdiom}, Fullscreen, DEVICE_ID, }, - window::{WindowAttributes, WindowId as RootWindowId}, + window::{WindowAttributes, WindowId}, }; pub struct WinitViewState { @@ -55,7 +54,7 @@ declare_class!( app_state::handle_nonuser_event( mtm, EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::RedrawRequested, }), ); @@ -90,7 +89,7 @@ declare_class!( app_state::handle_nonuser_event( mtm, EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::Resized(size), }), ); @@ -129,7 +128,7 @@ declare_class!( width: screen_frame.size.width as f64, height: screen_frame.size.height as f64, }; - let window_id = RootWindowId(window.id()); + let window_id = window.id(); app_state::handle_nonuser_events( mtm, std::iter::once(EventWrapper::ScaleFactorChanged( @@ -183,7 +182,7 @@ declare_class!( }; let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::PinchGesture { device_id: DEVICE_ID, delta: recognizer.velocity() as _, @@ -201,7 +200,7 @@ declare_class!( if recognizer.state() == UIGestureRecognizerState::Ended { let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::DoubleTapGesture { device_id: DEVICE_ID, }, @@ -229,7 +228,7 @@ declare_class!( // Flip the velocity to match macOS. let delta = -recognizer.velocity() as _; let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::RotationGesture { device_id: DEVICE_ID, delta, @@ -380,7 +379,7 @@ impl WinitView { ) }; touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::Touch(Touch { device_id: DEVICE_ID, id: touch_id, @@ -583,7 +582,7 @@ declare_class!( app_state::handle_nonuser_event( mtm, EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(self.id()), + window_id: self.id(), event: WindowEvent::Focused(true), }), ); @@ -596,7 +595,7 @@ declare_class!( app_state::handle_nonuser_event( mtm, EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(self.id()), + window_id: self.id(), event: WindowEvent::Focused(false), }), ); @@ -691,7 +690,7 @@ declare_class!( &*ptr }; events.push(EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::Destroyed, })); } @@ -721,7 +720,7 @@ impl WinitApplicationDelegate { &*ptr }; events.push(EventWrapper::StaticEvent(Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::Occluded(occluded), })); } diff --git a/winit/src/platform_impl/ios/window.rs b/winit/src/platform_impl/ios/window.rs index 5b22bd826..9f8948cb4 100644 --- a/winit/src/platform_impl/ios/window.rs +++ b/winit/src/platform_impl/ios/window.rs @@ -5,7 +5,6 @@ use std::collections::VecDeque; use icrate::Foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker}; use log::{debug, warn}; use objc2::rc::Id; -use objc2::runtime::AnyObject; use objc2::{class, msg_send}; use super::app_state::EventWrapper; @@ -23,7 +22,7 @@ use crate::{ }, window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, - WindowButtons, WindowId as RootWindowId, WindowLevel, + WindowButtons, WindowId, WindowLevel, }, }; @@ -465,7 +464,7 @@ impl Window { width: screen_frame.size.width as f64, height: screen_frame.size.height as f64, }; - let window_id = RootWindowId(window.id()); + let window_id = window.id(); app_state::handle_nonuser_events( mtm, std::iter::once(EventWrapper::ScaleFactorChanged( @@ -639,44 +638,6 @@ impl Inner { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId { - window: *mut WinitUIWindow, -} - -impl WindowId { - pub const unsafe fn dummy() -> Self { - WindowId { - window: std::ptr::null_mut(), - } - } -} - -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.window as u64 - } -} - -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self { - window: raw_id as _, - } - } -} - -unsafe impl Send for WindowId {} -unsafe impl Sync for WindowId {} - -impl From<&AnyObject> for WindowId { - fn from(window: &AnyObject) -> WindowId { - WindowId { - window: window as *const _ as _, - } - } -} - #[derive(Clone, Debug, Default)] pub struct PlatformSpecificWindowBuilderAttributes { pub scale_factor: Option, diff --git a/winit/src/platform_impl/linux/mod.rs b/winit/src/platform_impl/linux/mod.rs index c99c1c276..4a3eff6ac 100644 --- a/winit/src/platform_impl/linux/mod.rs +++ b/winit/src/platform_impl/linux/mod.rs @@ -142,27 +142,6 @@ pub(crate) enum Window { Wayland(wayland::Window), } -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(u64); - -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 - } -} - -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id) - } -} - -impl WindowId { - pub const unsafe fn dummy() -> Self { - Self(0) - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum DeviceId { #[cfg(x11_platform)] @@ -310,7 +289,7 @@ impl Window { } #[inline] - pub fn id(&self) -> WindowId { + pub fn id(&self) -> crate::window::WindowId { x11_or_wayland!(match self; Window(w) => w.id()) } diff --git a/winit/src/platform_impl/linux/wayland/event_loop/mod.rs b/winit/src/platform_impl/linux/wayland/event_loop/mod.rs index bbf61a269..69833e63f 100644 --- a/winit/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/winit/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -366,7 +366,7 @@ impl EventLoop { let new_inner_size = Arc::new(Mutex::new(physical_size)); callback( Event::WindowEvent { - window_id: crate::window::WindowId(window_id), + window_id, event: WindowEvent::ScaleFactorChanged { scale_factor, inner_size_writer: InnerSizeWriter::new(Arc::downgrade( @@ -420,7 +420,7 @@ impl EventLoop { callback( Event::WindowEvent { - window_id: crate::window::WindowId(window_id), + window_id, event: WindowEvent::Resized(physical_size), }, &self.window_target, @@ -430,7 +430,7 @@ impl EventLoop { if compositor_update.close_window { callback( Event::WindowEvent { - window_id: crate::window::WindowId(window_id), + window_id, event: WindowEvent::CloseRequested, }, &self.window_target, @@ -496,13 +496,7 @@ impl EventLoop { }); if let Some(event) = event { - callback( - Event::WindowEvent { - window_id: crate::window::WindowId(window_id), - event, - }, - &self.window_target, - ); + callback(Event::WindowEvent { window_id, event }, &self.window_target); } } diff --git a/winit/src/platform_impl/linux/wayland/event_loop/sink.rs b/winit/src/platform_impl/linux/wayland/event_loop/sink.rs index 13daeee35..b6b4db249 100644 --- a/winit/src/platform_impl/linux/wayland/event_loop/sink.rs +++ b/winit/src/platform_impl/linux/wayland/event_loop/sink.rs @@ -4,9 +4,9 @@ use std::vec::Drain; use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent}; use crate::platform_impl::platform::DeviceId as PlatformDeviceId; -use crate::window::WindowId as RootWindowId; +use crate::window::WindowId; -use super::{DeviceId, WindowId}; +use super::DeviceId; /// An event loop's sink to deliver events from the Wayland event callbacks /// to the winit's user. @@ -38,10 +38,8 @@ impl EventSink { /// Add new window event to a queue. #[inline] pub fn push_window_event(&mut self, event: WindowEvent, window_id: WindowId) { - self.window_events.push(Event::WindowEvent { - event, - window_id: RootWindowId(window_id), - }); + self.window_events + .push(Event::WindowEvent { event, window_id }); } #[inline] diff --git a/winit/src/platform_impl/linux/wayland/mod.rs b/winit/src/platform_impl/linux/wayland/mod.rs index 2c0d6b5d3..ebf3b108e 100644 --- a/winit/src/platform_impl/linux/wayland/mod.rs +++ b/winit/src/platform_impl/linux/wayland/mod.rs @@ -11,11 +11,13 @@ use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy}; pub(super) use crate::cursor::OnlyCursorImage as CustomCursor; use crate::dpi::{LogicalSize, PhysicalSize}; -pub use crate::platform_impl::platform::{OsError, WindowId}; +pub use crate::platform_impl::platform::OsError; pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget}; pub use output::{MonitorHandle, VideoModeHandle}; pub use window::Window; +use crate::window::WindowId; + mod event_loop; mod output; mod seat; @@ -76,7 +78,7 @@ impl DeviceId { /// Get the WindowId out of the surface. #[inline] fn make_wid(surface: &WlSurface) -> WindowId { - WindowId(surface.id().as_ptr() as u64) + WindowId::from(surface.id().as_ptr() as u64) } /// The default routine does floor, but we need round on Wayland. diff --git a/winit/src/platform_impl/linux/wayland/seat/text_input/mod.rs b/winit/src/platform_impl/linux/wayland/seat/text_input/mod.rs index a74733335..c3b355323 100644 --- a/winit/src/platform_impl/linux/wayland/seat/text_input/mod.rs +++ b/winit/src/platform_impl/linux/wayland/seat/text_input/mod.rs @@ -178,7 +178,7 @@ impl ZwpTextInputV3Ext for ZwpTextInputV3 { ImePurpose::Normal => (ContentHint::None, ContentPurpose::Normal), ImePurpose::Password => (ContentHint::SensitiveData, ContentPurpose::Password), ImePurpose::Terminal => (ContentHint::None, ContentPurpose::Terminal), - _ => unreachable!() + _ => unreachable!(), }; self.set_content_type(hint, purpose); } diff --git a/winit/src/platform_impl/linux/wayland/types/xdg_activation.rs b/winit/src/platform_impl/linux/wayland/types/xdg_activation.rs index be546d15b..852df84b8 100644 --- a/winit/src/platform_impl/linux/wayland/types/xdg_activation.rs +++ b/winit/src/platform_impl/linux/wayland/types/xdg_activation.rs @@ -18,8 +18,7 @@ use sctk::globals::GlobalData; use crate::event_loop::AsyncRequestSerial; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::WindowId; -use crate::window::ActivationToken; +use crate::window::{ActivationToken, WindowId}; pub struct XdgActivationState { xdg_activation: XdgActivationV1, diff --git a/winit/src/platform_impl/linux/wayland/window/state.rs b/winit/src/platform_impl/linux/wayland/window/state.rs index 3f8aa7724..05f9f922d 100644 --- a/winit/src/platform_impl/linux/wayland/window/state.rs +++ b/winit/src/platform_impl/linux/wayland/window/state.rs @@ -36,8 +36,8 @@ use crate::error::{ExternalError, NotSupportedError}; use crate::platform_impl::wayland::logical_to_physical_rounded; use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor}; use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; -use crate::platform_impl::{PlatformCustomCursor, WindowId}; -use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme}; +use crate::platform_impl::PlatformCustomCursor; +use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, WindowId}; use crate::platform_impl::wayland::seat::{ PointerConstraintsState, WinitPointerData, WinitPointerDataExt, ZwpTextInputV3Ext, diff --git a/winit/src/platform_impl/linux/x11/event_processor.rs b/winit/src/platform_impl/linux/x11/event_processor.rs index 67dc65907..e6304cbd4 100644 --- a/winit/src/platform_impl/linux/x11/event_processor.rs +++ b/winit/src/platform_impl/linux/x11/event_processor.rs @@ -18,7 +18,7 @@ use x11rb::{ use super::{ atoms::*, ffi, get_xtarget, mkdid, mkwid, util, CookieResultExt, Device, DeviceId, DeviceInfo, - Dnd, DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow, WindowId, + Dnd, DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow, }; use crate::{ @@ -77,7 +77,7 @@ impl EventProcessor { F: Fn(&Arc) -> Ret, { let mut deleted = false; - let window_id = WindowId(window_id as _); + let window_id = mkwid(window_id); let wt = get_xtarget(&self.target); let result = wt .windows @@ -568,7 +568,7 @@ impl EventProcessor { // In the event that the window's been destroyed without being dropped first, we // cleanup again here. - wt.windows.borrow_mut().remove(&WindowId(window as _)); + wt.windows.borrow_mut().remove(&mkwid(window)); // Since all XIM stuff needs to happen from the same thread, we destroy the input // context here instead of when dropping the window. diff --git a/winit/src/platform_impl/linux/x11/mod.rs b/winit/src/platform_impl/linux/x11/mod.rs index 9a0ac9bd4..0dabaf217 100644 --- a/winit/src/platform_impl/linux/x11/mod.rs +++ b/winit/src/platform_impl/linux/x11/mod.rs @@ -73,8 +73,8 @@ use crate::{ event::{Event, StartCause, WindowEvent}, event_loop::{DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW}, platform::pump_events::PumpStatus, - platform_impl::platform::{min_timeout, WindowId}, - window::WindowAttributes, + platform_impl::platform::min_timeout, + window::{WindowAttributes, WindowId}, }; // Xinput constants not defined in x11rb @@ -559,14 +559,14 @@ impl EventLoop { while let Ok((window_id, serial)) = self.activation_receiver.try_recv() { let token = self .event_processor - .with_window(window_id.0 as xproto::Window, |window| { + .with_window(u64::from(window_id) as xproto::Window, |window| { window.generate_activation_token() }); match token { Some(Ok(token)) => callback( crate::event::Event::WindowEvent { - window_id: crate::window::WindowId(window_id), + window_id, event: crate::event::WindowEvent::ActivationTokenDone { serial, token: crate::window::ActivationToken::_new(token), @@ -597,7 +597,6 @@ impl EventLoop { } for window_id in windows { - let window_id = crate::window::WindowId(window_id); callback( Event::WindowEvent { window_id, @@ -626,7 +625,7 @@ impl EventLoop { let mut xev = unsafe { xev.assume_init() }; self.event_processor.process_event(&mut xev, |event| { if let Event::WindowEvent { - window_id: crate::window::WindowId(wid), + window_id: wid, event: WindowEvent::RedrawRequested, } = event { @@ -854,7 +853,7 @@ impl Drop for Window { if let Ok(c) = xconn .xcb_connection() - .destroy_window(window.id().0 as xproto::Window) + .destroy_window(u64::from(window.id()) as xproto::Window) { c.ignore_error(); } @@ -1041,7 +1040,7 @@ impl<'a> Drop for GenericEventCookie<'a> { } fn mkwid(w: xproto::Window) -> crate::window::WindowId { - crate::window::WindowId(crate::platform_impl::platform::WindowId(w as _)) + WindowId::from(w as u64) } fn mkdid(w: xinput::DeviceId) -> crate::event::DeviceId { crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w))) diff --git a/winit/src/platform_impl/linux/x11/window.rs b/winit/src/platform_impl/linux/x11/window.rs index ba417e391..c0d0ae340 100644 --- a/winit/src/platform_impl/linux/x11/window.rs +++ b/winit/src/platform_impl/linux/x11/window.rs @@ -37,15 +37,14 @@ use crate::{ }, window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, - WindowButtons, WindowLevel, + WindowButtons, WindowId, WindowLevel, }, }; use super::{ ffi, util::{self, SelectedCursor}, - CookieResultExt, EventLoopWindowTarget, ImeRequest, ImeSender, VoidCookie, WindowId, - XConnection, + CookieResultExt, EventLoopWindowTarget, ImeRequest, ImeSender, VoidCookie, XConnection, }; #[derive(Debug)] @@ -965,7 +964,7 @@ impl UnownedWindow { &self.shared_state_lock(), ); - let window_id = crate::window::WindowId(self.id()); + let window_id = self.id(); let old_inner_size = PhysicalSize::new(width, height); let inner_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height))); callback(Event::WindowEvent { @@ -1911,13 +1910,13 @@ impl UnownedWindow { #[inline] pub fn id(&self) -> WindowId { - WindowId(self.xwindow as _) + WindowId::from(self.xwindow as u64) } #[inline] pub fn request_redraw(&self) { self.redraw_sender - .send(WindowId(self.xwindow as _)) + .send(WindowId::from(self.xwindow as u64)) .unwrap(); } diff --git a/winit/src/platform_impl/macos/app_delegate.rs b/winit/src/platform_impl/macos/app_delegate.rs index ee3ac878d..537d725bf 100644 --- a/winit/src/platform_impl/macos/app_delegate.rs +++ b/winit/src/platform_impl/macos/app_delegate.rs @@ -14,11 +14,11 @@ use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass}; use super::event_loop::{stop_app_immediately, PanicInfo}; use super::observer::{EventLoopWaker, RunLoop}; use super::window::WinitWindow; -use super::{menu, WindowId, DEVICE_ID}; +use super::{menu, DEVICE_ID}; use crate::dpi::PhysicalSize; use crate::event::{DeviceEvent, Event, InnerSizeWriter, StartCause, WindowEvent}; use crate::event_loop::{ControlFlow, EventLoopWindowTarget as RootWindowTarget}; -use crate::window::WindowId as RootWindowId; +use crate::window::WindowId; #[derive(Debug, Default)] pub(super) struct State { @@ -288,7 +288,7 @@ impl ApplicationDelegate { // -> Don't go back into the callback when our callstack originates from there if !self.ivars().in_callback.get() { self.handle_event(Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: WindowEvent::RedrawRequested, }); self.ivars().in_callback.set(false); @@ -399,10 +399,7 @@ impl ApplicationDelegate { for event in events { match event { QueuedEvent::WindowEvent(window_id, event) => { - self.handle_event(Event::WindowEvent { - window_id: RootWindowId(window_id), - event, - }); + self.handle_event(Event::WindowEvent { window_id, event }); } QueuedEvent::DeviceEvent(event) => { self.handle_event(Event::DeviceEvent { @@ -418,7 +415,7 @@ impl ApplicationDelegate { if let Some(ref mut callback) = *self.ivars().callback.borrow_mut() { let new_inner_size = Arc::new(Mutex::new(suggested_size)); let scale_factor_changed_event = Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::ScaleFactorChanged { scale_factor, inner_size_writer: InnerSizeWriter::new(Arc::downgrade( @@ -436,7 +433,7 @@ impl ApplicationDelegate { window.setContentSize(size); let resized_event = Event::WindowEvent { - window_id: RootWindowId(window.id()), + window_id: window.id(), event: WindowEvent::Resized(physical_size), }; callback.handle_event(resized_event); @@ -448,7 +445,7 @@ impl ApplicationDelegate { let redraw = mem::take(&mut *self.ivars().pending_redraw.borrow_mut()); for window_id in redraw { self.handle_event(Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: WindowEvent::RedrawRequested, }); } diff --git a/winit/src/platform_impl/macos/mod.rs b/winit/src/platform_impl/macos/mod.rs index 395050746..2d3e625bb 100644 --- a/winit/src/platform_impl/macos/mod.rs +++ b/winit/src/platform_impl/macos/mod.rs @@ -23,7 +23,6 @@ pub(crate) use self::{ PlatformSpecificEventLoopAttributes, }, monitor::{MonitorHandle, VideoModeHandle}, - window::WindowId, window_delegate::PlatformSpecificWindowBuilderAttributes, }; use crate::event::DeviceId as RootDeviceId; diff --git a/winit/src/platform_impl/macos/window.rs b/winit/src/platform_impl/macos/window.rs index c269fd724..5e10e23d3 100644 --- a/winit/src/platform_impl/macos/window.rs +++ b/winit/src/platform_impl/macos/window.rs @@ -8,7 +8,7 @@ use objc2::{declare_class, mutability, ClassType, DeclaredClass}; use super::event_loop::EventLoopWindowTarget; use super::window_delegate::WindowDelegate; use crate::error::OsError as RootOsError; -use crate::window::WindowAttributes; +use crate::window::{WindowAttributes, WindowId}; pub(crate) struct Window { window: MainThreadBound>, @@ -71,27 +71,6 @@ impl Window { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(pub usize); - -impl WindowId { - pub const unsafe fn dummy() -> Self { - Self(0) - } -} - -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 as u64 - } -} - -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id as usize) - } -} - declare_class!( #[derive(Debug)] pub struct WinitWindow; @@ -122,6 +101,6 @@ declare_class!( impl WinitWindow { pub(super) fn id(&self) -> WindowId { - WindowId(self as *const Self as usize) + WindowId::from(self as *const Self as u64) } } diff --git a/winit/src/platform_impl/macos/window_delegate.rs b/winit/src/platform_impl/macos/window_delegate.rs index 118e6da8b..26dc08ffd 100644 --- a/winit/src/platform_impl/macos/window_delegate.rs +++ b/winit/src/platform_impl/macos/window_delegate.rs @@ -33,14 +33,14 @@ use super::cursor::cursor_from_icon; use super::monitor::{self, flip_window_screen_coordinates, get_display_id}; use super::view::WinitView; use super::window::WinitWindow; -use super::{ffi, Fullscreen, MonitorHandle, OsError, WindowId}; +use super::{ffi, Fullscreen, MonitorHandle, OsError}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::event::WindowEvent; use crate::platform::macos::{OptionAsAlt, WindowExtMacOS}; use crate::window::{ Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType, - WindowAttributes, WindowButtons, WindowLevel, + WindowAttributes, WindowButtons, WindowId, WindowLevel, }; #[derive(Clone, Debug)] diff --git a/winit/src/platform_impl/orbital/event_loop.rs b/winit/src/platform_impl/orbital/event_loop.rs index aa7acb2a6..97ecf09a9 100644 --- a/winit/src/platform_impl/orbital/event_loop.rs +++ b/winit/src/platform_impl/orbital/event_loop.rs @@ -21,12 +21,12 @@ use crate::{ Key, KeyCode, KeyLocation, ModifiersKeys, ModifiersState, NativeKey, NativeKeyCode, PhysicalKey, }, - window::WindowId as RootWindowId, + window::WindowId, }; use super::{ DeviceId, KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes, - RedoxSocket, TimeSocket, WindowId, WindowProperties, + RedoxSocket, TimeSocket, WindowProperties, }; fn convert_scancode(scancode: u8) -> PhysicalKey { @@ -342,7 +342,7 @@ impl EventLoop { let modifiers_before = event_state.keyboard; event_state.key(physical_key, pressed); event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::KeyboardInput { device_id: event::DeviceId(DeviceId), event: event::KeyEvent { @@ -362,7 +362,7 @@ impl EventLoop { // If the state of the modifiers has changed, send the event. if modifiers_before != event_state.keyboard { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::ModifiersChanged(event_state.modifiers()), }) } @@ -370,17 +370,17 @@ impl EventLoop { } EventOption::TextInput(TextInputEvent { character }) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Ime(Ime::Preedit("".into(), None)), }); event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Ime(Ime::Commit(character.into())), }); } EventOption::Mouse(MouseEvent { x, y }) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::CursorMoved { device_id: event::DeviceId(DeviceId), position: (x, y).into(), @@ -394,7 +394,7 @@ impl EventLoop { }) => { while let Some((button, state)) = event_state.mouse(left, middle, right) { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::MouseInput { device_id: event::DeviceId(DeviceId), state, @@ -405,7 +405,7 @@ impl EventLoop { } EventOption::Scroll(ScrollEvent { x, y }) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::MouseWheel { device_id: event::DeviceId(DeviceId), delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), @@ -415,25 +415,25 @@ impl EventLoop { } EventOption::Quit(QuitEvent {}) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::CloseRequested, }); } EventOption::Focus(FocusEvent { focused }) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Focused(focused), }); } EventOption::Move(MoveEvent { x, y }) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Moved((x, y).into()), }); } EventOption::Resize(ResizeEvent { width, height }) => { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Resized((width, height).into()), }); @@ -444,14 +444,14 @@ impl EventLoop { EventOption::Hover(HoverEvent { entered }) => { if entered { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::CursorEntered { device_id: event::DeviceId(DeviceId), }, }); } else { event_handler(event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::CursorLeft { device_id: event::DeviceId(DeviceId), }, @@ -487,9 +487,7 @@ impl EventLoop { let mut creates = self.window_target.p.creates.lock().unwrap(); creates.pop_front() } { - let window_id = WindowId { - fd: window.fd as u64, - }; + let window_id = WindowId::from(window.fd as u64); let mut buf: [u8; 4096] = [0; 4096]; let path = window.fpath(&mut buf).expect("failed to read properties"); @@ -500,7 +498,7 @@ impl EventLoop { // Send resize event on create to indicate first size. event_handler( event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Resized((properties.w, properties.h).into()), }, &self.window_target, @@ -509,7 +507,7 @@ impl EventLoop { // Send resize event on create to indicate first position. event_handler( event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::Moved((properties.x, properties.y).into()), }, &self.window_target, @@ -523,23 +521,21 @@ impl EventLoop { } { event_handler( event::Event::WindowEvent { - window_id: RootWindowId(destroy_id), + window_id: destroy_id, event: event::WindowEvent::Destroyed, }, &self.window_target, ); self.windows - .retain(|(window, _event_state)| window.fd as u64 != destroy_id.fd); + .retain(|(window, _event_state)| window.fd as u64 != u64::from(destroy_id)); } // Handle window events. let mut i = 0; // While loop is used here because the same window may be processed more than once. while let Some((window, event_state)) = self.windows.get_mut(i) { - let window_id = WindowId { - fd: window.fd as u64, - }; + let window_id = WindowId::from(window.fd as u64); let mut event_buf = [0u8; 16 * mem::size_of::()]; let count = @@ -594,7 +590,7 @@ impl EventLoop { } { event_handler( event::Event::WindowEvent { - window_id: RootWindowId(window_id), + window_id, event: event::WindowEvent::RedrawRequested, }, &self.window_target, diff --git a/winit/src/platform_impl/orbital/mod.rs b/winit/src/platform_impl/orbital/mod.rs index 4d5449987..0f7a97198 100644 --- a/winit/src/platform_impl/orbital/mod.rs +++ b/winit/src/platform_impl/orbital/mod.rs @@ -95,31 +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 WindowId { - fd: u64, -} - -impl WindowId { - pub const fn dummy() -> Self { - WindowId { - fd: u64::max_value(), - } - } -} - -impl From for u64 { - fn from(id: WindowId) -> Self { - id.fd - } -} - -impl From for WindowId { - fn from(fd: u64) -> Self { - Self { fd } - } -} - #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DeviceId; diff --git a/winit/src/platform_impl/orbital/window.rs b/winit/src/platform_impl/orbital/window.rs index a019a8e6e..370bd1405 100644 --- a/winit/src/platform_impl/orbital/window.rs +++ b/winit/src/platform_impl/orbital/window.rs @@ -9,12 +9,10 @@ use crate::{ error, platform_impl::Fullscreen, window, - window::ImePurpose, + window::{ImePurpose, WindowId}, }; -use super::{ - EventLoopWindowTarget, MonitorHandle, RedoxSocket, TimeSocket, WindowId, WindowProperties, -}; +use super::{EventLoopWindowTarget, MonitorHandle, RedoxSocket, TimeSocket, WindowProperties}; // These values match the values uses in the `window_new` function in orbital: // https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs @@ -131,9 +129,7 @@ impl Window { #[inline] pub fn id(&self) -> WindowId { - WindowId { - fd: self.window_socket.fd as u64, - } + WindowId::from(self.window_socket.fd as u64) } #[inline] diff --git a/winit/src/platform_impl/web/event_loop/mod.rs b/winit/src/platform_impl/web/event_loop/mod.rs index 2cc9d27d5..6b97d5196 100644 --- a/winit/src/platform_impl/web/event_loop/mod.rs +++ b/winit/src/platform_impl/web/event_loop/mod.rs @@ -5,7 +5,7 @@ use crate::error::EventLoopError; use crate::event::Event; use crate::event_loop::EventLoopWindowTarget as RootEventLoopWindowTarget; -use super::{backend, device, window}; +use super::{backend, device}; mod proxy; pub(crate) mod runner; diff --git a/winit/src/platform_impl/web/event_loop/window_target.rs b/winit/src/platform_impl/web/event_loop/window_target.rs index 3b290dd3c..6f063552a 100644 --- a/winit/src/platform_impl/web/event_loop/window_target.rs +++ b/winit/src/platform_impl/web/event_loop/window_target.rs @@ -12,7 +12,6 @@ use super::{ backend, device::DeviceId, runner, - window::WindowId, }; use crate::event::{ DeviceId as RootDeviceId, ElementState, Event, KeyEvent, Touch, TouchPhase, WindowEvent, @@ -21,7 +20,7 @@ use crate::event_loop::{ControlFlow, DeviceEvents}; use crate::keyboard::ModifiersState; use crate::platform::web::PollStrategy; use crate::platform_impl::platform::r#async::Waker; -use crate::window::{Theme, WindowId as RootWindowId}; +use crate::window::{Theme, WindowId}; #[derive(Default)] struct ModifiersShared(Rc>); @@ -62,14 +61,14 @@ impl EventLoopWindowTarget { } pub fn generate_id(&self) -> WindowId { - WindowId(self.runner.generate_id()) + u64::from(self.runner.generate_id()).into() } pub fn register(&self, canvas: &Rc>, id: WindowId) { let canvas_clone = canvas.clone(); let mut canvas = canvas.borrow_mut(); #[cfg(any(feature = "rwh_04", feature = "rwh_05"))] - canvas.set_attribute("data-raw-handle", &id.0.to_string()); + canvas.set_attribute("data-raw-handle", &u64::from(id).to_string()); canvas.on_touch_start(); @@ -82,7 +81,7 @@ impl EventLoopWindowTarget { let clear_modifiers = (!modifiers.get().is_empty()).then(|| { modifiers.set(ModifiersState::empty()); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(ModifiersState::empty().into()), } }); @@ -91,7 +90,7 @@ impl EventLoopWindowTarget { clear_modifiers .into_iter() .chain(iter::once(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Focused(false), })), ); @@ -102,7 +101,7 @@ impl EventLoopWindowTarget { canvas.on_focus(move || { if !has_focus.replace(true) { runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Focused(true), }); } @@ -122,7 +121,7 @@ impl EventLoopWindowTarget { if focused { canvas.has_focus.set(true); self.runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Focused(true), }) } @@ -134,7 +133,7 @@ impl EventLoopWindowTarget { let modifiers_changed = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); @@ -143,7 +142,7 @@ impl EventLoopWindowTarget { runner.send_events( iter::once(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::KeyboardInput { device_id, event: KeyEvent { @@ -170,7 +169,7 @@ impl EventLoopWindowTarget { let modifiers_changed = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); @@ -179,7 +178,7 @@ impl EventLoopWindowTarget { runner.send_events( iter::once(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::KeyboardInput { device_id, event: KeyEvent { @@ -209,13 +208,13 @@ impl EventLoopWindowTarget { let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); let pointer = pointer_id.map(|pointer_id| Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::CursorLeft { device_id: RootDeviceId(DeviceId(pointer_id)), }, @@ -236,13 +235,13 @@ impl EventLoopWindowTarget { let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); let pointer = pointer_id.map(|pointer_id| Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::CursorEntered { device_id: RootDeviceId(DeviceId(pointer_id)), }, @@ -264,7 +263,7 @@ impl EventLoopWindowTarget { if has_focus.get() && modifiers.get() != active_modifiers { modifiers.set(active_modifiers); runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), }) } @@ -280,7 +279,7 @@ impl EventLoopWindowTarget { (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); @@ -289,7 +288,7 @@ impl EventLoopWindowTarget { let device_id = RootDeviceId(DeviceId(pointer_id)); iter::once(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::CursorMoved { device_id, position, @@ -308,14 +307,14 @@ impl EventLoopWindowTarget { (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers.into_iter().chain(events.map( |(location, force)| Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Touch(Touch { id: device_id as u64, device_id: RootDeviceId(DeviceId(device_id)), @@ -341,7 +340,7 @@ impl EventLoopWindowTarget { (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); @@ -359,14 +358,14 @@ impl EventLoopWindowTarget { // user code has the correct cursor position. runner.send_events(modifiers.into_iter().chain([ Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::CursorMoved { device_id, position, }, }, Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::MouseInput { device_id, state, @@ -387,7 +386,7 @@ impl EventLoopWindowTarget { if modifiers.get() != active_modifiers { modifiers.set(active_modifiers); runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), }) } @@ -401,7 +400,7 @@ impl EventLoopWindowTarget { let modifiers = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); @@ -413,14 +412,14 @@ impl EventLoopWindowTarget { // user code has the correct cursor position. runner.send_events(modifiers.into_iter().chain([ Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::CursorMoved { device_id, position, }, }, Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::MouseInput { device_id, state: ElementState::Pressed, @@ -438,14 +437,14 @@ impl EventLoopWindowTarget { let modifiers = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers.into_iter().chain(iter::once( Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Touch(Touch { id: device_id as u64, device_id: RootDeviceId(DeviceId(device_id)), @@ -469,7 +468,7 @@ impl EventLoopWindowTarget { if has_focus.get() && modifiers.get() != active_modifiers { modifiers.set(active_modifiers); runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), }); } @@ -485,7 +484,7 @@ impl EventLoopWindowTarget { (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); @@ -497,14 +496,14 @@ impl EventLoopWindowTarget { // user code has the correct cursor position. runner.send_events(modifiers.into_iter().chain([ Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::CursorMoved { device_id, position, }, }, Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::MouseInput { device_id, state: ElementState::Released, @@ -524,14 +523,14 @@ impl EventLoopWindowTarget { (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); runner_touch.send_events(modifiers.into_iter().chain(iter::once( Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Touch(Touch { id: device_id as u64, device_id: RootDeviceId(DeviceId(device_id)), @@ -552,14 +551,14 @@ impl EventLoopWindowTarget { (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers_changed.into_iter().chain(iter::once( Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::MouseWheel { device_id: RootDeviceId(DeviceId(pointer_id)), delta, @@ -572,7 +571,7 @@ impl EventLoopWindowTarget { let runner = self.runner.clone(); canvas.on_touch_cancel(move |device_id, location, force| { runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Touch(Touch { id: device_id as u64, device_id: RootDeviceId(DeviceId(device_id)), @@ -591,7 +590,7 @@ impl EventLoopWindowTarget { Theme::Light }; runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::ThemeChanged(theme), }); }); @@ -619,10 +618,10 @@ impl EventLoopWindowTarget { if canvas.old_size() != new_size { canvas.set_old_size(new_size); runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Resized(new_size), }); - runner.request_redraw(RootWindowId(id)); + runner.request_redraw(id); } } }, @@ -635,7 +634,7 @@ impl EventLoopWindowTarget { && !(is_intersecting && canvas_clone.borrow().is_intersecting.is_none()) { runner.send_event(Event::WindowEvent { - window_id: RootWindowId(id), + window_id: id, event: WindowEvent::Occluded(!is_intersecting), }); } @@ -644,7 +643,7 @@ impl EventLoopWindowTarget { }); let runner = self.runner.clone(); - canvas.on_animation_frame(move || runner.request_redraw(RootWindowId(id))); + canvas.on_animation_frame(move || runner.request_redraw(id)); canvas.on_context_menu(); } diff --git a/winit/src/platform_impl/web/keyboard.rs b/winit/src/platform_impl/web/keyboard.rs index 6f8d69c76..8e6651a23 100644 --- a/winit/src/platform_impl/web/keyboard.rs +++ b/winit/src/platform_impl/web/keyboard.rs @@ -5,518 +5,514 @@ use crate::keyboard::{Key, KeyCode, NamedKey, NativeKey, NativeKeyCode, Physical #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub(crate) struct KeyEventExtra; -impl Key { - pub(crate) fn from_key_attribute_value(kav: &str) -> Self { - Key::Named(match kav { - "Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))), - "Dead" => return Key::Dead(None), - "Alt" => NamedKey::Alt, - "AltGraph" => NamedKey::AltGraph, - "CapsLock" => NamedKey::CapsLock, - "Control" => NamedKey::Control, - "Fn" => NamedKey::Fn, - "FnLock" => NamedKey::FnLock, - "NumLock" => NamedKey::NumLock, - "ScrollLock" => NamedKey::ScrollLock, - "Shift" => NamedKey::Shift, - "Symbol" => NamedKey::Symbol, - "SymbolLock" => NamedKey::SymbolLock, - "Hyper" => NamedKey::Hyper, - "Meta" => NamedKey::Super, - "Enter" => NamedKey::Enter, - "Tab" => NamedKey::Tab, - " " => NamedKey::Space, - "ArrowDown" => NamedKey::ArrowDown, - "ArrowLeft" => NamedKey::ArrowLeft, - "ArrowRight" => NamedKey::ArrowRight, - "ArrowUp" => NamedKey::ArrowUp, - "End" => NamedKey::End, - "Home" => NamedKey::Home, - "PageDown" => NamedKey::PageDown, - "PageUp" => NamedKey::PageUp, - "Backspace" => NamedKey::Backspace, - "Clear" => NamedKey::Clear, - "Copy" => NamedKey::Copy, - "CrSel" => NamedKey::CrSel, - "Cut" => NamedKey::Cut, - "Delete" => NamedKey::Delete, - "EraseEof" => NamedKey::EraseEof, - "ExSel" => NamedKey::ExSel, - "Insert" => NamedKey::Insert, - "Paste" => NamedKey::Paste, - "Redo" => NamedKey::Redo, - "Undo" => NamedKey::Undo, - "Accept" => NamedKey::Accept, - "Again" => NamedKey::Again, - "Attn" => NamedKey::Attn, - "Cancel" => NamedKey::Cancel, - "ContextMenu" => NamedKey::ContextMenu, - "Escape" => NamedKey::Escape, - "Execute" => NamedKey::Execute, - "Find" => NamedKey::Find, - "Help" => NamedKey::Help, - "Pause" => NamedKey::Pause, - "Play" => NamedKey::Play, - "Props" => NamedKey::Props, - "Select" => NamedKey::Select, - "ZoomIn" => NamedKey::ZoomIn, - "ZoomOut" => NamedKey::ZoomOut, - "BrightnessDown" => NamedKey::BrightnessDown, - "BrightnessUp" => NamedKey::BrightnessUp, - "Eject" => NamedKey::Eject, - "LogOff" => NamedKey::LogOff, - "Power" => NamedKey::Power, - "PowerOff" => NamedKey::PowerOff, - "PrintScreen" => NamedKey::PrintScreen, - "Hibernate" => NamedKey::Hibernate, - "Standby" => NamedKey::Standby, - "WakeUp" => NamedKey::WakeUp, - "AllCandidates" => NamedKey::AllCandidates, - "Alphanumeric" => NamedKey::Alphanumeric, - "CodeInput" => NamedKey::CodeInput, - "Compose" => NamedKey::Compose, - "Convert" => NamedKey::Convert, - "FinalMode" => NamedKey::FinalMode, - "GroupFirst" => NamedKey::GroupFirst, - "GroupLast" => NamedKey::GroupLast, - "GroupNext" => NamedKey::GroupNext, - "GroupPrevious" => NamedKey::GroupPrevious, - "ModeChange" => NamedKey::ModeChange, - "NextCandidate" => NamedKey::NextCandidate, - "NonConvert" => NamedKey::NonConvert, - "PreviousCandidate" => NamedKey::PreviousCandidate, - "Process" => NamedKey::Process, - "SingleCandidate" => NamedKey::SingleCandidate, - "HangulMode" => NamedKey::HangulMode, - "HanjaMode" => NamedKey::HanjaMode, - "JunjaMode" => NamedKey::JunjaMode, - "Eisu" => NamedKey::Eisu, - "Hankaku" => NamedKey::Hankaku, - "Hiragana" => NamedKey::Hiragana, - "HiraganaKatakana" => NamedKey::HiraganaKatakana, - "KanaMode" => NamedKey::KanaMode, - "KanjiMode" => NamedKey::KanjiMode, - "Katakana" => NamedKey::Katakana, - "Romaji" => NamedKey::Romaji, - "Zenkaku" => NamedKey::Zenkaku, - "ZenkakuHankaku" => NamedKey::ZenkakuHankaku, - "Soft1" => NamedKey::Soft1, - "Soft2" => NamedKey::Soft2, - "Soft3" => NamedKey::Soft3, - "Soft4" => NamedKey::Soft4, - "ChannelDown" => NamedKey::ChannelDown, - "ChannelUp" => NamedKey::ChannelUp, - "Close" => NamedKey::Close, - "MailForward" => NamedKey::MailForward, - "MailReply" => NamedKey::MailReply, - "MailSend" => NamedKey::MailSend, - "MediaClose" => NamedKey::MediaClose, - "MediaFastForward" => NamedKey::MediaFastForward, - "MediaPause" => NamedKey::MediaPause, - "MediaPlay" => NamedKey::MediaPlay, - "MediaPlayPause" => NamedKey::MediaPlayPause, - "MediaRecord" => NamedKey::MediaRecord, - "MediaRewind" => NamedKey::MediaRewind, - "MediaStop" => NamedKey::MediaStop, - "MediaTrackNext" => NamedKey::MediaTrackNext, - "MediaTrackPrevious" => NamedKey::MediaTrackPrevious, - "New" => NamedKey::New, - "Open" => NamedKey::Open, - "Print" => NamedKey::Print, - "Save" => NamedKey::Save, - "SpellCheck" => NamedKey::SpellCheck, - "Key11" => NamedKey::Key11, - "Key12" => NamedKey::Key12, - "AudioBalanceLeft" => NamedKey::AudioBalanceLeft, - "AudioBalanceRight" => NamedKey::AudioBalanceRight, - "AudioBassBoostDown" => NamedKey::AudioBassBoostDown, - "AudioBassBoostToggle" => NamedKey::AudioBassBoostToggle, - "AudioBassBoostUp" => NamedKey::AudioBassBoostUp, - "AudioFaderFront" => NamedKey::AudioFaderFront, - "AudioFaderRear" => NamedKey::AudioFaderRear, - "AudioSurroundModeNext" => NamedKey::AudioSurroundModeNext, - "AudioTrebleDown" => NamedKey::AudioTrebleDown, - "AudioTrebleUp" => NamedKey::AudioTrebleUp, - "AudioVolumeDown" => NamedKey::AudioVolumeDown, - "AudioVolumeUp" => NamedKey::AudioVolumeUp, - "AudioVolumeMute" => NamedKey::AudioVolumeMute, - "MicrophoneToggle" => NamedKey::MicrophoneToggle, - "MicrophoneVolumeDown" => NamedKey::MicrophoneVolumeDown, - "MicrophoneVolumeUp" => NamedKey::MicrophoneVolumeUp, - "MicrophoneVolumeMute" => NamedKey::MicrophoneVolumeMute, - "SpeechCorrectionList" => NamedKey::SpeechCorrectionList, - "SpeechInputToggle" => NamedKey::SpeechInputToggle, - "LaunchApplication1" => NamedKey::LaunchApplication1, - "LaunchApplication2" => NamedKey::LaunchApplication2, - "LaunchCalendar" => NamedKey::LaunchCalendar, - "LaunchContacts" => NamedKey::LaunchContacts, - "LaunchMail" => NamedKey::LaunchMail, - "LaunchMediaPlayer" => NamedKey::LaunchMediaPlayer, - "LaunchMusicPlayer" => NamedKey::LaunchMusicPlayer, - "LaunchPhone" => NamedKey::LaunchPhone, - "LaunchScreenSaver" => NamedKey::LaunchScreenSaver, - "LaunchSpreadsheet" => NamedKey::LaunchSpreadsheet, - "LaunchWebBrowser" => NamedKey::LaunchWebBrowser, - "LaunchWebCam" => NamedKey::LaunchWebCam, - "LaunchWordProcessor" => NamedKey::LaunchWordProcessor, - "BrowserBack" => NamedKey::BrowserBack, - "BrowserFavorites" => NamedKey::BrowserFavorites, - "BrowserForward" => NamedKey::BrowserForward, - "BrowserHome" => NamedKey::BrowserHome, - "BrowserRefresh" => NamedKey::BrowserRefresh, - "BrowserSearch" => NamedKey::BrowserSearch, - "BrowserStop" => NamedKey::BrowserStop, - "AppSwitch" => NamedKey::AppSwitch, - "Call" => NamedKey::Call, - "Camera" => NamedKey::Camera, - "CameraFocus" => NamedKey::CameraFocus, - "EndCall" => NamedKey::EndCall, - "GoBack" => NamedKey::GoBack, - "GoHome" => NamedKey::GoHome, - "HeadsetHook" => NamedKey::HeadsetHook, - "LastNumberRedial" => NamedKey::LastNumberRedial, - "Notification" => NamedKey::Notification, - "MannerMode" => NamedKey::MannerMode, - "VoiceDial" => NamedKey::VoiceDial, - "TV" => NamedKey::TV, - "TV3DMode" => NamedKey::TV3DMode, - "TVAntennaCable" => NamedKey::TVAntennaCable, - "TVAudioDescription" => NamedKey::TVAudioDescription, - "TVAudioDescriptionMixDown" => NamedKey::TVAudioDescriptionMixDown, - "TVAudioDescriptionMixUp" => NamedKey::TVAudioDescriptionMixUp, - "TVContentsMenu" => NamedKey::TVContentsMenu, - "TVDataService" => NamedKey::TVDataService, - "TVInput" => NamedKey::TVInput, - "TVInputComponent1" => NamedKey::TVInputComponent1, - "TVInputComponent2" => NamedKey::TVInputComponent2, - "TVInputComposite1" => NamedKey::TVInputComposite1, - "TVInputComposite2" => NamedKey::TVInputComposite2, - "TVInputHDMI1" => NamedKey::TVInputHDMI1, - "TVInputHDMI2" => NamedKey::TVInputHDMI2, - "TVInputHDMI3" => NamedKey::TVInputHDMI3, - "TVInputHDMI4" => NamedKey::TVInputHDMI4, - "TVInputVGA1" => NamedKey::TVInputVGA1, - "TVMediaContext" => NamedKey::TVMediaContext, - "TVNetwork" => NamedKey::TVNetwork, - "TVNumberEntry" => NamedKey::TVNumberEntry, - "TVPower" => NamedKey::TVPower, - "TVRadioService" => NamedKey::TVRadioService, - "TVSatellite" => NamedKey::TVSatellite, - "TVSatelliteBS" => NamedKey::TVSatelliteBS, - "TVSatelliteCS" => NamedKey::TVSatelliteCS, - "TVSatelliteToggle" => NamedKey::TVSatelliteToggle, - "TVTerrestrialAnalog" => NamedKey::TVTerrestrialAnalog, - "TVTerrestrialDigital" => NamedKey::TVTerrestrialDigital, - "TVTimer" => NamedKey::TVTimer, - "AVRInput" => NamedKey::AVRInput, - "AVRPower" => NamedKey::AVRPower, - "ColorF0Red" => NamedKey::ColorF0Red, - "ColorF1Green" => NamedKey::ColorF1Green, - "ColorF2Yellow" => NamedKey::ColorF2Yellow, - "ColorF3Blue" => NamedKey::ColorF3Blue, - "ColorF4Grey" => NamedKey::ColorF4Grey, - "ColorF5Brown" => NamedKey::ColorF5Brown, - "ClosedCaptionToggle" => NamedKey::ClosedCaptionToggle, - "Dimmer" => NamedKey::Dimmer, - "DisplaySwap" => NamedKey::DisplaySwap, - "DVR" => NamedKey::DVR, - "Exit" => NamedKey::Exit, - "FavoriteClear0" => NamedKey::FavoriteClear0, - "FavoriteClear1" => NamedKey::FavoriteClear1, - "FavoriteClear2" => NamedKey::FavoriteClear2, - "FavoriteClear3" => NamedKey::FavoriteClear3, - "FavoriteRecall0" => NamedKey::FavoriteRecall0, - "FavoriteRecall1" => NamedKey::FavoriteRecall1, - "FavoriteRecall2" => NamedKey::FavoriteRecall2, - "FavoriteRecall3" => NamedKey::FavoriteRecall3, - "FavoriteStore0" => NamedKey::FavoriteStore0, - "FavoriteStore1" => NamedKey::FavoriteStore1, - "FavoriteStore2" => NamedKey::FavoriteStore2, - "FavoriteStore3" => NamedKey::FavoriteStore3, - "Guide" => NamedKey::Guide, - "GuideNextDay" => NamedKey::GuideNextDay, - "GuidePreviousDay" => NamedKey::GuidePreviousDay, - "Info" => NamedKey::Info, - "InstantReplay" => NamedKey::InstantReplay, - "Link" => NamedKey::Link, - "ListProgram" => NamedKey::ListProgram, - "LiveContent" => NamedKey::LiveContent, - "Lock" => NamedKey::Lock, - "MediaApps" => NamedKey::MediaApps, - "MediaAudioTrack" => NamedKey::MediaAudioTrack, - "MediaLast" => NamedKey::MediaLast, - "MediaSkipBackward" => NamedKey::MediaSkipBackward, - "MediaSkipForward" => NamedKey::MediaSkipForward, - "MediaStepBackward" => NamedKey::MediaStepBackward, - "MediaStepForward" => NamedKey::MediaStepForward, - "MediaTopMenu" => NamedKey::MediaTopMenu, - "NavigateIn" => NamedKey::NavigateIn, - "NavigateNext" => NamedKey::NavigateNext, - "NavigateOut" => NamedKey::NavigateOut, - "NavigatePrevious" => NamedKey::NavigatePrevious, - "NextFavoriteChannel" => NamedKey::NextFavoriteChannel, - "NextUserProfile" => NamedKey::NextUserProfile, - "OnDemand" => NamedKey::OnDemand, - "Pairing" => NamedKey::Pairing, - "PinPDown" => NamedKey::PinPDown, - "PinPMove" => NamedKey::PinPMove, - "PinPToggle" => NamedKey::PinPToggle, - "PinPUp" => NamedKey::PinPUp, - "PlaySpeedDown" => NamedKey::PlaySpeedDown, - "PlaySpeedReset" => NamedKey::PlaySpeedReset, - "PlaySpeedUp" => NamedKey::PlaySpeedUp, - "RandomToggle" => NamedKey::RandomToggle, - "RcLowBattery" => NamedKey::RcLowBattery, - "RecordSpeedNext" => NamedKey::RecordSpeedNext, - "RfBypass" => NamedKey::RfBypass, - "ScanChannelsToggle" => NamedKey::ScanChannelsToggle, - "ScreenModeNext" => NamedKey::ScreenModeNext, - "Settings" => NamedKey::Settings, - "SplitScreenToggle" => NamedKey::SplitScreenToggle, - "STBInput" => NamedKey::STBInput, - "STBPower" => NamedKey::STBPower, - "Subtitle" => NamedKey::Subtitle, - "Teletext" => NamedKey::Teletext, - "VideoModeNext" => NamedKey::VideoModeNext, - "Wink" => NamedKey::Wink, - "ZoomToggle" => NamedKey::ZoomToggle, - "F1" => NamedKey::F1, - "F2" => NamedKey::F2, - "F3" => NamedKey::F3, - "F4" => NamedKey::F4, - "F5" => NamedKey::F5, - "F6" => NamedKey::F6, - "F7" => NamedKey::F7, - "F8" => NamedKey::F8, - "F9" => NamedKey::F9, - "F10" => NamedKey::F10, - "F11" => NamedKey::F11, - "F12" => NamedKey::F12, - "F13" => NamedKey::F13, - "F14" => NamedKey::F14, - "F15" => NamedKey::F15, - "F16" => NamedKey::F16, - "F17" => NamedKey::F17, - "F18" => NamedKey::F18, - "F19" => NamedKey::F19, - "F20" => NamedKey::F20, - "F21" => NamedKey::F21, - "F22" => NamedKey::F22, - "F23" => NamedKey::F23, - "F24" => NamedKey::F24, - "F25" => NamedKey::F25, - "F26" => NamedKey::F26, - "F27" => NamedKey::F27, - "F28" => NamedKey::F28, - "F29" => NamedKey::F29, - "F30" => NamedKey::F30, - "F31" => NamedKey::F31, - "F32" => NamedKey::F32, - "F33" => NamedKey::F33, - "F34" => NamedKey::F34, - "F35" => NamedKey::F35, - string => return Key::Character(SmolStr::new(string)), - }) - } +pub(crate) fn from_key_attribute_value(kav: &str) -> Key { + Key::Named(match kav { + "Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))), + "Dead" => return Key::Dead(None), + "Alt" => NamedKey::Alt, + "AltGraph" => NamedKey::AltGraph, + "CapsLock" => NamedKey::CapsLock, + "Control" => NamedKey::Control, + "Fn" => NamedKey::Fn, + "FnLock" => NamedKey::FnLock, + "NumLock" => NamedKey::NumLock, + "ScrollLock" => NamedKey::ScrollLock, + "Shift" => NamedKey::Shift, + "Symbol" => NamedKey::Symbol, + "SymbolLock" => NamedKey::SymbolLock, + "Hyper" => NamedKey::Hyper, + "Meta" => NamedKey::Super, + "Enter" => NamedKey::Enter, + "Tab" => NamedKey::Tab, + " " => NamedKey::Space, + "ArrowDown" => NamedKey::ArrowDown, + "ArrowLeft" => NamedKey::ArrowLeft, + "ArrowRight" => NamedKey::ArrowRight, + "ArrowUp" => NamedKey::ArrowUp, + "End" => NamedKey::End, + "Home" => NamedKey::Home, + "PageDown" => NamedKey::PageDown, + "PageUp" => NamedKey::PageUp, + "Backspace" => NamedKey::Backspace, + "Clear" => NamedKey::Clear, + "Copy" => NamedKey::Copy, + "CrSel" => NamedKey::CrSel, + "Cut" => NamedKey::Cut, + "Delete" => NamedKey::Delete, + "EraseEof" => NamedKey::EraseEof, + "ExSel" => NamedKey::ExSel, + "Insert" => NamedKey::Insert, + "Paste" => NamedKey::Paste, + "Redo" => NamedKey::Redo, + "Undo" => NamedKey::Undo, + "Accept" => NamedKey::Accept, + "Again" => NamedKey::Again, + "Attn" => NamedKey::Attn, + "Cancel" => NamedKey::Cancel, + "ContextMenu" => NamedKey::ContextMenu, + "Escape" => NamedKey::Escape, + "Execute" => NamedKey::Execute, + "Find" => NamedKey::Find, + "Help" => NamedKey::Help, + "Pause" => NamedKey::Pause, + "Play" => NamedKey::Play, + "Props" => NamedKey::Props, + "Select" => NamedKey::Select, + "ZoomIn" => NamedKey::ZoomIn, + "ZoomOut" => NamedKey::ZoomOut, + "BrightnessDown" => NamedKey::BrightnessDown, + "BrightnessUp" => NamedKey::BrightnessUp, + "Eject" => NamedKey::Eject, + "LogOff" => NamedKey::LogOff, + "Power" => NamedKey::Power, + "PowerOff" => NamedKey::PowerOff, + "PrintScreen" => NamedKey::PrintScreen, + "Hibernate" => NamedKey::Hibernate, + "Standby" => NamedKey::Standby, + "WakeUp" => NamedKey::WakeUp, + "AllCandidates" => NamedKey::AllCandidates, + "Alphanumeric" => NamedKey::Alphanumeric, + "CodeInput" => NamedKey::CodeInput, + "Compose" => NamedKey::Compose, + "Convert" => NamedKey::Convert, + "FinalMode" => NamedKey::FinalMode, + "GroupFirst" => NamedKey::GroupFirst, + "GroupLast" => NamedKey::GroupLast, + "GroupNext" => NamedKey::GroupNext, + "GroupPrevious" => NamedKey::GroupPrevious, + "ModeChange" => NamedKey::ModeChange, + "NextCandidate" => NamedKey::NextCandidate, + "NonConvert" => NamedKey::NonConvert, + "PreviousCandidate" => NamedKey::PreviousCandidate, + "Process" => NamedKey::Process, + "SingleCandidate" => NamedKey::SingleCandidate, + "HangulMode" => NamedKey::HangulMode, + "HanjaMode" => NamedKey::HanjaMode, + "JunjaMode" => NamedKey::JunjaMode, + "Eisu" => NamedKey::Eisu, + "Hankaku" => NamedKey::Hankaku, + "Hiragana" => NamedKey::Hiragana, + "HiraganaKatakana" => NamedKey::HiraganaKatakana, + "KanaMode" => NamedKey::KanaMode, + "KanjiMode" => NamedKey::KanjiMode, + "Katakana" => NamedKey::Katakana, + "Romaji" => NamedKey::Romaji, + "Zenkaku" => NamedKey::Zenkaku, + "ZenkakuHankaku" => NamedKey::ZenkakuHankaku, + "Soft1" => NamedKey::Soft1, + "Soft2" => NamedKey::Soft2, + "Soft3" => NamedKey::Soft3, + "Soft4" => NamedKey::Soft4, + "ChannelDown" => NamedKey::ChannelDown, + "ChannelUp" => NamedKey::ChannelUp, + "Close" => NamedKey::Close, + "MailForward" => NamedKey::MailForward, + "MailReply" => NamedKey::MailReply, + "MailSend" => NamedKey::MailSend, + "MediaClose" => NamedKey::MediaClose, + "MediaFastForward" => NamedKey::MediaFastForward, + "MediaPause" => NamedKey::MediaPause, + "MediaPlay" => NamedKey::MediaPlay, + "MediaPlayPause" => NamedKey::MediaPlayPause, + "MediaRecord" => NamedKey::MediaRecord, + "MediaRewind" => NamedKey::MediaRewind, + "MediaStop" => NamedKey::MediaStop, + "MediaTrackNext" => NamedKey::MediaTrackNext, + "MediaTrackPrevious" => NamedKey::MediaTrackPrevious, + "New" => NamedKey::New, + "Open" => NamedKey::Open, + "Print" => NamedKey::Print, + "Save" => NamedKey::Save, + "SpellCheck" => NamedKey::SpellCheck, + "Key11" => NamedKey::Key11, + "Key12" => NamedKey::Key12, + "AudioBalanceLeft" => NamedKey::AudioBalanceLeft, + "AudioBalanceRight" => NamedKey::AudioBalanceRight, + "AudioBassBoostDown" => NamedKey::AudioBassBoostDown, + "AudioBassBoostToggle" => NamedKey::AudioBassBoostToggle, + "AudioBassBoostUp" => NamedKey::AudioBassBoostUp, + "AudioFaderFront" => NamedKey::AudioFaderFront, + "AudioFaderRear" => NamedKey::AudioFaderRear, + "AudioSurroundModeNext" => NamedKey::AudioSurroundModeNext, + "AudioTrebleDown" => NamedKey::AudioTrebleDown, + "AudioTrebleUp" => NamedKey::AudioTrebleUp, + "AudioVolumeDown" => NamedKey::AudioVolumeDown, + "AudioVolumeUp" => NamedKey::AudioVolumeUp, + "AudioVolumeMute" => NamedKey::AudioVolumeMute, + "MicrophoneToggle" => NamedKey::MicrophoneToggle, + "MicrophoneVolumeDown" => NamedKey::MicrophoneVolumeDown, + "MicrophoneVolumeUp" => NamedKey::MicrophoneVolumeUp, + "MicrophoneVolumeMute" => NamedKey::MicrophoneVolumeMute, + "SpeechCorrectionList" => NamedKey::SpeechCorrectionList, + "SpeechInputToggle" => NamedKey::SpeechInputToggle, + "LaunchApplication1" => NamedKey::LaunchApplication1, + "LaunchApplication2" => NamedKey::LaunchApplication2, + "LaunchCalendar" => NamedKey::LaunchCalendar, + "LaunchContacts" => NamedKey::LaunchContacts, + "LaunchMail" => NamedKey::LaunchMail, + "LaunchMediaPlayer" => NamedKey::LaunchMediaPlayer, + "LaunchMusicPlayer" => NamedKey::LaunchMusicPlayer, + "LaunchPhone" => NamedKey::LaunchPhone, + "LaunchScreenSaver" => NamedKey::LaunchScreenSaver, + "LaunchSpreadsheet" => NamedKey::LaunchSpreadsheet, + "LaunchWebBrowser" => NamedKey::LaunchWebBrowser, + "LaunchWebCam" => NamedKey::LaunchWebCam, + "LaunchWordProcessor" => NamedKey::LaunchWordProcessor, + "BrowserBack" => NamedKey::BrowserBack, + "BrowserFavorites" => NamedKey::BrowserFavorites, + "BrowserForward" => NamedKey::BrowserForward, + "BrowserHome" => NamedKey::BrowserHome, + "BrowserRefresh" => NamedKey::BrowserRefresh, + "BrowserSearch" => NamedKey::BrowserSearch, + "BrowserStop" => NamedKey::BrowserStop, + "AppSwitch" => NamedKey::AppSwitch, + "Call" => NamedKey::Call, + "Camera" => NamedKey::Camera, + "CameraFocus" => NamedKey::CameraFocus, + "EndCall" => NamedKey::EndCall, + "GoBack" => NamedKey::GoBack, + "GoHome" => NamedKey::GoHome, + "HeadsetHook" => NamedKey::HeadsetHook, + "LastNumberRedial" => NamedKey::LastNumberRedial, + "Notification" => NamedKey::Notification, + "MannerMode" => NamedKey::MannerMode, + "VoiceDial" => NamedKey::VoiceDial, + "TV" => NamedKey::TV, + "TV3DMode" => NamedKey::TV3DMode, + "TVAntennaCable" => NamedKey::TVAntennaCable, + "TVAudioDescription" => NamedKey::TVAudioDescription, + "TVAudioDescriptionMixDown" => NamedKey::TVAudioDescriptionMixDown, + "TVAudioDescriptionMixUp" => NamedKey::TVAudioDescriptionMixUp, + "TVContentsMenu" => NamedKey::TVContentsMenu, + "TVDataService" => NamedKey::TVDataService, + "TVInput" => NamedKey::TVInput, + "TVInputComponent1" => NamedKey::TVInputComponent1, + "TVInputComponent2" => NamedKey::TVInputComponent2, + "TVInputComposite1" => NamedKey::TVInputComposite1, + "TVInputComposite2" => NamedKey::TVInputComposite2, + "TVInputHDMI1" => NamedKey::TVInputHDMI1, + "TVInputHDMI2" => NamedKey::TVInputHDMI2, + "TVInputHDMI3" => NamedKey::TVInputHDMI3, + "TVInputHDMI4" => NamedKey::TVInputHDMI4, + "TVInputVGA1" => NamedKey::TVInputVGA1, + "TVMediaContext" => NamedKey::TVMediaContext, + "TVNetwork" => NamedKey::TVNetwork, + "TVNumberEntry" => NamedKey::TVNumberEntry, + "TVPower" => NamedKey::TVPower, + "TVRadioService" => NamedKey::TVRadioService, + "TVSatellite" => NamedKey::TVSatellite, + "TVSatelliteBS" => NamedKey::TVSatelliteBS, + "TVSatelliteCS" => NamedKey::TVSatelliteCS, + "TVSatelliteToggle" => NamedKey::TVSatelliteToggle, + "TVTerrestrialAnalog" => NamedKey::TVTerrestrialAnalog, + "TVTerrestrialDigital" => NamedKey::TVTerrestrialDigital, + "TVTimer" => NamedKey::TVTimer, + "AVRInput" => NamedKey::AVRInput, + "AVRPower" => NamedKey::AVRPower, + "ColorF0Red" => NamedKey::ColorF0Red, + "ColorF1Green" => NamedKey::ColorF1Green, + "ColorF2Yellow" => NamedKey::ColorF2Yellow, + "ColorF3Blue" => NamedKey::ColorF3Blue, + "ColorF4Grey" => NamedKey::ColorF4Grey, + "ColorF5Brown" => NamedKey::ColorF5Brown, + "ClosedCaptionToggle" => NamedKey::ClosedCaptionToggle, + "Dimmer" => NamedKey::Dimmer, + "DisplaySwap" => NamedKey::DisplaySwap, + "DVR" => NamedKey::DVR, + "Exit" => NamedKey::Exit, + "FavoriteClear0" => NamedKey::FavoriteClear0, + "FavoriteClear1" => NamedKey::FavoriteClear1, + "FavoriteClear2" => NamedKey::FavoriteClear2, + "FavoriteClear3" => NamedKey::FavoriteClear3, + "FavoriteRecall0" => NamedKey::FavoriteRecall0, + "FavoriteRecall1" => NamedKey::FavoriteRecall1, + "FavoriteRecall2" => NamedKey::FavoriteRecall2, + "FavoriteRecall3" => NamedKey::FavoriteRecall3, + "FavoriteStore0" => NamedKey::FavoriteStore0, + "FavoriteStore1" => NamedKey::FavoriteStore1, + "FavoriteStore2" => NamedKey::FavoriteStore2, + "FavoriteStore3" => NamedKey::FavoriteStore3, + "Guide" => NamedKey::Guide, + "GuideNextDay" => NamedKey::GuideNextDay, + "GuidePreviousDay" => NamedKey::GuidePreviousDay, + "Info" => NamedKey::Info, + "InstantReplay" => NamedKey::InstantReplay, + "Link" => NamedKey::Link, + "ListProgram" => NamedKey::ListProgram, + "LiveContent" => NamedKey::LiveContent, + "Lock" => NamedKey::Lock, + "MediaApps" => NamedKey::MediaApps, + "MediaAudioTrack" => NamedKey::MediaAudioTrack, + "MediaLast" => NamedKey::MediaLast, + "MediaSkipBackward" => NamedKey::MediaSkipBackward, + "MediaSkipForward" => NamedKey::MediaSkipForward, + "MediaStepBackward" => NamedKey::MediaStepBackward, + "MediaStepForward" => NamedKey::MediaStepForward, + "MediaTopMenu" => NamedKey::MediaTopMenu, + "NavigateIn" => NamedKey::NavigateIn, + "NavigateNext" => NamedKey::NavigateNext, + "NavigateOut" => NamedKey::NavigateOut, + "NavigatePrevious" => NamedKey::NavigatePrevious, + "NextFavoriteChannel" => NamedKey::NextFavoriteChannel, + "NextUserProfile" => NamedKey::NextUserProfile, + "OnDemand" => NamedKey::OnDemand, + "Pairing" => NamedKey::Pairing, + "PinPDown" => NamedKey::PinPDown, + "PinPMove" => NamedKey::PinPMove, + "PinPToggle" => NamedKey::PinPToggle, + "PinPUp" => NamedKey::PinPUp, + "PlaySpeedDown" => NamedKey::PlaySpeedDown, + "PlaySpeedReset" => NamedKey::PlaySpeedReset, + "PlaySpeedUp" => NamedKey::PlaySpeedUp, + "RandomToggle" => NamedKey::RandomToggle, + "RcLowBattery" => NamedKey::RcLowBattery, + "RecordSpeedNext" => NamedKey::RecordSpeedNext, + "RfBypass" => NamedKey::RfBypass, + "ScanChannelsToggle" => NamedKey::ScanChannelsToggle, + "ScreenModeNext" => NamedKey::ScreenModeNext, + "Settings" => NamedKey::Settings, + "SplitScreenToggle" => NamedKey::SplitScreenToggle, + "STBInput" => NamedKey::STBInput, + "STBPower" => NamedKey::STBPower, + "Subtitle" => NamedKey::Subtitle, + "Teletext" => NamedKey::Teletext, + "VideoModeNext" => NamedKey::VideoModeNext, + "Wink" => NamedKey::Wink, + "ZoomToggle" => NamedKey::ZoomToggle, + "F1" => NamedKey::F1, + "F2" => NamedKey::F2, + "F3" => NamedKey::F3, + "F4" => NamedKey::F4, + "F5" => NamedKey::F5, + "F6" => NamedKey::F6, + "F7" => NamedKey::F7, + "F8" => NamedKey::F8, + "F9" => NamedKey::F9, + "F10" => NamedKey::F10, + "F11" => NamedKey::F11, + "F12" => NamedKey::F12, + "F13" => NamedKey::F13, + "F14" => NamedKey::F14, + "F15" => NamedKey::F15, + "F16" => NamedKey::F16, + "F17" => NamedKey::F17, + "F18" => NamedKey::F18, + "F19" => NamedKey::F19, + "F20" => NamedKey::F20, + "F21" => NamedKey::F21, + "F22" => NamedKey::F22, + "F23" => NamedKey::F23, + "F24" => NamedKey::F24, + "F25" => NamedKey::F25, + "F26" => NamedKey::F26, + "F27" => NamedKey::F27, + "F28" => NamedKey::F28, + "F29" => NamedKey::F29, + "F30" => NamedKey::F30, + "F31" => NamedKey::F31, + "F32" => NamedKey::F32, + "F33" => NamedKey::F33, + "F34" => NamedKey::F34, + "F35" => NamedKey::F35, + string => return Key::Character(SmolStr::new(string)), + }) } -impl PhysicalKey { - pub fn from_key_code_attribute_value(kcav: &str) -> Self { - PhysicalKey::Code(match kcav { - "Backquote" => KeyCode::Backquote, - "Backslash" => KeyCode::Backslash, - "BracketLeft" => KeyCode::BracketLeft, - "BracketRight" => KeyCode::BracketRight, - "Comma" => KeyCode::Comma, - "Digit0" => KeyCode::Digit0, - "Digit1" => KeyCode::Digit1, - "Digit2" => KeyCode::Digit2, - "Digit3" => KeyCode::Digit3, - "Digit4" => KeyCode::Digit4, - "Digit5" => KeyCode::Digit5, - "Digit6" => KeyCode::Digit6, - "Digit7" => KeyCode::Digit7, - "Digit8" => KeyCode::Digit8, - "Digit9" => KeyCode::Digit9, - "Equal" => KeyCode::Equal, - "IntlBackslash" => KeyCode::IntlBackslash, - "IntlRo" => KeyCode::IntlRo, - "IntlYen" => KeyCode::IntlYen, - "KeyA" => KeyCode::KeyA, - "KeyB" => KeyCode::KeyB, - "KeyC" => KeyCode::KeyC, - "KeyD" => KeyCode::KeyD, - "KeyE" => KeyCode::KeyE, - "KeyF" => KeyCode::KeyF, - "KeyG" => KeyCode::KeyG, - "KeyH" => KeyCode::KeyH, - "KeyI" => KeyCode::KeyI, - "KeyJ" => KeyCode::KeyJ, - "KeyK" => KeyCode::KeyK, - "KeyL" => KeyCode::KeyL, - "KeyM" => KeyCode::KeyM, - "KeyN" => KeyCode::KeyN, - "KeyO" => KeyCode::KeyO, - "KeyP" => KeyCode::KeyP, - "KeyQ" => KeyCode::KeyQ, - "KeyR" => KeyCode::KeyR, - "KeyS" => KeyCode::KeyS, - "KeyT" => KeyCode::KeyT, - "KeyU" => KeyCode::KeyU, - "KeyV" => KeyCode::KeyV, - "KeyW" => KeyCode::KeyW, - "KeyX" => KeyCode::KeyX, - "KeyY" => KeyCode::KeyY, - "KeyZ" => KeyCode::KeyZ, - "Minus" => KeyCode::Minus, - "Period" => KeyCode::Period, - "Quote" => KeyCode::Quote, - "Semicolon" => KeyCode::Semicolon, - "Slash" => KeyCode::Slash, - "AltLeft" => KeyCode::AltLeft, - "AltRight" => KeyCode::AltRight, - "Backspace" => KeyCode::Backspace, - "CapsLock" => KeyCode::CapsLock, - "ContextMenu" => KeyCode::ContextMenu, - "ControlLeft" => KeyCode::ControlLeft, - "ControlRight" => KeyCode::ControlRight, - "Enter" => KeyCode::Enter, - "MetaLeft" => KeyCode::SuperLeft, - "MetaRight" => KeyCode::SuperRight, - "ShiftLeft" => KeyCode::ShiftLeft, - "ShiftRight" => KeyCode::ShiftRight, - "Space" => KeyCode::Space, - "Tab" => KeyCode::Tab, - "Convert" => KeyCode::Convert, - "KanaMode" => KeyCode::KanaMode, - "Lang1" => KeyCode::Lang1, - "Lang2" => KeyCode::Lang2, - "Lang3" => KeyCode::Lang3, - "Lang4" => KeyCode::Lang4, - "Lang5" => KeyCode::Lang5, - "NonConvert" => KeyCode::NonConvert, - "Delete" => KeyCode::Delete, - "End" => KeyCode::End, - "Help" => KeyCode::Help, - "Home" => KeyCode::Home, - "Insert" => KeyCode::Insert, - "PageDown" => KeyCode::PageDown, - "PageUp" => KeyCode::PageUp, - "ArrowDown" => KeyCode::ArrowDown, - "ArrowLeft" => KeyCode::ArrowLeft, - "ArrowRight" => KeyCode::ArrowRight, - "ArrowUp" => KeyCode::ArrowUp, - "NumLock" => KeyCode::NumLock, - "Numpad0" => KeyCode::Numpad0, - "Numpad1" => KeyCode::Numpad1, - "Numpad2" => KeyCode::Numpad2, - "Numpad3" => KeyCode::Numpad3, - "Numpad4" => KeyCode::Numpad4, - "Numpad5" => KeyCode::Numpad5, - "Numpad6" => KeyCode::Numpad6, - "Numpad7" => KeyCode::Numpad7, - "Numpad8" => KeyCode::Numpad8, - "Numpad9" => KeyCode::Numpad9, - "NumpadAdd" => KeyCode::NumpadAdd, - "NumpadBackspace" => KeyCode::NumpadBackspace, - "NumpadClear" => KeyCode::NumpadClear, - "NumpadClearEntry" => KeyCode::NumpadClearEntry, - "NumpadComma" => KeyCode::NumpadComma, - "NumpadDecimal" => KeyCode::NumpadDecimal, - "NumpadDivide" => KeyCode::NumpadDivide, - "NumpadEnter" => KeyCode::NumpadEnter, - "NumpadEqual" => KeyCode::NumpadEqual, - "NumpadHash" => KeyCode::NumpadHash, - "NumpadMemoryAdd" => KeyCode::NumpadMemoryAdd, - "NumpadMemoryClear" => KeyCode::NumpadMemoryClear, - "NumpadMemoryRecall" => KeyCode::NumpadMemoryRecall, - "NumpadMemoryStore" => KeyCode::NumpadMemoryStore, - "NumpadMemorySubtract" => KeyCode::NumpadMemorySubtract, - "NumpadMultiply" => KeyCode::NumpadMultiply, - "NumpadParenLeft" => KeyCode::NumpadParenLeft, - "NumpadParenRight" => KeyCode::NumpadParenRight, - "NumpadStar" => KeyCode::NumpadStar, - "NumpadSubtract" => KeyCode::NumpadSubtract, - "Escape" => KeyCode::Escape, - "Fn" => KeyCode::Fn, - "FnLock" => KeyCode::FnLock, - "PrintScreen" => KeyCode::PrintScreen, - "ScrollLock" => KeyCode::ScrollLock, - "Pause" => KeyCode::Pause, - "BrowserBack" => KeyCode::BrowserBack, - "BrowserFavorites" => KeyCode::BrowserFavorites, - "BrowserForward" => KeyCode::BrowserForward, - "BrowserHome" => KeyCode::BrowserHome, - "BrowserRefresh" => KeyCode::BrowserRefresh, - "BrowserSearch" => KeyCode::BrowserSearch, - "BrowserStop" => KeyCode::BrowserStop, - "Eject" => KeyCode::Eject, - "LaunchApp1" => KeyCode::LaunchApp1, - "LaunchApp2" => KeyCode::LaunchApp2, - "LaunchMail" => KeyCode::LaunchMail, - "MediaPlayPause" => KeyCode::MediaPlayPause, - "MediaSelect" => KeyCode::MediaSelect, - "MediaStop" => KeyCode::MediaStop, - "MediaTrackNext" => KeyCode::MediaTrackNext, - "MediaTrackPrevious" => KeyCode::MediaTrackPrevious, - "Power" => KeyCode::Power, - "Sleep" => KeyCode::Sleep, - "AudioVolumeDown" => KeyCode::AudioVolumeDown, - "AudioVolumeMute" => KeyCode::AudioVolumeMute, - "AudioVolumeUp" => KeyCode::AudioVolumeUp, - "WakeUp" => KeyCode::WakeUp, - "Hyper" => KeyCode::Hyper, - "Turbo" => KeyCode::Turbo, - "Abort" => KeyCode::Abort, - "Resume" => KeyCode::Resume, - "Suspend" => KeyCode::Suspend, - "Again" => KeyCode::Again, - "Copy" => KeyCode::Copy, - "Cut" => KeyCode::Cut, - "Find" => KeyCode::Find, - "Open" => KeyCode::Open, - "Paste" => KeyCode::Paste, - "Props" => KeyCode::Props, - "Select" => KeyCode::Select, - "Undo" => KeyCode::Undo, - "Hiragana" => KeyCode::Hiragana, - "Katakana" => KeyCode::Katakana, - "F1" => KeyCode::F1, - "F2" => KeyCode::F2, - "F3" => KeyCode::F3, - "F4" => KeyCode::F4, - "F5" => KeyCode::F5, - "F6" => KeyCode::F6, - "F7" => KeyCode::F7, - "F8" => KeyCode::F8, - "F9" => KeyCode::F9, - "F10" => KeyCode::F10, - "F11" => KeyCode::F11, - "F12" => KeyCode::F12, - "F13" => KeyCode::F13, - "F14" => KeyCode::F14, - "F15" => KeyCode::F15, - "F16" => KeyCode::F16, - "F17" => KeyCode::F17, - "F18" => KeyCode::F18, - "F19" => KeyCode::F19, - "F20" => KeyCode::F20, - "F21" => KeyCode::F21, - "F22" => KeyCode::F22, - "F23" => KeyCode::F23, - "F24" => KeyCode::F24, - "F25" => KeyCode::F25, - "F26" => KeyCode::F26, - "F27" => KeyCode::F27, - "F28" => KeyCode::F28, - "F29" => KeyCode::F29, - "F30" => KeyCode::F30, - "F31" => KeyCode::F31, - "F32" => KeyCode::F32, - "F33" => KeyCode::F33, - "F34" => KeyCode::F34, - "F35" => KeyCode::F35, - _ => return PhysicalKey::Unidentified(NativeKeyCode::Unidentified), - }) - } +pub fn from_key_code_attribute_value(kcav: &str) -> PhysicalKey { + PhysicalKey::Code(match kcav { + "Backquote" => KeyCode::Backquote, + "Backslash" => KeyCode::Backslash, + "BracketLeft" => KeyCode::BracketLeft, + "BracketRight" => KeyCode::BracketRight, + "Comma" => KeyCode::Comma, + "Digit0" => KeyCode::Digit0, + "Digit1" => KeyCode::Digit1, + "Digit2" => KeyCode::Digit2, + "Digit3" => KeyCode::Digit3, + "Digit4" => KeyCode::Digit4, + "Digit5" => KeyCode::Digit5, + "Digit6" => KeyCode::Digit6, + "Digit7" => KeyCode::Digit7, + "Digit8" => KeyCode::Digit8, + "Digit9" => KeyCode::Digit9, + "Equal" => KeyCode::Equal, + "IntlBackslash" => KeyCode::IntlBackslash, + "IntlRo" => KeyCode::IntlRo, + "IntlYen" => KeyCode::IntlYen, + "KeyA" => KeyCode::KeyA, + "KeyB" => KeyCode::KeyB, + "KeyC" => KeyCode::KeyC, + "KeyD" => KeyCode::KeyD, + "KeyE" => KeyCode::KeyE, + "KeyF" => KeyCode::KeyF, + "KeyG" => KeyCode::KeyG, + "KeyH" => KeyCode::KeyH, + "KeyI" => KeyCode::KeyI, + "KeyJ" => KeyCode::KeyJ, + "KeyK" => KeyCode::KeyK, + "KeyL" => KeyCode::KeyL, + "KeyM" => KeyCode::KeyM, + "KeyN" => KeyCode::KeyN, + "KeyO" => KeyCode::KeyO, + "KeyP" => KeyCode::KeyP, + "KeyQ" => KeyCode::KeyQ, + "KeyR" => KeyCode::KeyR, + "KeyS" => KeyCode::KeyS, + "KeyT" => KeyCode::KeyT, + "KeyU" => KeyCode::KeyU, + "KeyV" => KeyCode::KeyV, + "KeyW" => KeyCode::KeyW, + "KeyX" => KeyCode::KeyX, + "KeyY" => KeyCode::KeyY, + "KeyZ" => KeyCode::KeyZ, + "Minus" => KeyCode::Minus, + "Period" => KeyCode::Period, + "Quote" => KeyCode::Quote, + "Semicolon" => KeyCode::Semicolon, + "Slash" => KeyCode::Slash, + "AltLeft" => KeyCode::AltLeft, + "AltRight" => KeyCode::AltRight, + "Backspace" => KeyCode::Backspace, + "CapsLock" => KeyCode::CapsLock, + "ContextMenu" => KeyCode::ContextMenu, + "ControlLeft" => KeyCode::ControlLeft, + "ControlRight" => KeyCode::ControlRight, + "Enter" => KeyCode::Enter, + "MetaLeft" => KeyCode::SuperLeft, + "MetaRight" => KeyCode::SuperRight, + "ShiftLeft" => KeyCode::ShiftLeft, + "ShiftRight" => KeyCode::ShiftRight, + "Space" => KeyCode::Space, + "Tab" => KeyCode::Tab, + "Convert" => KeyCode::Convert, + "KanaMode" => KeyCode::KanaMode, + "Lang1" => KeyCode::Lang1, + "Lang2" => KeyCode::Lang2, + "Lang3" => KeyCode::Lang3, + "Lang4" => KeyCode::Lang4, + "Lang5" => KeyCode::Lang5, + "NonConvert" => KeyCode::NonConvert, + "Delete" => KeyCode::Delete, + "End" => KeyCode::End, + "Help" => KeyCode::Help, + "Home" => KeyCode::Home, + "Insert" => KeyCode::Insert, + "PageDown" => KeyCode::PageDown, + "PageUp" => KeyCode::PageUp, + "ArrowDown" => KeyCode::ArrowDown, + "ArrowLeft" => KeyCode::ArrowLeft, + "ArrowRight" => KeyCode::ArrowRight, + "ArrowUp" => KeyCode::ArrowUp, + "NumLock" => KeyCode::NumLock, + "Numpad0" => KeyCode::Numpad0, + "Numpad1" => KeyCode::Numpad1, + "Numpad2" => KeyCode::Numpad2, + "Numpad3" => KeyCode::Numpad3, + "Numpad4" => KeyCode::Numpad4, + "Numpad5" => KeyCode::Numpad5, + "Numpad6" => KeyCode::Numpad6, + "Numpad7" => KeyCode::Numpad7, + "Numpad8" => KeyCode::Numpad8, + "Numpad9" => KeyCode::Numpad9, + "NumpadAdd" => KeyCode::NumpadAdd, + "NumpadBackspace" => KeyCode::NumpadBackspace, + "NumpadClear" => KeyCode::NumpadClear, + "NumpadClearEntry" => KeyCode::NumpadClearEntry, + "NumpadComma" => KeyCode::NumpadComma, + "NumpadDecimal" => KeyCode::NumpadDecimal, + "NumpadDivide" => KeyCode::NumpadDivide, + "NumpadEnter" => KeyCode::NumpadEnter, + "NumpadEqual" => KeyCode::NumpadEqual, + "NumpadHash" => KeyCode::NumpadHash, + "NumpadMemoryAdd" => KeyCode::NumpadMemoryAdd, + "NumpadMemoryClear" => KeyCode::NumpadMemoryClear, + "NumpadMemoryRecall" => KeyCode::NumpadMemoryRecall, + "NumpadMemoryStore" => KeyCode::NumpadMemoryStore, + "NumpadMemorySubtract" => KeyCode::NumpadMemorySubtract, + "NumpadMultiply" => KeyCode::NumpadMultiply, + "NumpadParenLeft" => KeyCode::NumpadParenLeft, + "NumpadParenRight" => KeyCode::NumpadParenRight, + "NumpadStar" => KeyCode::NumpadStar, + "NumpadSubtract" => KeyCode::NumpadSubtract, + "Escape" => KeyCode::Escape, + "Fn" => KeyCode::Fn, + "FnLock" => KeyCode::FnLock, + "PrintScreen" => KeyCode::PrintScreen, + "ScrollLock" => KeyCode::ScrollLock, + "Pause" => KeyCode::Pause, + "BrowserBack" => KeyCode::BrowserBack, + "BrowserFavorites" => KeyCode::BrowserFavorites, + "BrowserForward" => KeyCode::BrowserForward, + "BrowserHome" => KeyCode::BrowserHome, + "BrowserRefresh" => KeyCode::BrowserRefresh, + "BrowserSearch" => KeyCode::BrowserSearch, + "BrowserStop" => KeyCode::BrowserStop, + "Eject" => KeyCode::Eject, + "LaunchApp1" => KeyCode::LaunchApp1, + "LaunchApp2" => KeyCode::LaunchApp2, + "LaunchMail" => KeyCode::LaunchMail, + "MediaPlayPause" => KeyCode::MediaPlayPause, + "MediaSelect" => KeyCode::MediaSelect, + "MediaStop" => KeyCode::MediaStop, + "MediaTrackNext" => KeyCode::MediaTrackNext, + "MediaTrackPrevious" => KeyCode::MediaTrackPrevious, + "Power" => KeyCode::Power, + "Sleep" => KeyCode::Sleep, + "AudioVolumeDown" => KeyCode::AudioVolumeDown, + "AudioVolumeMute" => KeyCode::AudioVolumeMute, + "AudioVolumeUp" => KeyCode::AudioVolumeUp, + "WakeUp" => KeyCode::WakeUp, + "Hyper" => KeyCode::Hyper, + "Turbo" => KeyCode::Turbo, + "Abort" => KeyCode::Abort, + "Resume" => KeyCode::Resume, + "Suspend" => KeyCode::Suspend, + "Again" => KeyCode::Again, + "Copy" => KeyCode::Copy, + "Cut" => KeyCode::Cut, + "Find" => KeyCode::Find, + "Open" => KeyCode::Open, + "Paste" => KeyCode::Paste, + "Props" => KeyCode::Props, + "Select" => KeyCode::Select, + "Undo" => KeyCode::Undo, + "Hiragana" => KeyCode::Hiragana, + "Katakana" => KeyCode::Katakana, + "F1" => KeyCode::F1, + "F2" => KeyCode::F2, + "F3" => KeyCode::F3, + "F4" => KeyCode::F4, + "F5" => KeyCode::F5, + "F6" => KeyCode::F6, + "F7" => KeyCode::F7, + "F8" => KeyCode::F8, + "F9" => KeyCode::F9, + "F10" => KeyCode::F10, + "F11" => KeyCode::F11, + "F12" => KeyCode::F12, + "F13" => KeyCode::F13, + "F14" => KeyCode::F14, + "F15" => KeyCode::F15, + "F16" => KeyCode::F16, + "F17" => KeyCode::F17, + "F18" => KeyCode::F18, + "F19" => KeyCode::F19, + "F20" => KeyCode::F20, + "F21" => KeyCode::F21, + "F22" => KeyCode::F22, + "F23" => KeyCode::F23, + "F24" => KeyCode::F24, + "F25" => KeyCode::F25, + "F26" => KeyCode::F26, + "F27" => KeyCode::F27, + "F28" => KeyCode::F28, + "F29" => KeyCode::F29, + "F30" => KeyCode::F30, + "F31" => KeyCode::F31, + "F32" => KeyCode::F32, + "F33" => KeyCode::F33, + "F34" => KeyCode::F34, + "F35" => KeyCode::F35, + _ => return PhysicalKey::Unidentified(NativeKeyCode::Unidentified), + }) } diff --git a/winit/src/platform_impl/web/mod.rs b/winit/src/platform_impl/web/mod.rs index a70dacd04..bbc02d838 100644 --- a/winit/src/platform_impl/web/mod.rs +++ b/winit/src/platform_impl/web/mod.rs @@ -37,7 +37,7 @@ pub(crate) use self::event_loop::{ PlatformSpecificEventLoopAttributes, }; pub use self::monitor::{MonitorHandle, VideoModeHandle}; -pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}; +pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window}; pub(crate) use self::keyboard::KeyEventExtra; pub(crate) use crate::icon::NoIcon as PlatformIcon; diff --git a/winit/src/platform_impl/web/web_sys/canvas.rs b/winit/src/platform_impl/web/web_sys/canvas.rs index eb836a870..e2cbebcce 100644 --- a/winit/src/platform_impl/web/web_sys/canvas.rs +++ b/winit/src/platform_impl/web/web_sys/canvas.rs @@ -15,11 +15,10 @@ use crate::error::OsError as RootOE; use crate::event::{Force, InnerSizeWriter, MouseButton, MouseScrollDelta}; use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; use crate::platform_impl::OsError; -use crate::window::{WindowAttributes, WindowId as RootWindowId}; +use crate::window::{WindowAttributes, WindowId}; use super::super::cursor::CursorHandler; use super::super::main_thread::MainThreadMarker; -use super::super::WindowId; use super::animation_frame::AnimationFrameHandler; use super::event_handle::EventListenerHandle; use super::intersection_handle::IntersectionObserverHandle; @@ -497,7 +496,7 @@ impl Canvas { let new_size = { let new_size = Arc::new(Mutex::new(current_size)); event_handler(crate::event::Event::WindowEvent { - window_id: RootWindowId(self.id), + window_id: self.id, event: crate::event::WindowEvent::ScaleFactorChanged { scale_factor: scale, inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_size)), @@ -523,7 +522,7 @@ impl Canvas { // Then we at least send a resized event. self.set_old_size(new_size); runner.send_event(crate::event::Event::WindowEvent { - window_id: RootWindowId(self.id), + window_id: self.id, event: crate::event::WindowEvent::Resized(new_size), }) } diff --git a/winit/src/platform_impl/web/web_sys/event.rs b/winit/src/platform_impl/web/web_sys/event.rs index 86ebd06ac..e848c280f 100644 --- a/winit/src/platform_impl/web/web_sys/event.rs +++ b/winit/src/platform_impl/web/web_sys/event.rs @@ -164,16 +164,16 @@ pub fn mouse_scroll_delta( pub fn key_code(event: &KeyboardEvent) -> PhysicalKey { let code = event.code(); - PhysicalKey::from_key_code_attribute_value(&code) + super::super::keyboard::from_key_code_attribute_value(&code) } pub fn key(event: &KeyboardEvent) -> Key { - Key::from_key_attribute_value(&event.key()) + super::super::keyboard::from_key_attribute_value(&event.key()) } pub fn key_text(event: &KeyboardEvent) -> Option { let key = event.key(); - let key = Key::from_key_attribute_value(&key); + let key = super::super::keyboard::from_key_attribute_value(&key); match &key { Key::Character(text) => Some(text.clone()), Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")), diff --git a/winit/src/platform_impl/web/window.rs b/winit/src/platform_impl/web/window.rs index 7f4239360..438463e17 100644 --- a/winit/src/platform_impl/web/window.rs +++ b/winit/src/platform_impl/web/window.rs @@ -3,7 +3,7 @@ use crate::error::{ExternalError, NotSupportedError, OsError as RootOE}; use crate::icon::Icon; use crate::window::{ Cursor, CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, - WindowAttributes, WindowButtons, WindowId as RootWI, WindowLevel, + WindowAttributes, WindowButtons, WindowId, WindowLevel, }; use super::main_thread::{MainThreadMarker, MainThreadSafe}; @@ -48,7 +48,7 @@ impl Window { target.register(&canvas, id); let runner = target.runner.clone(); - let destroy_fn = Box::new(move || runner.notify_destroy_window(RootWI(id))); + let destroy_fn = Box::new(move || runner.notify_destroy_window(id)); let inner = Inner { id, @@ -65,7 +65,7 @@ impl Window { let canvas = Rc::downgrade(&inner.canvas); let (dispatcher, runner) = Dispatcher::new(target.runner.main_thread(), inner).unwrap(); - target.runner.add_canvas(RootWI(id), canvas, runner); + target.runner.add_canvas(id, canvas, runner); Ok(Window { inner: dispatcher }) } @@ -397,7 +397,7 @@ impl Inner { #[inline] pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle { let mut window_handle = rwh_05::WebWindowHandle::empty(); - window_handle.id = self.id.0; + window_handle.id = u64::from(self.id) as u32; rwh_05::RawWindowHandle::Web(window_handle) } @@ -444,26 +444,6 @@ impl Drop for Inner { } } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(pub(crate) u32); - -impl WindowId { - pub const unsafe fn dummy() -> Self { - Self(0) - } -} - -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 as u64 - } -} - -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id as u32) - } -} #[derive(Clone, Debug)] pub struct PlatformSpecificWindowBuilderAttributes { diff --git a/winit/src/platform_impl/windows/drop_handler.rs b/winit/src/platform_impl/windows/drop_handler.rs index ced6629ad..d665976d3 100644 --- a/winit/src/platform_impl/windows/drop_handler.rs +++ b/winit/src/platform_impl/windows/drop_handler.rs @@ -20,12 +20,11 @@ use windows_sys::{ use log::debug; -use crate::platform_impl::platform::{ - definitions::{IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl}, - WindowId, +use crate::platform_impl::platform::definitions::{ + IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl, }; -use crate::{event::Event, window::WindowId as RootWindowId}; +use crate::{event::Event, window::WindowId}; #[repr(C)] pub struct FileDropHandlerData { @@ -98,7 +97,7 @@ impl FileDropHandler { let hdrop = unsafe { Self::iterate_filenames(pDataObj, |filename| { drop_handler.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(drop_handler.window)), + window_id: WindowId::from(drop_handler.window as u64), event: HoveredFile(filename), }); }) @@ -135,7 +134,7 @@ impl FileDropHandler { let drop_handler = unsafe { Self::from_interface(this) }; if drop_handler.hovered_is_valid { drop_handler.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(drop_handler.window)), + window_id: WindowId::from(drop_handler.window as u64), event: HoveredFileCancelled, }); } @@ -155,7 +154,7 @@ impl FileDropHandler { let hdrop = unsafe { Self::iterate_filenames(pDataObj, |filename| { drop_handler.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(drop_handler.window)), + window_id: WindowId::from(drop_handler.window as u64), event: DroppedFile(filename), }); }) diff --git a/winit/src/platform_impl/windows/event_loop.rs b/winit/src/platform_impl/windows/event_loop.rs index 21ca4c032..a0eca6c6e 100644 --- a/winit/src/platform_impl/windows/event_loop.rs +++ b/winit/src/platform_impl/windows/event_loop.rs @@ -88,9 +88,9 @@ use crate::{ raw_input, util, window::InitData, window_state::{CursorFlags, ImeState, WindowFlags, WindowState}, - wrap_device_id, Fullscreen, WindowId, DEVICE_ID, + wrap_device_id, Fullscreen, DEVICE_ID, }, - window::WindowId as RootWindowId, + window::WindowId, }; use runner::{EventLoopRunner, EventLoopRunnerShared}; @@ -959,7 +959,7 @@ fn update_modifiers(window: HWND, userdata: &WindowData) { drop(window_state); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: ModifiersChanged(modifiers.into()), }); } @@ -971,7 +971,7 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) { update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: Focused(true), }); } @@ -981,12 +981,12 @@ unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) { userdata.window_state_lock().modifiers_state = ModifiersState::empty(); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: ModifiersChanged(ModifiersState::empty().into()), }); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: Focused(false), }); } @@ -1087,7 +1087,7 @@ unsafe fn public_window_callback_inner( .process_message(window, msg, wparam, lparam, &mut result); for event in events { userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: KeyboardInput { device_id: DEVICE_ID, event: event.event, @@ -1172,7 +1172,7 @@ unsafe fn public_window_callback_inner( WM_CLOSE => { use crate::event::WindowEvent::CloseRequested; userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: CloseRequested, }); result = ProcResult::Value(0); @@ -1182,7 +1182,7 @@ unsafe fn public_window_callback_inner( use crate::event::WindowEvent::Destroyed; unsafe { RevokeDragDrop(window) }; userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: Destroyed, }); result = ProcResult::Value(0); @@ -1203,7 +1203,7 @@ unsafe fn public_window_callback_inner( // and request a normal redraw with `RedrawWindow`. if !userdata.event_loop_runner.should_buffer() { userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::RedrawRequested, }); } @@ -1304,7 +1304,7 @@ unsafe fn public_window_callback_inner( let physical_position = unsafe { PhysicalPosition::new((*windowpos).x, (*windowpos).y) }; userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: Moved(physical_position), }); } @@ -1320,7 +1320,7 @@ unsafe fn public_window_callback_inner( let physical_size = PhysicalSize::new(w, h); let event = Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: Resized(physical_size), }; @@ -1349,7 +1349,7 @@ unsafe fn public_window_callback_inner( userdata.window_state_lock().ime_state = ImeState::Enabled; userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Enabled), }); } @@ -1369,7 +1369,7 @@ unsafe fn public_window_callback_inner( if lparam == 0 { userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), }); } @@ -1381,11 +1381,11 @@ unsafe fn public_window_callback_inner( userdata.window_state_lock().ime_state = ImeState::Enabled; userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), }); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Commit(text)), }); } @@ -1400,7 +1400,7 @@ unsafe fn public_window_callback_inner( let cursor_range = first.map(|f| (f, last.unwrap_or(f))); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Preedit(text, cursor_range)), }); } @@ -1423,11 +1423,11 @@ unsafe fn public_window_callback_inner( let ime_context = unsafe { ImeContext::current(window) }; if let Some(text) = unsafe { ime_context.get_composed_text() } { userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), }); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Commit(text)), }); } @@ -1436,7 +1436,7 @@ unsafe fn public_window_callback_inner( userdata.window_state_lock().ime_state = ImeState::Disabled; userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Ime(Ime::Disabled), }); } @@ -1494,7 +1494,7 @@ unsafe fn public_window_callback_inner( drop(w); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: CursorEntered { device_id: DEVICE_ID, }, @@ -1517,7 +1517,7 @@ unsafe fn public_window_callback_inner( drop(w); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: CursorLeft { device_id: DEVICE_ID, }, @@ -1538,7 +1538,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: CursorMoved { device_id: DEVICE_ID, position, @@ -1559,7 +1559,7 @@ unsafe fn public_window_callback_inner( } userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: CursorLeft { device_id: DEVICE_ID, }, @@ -1577,7 +1577,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::MouseWheel { device_id: DEVICE_ID, delta: LineDelta(0.0, value), @@ -1597,7 +1597,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::MouseWheel { device_id: DEVICE_ID, delta: LineDelta(value, 0.0), @@ -1630,7 +1630,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Pressed, @@ -1650,7 +1650,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Released, @@ -1670,7 +1670,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Pressed, @@ -1690,7 +1690,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Released, @@ -1710,7 +1710,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Pressed, @@ -1730,7 +1730,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Released, @@ -1752,7 +1752,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Pressed, @@ -1778,7 +1778,7 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: MouseInput { device_id: DEVICE_ID, state: Released, @@ -1830,7 +1830,7 @@ unsafe fn public_window_callback_inner( let y = location.y as f64 + (input.y % 100) as f64 / 100f64; let location = PhysicalPosition::new(x, y); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Touch(Touch { phase: if util::has_flag(input.dwFlags, TOUCHEVENTF_DOWN) { TouchPhase::Started @@ -1977,7 +1977,7 @@ unsafe fn public_window_callback_inner( let y = location.y as f64 + y.fract(); let location = PhysicalPosition::new(x, y); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: WindowEvent::Touch(Touch { phase: if util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_DOWN) { TouchPhase::Started @@ -2165,7 +2165,7 @@ unsafe fn public_window_callback_inner( let new_inner_size = Arc::new(Mutex::new(new_physical_inner_size)); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: ScaleFactorChanged { scale_factor: new_scale_factor, inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), @@ -2320,7 +2320,7 @@ unsafe fn public_window_callback_inner( window_state.current_theme = new_theme; drop(window_state); userdata.send_event(Event::WindowEvent { - window_id: RootWindowId(WindowId(window)), + window_id: WindowId::from(window as u64), event: ThemeChanged(new_theme), }); } diff --git a/winit/src/platform_impl/windows/event_loop/runner.rs b/winit/src/platform_impl/windows/event_loop/runner.rs index b7130b579..504f90cad 100644 --- a/winit/src/platform_impl/windows/event_loop/runner.rs +++ b/winit/src/platform_impl/windows/event_loop/runner.rs @@ -416,7 +416,7 @@ impl BufferedEvent { if inner_size != new_inner_size { let window_flags = unsafe { let userdata = - get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData; + get_window_long(u64::from(window_id) as HWND, GWL_USERDATA) as *mut WindowData; (*userdata).window_state_lock().window_flags }; diff --git a/winit/src/platform_impl/windows/mod.rs b/winit/src/platform_impl/windows/mod.rs index 8f1f33512..775428523 100644 --- a/winit/src/platform_impl/windows/mod.rs +++ b/winit/src/platform_impl/windows/mod.rs @@ -109,35 +109,6 @@ pub struct KeyEventExtra { pub key_without_modifiers: Key, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(HWND); -unsafe impl Send for WindowId {} -unsafe impl Sync for WindowId {} - -impl WindowId { - pub const unsafe fn dummy() -> Self { - WindowId(0) - } -} - -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0 as u64 - } -} - -impl From for HWND { - fn from(window_id: WindowId) -> Self { - window_id.0 - } -} - -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id as HWND) - } -} - #[inline(always)] const fn get_xbutton_wparam(x: u32) -> u16 { hiword(x) diff --git a/winit/src/platform_impl/windows/window.rs b/winit/src/platform_impl/windows/window.rs index 546128cc2..9a176a4ed 100644 --- a/winit/src/platform_impl/windows/window.rs +++ b/winit/src/platform_impl/windows/window.rs @@ -81,11 +81,11 @@ use crate::{ monitor::{self, MonitorHandle}, util, window_state::{CursorFlags, SavedWindow, WindowFlags, WindowState}, - Fullscreen, SelectedCursor, WindowId, + Fullscreen, SelectedCursor, }, window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, - WindowButtons, WindowLevel, + WindowButtons, WindowId, WindowLevel, }, }; @@ -653,7 +653,7 @@ impl Window { #[inline] pub fn id(&self) -> WindowId { - WindowId(self.hwnd()) + WindowId::from(self.hwnd() as u64) } #[inline] diff --git a/winit/src/window.rs b/winit/src/window.rs index 0f30c8b91..bb4e46bf4 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -86,43 +86,6 @@ impl Drop for Window { } } -/// Identifier of a window. Unique for each window. -/// -/// Can be obtained with [`window.id()`](`Window::id`). -/// -/// Whenever you receive an event specific to a window, this event contains a `WindowId` which you -/// can then compare to the ids of your windows. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(pub(crate) platform_impl::WindowId); - -impl WindowId { - /// 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 [`WindowId`]. - /// - /// **Passing this into a winit function will result in undefined behavior.** - pub const unsafe fn dummy() -> Self { - #[allow(unused_unsafe)] - WindowId(unsafe { platform_impl::WindowId::dummy() }) - } -} - -impl From for u64 { - fn from(window_id: WindowId) -> Self { - window_id.0.into() - } -} - -impl From for WindowId { - fn from(raw_id: u64) -> Self { - Self(raw_id.into()) - } -} - /// Configure windows before creation. /// /// You can access this from [`Window::builder`]. @@ -579,7 +542,7 @@ impl Window { /// Returns an identifier unique to the window. #[inline] pub fn id(&self) -> WindowId { - self.window.maybe_wait_on_main(|w| WindowId(w.id())) + self.window.maybe_wait_on_main(|w| w.id()) } /// Returns the scale factor that can be used to map logical pixels to physical pixels, and