mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
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 <dev@notgull.net>
This commit is contained in:
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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.
|
||||
|
||||
@@ -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<RwLock<bool>> = Lazy::new(|| RwLock::new(true));
|
||||
const WINDOW_ID: u64 = 0;
|
||||
|
||||
/// Returns the minimum `Option<Duration>`, taking into account that `None`
|
||||
/// equates to an infinite timeout, not a zero timeout (so can't just use
|
||||
@@ -234,7 +236,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
*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<T: 'static> EventLoop<T> {
|
||||
*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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
);
|
||||
|
||||
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<WindowId> for u64 {
|
||||
fn from(_: WindowId) -> Self {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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<MonitorHandle> {
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.window as u64
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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<f64>,
|
||||
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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())
|
||||
}
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
|
||||
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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<UnownedWindow>) -> 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.
|
||||
|
||||
@@ -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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
}
|
||||
|
||||
for window_id in windows {
|
||||
let window_id = crate::window::WindowId(window_id);
|
||||
callback(
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
@@ -626,7 +625,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
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)))
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ pub(crate) use self::{
|
||||
PlatformSpecificEventLoopAttributes,
|
||||
},
|
||||
monitor::{MonitorHandle, VideoModeHandle},
|
||||
window::WindowId,
|
||||
window_delegate::PlatformSpecificWindowBuilderAttributes,
|
||||
};
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
|
||||
@@ -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<Id<WinitWindow>>,
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0 as u64
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
// 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<T: 'static> EventLoop<T> {
|
||||
}
|
||||
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<T: 'static> EventLoop<T> {
|
||||
}) => {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
}
|
||||
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<T: 'static> EventLoop<T> {
|
||||
}
|
||||
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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
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<T: 'static> EventLoop<T> {
|
||||
// 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<T: 'static> EventLoop<T> {
|
||||
// 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<T: 'static> EventLoop<T> {
|
||||
} {
|
||||
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::<orbclient::Event>()];
|
||||
let count =
|
||||
@@ -594,7 +590,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
} {
|
||||
event_handler(
|
||||
event::Event::WindowEvent {
|
||||
window_id: RootWindowId(window_id),
|
||||
window_id,
|
||||
event: event::WindowEvent::RedrawRequested,
|
||||
},
|
||||
&self.window_target,
|
||||
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(id: WindowId) -> Self {
|
||||
id.fd
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for WindowId {
|
||||
fn from(fd: u64) -> Self {
|
||||
Self { fd }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct DeviceId;
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Cell<ModifiersState>>);
|
||||
@@ -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<RefCell<backend::Canvas>>, 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();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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<SmolStr> {
|
||||
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")),
|
||||
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0 as u64
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for WindowId {
|
||||
fn from(raw_id: u64) -> Self {
|
||||
Self(raw_id as u32)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
|
||||
@@ -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),
|
||||
});
|
||||
})
|
||||
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ impl<T> BufferedEvent<T> {
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0 as u64
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WindowId> for HWND {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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<WindowId> for u64 {
|
||||
fn from(window_id: WindowId) -> Self {
|
||||
window_id.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> 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
|
||||
|
||||
Reference in New Issue
Block a user