mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-24 02:46:33 +11:00
Add WindowId type
This commit is contained in:
parent
9cd0430ec7
commit
b988c174fe
4 changed files with 20 additions and 6 deletions
|
@ -31,7 +31,7 @@ macro_rules! gen_api_transition {
|
|||
for window in windows.iter() {
|
||||
for event in window.poll_events() {
|
||||
callback(::Event::WindowEvent {
|
||||
window_id: &**window as *const Window as usize,
|
||||
window_id: ::WindowId(WindowId(&**window as *const Window as usize)),
|
||||
event: event,
|
||||
})
|
||||
}
|
||||
|
@ -54,6 +54,9 @@ macro_rules! gen_api_transition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct WindowId(usize);
|
||||
|
||||
pub struct Window2 {
|
||||
pub window: ::std::sync::Arc<Window>,
|
||||
events_loop: ::std::sync::Weak<EventsLoop>,
|
||||
|
@ -81,8 +84,8 @@ macro_rules! gen_api_transition {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> usize {
|
||||
&*self.window as *const Window as usize
|
||||
pub fn id(&self) -> WindowId {
|
||||
WindowId(&*self.window as *const Window as usize)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
use WindowId;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Event {
|
||||
WindowEvent {
|
||||
window_id: usize,
|
||||
window_id: WindowId,
|
||||
event: WindowEvent,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,6 +161,15 @@ pub struct Window {
|
|||
window: platform::Window2,
|
||||
}
|
||||
|
||||
/// Identifier of a window. Unique for each window.
|
||||
///
|
||||
/// Can be obtained with `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(platform::WindowId);
|
||||
|
||||
/// Provides a way to retreive events from the windows that were registered to it.
|
||||
// TODO: document usage in multiple threads
|
||||
pub struct EventsLoop {
|
||||
|
|
|
@ -7,6 +7,7 @@ use EventsLoop;
|
|||
use MouseCursor;
|
||||
use Window;
|
||||
use WindowBuilder;
|
||||
use WindowId;
|
||||
use native_monitor::NativeMonitorId;
|
||||
|
||||
use libc;
|
||||
|
@ -293,8 +294,8 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> usize {
|
||||
self.window.id()
|
||||
pub fn id(&self) -> WindowId {
|
||||
WindowId(self.window.id())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue