chore: remove platform WindowId's

WindowId is a window _identifier_, and as such doesn't store anything
(unlike a _handle_). So we can safely make only be defined once, in the
core crate.

There are a few backends where we still use `into_raw` internally; I
consider these patterns discouraged, we should not be passing around
important state in the window id.
This commit is contained in:
Mads Marquart 2024-10-08 15:29:40 +02:00 committed by GitHub
parent eccd9e415d
commit da2268ae22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 226 additions and 379 deletions

View file

@ -24,7 +24,8 @@ use crate::monitor::MonitorHandle as RootMonitorHandle;
use crate::platform::pump_events::PumpStatus;
use crate::window::{
self, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, ImePurpose,
ResizeDirection, Theme, Window as CoreWindow, WindowAttributes, WindowButtons, WindowLevel,
ResizeDirection, Theme, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId,
WindowLevel,
};
mod keycodes;
@ -122,6 +123,9 @@ impl Default for PlatformSpecificEventLoopAttributes {
}
}
// Android currently only supports one window
const GLOBAL_WINDOW: WindowId = WindowId::from_raw(0);
impl EventLoop {
pub(crate) fn new(
attributes: &PlatformSpecificEventLoopAttributes,
@ -187,22 +191,19 @@ impl EventLoop {
},
MainEvent::GainedFocus => {
HAS_FOCUS.store(true, Ordering::Relaxed);
let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::Focused(true);
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
},
MainEvent::LostFocus => {
HAS_FOCUS.store(false, Ordering::Relaxed);
let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::Focused(false);
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
},
MainEvent::ConfigChanged { .. } => {
let old_scale_factor = scale_factor(&self.android_app);
let scale_factor = scale_factor(&self.android_app);
if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
let new_surface_size = Arc::new(Mutex::new(screen_size(&self.android_app)));
let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::ScaleFactorChanged {
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
&new_surface_size,
@ -210,7 +211,7 @@ impl EventLoop {
scale_factor,
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
}
},
MainEvent::LowMemory => {
@ -286,17 +287,15 @@ impl EventLoop {
} else {
PhysicalSize::new(0, 0)
};
let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::SurfaceResized(size);
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
}
pending_redraw |= self.redraw_flag.get_and_reset();
if pending_redraw {
pending_redraw = false;
let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::RedrawRequested;
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
}
}
@ -315,7 +314,6 @@ impl EventLoop {
let mut input_status = InputStatus::Handled;
match event {
InputEvent::MotionEvent(motion_event) => {
let window_id = window::WindowId(WindowId);
let device_id = Some(event::DeviceId(DeviceId(motion_event.device_id())));
let action = motion_event.action();
@ -361,7 +359,7 @@ impl EventLoop {
_ => event::PointerKind::Unknown,
},
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
let event = event::WindowEvent::PointerButton {
device_id,
state: event::ElementState::Pressed,
@ -375,7 +373,7 @@ impl EventLoop {
_ => event::ButtonSource::Unknown(0),
},
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
},
MotionAction::Move => {
let event = event::WindowEvent::PointerMoved {
@ -390,7 +388,7 @@ impl EventLoop {
_ => event::PointerSource::Unknown,
},
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
},
MotionAction::Up | MotionAction::PointerUp | MotionAction::Cancel => {
if let MotionAction::Up | MotionAction::PointerUp = action {
@ -407,7 +405,7 @@ impl EventLoop {
_ => event::ButtonSource::Unknown(0),
},
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
}
let event = event::WindowEvent::PointerLeft {
@ -422,7 +420,7 @@ impl EventLoop {
_ => event::PointerKind::Unknown,
},
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
},
_ => unreachable!(),
}
@ -453,7 +451,6 @@ impl EventLoop {
&mut self.combining_accent,
);
let window_id = window::WindowId(WindowId);
let event = event::WindowEvent::KeyboardInput {
device_id: Some(event::DeviceId(DeviceId(key.device_id()))),
event: event::KeyEvent {
@ -468,7 +465,7 @@ impl EventLoop {
is_synthetic: false,
};
app.window_event(&self.window_target, window_id, event);
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
},
}
},
@ -731,19 +728,6 @@ impl OwnedDisplayHandle {
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct WindowId;
impl WindowId {
pub const fn into_raw(self) -> u64 {
0
}
pub const fn from_raw(_id: u64) -> Self {
Self
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct DeviceId(i32);
@ -824,8 +808,8 @@ impl rwh_06::HasWindowHandle for Window {
}
impl CoreWindow for Window {
fn id(&self) -> window::WindowId {
window::WindowId(WindowId)
fn id(&self) -> WindowId {
GLOBAL_WINDOW
}
fn primary_monitor(&self) -> Option<RootMonitorHandle> {

View file

@ -10,12 +10,12 @@ use objc2_foundation::{MainThreadMarker, NSNotification};
use super::super::event_handler::EventHandler;
use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo};
use super::menu;
use super::observer::{EventLoopWaker, RunLoop};
use super::{menu, WindowId};
use crate::application::ApplicationHandler;
use crate::event::{StartCause, WindowEvent};
use crate::event_loop::ControlFlow;
use crate::window::WindowId as RootWindowId;
use crate::window::WindowId;
#[derive(Debug)]
pub(super) struct AppState {
@ -245,7 +245,7 @@ impl AppState {
// -> Don't go back into the event handler when our callstack originates from there
if !self.event_handler.in_use() {
self.with_handler(|app, event_loop| {
app.window_event(event_loop, RootWindowId(window_id), WindowEvent::RedrawRequested);
app.window_event(event_loop, window_id, WindowEvent::RedrawRequested);
});
// `pump_events` will request to stop immediately _after_ dispatching RedrawRequested
@ -357,7 +357,7 @@ impl AppState {
let redraw = mem::take(&mut *self.pending_redraw.borrow_mut());
for window_id in redraw {
self.with_handler(|app, event_loop| {
app.window_event(event_loop, RootWindowId(window_id), WindowEvent::RedrawRequested);
app.window_event(event_loop, window_id, WindowEvent::RedrawRequested);
});
}
self.with_handler(|app, event_loop| {

View file

@ -21,7 +21,7 @@ pub(crate) use self::event_loop::{
PlatformSpecificEventLoopAttributes,
};
pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle};
pub(crate) use self::window::{Window, WindowId};
pub(crate) use self::window::Window;
pub(crate) use self::window_delegate::PlatformSpecificWindowAttributes;
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource;
pub(crate) use crate::icon::NoIcon as PlatformIcon;

View file

@ -31,7 +31,6 @@ use crate::event::{
};
use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey};
use crate::platform::macos::OptionAsAlt;
use crate::window::WindowId as RootWindowId;
#[derive(Debug)]
struct CursorState {
@ -842,7 +841,7 @@ impl WinitView {
}
fn queue_event(&self, event: WindowEvent) {
let window_id = RootWindowId(self.window().id());
let window_id = self.window().id();
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| {
app.window_event(event_loop, window_id, event);
});

View file

@ -12,7 +12,7 @@ use crate::error::RequestError;
use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::window::{
Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow,
WindowAttributes, WindowButtons, WindowLevel,
WindowAttributes, WindowButtons, WindowId, WindowLevel,
};
pub(crate) struct Window {
@ -92,7 +92,7 @@ impl rwh_06::HasWindowHandle for Window {
impl CoreWindow for Window {
fn id(&self) -> crate::window::WindowId {
self.maybe_wait_on_main(|delegate| crate::window::WindowId(delegate.id()))
self.maybe_wait_on_main(|delegate| delegate.id())
}
fn scale_factor(&self) -> f64 {
@ -335,19 +335,6 @@ impl CoreWindow for Window {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(pub usize);
impl WindowId {
pub const fn into_raw(self) -> u64 {
self.0 as u64
}
pub const fn from_raw(id: u64) -> Self {
Self(id as usize)
}
}
declare_class!(
#[derive(Debug)]
pub struct WinitWindow;
@ -378,6 +365,6 @@ declare_class!(
impl WinitWindow {
pub(super) fn id(&self) -> WindowId {
WindowId(self as *const Self as usize)
WindowId::from_raw(self as *const Self as usize)
}
}

View file

@ -33,14 +33,14 @@ use super::monitor::{self, flip_window_screen_coordinates, get_display_id};
use super::observer::RunLoop;
use super::view::WinitView;
use super::window::WinitWindow;
use super::{ffi, Fullscreen, MonitorHandle, WindowId};
use super::{ffi, Fullscreen, MonitorHandle};
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{NotSupportedError, RequestError};
use crate::event::{SurfaceSizeWriter, WindowEvent};
use crate::platform::macos::{OptionAsAlt, WindowExtMacOS};
use crate::window::{
Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
WindowAttributes, WindowButtons, WindowId as RootWindowId, WindowLevel,
WindowAttributes, WindowButtons, WindowId, WindowLevel,
};
#[derive(Clone, Debug, PartialEq)]
@ -819,7 +819,7 @@ impl WindowDelegate {
}
pub(crate) fn queue_event(&self, event: WindowEvent) {
let window_id = RootWindowId(self.window().id());
let window_id = self.window().id();
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| {
app.window_event(event_loop, window_id, event);
});

View file

@ -29,7 +29,6 @@ use crate::application::ApplicationHandler;
use crate::dpi::PhysicalSize;
use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
use crate::event_loop::ControlFlow;
use crate::window::WindowId as RootWindowId;
macro_rules! bug {
($($msg:tt)*) => {
@ -599,7 +598,7 @@ pub(crate) fn send_occluded_event_for_all_windows(application: &UIApplication, o
&*ptr
};
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
window_id: window.id(),
event: WindowEvent::Occluded(occluded),
}));
}
@ -626,7 +625,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,
})
})
@ -655,7 +654,7 @@ pub(crate) fn terminated(application: &UIApplication) {
&*ptr
};
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
window_id: window.id(),
event: WindowEvent::Destroyed,
}));
}
@ -673,7 +672,7 @@ fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) {
let ScaleFactorChanged { suggested_size, scale_factor, window } = event;
let new_surface_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,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),

View file

@ -14,7 +14,7 @@ pub(crate) use self::event_loop::{
PlatformSpecificEventLoopAttributes,
};
pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle};
pub(crate) use self::window::{PlatformSpecificWindowAttributes, Window, WindowId};
pub(crate) use self::window::{PlatformSpecificWindowAttributes, Window};
pub(crate) use crate::cursor::{
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
};

View file

@ -22,7 +22,7 @@ use crate::event::{
};
use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKeyCode, PhysicalKey};
use crate::platform_impl::KeyEventExtra;
use crate::window::{WindowAttributes, WindowId as RootWindowId};
use crate::window::WindowAttributes;
pub struct WinitViewState {
pinch_gesture_recognizer: RefCell<Option<Retained<UIPinchGestureRecognizer>>>,
@ -58,7 +58,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,
}),
);
@ -93,7 +93,7 @@ declare_class!(
app_state::handle_nonuser_event(
mtm,
EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
window_id: window.id(),
event: WindowEvent::SurfaceResized(size),
}),
);
@ -132,7 +132,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(
@ -197,7 +197,7 @@ declare_class!(
};
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
window_id: window.id(),
event: WindowEvent::PinchGesture {
device_id: None,
delta: delta as f64,
@ -215,7 +215,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: None,
},
@ -257,7 +257,7 @@ declare_class!(
// Make delta negative to match macos, convert to degrees
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
window_id: window.id(),
event: WindowEvent::RotationGesture {
device_id: None,
delta: -delta.to_degrees() as _,
@ -308,7 +308,7 @@ declare_class!(
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
window_id: window.id(),
event: WindowEvent::PanGesture {
device_id: None,
delta: PhysicalPosition::new(dx as _, dy as _),
@ -512,7 +512,7 @@ impl WinitView {
scale_factor as f64,
)
};
let window_id = RootWindowId(window.id());
let window_id = window.id();
let finger_id = RootFingerId(FingerId(touch_id));
match phase {
@ -597,7 +597,7 @@ impl WinitView {
fn handle_insert_text(&self, text: &NSString) {
let window = self.window().unwrap();
let window_id = RootWindowId(window.id());
let window_id = window.id();
let mtm = MainThreadMarker::new().unwrap();
// send individual events for each character
app_state::handle_nonuser_events(
@ -635,7 +635,7 @@ impl WinitView {
fn handle_delete_backward(&self) {
let window = self.window().unwrap();
let window_id = RootWindowId(window.id());
let window_id = window.id();
let mtm = MainThreadMarker::new().unwrap();
app_state::handle_nonuser_events(
mtm,

View file

@ -26,7 +26,7 @@ use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations};
use crate::window::{
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
WindowAttributes, WindowButtons, WindowId as CoreWindowId, WindowLevel,
WindowAttributes, WindowButtons, WindowId, WindowLevel,
};
declare_class!(
@ -49,7 +49,7 @@ declare_class!(
app_state::handle_nonuser_event(
mtm,
EventWrapper::StaticEvent(Event::WindowEvent {
window_id: CoreWindowId(self.id()),
window_id: self.id(),
event: WindowEvent::Focused(true),
}),
);
@ -62,7 +62,7 @@ declare_class!(
app_state::handle_nonuser_event(
mtm,
EventWrapper::StaticEvent(Event::WindowEvent {
window_id: CoreWindowId(self.id()),
window_id: self.id(),
event: WindowEvent::Focused(false),
}),
);
@ -105,7 +105,7 @@ impl WinitUIWindow {
}
pub(crate) fn id(&self) -> WindowId {
WindowId::from_window(self)
WindowId::from_raw(self as *const Self as usize)
}
}
@ -522,7 +522,6 @@ impl Window {
width: screen_frame.size.width as f64,
height: screen_frame.size.height as f64,
};
let window_id = CoreWindowId(window.id());
app_state::handle_nonuser_events(
mtm,
std::iter::once(EventWrapper::ScaleFactorChanged(app_state::ScaleFactorChanged {
@ -532,7 +531,7 @@ impl Window {
}))
.chain(std::iter::once(EventWrapper::StaticEvent(
Event::WindowEvent {
window_id,
window_id: window.id(),
event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)),
},
))),
@ -586,7 +585,7 @@ impl rwh_06::HasWindowHandle for Window {
impl CoreWindow for Window {
fn id(&self) -> crate::window::WindowId {
self.maybe_wait_on_main(|delegate| crate::window::WindowId(delegate.id()))
self.maybe_wait_on_main(|delegate| delegate.id())
}
fn scale_factor(&self) -> f64 {
@ -940,23 +939,6 @@ impl Inner {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(usize);
impl WindowId {
pub const fn into_raw(self) -> u64 {
self.0 as _
}
pub const fn from_raw(id: u64) -> Self {
Self(id as _)
}
fn from_window(window: &UIWindow) -> Self {
Self(window as *const UIWindow as usize)
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct PlatformSpecificWindowAttributes {
pub scale_factor: Option<f64>,

View file

@ -107,19 +107,6 @@ impl Default for PlatformSpecificWindowAttributes {
pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported>>> =
Lazy::new(|| Mutex::new(XConnection::new(Some(x_error_callback)).map(Arc::new)));
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(u64);
impl WindowId {
pub const fn into_raw(self) -> u64 {
self.0
}
pub const fn from_raw(id: u64) -> Self {
Self(id)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DeviceId {
#[cfg(x11_platform)]

View file

@ -312,13 +312,12 @@ impl EventLoop {
let old_physical_size = physical_size;
let new_surface_size = Arc::new(Mutex::new(physical_size));
let root_window_id = crate::window::WindowId(window_id);
let event = WindowEvent::ScaleFactorChanged {
scale_factor,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
};
app.window_event(&self.active_event_loop, root_window_id, event);
app.window_event(&self.active_event_loop, window_id, event);
let physical_size = *new_surface_size.lock().unwrap();
drop(new_surface_size);
@ -361,13 +360,11 @@ impl EventLoop {
size
});
let window_id = crate::window::WindowId(window_id);
let event = WindowEvent::SurfaceResized(physical_size);
app.window_event(&self.active_event_loop, window_id, event);
}
if compositor_update.close_window {
let window_id = crate::window::WindowId(window_id);
app.window_event(&self.active_event_loop, window_id, WindowEvent::CloseRequested);
}
}
@ -437,8 +434,7 @@ impl EventLoop {
});
if let Some(event) = event {
let window_id = crate::window::WindowId(*window_id);
app.window_event(&self.active_event_loop, window_id, event);
app.window_event(&self.active_event_loop, *window_id, event);
}
}

View file

@ -2,9 +2,8 @@
use std::vec::Drain;
use super::WindowId;
use crate::event::{DeviceEvent, Event, WindowEvent};
use crate::window::WindowId as RootWindowId;
use crate::window::WindowId;
/// An event loop's sink to deliver events from the Wayland event callbacks
/// to the winit's user.
@ -33,7 +32,7 @@ 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]

View file

@ -8,7 +8,7 @@ pub use window::Window;
pub(super) use crate::cursor::OnlyCursorImage as CustomCursor;
use crate::dpi::{LogicalSize, PhysicalSize};
pub use crate::platform_impl::platform::WindowId;
use crate::window::WindowId;
mod event_loop;
mod output;
@ -34,7 +34,7 @@ impl FingerId {
/// Get the WindowId out of the surface.
#[inline]
fn make_wid(surface: &WlSurface) -> WindowId {
WindowId(surface.id().as_ptr() as u64)
WindowId::from_raw(surface.id().as_ptr() as usize)
}
/// The default routine does floor, but we need round on Wayland.

View file

@ -14,8 +14,7 @@ use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::
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,

View file

@ -16,7 +16,7 @@ use super::event_loop::sink::EventSink;
use super::output::MonitorHandle;
use super::state::WinitState;
use super::types::xdg_activation::XdgActivationTokenData;
use super::{ActiveEventLoop, WindowId};
use super::ActiveEventLoop;
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{NotSupportedError, RequestError};
use crate::event::{Ime, WindowEvent};
@ -25,8 +25,8 @@ use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle};
use crate::window::{
Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons,
WindowId as CoreWindowId, WindowLevel,
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId,
WindowLevel,
};
pub(crate) mod state;
@ -273,8 +273,8 @@ impl rwh_06::HasDisplayHandle for Window {
}
impl CoreWindow for Window {
fn id(&self) -> CoreWindowId {
CoreWindowId(self.window_id)
fn id(&self) -> WindowId {
self.window_id
}
fn request_redraw(&self) {

View file

@ -38,8 +38,8 @@ use crate::platform_impl::wayland::seat::{
use crate::platform_impl::wayland::state::{WindowCompositorUpdate, WinitState};
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};
#[cfg(feature = "sctk-adwaita")]
pub type WinitFrame = sctk_adwaita::AdwaitaFrame<WinitState>;

View file

@ -329,7 +329,7 @@ impl EventProcessor {
F: Fn(&Arc<UnownedWindow>) -> Ret,
{
let mut deleted = false;
let window_id = WindowId(window_id as _);
let window_id = WindowId::from_raw(window_id as _);
let result = self
.target
.windows
@ -798,7 +798,7 @@ impl EventProcessor {
// In the event that the window's been destroyed without being dropped first, we
// cleanup again here.
self.target.windows.borrow_mut().remove(&WindowId(window as _));
self.target.windows.borrow_mut().remove(&WindowId::from_raw(window as _));
// Since all XIM stuff needs to happen from the same thread, we destroy the input
// context here instead of when dropping the window.

View file

@ -31,12 +31,12 @@ use crate::event_loop::{
};
use crate::platform::pump_events::PumpStatus;
use crate::platform_impl::common::xkb::Context;
use crate::platform_impl::platform::{min_timeout, WindowId};
use crate::platform_impl::platform::min_timeout;
use crate::platform_impl::x11::window::Window;
use crate::platform_impl::{OwnedDisplayHandle, PlatformCustomCursor};
use crate::window::{
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
WindowAttributes,
WindowAttributes, WindowId,
};
mod activation;
@ -521,13 +521,14 @@ impl EventLoop {
// Empty activation tokens.
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| {
window.generate_activation_token()
});
let token = self
.event_processor
.with_window(window_id.into_raw() as xproto::Window, |window| {
window.generate_activation_token()
});
match token {
Some(Ok(token)) => {
let window_id = crate::window::WindowId(window_id);
let event = WindowEvent::ActivationTokenDone {
serial,
token: crate::window::ActivationToken::_new(token),
@ -555,7 +556,6 @@ impl EventLoop {
}
for window_id in windows {
let window_id = crate::window::WindowId(window_id);
app.window_event(
&self.event_processor.target,
window_id,
@ -574,12 +574,9 @@ impl EventLoop {
while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } {
let mut xev = unsafe { xev.assume_init() };
self.event_processor.process_event(&mut xev, |window_target, event: Event| {
if let Event::WindowEvent {
window_id: crate::window::WindowId(wid),
event: WindowEvent::RedrawRequested,
} = event
if let Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } = event
{
window_target.redraw_sender.send(wid);
window_target.redraw_sender.send(window_id);
} else {
match event {
Event::WindowEvent { window_id, event } => {
@ -994,7 +991,7 @@ impl<'a, E: fmt::Debug> CookieResultExt for Result<VoidCookie<'a>, E> {
}
fn mkwid(w: xproto::Window) -> crate::window::WindowId {
crate::window::WindowId(crate::platform_impl::platform::WindowId(w as _))
crate::window::WindowId::from_raw(w as _)
}
fn mkdid(w: xinput::DeviceId) -> crate::event::DeviceId {
crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w)))

View file

@ -18,7 +18,7 @@ use x11rb::protocol::{randr, xinput};
use super::util::{self, SelectedCursor};
use super::{
ffi, ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, WindowId, XConnection,
ffi, ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, XConnection,
};
use crate::cursor::{Cursor, CustomCursor as RootCustomCursor};
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
@ -36,7 +36,7 @@ use crate::platform_impl::{
};
use crate::window::{
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
WindowAttributes, WindowButtons, WindowLevel,
WindowAttributes, WindowButtons, WindowId, WindowLevel,
};
pub(crate) struct Window(Arc<UnownedWindow>);
@ -62,8 +62,8 @@ impl Window {
}
impl CoreWindow for Window {
fn id(&self) -> crate::window::WindowId {
crate::window::WindowId(self.0.id())
fn id(&self) -> WindowId {
self.0.id()
}
fn scale_factor(&self) -> f64 {
@ -331,7 +331,9 @@ impl Drop for Window {
window.set_fullscreen(None);
}
if let Ok(c) = xconn.xcb_connection().destroy_window(window.id().0 as xproto::Window) {
if let Ok(c) =
xconn.xcb_connection().destroy_window(window.id().into_raw() as xproto::Window)
{
c.ignore_error();
}
}
@ -1220,11 +1222,10 @@ impl UnownedWindow {
&self.shared_state_lock(),
);
let window_id = crate::window::WindowId(self.id());
let old_surface_size = PhysicalSize::new(width, height);
let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height)));
callback(Event::WindowEvent {
window_id,
window_id: self.id(),
event: WindowEvent::ScaleFactorChanged {
scale_factor: new_monitor.scale_factor,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)),
@ -2134,7 +2135,7 @@ impl UnownedWindow {
#[inline]
pub fn id(&self) -> WindowId {
WindowId(self.xwindow as _)
WindowId::from_raw(self.xwindow as _)
}
pub(super) fn sync_counter_id(&self) -> Option<NonZeroU32> {
@ -2143,7 +2144,7 @@ impl UnownedWindow {
#[inline]
pub fn request_redraw(&self) {
self.redraw_sender.send(WindowId(self.xwindow as _));
self.redraw_sender.send(WindowId::from_raw(self.xwindow as _));
}
#[inline]

View file

@ -13,7 +13,7 @@ use smol_str::SmolStr;
use super::{
KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket,
WindowId, WindowProperties,
WindowProperties,
};
use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, NotSupportedError, RequestError};
@ -25,8 +25,7 @@ use crate::keyboard::{
};
use crate::platform_impl::Window;
use crate::window::{
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
WindowId as RootWindowId,
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, WindowId,
};
fn convert_scancode(scancode: u8) -> (PhysicalKey, Option<NamedKey>) {
@ -362,7 +361,6 @@ impl EventLoop {
key_without_modifiers = logical_key.clone();
}
let window_id = RootWindowId(window_id);
let event = event::WindowEvent::KeyboardInput {
device_id: None,
event: event::KeyEvent {
@ -394,25 +392,21 @@ impl EventLoop {
EventOption::TextInput(TextInputEvent { character }) => {
app.window_event(
window_target,
RootWindowId(window_id),
window_id,
event::WindowEvent::Ime(Ime::Preedit("".into(), None)),
);
app.window_event(
window_target,
RootWindowId(window_id),
window_id,
event::WindowEvent::Ime(Ime::Commit(character.into())),
);
},
EventOption::Mouse(MouseEvent { x, y }) => {
app.window_event(
window_target,
RootWindowId(window_id),
event::WindowEvent::PointerMoved {
device_id: None,
position: (x, y).into(),
source: event::PointerSource::Mouse,
},
);
app.window_event(window_target, window_id, event::WindowEvent::PointerMoved {
device_id: None,
position: (x, y).into(),
source: event::PointerSource::Mouse,
});
},
EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => {
app.device_event(window_target, None, event::DeviceEvent::PointerMotion {
@ -421,54 +415,38 @@ impl EventLoop {
},
EventOption::Button(ButtonEvent { left, middle, right }) => {
while let Some((button, state)) = event_state.mouse(left, middle, right) {
app.window_event(
window_target,
RootWindowId(window_id),
event::WindowEvent::PointerButton {
device_id: None,
state,
position: dpi::PhysicalPosition::default(),
button: button.into(),
},
);
app.window_event(window_target, window_id, event::WindowEvent::PointerButton {
device_id: None,
state,
position: dpi::PhysicalPosition::default(),
button: button.into(),
});
}
},
EventOption::Scroll(ScrollEvent { x, y }) => {
app.window_event(
window_target,
RootWindowId(window_id),
event::WindowEvent::MouseWheel {
device_id: None,
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
phase: event::TouchPhase::Moved,
},
);
app.window_event(window_target, window_id, event::WindowEvent::MouseWheel {
device_id: None,
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
phase: event::TouchPhase::Moved,
});
},
EventOption::Quit(QuitEvent {}) => {
app.window_event(
window_target,
RootWindowId(window_id),
event::WindowEvent::CloseRequested,
);
app.window_event(window_target, window_id, event::WindowEvent::CloseRequested);
},
EventOption::Focus(FocusEvent { focused }) => {
app.window_event(
window_target,
RootWindowId(window_id),
event::WindowEvent::Focused(focused),
);
app.window_event(window_target, window_id, event::WindowEvent::Focused(focused));
},
EventOption::Move(MoveEvent { x, y }) => {
app.window_event(
window_target,
RootWindowId(window_id),
window_id,
event::WindowEvent::Moved((x, y).into()),
);
},
EventOption::Resize(ResizeEvent { width, height }) => {
app.window_event(
window_target,
RootWindowId(window_id),
window_id,
event::WindowEvent::SurfaceResized((width, height).into()),
);
@ -491,7 +469,7 @@ impl EventLoop {
}
};
app.window_event(window_target, RootWindowId(window_id), event);
app.window_event(window_target, window_id, event);
},
other => {
tracing::warn!("unhandled event: {:?}", other);
@ -513,7 +491,7 @@ impl EventLoop {
let mut creates = self.window_target.creates.lock().unwrap();
creates.pop_front()
} {
let window_id = WindowId { fd: window.fd as u64 };
let window_id = WindowId::from_raw(window.fd);
let mut buf: [u8; 4096] = [0; 4096];
let path = window.fpath(&mut buf).expect("failed to read properties");
@ -521,8 +499,6 @@ impl EventLoop {
self.windows.push((window, EventState::default()));
let window_id = RootWindowId(window_id);
// Send resize event on create to indicate first size.
let event = event::WindowEvent::SurfaceResized((properties.w, properties.h).into());
app.window_event(&self.window_target, window_id, event);
@ -537,16 +513,16 @@ impl EventLoop {
let mut destroys = self.window_target.destroys.lock().unwrap();
destroys.pop_front()
} {
let window_id = RootWindowId(destroy_id);
app.window_event(&self.window_target, window_id, event::WindowEvent::Destroyed);
self.windows.retain(|(window, _event_state)| window.fd as u64 != destroy_id.fd);
app.window_event(&self.window_target, destroy_id, event::WindowEvent::Destroyed);
self.windows
.retain(|(window, _event_state)| WindowId::from_raw(window.fd) != 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_raw(window.fd);
let mut event_buf = [0u8; 16 * mem::size_of::<orbclient::Event>()];
let count =
@ -604,7 +580,7 @@ impl EventLoop {
} {
app.window_event(
&self.window_target,
RootWindowId(window_id),
window_id,
event::WindowEvent::RedrawRequested,
);
}

View file

@ -99,21 +99,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 into_raw(self) -> u64 {
self.fd
}
pub const fn from_raw(id: u64) -> Self {
Self { fd: id }
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct DeviceId;

View file

@ -1,12 +1,12 @@
use std::collections::VecDeque;
use std::sync::{Arc, Mutex};
use super::{ActiveEventLoop, MonitorHandle, RedoxSocket, TimeSocket, WindowId, WindowProperties};
use super::{ActiveEventLoop, MonitorHandle, RedoxSocket, TimeSocket, WindowProperties};
use crate::cursor::Cursor;
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{NotSupportedError, RequestError};
use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId as CoreWindowId};
use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId};
// 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
@ -155,8 +155,8 @@ impl Window {
}
impl CoreWindow for Window {
fn id(&self) -> CoreWindowId {
CoreWindowId(WindowId { fd: self.window_socket.fd as u64 })
fn id(&self) -> WindowId {
WindowId::from_raw(self.window_socket.fd)
}
#[inline]
@ -181,7 +181,7 @@ impl CoreWindow for Window {
#[inline]
fn request_redraw(&self) {
let window_id = self.id().0;
let window_id = self.id();
let mut redraws = self.redraws.lock().unwrap();
if !redraws.contains(&window_id) {
redraws.push_back(window_id);
@ -478,7 +478,7 @@ impl Drop for Window {
fn drop(&mut self) {
{
let mut destroys = self.destroys.lock().unwrap();
destroys.push_back(self.id().0);
destroys.push_back(self.id());
}
self.wake_socket.wake().unwrap();

View file

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

View file

@ -49,7 +49,7 @@ struct Execution {
suspended: Cell<bool>,
event_loop_recreation: Cell<bool>,
events: RefCell<VecDeque<EventWrapper>>,
id: Cell<u64>,
id: Cell<usize>,
window: web_sys::Window,
navigator: Navigator,
document: Document,
@ -438,7 +438,7 @@ impl Shared {
// Generate a strictly increasing ID
// This is used to differentiate windows when handling events
pub fn generate_id(&self) -> u64 {
pub fn generate_id(&self) -> usize {
let id = self.0.id.get();
self.0.id.set(id.checked_add(1).expect("exhausted `WindowId`"));

View file

@ -8,7 +8,6 @@ use web_sys::Element;
use super::super::monitor::MonitorPermissionFuture;
use super::super::{lock, KeyEventExtra};
use super::runner::{EventWrapper, WeakShared};
use super::window::WindowId;
use super::{backend, runner, EventLoopProxy};
use crate::error::{NotSupportedError, RequestError};
use crate::event::{
@ -24,9 +23,7 @@ use crate::platform::web::{CustomCursorFuture, PollStrategy, WaitUntilStrategy};
use crate::platform_impl::platform::cursor::CustomCursor;
use crate::platform_impl::platform::r#async::Waker;
use crate::platform_impl::Window;
use crate::window::{
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId as RootWindowId,
};
use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId};
#[derive(Default)]
struct ModifiersShared(Rc<Cell<ModifiersState>>);
@ -68,14 +65,14 @@ impl ActiveEventLoop {
}
pub fn generate_id(&self) -> WindowId {
WindowId(self.runner.generate_id())
WindowId::from_raw(self.runner.generate_id())
}
pub fn create_custom_cursor_async(&self, source: CustomCursorSource) -> CustomCursorFuture {
CustomCursorFuture(CustomCursor::new_async(self, source.inner))
}
pub fn register(&self, canvas: &Rc<backend::Canvas>, id: WindowId) {
pub fn register(&self, canvas: &Rc<backend::Canvas>, window_id: WindowId) {
let canvas_clone = canvas.clone();
canvas.on_touch_start();
@ -89,13 +86,13 @@ impl ActiveEventLoop {
let clear_modifiers = (!modifiers.get().is_empty()).then(|| {
modifiers.set(ModifiersState::empty());
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(ModifiersState::empty().into()),
}
});
runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::Focused(false),
})));
});
@ -105,7 +102,7 @@ impl ActiveEventLoop {
canvas.on_focus(move || {
if !has_focus.replace(true) {
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::Focused(true),
});
}
@ -124,10 +121,8 @@ impl ActiveEventLoop {
if focused {
canvas.has_focus.set(true);
self.runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::Focused(true),
})
self.runner
.send_event(Event::WindowEvent { window_id, event: WindowEvent::Focused(true) })
}
let runner = self.runner.clone();
@ -137,14 +132,14 @@ impl ActiveEventLoop {
let modifiers_changed = (modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
runner.send_events(
iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::KeyboardInput {
device_id: None,
event: KeyEvent {
@ -171,14 +166,14 @@ impl ActiveEventLoop {
let modifiers_changed = (modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
runner.send_events(
iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::KeyboardInput {
device_id: None,
event: KeyEvent {
@ -208,13 +203,13 @@ impl ActiveEventLoop {
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::PointerLeft {
device_id: device_id.map(RootDeviceId),
position: Some(position),
@ -233,13 +228,13 @@ impl ActiveEventLoop {
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::PointerEntered {
device_id: device_id.map(RootDeviceId),
position,
@ -263,13 +258,13 @@ impl ActiveEventLoop {
.then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
modifiers.into_iter().chain(iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::PointerMoved { device_id, position, source },
}))
}));
@ -285,7 +280,7 @@ impl ActiveEventLoop {
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
@ -293,7 +288,7 @@ impl ActiveEventLoop {
let device_id = device_id.map(RootDeviceId);
runner.send_events(modifiers.into_iter().chain([Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::PointerButton { device_id, state, position, button },
}]));
}
@ -308,14 +303,14 @@ impl ActiveEventLoop {
let modifiers = (modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
let device_id = pointer_id.map(RootDeviceId);
runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::PointerButton {
device_id,
state: ElementState::Pressed,
@ -336,7 +331,7 @@ impl ActiveEventLoop {
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
}
});
@ -344,7 +339,7 @@ impl ActiveEventLoop {
let device_id = pointer_id.map(RootDeviceId);
runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::PointerButton {
device_id,
state: ElementState::Released,
@ -362,14 +357,14 @@ impl ActiveEventLoop {
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
window_id: RootWindowId(id),
window_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,
event: WindowEvent::MouseWheel {
device_id: None,
delta,
@ -383,7 +378,7 @@ impl ActiveEventLoop {
canvas.on_dark_mode(move |is_dark_mode| {
let theme = if is_dark_mode { Theme::Dark } else { Theme::Light };
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::ThemeChanged(theme),
});
});
@ -410,7 +405,7 @@ impl ActiveEventLoop {
if canvas.old_size() != new_size {
canvas.set_old_size(new_size);
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::SurfaceResized(new_size),
});
canvas.request_animation_frame();
@ -426,7 +421,7 @@ impl ActiveEventLoop {
&& !(is_intersecting && canvas_clone.is_intersecting.get().is_none())
{
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
window_id,
event: WindowEvent::Occluded(!is_intersecting),
});
}
@ -435,7 +430,7 @@ impl ActiveEventLoop {
});
let runner = self.runner.clone();
canvas.on_animation_frame(move || runner.request_redraw(RootWindowId(id)));
canvas.on_animation_frame(move || runner.request_redraw(window_id));
canvas.on_context_menu();
}

View file

@ -48,5 +48,5 @@ pub(crate) use self::monitor::{
VideoModeHandle,
};
use self::web_sys as backend;
pub use self::window::{PlatformSpecificWindowAttributes, Window, WindowId};
pub use self::window::{PlatformSpecificWindowAttributes, Window};
pub(crate) use crate::icon::NoIcon as PlatformIcon;

View file

@ -14,7 +14,6 @@ use web_sys::{
use super::super::cursor::CursorHandler;
use super::super::event::DeviceId;
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;
@ -28,7 +27,7 @@ use crate::event::{
};
use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey};
use crate::platform_impl::Fullscreen;
use crate::window::{WindowAttributes, WindowId as RootWindowId};
use crate::window::{WindowAttributes, WindowId};
#[allow(dead_code)]
pub struct Canvas {
@ -490,7 +489,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,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_size)),
@ -518,7 +517,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::SurfaceResized(new_size),
})
}

View file

@ -14,7 +14,7 @@ use crate::icon::Icon;
use crate::monitor::MonitorHandle as RootMonitorHandle;
use crate::window::{
Cursor, CursorGrabMode, Fullscreen as RootFullscreen, ImePurpose, ResizeDirection, Theme,
UserAttentionType, Window as RootWindow, WindowAttributes, WindowButtons, WindowId as RootWI,
UserAttentionType, Window as RootWindow, WindowAttributes, WindowButtons, WindowId,
WindowLevel,
};
@ -53,7 +53,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);
target.runner.add_canvas(RootWI(id), canvas, runner);
target.runner.add_canvas(id, canvas, runner);
Ok(Window { inner: dispatcher })
}
@ -91,8 +91,8 @@ impl Window {
}
impl RootWindow for Window {
fn id(&self) -> RootWI {
RootWI(self.inner.queue(|inner| inner.id))
fn id(&self) -> WindowId {
self.inner.queue(|inner| inner.id)
}
fn scale_factor(&self) -> f64 {
@ -429,19 +429,6 @@ impl Drop for Inner {
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(pub(crate) u64);
impl WindowId {
pub const fn into_raw(self) -> u64 {
self.0
}
pub const fn from_raw(id: u64) -> Self {
Self(id)
}
}
#[derive(Clone, Debug)]
pub struct PlatformSpecificWindowAttributes {
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,

View file

@ -15,8 +15,7 @@ use crate::event::Event;
use crate::platform_impl::platform::definitions::{
IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl,
};
use crate::platform_impl::platform::WindowId;
use crate::window::WindowId as RootWindowId;
use crate::window::WindowId;
#[repr(C)]
pub struct FileDropHandlerData {
@ -86,7 +85,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_raw(drop_handler.window as usize),
event: HoveredFile(filename),
});
})
@ -120,7 +119,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_raw(drop_handler.window as usize),
event: HoveredFileCancelled,
});
}
@ -140,7 +139,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_raw(drop_handler.window as usize),
event: DroppedFile(filename),
});
})

View file

@ -80,14 +80,12 @@ use crate::platform_impl::platform::window::InitData;
use crate::platform_impl::platform::window_state::{
CursorFlags, ImeState, WindowFlags, WindowState,
};
use crate::platform_impl::platform::{
raw_input, util, wrap_device_id, FingerId, Fullscreen, WindowId,
};
use crate::platform_impl::platform::{raw_input, util, wrap_device_id, FingerId, Fullscreen};
use crate::platform_impl::Window;
use crate::utils::Lazy;
use crate::window::{
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
WindowAttributes, WindowId as CoreWindowId,
WindowAttributes, WindowId,
};
pub(crate) struct WindowData {
@ -920,7 +918,7 @@ fn update_modifiers(window: HWND, userdata: &WindowData) {
drop(window_state);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: ModifiersChanged(modifiers.into()),
});
}
@ -932,7 +930,7 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) {
update_modifiers(window, userdata);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: Focused(true),
});
}
@ -942,12 +940,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: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: ModifiersChanged(ModifiersState::empty().into()),
});
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: Focused(false),
});
}
@ -1045,7 +1043,7 @@ unsafe fn public_window_callback_inner(
userdata.key_event_builder.process_message(window, msg, wparam, lparam, &mut result);
for event in events {
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: KeyboardInput {
device_id: None,
event: event.event,
@ -1130,7 +1128,7 @@ unsafe fn public_window_callback_inner(
WM_CLOSE => {
use crate::event::WindowEvent::CloseRequested;
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: CloseRequested,
});
result = ProcResult::Value(0);
@ -1140,7 +1138,7 @@ unsafe fn public_window_callback_inner(
use crate::event::WindowEvent::Destroyed;
unsafe { RevokeDragDrop(window) };
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: Destroyed,
});
result = ProcResult::Value(0);
@ -1161,7 +1159,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: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::RedrawRequested,
});
}
@ -1264,7 +1262,7 @@ unsafe fn public_window_callback_inner(
let physical_position =
unsafe { PhysicalPosition::new((*windowpos).x, (*windowpos).y) };
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: Moved(physical_position),
});
}
@ -1280,7 +1278,7 @@ unsafe fn public_window_callback_inner(
let physical_size = PhysicalSize::new(w, h);
let event = Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: SurfaceResized(physical_size),
};
@ -1395,7 +1393,7 @@ unsafe fn public_window_callback_inner(
userdata.window_state_lock().ime_state = ImeState::Enabled;
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Enabled),
});
}
@ -1415,7 +1413,7 @@ unsafe fn public_window_callback_inner(
if lparam == 0 {
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
});
}
@ -1427,11 +1425,11 @@ unsafe fn public_window_callback_inner(
userdata.window_state_lock().ime_state = ImeState::Enabled;
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
});
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Commit(text)),
});
}
@ -1446,7 +1444,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: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Preedit(text, cursor_range)),
});
}
@ -1469,11 +1467,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: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
});
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Commit(text)),
});
}
@ -1482,7 +1480,7 @@ unsafe fn public_window_callback_inner(
userdata.window_state_lock().ime_state = ImeState::Disabled;
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::Ime(Ime::Disabled),
});
}
@ -1541,7 +1539,7 @@ unsafe fn public_window_callback_inner(
drop(w);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerEntered {
device_id: None,
position,
@ -1566,7 +1564,7 @@ unsafe fn public_window_callback_inner(
drop(w);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerLeft {
device_id: None,
position: Some(position),
@ -1589,7 +1587,7 @@ unsafe fn public_window_callback_inner(
update_modifiers(window, userdata);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerMoved { device_id: None, position, source: PointerSource::Mouse },
});
}
@ -1607,7 +1605,7 @@ unsafe fn public_window_callback_inner(
}
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerLeft { device_id: None, position: None, kind: Mouse },
});
@ -1623,7 +1621,7 @@ unsafe fn public_window_callback_inner(
update_modifiers(window, userdata);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::MouseWheel {
device_id: None,
delta: LineDelta(0.0, value),
@ -1643,7 +1641,7 @@ unsafe fn public_window_callback_inner(
update_modifiers(window, userdata);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::MouseWheel {
device_id: None,
delta: LineDelta(value, 0.0),
@ -1682,7 +1680,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Pressed,
@ -1707,7 +1705,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Released,
@ -1732,7 +1730,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Pressed,
@ -1757,7 +1755,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Released,
@ -1782,7 +1780,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Pressed,
@ -1807,7 +1805,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Released,
@ -1833,7 +1831,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Pressed,
@ -1864,7 +1862,7 @@ unsafe fn public_window_callback_inner(
let position = PhysicalPosition::new(x as f64, y as f64);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: PointerButton {
device_id: None,
state: Released,
@ -1919,7 +1917,7 @@ unsafe fn public_window_callback_inner(
let y = position.y as f64 + (input.y % 100) as f64 / 100f64;
let position = PhysicalPosition::new(x, y);
let window_id = CoreWindowId(WindowId(window));
let window_id = WindowId::from_raw(window as usize);
let finger_id = RootFingerId(FingerId {
id: input.dwID,
primary: util::has_flag(input.dwFlags, TOUCHEVENTF_PRIMARY),
@ -2087,7 +2085,7 @@ unsafe fn public_window_callback_inner(
let y = location.y as f64 + y.fract();
let position = PhysicalPosition::new(x, y);
let window_id = CoreWindowId(WindowId(window));
let window_id = WindowId::from_raw(window as usize);
let finger_id = RootFingerId(FingerId {
id: pointer_info.pointerId,
primary: util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_PRIMARY),
@ -2320,7 +2318,7 @@ unsafe fn public_window_callback_inner(
let new_surface_size = Arc::new(Mutex::new(new_physical_surface_size));
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: ScaleFactorChanged {
scale_factor: new_scale_factor,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
@ -2472,7 +2470,7 @@ unsafe fn public_window_callback_inner(
window_state.current_theme = new_theme;
drop(window_state);
userdata.send_event(Event::WindowEvent {
window_id: CoreWindowId(WindowId(window)),
window_id: WindowId::from_raw(window as usize),
event: ThemeChanged(new_theme),
});
}

View file

@ -53,7 +53,7 @@ pub(crate) enum RunnerState {
enum BufferedEvent {
Event(Event),
ScaleFactorChanged(WindowId, f64, PhysicalSize<u32>),
ScaleFactorChanged(HWND, f64, PhysicalSize<u32>),
}
impl EventLoopRunner {
@ -360,7 +360,7 @@ impl BufferedEvent {
event: WindowEvent::ScaleFactorChanged { scale_factor, surface_size_writer },
window_id,
} => BufferedEvent::ScaleFactorChanged(
window_id,
window_id.into_raw() as HWND,
scale_factor,
*surface_size_writer.new_surface_size.upgrade().unwrap().lock().unwrap(),
),
@ -371,10 +371,10 @@ impl BufferedEvent {
pub fn dispatch_event(self, dispatch: impl FnOnce(Event)) {
match self {
Self::Event(event) => dispatch(event),
Self::ScaleFactorChanged(window_id, scale_factor, new_surface_size) => {
Self::ScaleFactorChanged(window, scale_factor, new_surface_size) => {
let user_new_surface_size = Arc::new(Mutex::new(new_surface_size));
dispatch(Event::WindowEvent {
window_id,
window_id: WindowId::from_raw(window as usize),
event: WindowEvent::ScaleFactorChanged {
scale_factor,
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
@ -388,12 +388,11 @@ impl BufferedEvent {
if surface_size != new_surface_size {
let window_flags = unsafe {
let userdata =
get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData;
let userdata = get_window_long(window, GWL_USERDATA) as *mut WindowData;
(*userdata).window_state_lock().window_flags
};
window_flags.set_size((window_id.0).0, surface_size);
window_flags.set_size(window, surface_size);
}
},
}

View file

@ -101,27 +101,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 fn into_raw(self) -> u64 {
self.0 as u64
}
pub const fn from_raw(id: u64) -> Self {
Self(id as HWND)
}
}
impl From<WindowId> for HWND {
fn from(window_id: WindowId) -> Self {
window_id.0
}
}
#[inline(always)]
const fn get_xbutton_wparam(x: u32) -> u16 {
hiword(x)

View file

@ -66,11 +66,11 @@ use crate::platform_impl::platform::keyboard::KeyEventBuilder;
use crate::platform_impl::platform::window_state::{
CursorFlags, SavedWindow, WindowFlags, WindowState,
};
use crate::platform_impl::platform::{monitor, util, Fullscreen, SelectedCursor, WindowId};
use crate::platform_impl::platform::{monitor, util, Fullscreen, SelectedCursor};
use crate::window::{
CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons,
WindowId as CoreWindowId, WindowLevel,
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId,
WindowLevel,
};
/// The Win32 implementation of the main `Window` object.
@ -696,8 +696,8 @@ impl CoreWindow for Window {
Ok(())
}
fn id(&self) -> CoreWindowId {
CoreWindowId(WindowId(self.hwnd()))
fn id(&self) -> WindowId {
WindowId::from_raw(self.hwnd() as usize)
}
fn set_minimized(&self, minimized: bool) {

View file

@ -11,7 +11,7 @@ use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::RequestError;
pub use crate::icon::{BadIcon, Icon};
use crate::monitor::{MonitorHandle, VideoModeHandle};
use crate::platform_impl::{self, PlatformSpecificWindowAttributes};
use crate::platform_impl::PlatformSpecificWindowAttributes;
use crate::utils::AsAny;
/// Identifier of a window. Unique for each window.
@ -21,21 +21,21 @@ use crate::utils::AsAny;
/// 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(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(pub(crate) platform_impl::WindowId);
pub struct WindowId(usize);
impl WindowId {
/// Convert the `WindowId` into the underlying integer.
///
/// This is useful if you need to pass the ID across an FFI boundary, or store it in an atomic.
pub const fn into_raw(self) -> u64 {
self.0.into_raw()
pub const fn into_raw(self) -> usize {
self.0
}
/// Construct a `WindowId` from the underlying integer.
///
/// This should only be called with integers returned from [`WindowId::into_raw`].
pub const fn from_raw(id: u64) -> Self {
Self(platform_impl::WindowId::from_raw(id))
pub const fn from_raw(id: usize) -> Self {
Self(id)
}
}