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:
parent
eccd9e415d
commit
da2268ae22
35 changed files with 226 additions and 379 deletions
|
|
@ -24,7 +24,8 @@ use crate::monitor::MonitorHandle as RootMonitorHandle;
|
||||||
use crate::platform::pump_events::PumpStatus;
|
use crate::platform::pump_events::PumpStatus;
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
self, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, ImePurpose,
|
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;
|
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 {
|
impl EventLoop {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
attributes: &PlatformSpecificEventLoopAttributes,
|
attributes: &PlatformSpecificEventLoopAttributes,
|
||||||
|
|
@ -187,22 +191,19 @@ impl EventLoop {
|
||||||
},
|
},
|
||||||
MainEvent::GainedFocus => {
|
MainEvent::GainedFocus => {
|
||||||
HAS_FOCUS.store(true, Ordering::Relaxed);
|
HAS_FOCUS.store(true, Ordering::Relaxed);
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let event = event::WindowEvent::Focused(true);
|
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 => {
|
MainEvent::LostFocus => {
|
||||||
HAS_FOCUS.store(false, Ordering::Relaxed);
|
HAS_FOCUS.store(false, Ordering::Relaxed);
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let event = event::WindowEvent::Focused(false);
|
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 { .. } => {
|
MainEvent::ConfigChanged { .. } => {
|
||||||
let old_scale_factor = scale_factor(&self.android_app);
|
let old_scale_factor = scale_factor(&self.android_app);
|
||||||
let scale_factor = scale_factor(&self.android_app);
|
let scale_factor = scale_factor(&self.android_app);
|
||||||
if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
|
if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
|
||||||
let new_surface_size = Arc::new(Mutex::new(screen_size(&self.android_app)));
|
let new_surface_size = Arc::new(Mutex::new(screen_size(&self.android_app)));
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let event = event::WindowEvent::ScaleFactorChanged {
|
let event = event::WindowEvent::ScaleFactorChanged {
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
|
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
|
||||||
&new_surface_size,
|
&new_surface_size,
|
||||||
|
|
@ -210,7 +211,7 @@ impl EventLoop {
|
||||||
scale_factor,
|
scale_factor,
|
||||||
};
|
};
|
||||||
|
|
||||||
app.window_event(&self.window_target, window_id, event);
|
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MainEvent::LowMemory => {
|
MainEvent::LowMemory => {
|
||||||
|
|
@ -286,17 +287,15 @@ impl EventLoop {
|
||||||
} else {
|
} else {
|
||||||
PhysicalSize::new(0, 0)
|
PhysicalSize::new(0, 0)
|
||||||
};
|
};
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let event = event::WindowEvent::SurfaceResized(size);
|
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();
|
pending_redraw |= self.redraw_flag.get_and_reset();
|
||||||
if pending_redraw {
|
if pending_redraw {
|
||||||
pending_redraw = false;
|
pending_redraw = false;
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let event = event::WindowEvent::RedrawRequested;
|
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;
|
let mut input_status = InputStatus::Handled;
|
||||||
match event {
|
match event {
|
||||||
InputEvent::MotionEvent(motion_event) => {
|
InputEvent::MotionEvent(motion_event) => {
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let device_id = Some(event::DeviceId(DeviceId(motion_event.device_id())));
|
let device_id = Some(event::DeviceId(DeviceId(motion_event.device_id())));
|
||||||
let action = motion_event.action();
|
let action = motion_event.action();
|
||||||
|
|
||||||
|
|
@ -361,7 +359,7 @@ impl EventLoop {
|
||||||
_ => event::PointerKind::Unknown,
|
_ => 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 {
|
let event = event::WindowEvent::PointerButton {
|
||||||
device_id,
|
device_id,
|
||||||
state: event::ElementState::Pressed,
|
state: event::ElementState::Pressed,
|
||||||
|
|
@ -375,7 +373,7 @@ impl EventLoop {
|
||||||
_ => event::ButtonSource::Unknown(0),
|
_ => event::ButtonSource::Unknown(0),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
app.window_event(&self.window_target, window_id, event);
|
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
|
||||||
},
|
},
|
||||||
MotionAction::Move => {
|
MotionAction::Move => {
|
||||||
let event = event::WindowEvent::PointerMoved {
|
let event = event::WindowEvent::PointerMoved {
|
||||||
|
|
@ -390,7 +388,7 @@ impl EventLoop {
|
||||||
_ => event::PointerSource::Unknown,
|
_ => 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 => {
|
MotionAction::Up | MotionAction::PointerUp | MotionAction::Cancel => {
|
||||||
if let MotionAction::Up | MotionAction::PointerUp = action {
|
if let MotionAction::Up | MotionAction::PointerUp = action {
|
||||||
|
|
@ -407,7 +405,7 @@ impl EventLoop {
|
||||||
_ => event::ButtonSource::Unknown(0),
|
_ => 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 {
|
let event = event::WindowEvent::PointerLeft {
|
||||||
|
|
@ -422,7 +420,7 @@ impl EventLoop {
|
||||||
_ => event::PointerKind::Unknown,
|
_ => event::PointerKind::Unknown,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
app.window_event(&self.window_target, window_id, event);
|
app.window_event(&self.window_target, GLOBAL_WINDOW, event);
|
||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
@ -453,7 +451,6 @@ impl EventLoop {
|
||||||
&mut self.combining_accent,
|
&mut self.combining_accent,
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let event = event::WindowEvent::KeyboardInput {
|
let event = event::WindowEvent::KeyboardInput {
|
||||||
device_id: Some(event::DeviceId(DeviceId(key.device_id()))),
|
device_id: Some(event::DeviceId(DeviceId(key.device_id()))),
|
||||||
event: event::KeyEvent {
|
event: event::KeyEvent {
|
||||||
|
|
@ -468,7 +465,7 @@ impl EventLoop {
|
||||||
is_synthetic: false,
|
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)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct DeviceId(i32);
|
pub struct DeviceId(i32);
|
||||||
|
|
||||||
|
|
@ -824,8 +808,8 @@ impl rwh_06::HasWindowHandle for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoreWindow for Window {
|
impl CoreWindow for Window {
|
||||||
fn id(&self) -> window::WindowId {
|
fn id(&self) -> WindowId {
|
||||||
window::WindowId(WindowId)
|
GLOBAL_WINDOW
|
||||||
}
|
}
|
||||||
|
|
||||||
fn primary_monitor(&self) -> Option<RootMonitorHandle> {
|
fn primary_monitor(&self) -> Option<RootMonitorHandle> {
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ use objc2_foundation::{MainThreadMarker, NSNotification};
|
||||||
|
|
||||||
use super::super::event_handler::EventHandler;
|
use super::super::event_handler::EventHandler;
|
||||||
use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo};
|
use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo};
|
||||||
|
use super::menu;
|
||||||
use super::observer::{EventLoopWaker, RunLoop};
|
use super::observer::{EventLoopWaker, RunLoop};
|
||||||
use super::{menu, WindowId};
|
|
||||||
use crate::application::ApplicationHandler;
|
use crate::application::ApplicationHandler;
|
||||||
use crate::event::{StartCause, WindowEvent};
|
use crate::event::{StartCause, WindowEvent};
|
||||||
use crate::event_loop::ControlFlow;
|
use crate::event_loop::ControlFlow;
|
||||||
use crate::window::WindowId as RootWindowId;
|
use crate::window::WindowId;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct AppState {
|
pub(super) struct AppState {
|
||||||
|
|
@ -245,7 +245,7 @@ impl AppState {
|
||||||
// -> Don't go back into the event handler when our callstack originates from there
|
// -> Don't go back into the event handler when our callstack originates from there
|
||||||
if !self.event_handler.in_use() {
|
if !self.event_handler.in_use() {
|
||||||
self.with_handler(|app, event_loop| {
|
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
|
// `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());
|
let redraw = mem::take(&mut *self.pending_redraw.borrow_mut());
|
||||||
for window_id in redraw {
|
for window_id in redraw {
|
||||||
self.with_handler(|app, event_loop| {
|
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| {
|
self.with_handler(|app, event_loop| {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ pub(crate) use self::event_loop::{
|
||||||
PlatformSpecificEventLoopAttributes,
|
PlatformSpecificEventLoopAttributes,
|
||||||
};
|
};
|
||||||
pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle};
|
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 self::window_delegate::PlatformSpecificWindowAttributes;
|
||||||
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource;
|
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource;
|
||||||
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ use crate::event::{
|
||||||
};
|
};
|
||||||
use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey};
|
use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey};
|
||||||
use crate::platform::macos::OptionAsAlt;
|
use crate::platform::macos::OptionAsAlt;
|
||||||
use crate::window::WindowId as RootWindowId;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct CursorState {
|
struct CursorState {
|
||||||
|
|
@ -842,7 +841,7 @@ impl WinitView {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_event(&self, event: WindowEvent) {
|
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| {
|
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| {
|
||||||
app.window_event(event_loop, window_id, event);
|
app.window_event(event_loop, window_id, event);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::error::RequestError;
|
||||||
use crate::monitor::MonitorHandle as CoreMonitorHandle;
|
use crate::monitor::MonitorHandle as CoreMonitorHandle;
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow,
|
Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow,
|
||||||
WindowAttributes, WindowButtons, WindowLevel,
|
WindowAttributes, WindowButtons, WindowId, WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct Window {
|
pub(crate) struct Window {
|
||||||
|
|
@ -92,7 +92,7 @@ impl rwh_06::HasWindowHandle for Window {
|
||||||
|
|
||||||
impl CoreWindow for Window {
|
impl CoreWindow for Window {
|
||||||
fn id(&self) -> crate::window::WindowId {
|
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 {
|
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!(
|
declare_class!(
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WinitWindow;
|
pub struct WinitWindow;
|
||||||
|
|
@ -378,6 +365,6 @@ declare_class!(
|
||||||
|
|
||||||
impl WinitWindow {
|
impl WinitWindow {
|
||||||
pub(super) fn id(&self) -> WindowId {
|
pub(super) fn id(&self) -> WindowId {
|
||||||
WindowId(self as *const Self as usize)
|
WindowId::from_raw(self as *const Self as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,14 @@ use super::monitor::{self, flip_window_screen_coordinates, get_display_id};
|
||||||
use super::observer::RunLoop;
|
use super::observer::RunLoop;
|
||||||
use super::view::WinitView;
|
use super::view::WinitView;
|
||||||
use super::window::WinitWindow;
|
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::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
|
||||||
use crate::error::{NotSupportedError, RequestError};
|
use crate::error::{NotSupportedError, RequestError};
|
||||||
use crate::event::{SurfaceSizeWriter, WindowEvent};
|
use crate::event::{SurfaceSizeWriter, WindowEvent};
|
||||||
use crate::platform::macos::{OptionAsAlt, WindowExtMacOS};
|
use crate::platform::macos::{OptionAsAlt, WindowExtMacOS};
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
|
||||||
WindowAttributes, WindowButtons, WindowId as RootWindowId, WindowLevel,
|
WindowAttributes, WindowButtons, WindowId, WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
|
@ -819,7 +819,7 @@ impl WindowDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn queue_event(&self, event: WindowEvent) {
|
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| {
|
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| {
|
||||||
app.window_event(event_loop, window_id, event);
|
app.window_event(event_loop, window_id, event);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ use crate::application::ApplicationHandler;
|
||||||
use crate::dpi::PhysicalSize;
|
use crate::dpi::PhysicalSize;
|
||||||
use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
|
use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
|
||||||
use crate::event_loop::ControlFlow;
|
use crate::event_loop::ControlFlow;
|
||||||
use crate::window::WindowId as RootWindowId;
|
|
||||||
|
|
||||||
macro_rules! bug {
|
macro_rules! bug {
|
||||||
($($msg:tt)*) => {
|
($($msg:tt)*) => {
|
||||||
|
|
@ -599,7 +598,7 @@ pub(crate) fn send_occluded_event_for_all_windows(application: &UIApplication, o
|
||||||
&*ptr
|
&*ptr
|
||||||
};
|
};
|
||||||
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
|
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::Occluded(occluded),
|
event: WindowEvent::Occluded(occluded),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -626,7 +625,7 @@ pub fn handle_main_events_cleared(mtm: MainThreadMarker) {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|window| {
|
.map(|window| {
|
||||||
EventWrapper::StaticEvent(Event::WindowEvent {
|
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::RedrawRequested,
|
event: WindowEvent::RedrawRequested,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -655,7 +654,7 @@ pub(crate) fn terminated(application: &UIApplication) {
|
||||||
&*ptr
|
&*ptr
|
||||||
};
|
};
|
||||||
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
|
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::Destroyed,
|
event: WindowEvent::Destroyed,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -673,7 +672,7 @@ fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) {
|
||||||
let ScaleFactorChanged { suggested_size, scale_factor, window } = event;
|
let ScaleFactorChanged { suggested_size, scale_factor, window } = event;
|
||||||
let new_surface_size = Arc::new(Mutex::new(suggested_size));
|
let new_surface_size = Arc::new(Mutex::new(suggested_size));
|
||||||
let event = Event::WindowEvent {
|
let event = Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::ScaleFactorChanged {
|
event: WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor,
|
scale_factor,
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
|
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub(crate) use self::event_loop::{
|
||||||
PlatformSpecificEventLoopAttributes,
|
PlatformSpecificEventLoopAttributes,
|
||||||
};
|
};
|
||||||
pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle};
|
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::{
|
pub(crate) use crate::cursor::{
|
||||||
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
|
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use crate::event::{
|
||||||
};
|
};
|
||||||
use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKeyCode, PhysicalKey};
|
use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKeyCode, PhysicalKey};
|
||||||
use crate::platform_impl::KeyEventExtra;
|
use crate::platform_impl::KeyEventExtra;
|
||||||
use crate::window::{WindowAttributes, WindowId as RootWindowId};
|
use crate::window::WindowAttributes;
|
||||||
|
|
||||||
pub struct WinitViewState {
|
pub struct WinitViewState {
|
||||||
pinch_gesture_recognizer: RefCell<Option<Retained<UIPinchGestureRecognizer>>>,
|
pinch_gesture_recognizer: RefCell<Option<Retained<UIPinchGestureRecognizer>>>,
|
||||||
|
|
@ -58,7 +58,7 @@ declare_class!(
|
||||||
app_state::handle_nonuser_event(
|
app_state::handle_nonuser_event(
|
||||||
mtm,
|
mtm,
|
||||||
EventWrapper::StaticEvent(Event::WindowEvent {
|
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::RedrawRequested,
|
event: WindowEvent::RedrawRequested,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
@ -93,7 +93,7 @@ declare_class!(
|
||||||
app_state::handle_nonuser_event(
|
app_state::handle_nonuser_event(
|
||||||
mtm,
|
mtm,
|
||||||
EventWrapper::StaticEvent(Event::WindowEvent {
|
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::SurfaceResized(size),
|
event: WindowEvent::SurfaceResized(size),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
@ -132,7 +132,7 @@ declare_class!(
|
||||||
width: screen_frame.size.width as f64,
|
width: screen_frame.size.width as f64,
|
||||||
height: screen_frame.size.height 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(
|
app_state::handle_nonuser_events(
|
||||||
mtm,
|
mtm,
|
||||||
std::iter::once(EventWrapper::ScaleFactorChanged(
|
std::iter::once(EventWrapper::ScaleFactorChanged(
|
||||||
|
|
@ -197,7 +197,7 @@ declare_class!(
|
||||||
};
|
};
|
||||||
|
|
||||||
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::PinchGesture {
|
event: WindowEvent::PinchGesture {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
delta: delta as f64,
|
delta: delta as f64,
|
||||||
|
|
@ -215,7 +215,7 @@ declare_class!(
|
||||||
|
|
||||||
if recognizer.state() == UIGestureRecognizerState::Ended {
|
if recognizer.state() == UIGestureRecognizerState::Ended {
|
||||||
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::DoubleTapGesture {
|
event: WindowEvent::DoubleTapGesture {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
},
|
},
|
||||||
|
|
@ -257,7 +257,7 @@ declare_class!(
|
||||||
|
|
||||||
// Make delta negative to match macos, convert to degrees
|
// Make delta negative to match macos, convert to degrees
|
||||||
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::RotationGesture {
|
event: WindowEvent::RotationGesture {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
delta: -delta.to_degrees() as _,
|
delta: -delta.to_degrees() as _,
|
||||||
|
|
@ -308,7 +308,7 @@ declare_class!(
|
||||||
|
|
||||||
|
|
||||||
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.id()),
|
window_id: window.id(),
|
||||||
event: WindowEvent::PanGesture {
|
event: WindowEvent::PanGesture {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
delta: PhysicalPosition::new(dx as _, dy as _),
|
delta: PhysicalPosition::new(dx as _, dy as _),
|
||||||
|
|
@ -512,7 +512,7 @@ impl WinitView {
|
||||||
scale_factor as f64,
|
scale_factor as f64,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let window_id = RootWindowId(window.id());
|
let window_id = window.id();
|
||||||
let finger_id = RootFingerId(FingerId(touch_id));
|
let finger_id = RootFingerId(FingerId(touch_id));
|
||||||
|
|
||||||
match phase {
|
match phase {
|
||||||
|
|
@ -597,7 +597,7 @@ impl WinitView {
|
||||||
|
|
||||||
fn handle_insert_text(&self, text: &NSString) {
|
fn handle_insert_text(&self, text: &NSString) {
|
||||||
let window = self.window().unwrap();
|
let window = self.window().unwrap();
|
||||||
let window_id = RootWindowId(window.id());
|
let window_id = window.id();
|
||||||
let mtm = MainThreadMarker::new().unwrap();
|
let mtm = MainThreadMarker::new().unwrap();
|
||||||
// send individual events for each character
|
// send individual events for each character
|
||||||
app_state::handle_nonuser_events(
|
app_state::handle_nonuser_events(
|
||||||
|
|
@ -635,7 +635,7 @@ impl WinitView {
|
||||||
|
|
||||||
fn handle_delete_backward(&self) {
|
fn handle_delete_backward(&self) {
|
||||||
let window = self.window().unwrap();
|
let window = self.window().unwrap();
|
||||||
let window_id = RootWindowId(window.id());
|
let window_id = window.id();
|
||||||
let mtm = MainThreadMarker::new().unwrap();
|
let mtm = MainThreadMarker::new().unwrap();
|
||||||
app_state::handle_nonuser_events(
|
app_state::handle_nonuser_events(
|
||||||
mtm,
|
mtm,
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ use crate::monitor::MonitorHandle as CoreMonitorHandle;
|
||||||
use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations};
|
use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations};
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
|
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
|
||||||
WindowAttributes, WindowButtons, WindowId as CoreWindowId, WindowLevel,
|
WindowAttributes, WindowButtons, WindowId, WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
declare_class!(
|
declare_class!(
|
||||||
|
|
@ -49,7 +49,7 @@ declare_class!(
|
||||||
app_state::handle_nonuser_event(
|
app_state::handle_nonuser_event(
|
||||||
mtm,
|
mtm,
|
||||||
EventWrapper::StaticEvent(Event::WindowEvent {
|
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(self.id()),
|
window_id: self.id(),
|
||||||
event: WindowEvent::Focused(true),
|
event: WindowEvent::Focused(true),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
@ -62,7 +62,7 @@ declare_class!(
|
||||||
app_state::handle_nonuser_event(
|
app_state::handle_nonuser_event(
|
||||||
mtm,
|
mtm,
|
||||||
EventWrapper::StaticEvent(Event::WindowEvent {
|
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(self.id()),
|
window_id: self.id(),
|
||||||
event: WindowEvent::Focused(false),
|
event: WindowEvent::Focused(false),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
@ -105,7 +105,7 @@ impl WinitUIWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn id(&self) -> WindowId {
|
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,
|
width: screen_frame.size.width as f64,
|
||||||
height: screen_frame.size.height as f64,
|
height: screen_frame.size.height as f64,
|
||||||
};
|
};
|
||||||
let window_id = CoreWindowId(window.id());
|
|
||||||
app_state::handle_nonuser_events(
|
app_state::handle_nonuser_events(
|
||||||
mtm,
|
mtm,
|
||||||
std::iter::once(EventWrapper::ScaleFactorChanged(app_state::ScaleFactorChanged {
|
std::iter::once(EventWrapper::ScaleFactorChanged(app_state::ScaleFactorChanged {
|
||||||
|
|
@ -532,7 +531,7 @@ impl Window {
|
||||||
}))
|
}))
|
||||||
.chain(std::iter::once(EventWrapper::StaticEvent(
|
.chain(std::iter::once(EventWrapper::StaticEvent(
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id,
|
window_id: window.id(),
|
||||||
event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)),
|
event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)),
|
||||||
},
|
},
|
||||||
))),
|
))),
|
||||||
|
|
@ -586,7 +585,7 @@ impl rwh_06::HasWindowHandle for Window {
|
||||||
|
|
||||||
impl CoreWindow for Window {
|
impl CoreWindow for Window {
|
||||||
fn id(&self) -> crate::window::WindowId {
|
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 {
|
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)]
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
pub struct PlatformSpecificWindowAttributes {
|
pub struct PlatformSpecificWindowAttributes {
|
||||||
pub scale_factor: Option<f64>,
|
pub scale_factor: Option<f64>,
|
||||||
|
|
|
||||||
|
|
@ -107,19 +107,6 @@ impl Default for PlatformSpecificWindowAttributes {
|
||||||
pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported>>> =
|
pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported>>> =
|
||||||
Lazy::new(|| Mutex::new(XConnection::new(Some(x_error_callback)).map(Arc::new)));
|
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)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum DeviceId {
|
pub enum DeviceId {
|
||||||
#[cfg(x11_platform)]
|
#[cfg(x11_platform)]
|
||||||
|
|
|
||||||
|
|
@ -312,13 +312,12 @@ impl EventLoop {
|
||||||
let old_physical_size = physical_size;
|
let old_physical_size = physical_size;
|
||||||
|
|
||||||
let new_surface_size = Arc::new(Mutex::new(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 {
|
let event = WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor,
|
scale_factor,
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
|
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();
|
let physical_size = *new_surface_size.lock().unwrap();
|
||||||
drop(new_surface_size);
|
drop(new_surface_size);
|
||||||
|
|
@ -361,13 +360,11 @@ impl EventLoop {
|
||||||
size
|
size
|
||||||
});
|
});
|
||||||
|
|
||||||
let window_id = crate::window::WindowId(window_id);
|
|
||||||
let event = WindowEvent::SurfaceResized(physical_size);
|
let event = WindowEvent::SurfaceResized(physical_size);
|
||||||
app.window_event(&self.active_event_loop, window_id, event);
|
app.window_event(&self.active_event_loop, window_id, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if compositor_update.close_window {
|
if compositor_update.close_window {
|
||||||
let window_id = crate::window::WindowId(window_id);
|
|
||||||
app.window_event(&self.active_event_loop, window_id, WindowEvent::CloseRequested);
|
app.window_event(&self.active_event_loop, window_id, WindowEvent::CloseRequested);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -437,8 +434,7 @@ impl EventLoop {
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(event) = event {
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
use std::vec::Drain;
|
use std::vec::Drain;
|
||||||
|
|
||||||
use super::WindowId;
|
|
||||||
use crate::event::{DeviceEvent, Event, WindowEvent};
|
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
|
/// An event loop's sink to deliver events from the Wayland event callbacks
|
||||||
/// to the winit's user.
|
/// to the winit's user.
|
||||||
|
|
@ -33,7 +32,7 @@ impl EventSink {
|
||||||
/// Add new window event to a queue.
|
/// Add new window event to a queue.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn push_window_event(&mut self, event: WindowEvent, window_id: WindowId) {
|
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]
|
#[inline]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub use window::Window;
|
||||||
|
|
||||||
pub(super) use crate::cursor::OnlyCursorImage as CustomCursor;
|
pub(super) use crate::cursor::OnlyCursorImage as CustomCursor;
|
||||||
use crate::dpi::{LogicalSize, PhysicalSize};
|
use crate::dpi::{LogicalSize, PhysicalSize};
|
||||||
pub use crate::platform_impl::platform::WindowId;
|
use crate::window::WindowId;
|
||||||
|
|
||||||
mod event_loop;
|
mod event_loop;
|
||||||
mod output;
|
mod output;
|
||||||
|
|
@ -34,7 +34,7 @@ impl FingerId {
|
||||||
/// Get the WindowId out of the surface.
|
/// Get the WindowId out of the surface.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn make_wid(surface: &WlSurface) -> WindowId {
|
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.
|
/// The default routine does floor, but we need round on Wayland.
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,7 @@ use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::
|
||||||
|
|
||||||
use crate::event_loop::AsyncRequestSerial;
|
use crate::event_loop::AsyncRequestSerial;
|
||||||
use crate::platform_impl::wayland::state::WinitState;
|
use crate::platform_impl::wayland::state::WinitState;
|
||||||
use crate::platform_impl::WindowId;
|
use crate::window::{ActivationToken, WindowId};
|
||||||
use crate::window::ActivationToken;
|
|
||||||
|
|
||||||
pub struct XdgActivationState {
|
pub struct XdgActivationState {
|
||||||
xdg_activation: XdgActivationV1,
|
xdg_activation: XdgActivationV1,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use super::event_loop::sink::EventSink;
|
||||||
use super::output::MonitorHandle;
|
use super::output::MonitorHandle;
|
||||||
use super::state::WinitState;
|
use super::state::WinitState;
|
||||||
use super::types::xdg_activation::XdgActivationTokenData;
|
use super::types::xdg_activation::XdgActivationTokenData;
|
||||||
use super::{ActiveEventLoop, WindowId};
|
use super::ActiveEventLoop;
|
||||||
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
|
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
|
||||||
use crate::error::{NotSupportedError, RequestError};
|
use crate::error::{NotSupportedError, RequestError};
|
||||||
use crate::event::{Ime, WindowEvent};
|
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::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle};
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
|
Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
|
||||||
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons,
|
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId,
|
||||||
WindowId as CoreWindowId, WindowLevel,
|
WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) mod state;
|
pub(crate) mod state;
|
||||||
|
|
@ -273,8 +273,8 @@ impl rwh_06::HasDisplayHandle for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoreWindow for Window {
|
impl CoreWindow for Window {
|
||||||
fn id(&self) -> CoreWindowId {
|
fn id(&self) -> WindowId {
|
||||||
CoreWindowId(self.window_id)
|
self.window_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_redraw(&self) {
|
fn request_redraw(&self) {
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ use crate::platform_impl::wayland::seat::{
|
||||||
use crate::platform_impl::wayland::state::{WindowCompositorUpdate, WinitState};
|
use crate::platform_impl::wayland::state::{WindowCompositorUpdate, WinitState};
|
||||||
use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor};
|
use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor};
|
||||||
use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager;
|
use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager;
|
||||||
use crate::platform_impl::{PlatformCustomCursor, WindowId};
|
use crate::platform_impl::PlatformCustomCursor;
|
||||||
use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme};
|
use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, WindowId};
|
||||||
|
|
||||||
#[cfg(feature = "sctk-adwaita")]
|
#[cfg(feature = "sctk-adwaita")]
|
||||||
pub type WinitFrame = sctk_adwaita::AdwaitaFrame<WinitState>;
|
pub type WinitFrame = sctk_adwaita::AdwaitaFrame<WinitState>;
|
||||||
|
|
|
||||||
|
|
@ -329,7 +329,7 @@ impl EventProcessor {
|
||||||
F: Fn(&Arc<UnownedWindow>) -> Ret,
|
F: Fn(&Arc<UnownedWindow>) -> Ret,
|
||||||
{
|
{
|
||||||
let mut deleted = false;
|
let mut deleted = false;
|
||||||
let window_id = WindowId(window_id as _);
|
let window_id = WindowId::from_raw(window_id as _);
|
||||||
let result = self
|
let result = self
|
||||||
.target
|
.target
|
||||||
.windows
|
.windows
|
||||||
|
|
@ -798,7 +798,7 @@ impl EventProcessor {
|
||||||
|
|
||||||
// In the event that the window's been destroyed without being dropped first, we
|
// In the event that the window's been destroyed without being dropped first, we
|
||||||
// cleanup again here.
|
// 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
|
// Since all XIM stuff needs to happen from the same thread, we destroy the input
|
||||||
// context here instead of when dropping the window.
|
// context here instead of when dropping the window.
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,12 @@ use crate::event_loop::{
|
||||||
};
|
};
|
||||||
use crate::platform::pump_events::PumpStatus;
|
use crate::platform::pump_events::PumpStatus;
|
||||||
use crate::platform_impl::common::xkb::Context;
|
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::x11::window::Window;
|
||||||
use crate::platform_impl::{OwnedDisplayHandle, PlatformCustomCursor};
|
use crate::platform_impl::{OwnedDisplayHandle, PlatformCustomCursor};
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
|
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
|
||||||
WindowAttributes,
|
WindowAttributes, WindowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod activation;
|
mod activation;
|
||||||
|
|
@ -521,13 +521,14 @@ impl EventLoop {
|
||||||
|
|
||||||
// Empty activation tokens.
|
// Empty activation tokens.
|
||||||
while let Ok((window_id, serial)) = self.activation_receiver.try_recv() {
|
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| {
|
let token = self
|
||||||
window.generate_activation_token()
|
.event_processor
|
||||||
});
|
.with_window(window_id.into_raw() as xproto::Window, |window| {
|
||||||
|
window.generate_activation_token()
|
||||||
|
});
|
||||||
|
|
||||||
match token {
|
match token {
|
||||||
Some(Ok(token)) => {
|
Some(Ok(token)) => {
|
||||||
let window_id = crate::window::WindowId(window_id);
|
|
||||||
let event = WindowEvent::ActivationTokenDone {
|
let event = WindowEvent::ActivationTokenDone {
|
||||||
serial,
|
serial,
|
||||||
token: crate::window::ActivationToken::_new(token),
|
token: crate::window::ActivationToken::_new(token),
|
||||||
|
|
@ -555,7 +556,6 @@ impl EventLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
for window_id in windows {
|
for window_id in windows {
|
||||||
let window_id = crate::window::WindowId(window_id);
|
|
||||||
app.window_event(
|
app.window_event(
|
||||||
&self.event_processor.target,
|
&self.event_processor.target,
|
||||||
window_id,
|
window_id,
|
||||||
|
|
@ -574,12 +574,9 @@ impl EventLoop {
|
||||||
while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } {
|
while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } {
|
||||||
let mut xev = unsafe { xev.assume_init() };
|
let mut xev = unsafe { xev.assume_init() };
|
||||||
self.event_processor.process_event(&mut xev, |window_target, event: Event| {
|
self.event_processor.process_event(&mut xev, |window_target, event: Event| {
|
||||||
if let Event::WindowEvent {
|
if let Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } = event
|
||||||
window_id: crate::window::WindowId(wid),
|
|
||||||
event: WindowEvent::RedrawRequested,
|
|
||||||
} = event
|
|
||||||
{
|
{
|
||||||
window_target.redraw_sender.send(wid);
|
window_target.redraw_sender.send(window_id);
|
||||||
} else {
|
} else {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { window_id, 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 {
|
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 {
|
fn mkdid(w: xinput::DeviceId) -> crate::event::DeviceId {
|
||||||
crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w)))
|
crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w)))
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use x11rb::protocol::{randr, xinput};
|
||||||
|
|
||||||
use super::util::{self, SelectedCursor};
|
use super::util::{self, SelectedCursor};
|
||||||
use super::{
|
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::cursor::{Cursor, CustomCursor as RootCustomCursor};
|
||||||
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||||
|
|
@ -36,7 +36,7 @@ use crate::platform_impl::{
|
||||||
};
|
};
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
|
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
|
||||||
WindowAttributes, WindowButtons, WindowLevel,
|
WindowAttributes, WindowButtons, WindowId, WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct Window(Arc<UnownedWindow>);
|
pub(crate) struct Window(Arc<UnownedWindow>);
|
||||||
|
|
@ -62,8 +62,8 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoreWindow for Window {
|
impl CoreWindow for Window {
|
||||||
fn id(&self) -> crate::window::WindowId {
|
fn id(&self) -> WindowId {
|
||||||
crate::window::WindowId(self.0.id())
|
self.0.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self) -> f64 {
|
fn scale_factor(&self) -> f64 {
|
||||||
|
|
@ -331,7 +331,9 @@ impl Drop for Window {
|
||||||
window.set_fullscreen(None);
|
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();
|
c.ignore_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1220,11 +1222,10 @@ impl UnownedWindow {
|
||||||
&self.shared_state_lock(),
|
&self.shared_state_lock(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_id = crate::window::WindowId(self.id());
|
|
||||||
let old_surface_size = PhysicalSize::new(width, height);
|
let old_surface_size = PhysicalSize::new(width, height);
|
||||||
let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height)));
|
let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height)));
|
||||||
callback(Event::WindowEvent {
|
callback(Event::WindowEvent {
|
||||||
window_id,
|
window_id: self.id(),
|
||||||
event: WindowEvent::ScaleFactorChanged {
|
event: WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor: new_monitor.scale_factor,
|
scale_factor: new_monitor.scale_factor,
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)),
|
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)),
|
||||||
|
|
@ -2134,7 +2135,7 @@ impl UnownedWindow {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn id(&self) -> WindowId {
|
pub fn id(&self) -> WindowId {
|
||||||
WindowId(self.xwindow as _)
|
WindowId::from_raw(self.xwindow as _)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn sync_counter_id(&self) -> Option<NonZeroU32> {
|
pub(super) fn sync_counter_id(&self) -> Option<NonZeroU32> {
|
||||||
|
|
@ -2143,7 +2144,7 @@ impl UnownedWindow {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn request_redraw(&self) {
|
pub fn request_redraw(&self) {
|
||||||
self.redraw_sender.send(WindowId(self.xwindow as _));
|
self.redraw_sender.send(WindowId::from_raw(self.xwindow as _));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use smol_str::SmolStr;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket,
|
KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket,
|
||||||
WindowId, WindowProperties,
|
WindowProperties,
|
||||||
};
|
};
|
||||||
use crate::application::ApplicationHandler;
|
use crate::application::ApplicationHandler;
|
||||||
use crate::error::{EventLoopError, NotSupportedError, RequestError};
|
use crate::error::{EventLoopError, NotSupportedError, RequestError};
|
||||||
|
|
@ -25,8 +25,7 @@ use crate::keyboard::{
|
||||||
};
|
};
|
||||||
use crate::platform_impl::Window;
|
use crate::platform_impl::Window;
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
|
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, WindowId,
|
||||||
WindowId as RootWindowId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn convert_scancode(scancode: u8) -> (PhysicalKey, Option<NamedKey>) {
|
fn convert_scancode(scancode: u8) -> (PhysicalKey, Option<NamedKey>) {
|
||||||
|
|
@ -362,7 +361,6 @@ impl EventLoop {
|
||||||
key_without_modifiers = logical_key.clone();
|
key_without_modifiers = logical_key.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let window_id = RootWindowId(window_id);
|
|
||||||
let event = event::WindowEvent::KeyboardInput {
|
let event = event::WindowEvent::KeyboardInput {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
event: event::KeyEvent {
|
event: event::KeyEvent {
|
||||||
|
|
@ -394,25 +392,21 @@ impl EventLoop {
|
||||||
EventOption::TextInput(TextInputEvent { character }) => {
|
EventOption::TextInput(TextInputEvent { character }) => {
|
||||||
app.window_event(
|
app.window_event(
|
||||||
window_target,
|
window_target,
|
||||||
RootWindowId(window_id),
|
window_id,
|
||||||
event::WindowEvent::Ime(Ime::Preedit("".into(), None)),
|
event::WindowEvent::Ime(Ime::Preedit("".into(), None)),
|
||||||
);
|
);
|
||||||
app.window_event(
|
app.window_event(
|
||||||
window_target,
|
window_target,
|
||||||
RootWindowId(window_id),
|
window_id,
|
||||||
event::WindowEvent::Ime(Ime::Commit(character.into())),
|
event::WindowEvent::Ime(Ime::Commit(character.into())),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
EventOption::Mouse(MouseEvent { x, y }) => {
|
EventOption::Mouse(MouseEvent { x, y }) => {
|
||||||
app.window_event(
|
app.window_event(window_target, window_id, event::WindowEvent::PointerMoved {
|
||||||
window_target,
|
device_id: None,
|
||||||
RootWindowId(window_id),
|
position: (x, y).into(),
|
||||||
event::WindowEvent::PointerMoved {
|
source: event::PointerSource::Mouse,
|
||||||
device_id: None,
|
});
|
||||||
position: (x, y).into(),
|
|
||||||
source: event::PointerSource::Mouse,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => {
|
EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => {
|
||||||
app.device_event(window_target, None, event::DeviceEvent::PointerMotion {
|
app.device_event(window_target, None, event::DeviceEvent::PointerMotion {
|
||||||
|
|
@ -421,54 +415,38 @@ impl EventLoop {
|
||||||
},
|
},
|
||||||
EventOption::Button(ButtonEvent { left, middle, right }) => {
|
EventOption::Button(ButtonEvent { left, middle, right }) => {
|
||||||
while let Some((button, state)) = event_state.mouse(left, middle, right) {
|
while let Some((button, state)) = event_state.mouse(left, middle, right) {
|
||||||
app.window_event(
|
app.window_event(window_target, window_id, event::WindowEvent::PointerButton {
|
||||||
window_target,
|
device_id: None,
|
||||||
RootWindowId(window_id),
|
state,
|
||||||
event::WindowEvent::PointerButton {
|
position: dpi::PhysicalPosition::default(),
|
||||||
device_id: None,
|
button: button.into(),
|
||||||
state,
|
});
|
||||||
position: dpi::PhysicalPosition::default(),
|
|
||||||
button: button.into(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
EventOption::Scroll(ScrollEvent { x, y }) => {
|
EventOption::Scroll(ScrollEvent { x, y }) => {
|
||||||
app.window_event(
|
app.window_event(window_target, window_id, event::WindowEvent::MouseWheel {
|
||||||
window_target,
|
device_id: None,
|
||||||
RootWindowId(window_id),
|
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
|
||||||
event::WindowEvent::MouseWheel {
|
phase: event::TouchPhase::Moved,
|
||||||
device_id: None,
|
});
|
||||||
delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32),
|
|
||||||
phase: event::TouchPhase::Moved,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
EventOption::Quit(QuitEvent {}) => {
|
EventOption::Quit(QuitEvent {}) => {
|
||||||
app.window_event(
|
app.window_event(window_target, window_id, event::WindowEvent::CloseRequested);
|
||||||
window_target,
|
|
||||||
RootWindowId(window_id),
|
|
||||||
event::WindowEvent::CloseRequested,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
EventOption::Focus(FocusEvent { focused }) => {
|
EventOption::Focus(FocusEvent { focused }) => {
|
||||||
app.window_event(
|
app.window_event(window_target, window_id, event::WindowEvent::Focused(focused));
|
||||||
window_target,
|
|
||||||
RootWindowId(window_id),
|
|
||||||
event::WindowEvent::Focused(focused),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
EventOption::Move(MoveEvent { x, y }) => {
|
EventOption::Move(MoveEvent { x, y }) => {
|
||||||
app.window_event(
|
app.window_event(
|
||||||
window_target,
|
window_target,
|
||||||
RootWindowId(window_id),
|
window_id,
|
||||||
event::WindowEvent::Moved((x, y).into()),
|
event::WindowEvent::Moved((x, y).into()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
EventOption::Resize(ResizeEvent { width, height }) => {
|
EventOption::Resize(ResizeEvent { width, height }) => {
|
||||||
app.window_event(
|
app.window_event(
|
||||||
window_target,
|
window_target,
|
||||||
RootWindowId(window_id),
|
window_id,
|
||||||
event::WindowEvent::SurfaceResized((width, height).into()),
|
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 => {
|
other => {
|
||||||
tracing::warn!("unhandled event: {:?}", other);
|
tracing::warn!("unhandled event: {:?}", other);
|
||||||
|
|
@ -513,7 +491,7 @@ impl EventLoop {
|
||||||
let mut creates = self.window_target.creates.lock().unwrap();
|
let mut creates = self.window_target.creates.lock().unwrap();
|
||||||
creates.pop_front()
|
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 mut buf: [u8; 4096] = [0; 4096];
|
||||||
let path = window.fpath(&mut buf).expect("failed to read properties");
|
let path = window.fpath(&mut buf).expect("failed to read properties");
|
||||||
|
|
@ -521,8 +499,6 @@ impl EventLoop {
|
||||||
|
|
||||||
self.windows.push((window, EventState::default()));
|
self.windows.push((window, EventState::default()));
|
||||||
|
|
||||||
let window_id = RootWindowId(window_id);
|
|
||||||
|
|
||||||
// Send resize event on create to indicate first size.
|
// Send resize event on create to indicate first size.
|
||||||
let event = event::WindowEvent::SurfaceResized((properties.w, properties.h).into());
|
let event = event::WindowEvent::SurfaceResized((properties.w, properties.h).into());
|
||||||
app.window_event(&self.window_target, window_id, event);
|
app.window_event(&self.window_target, window_id, event);
|
||||||
|
|
@ -537,16 +513,16 @@ impl EventLoop {
|
||||||
let mut destroys = self.window_target.destroys.lock().unwrap();
|
let mut destroys = self.window_target.destroys.lock().unwrap();
|
||||||
destroys.pop_front()
|
destroys.pop_front()
|
||||||
} {
|
} {
|
||||||
let window_id = RootWindowId(destroy_id);
|
app.window_event(&self.window_target, destroy_id, event::WindowEvent::Destroyed);
|
||||||
app.window_event(&self.window_target, window_id, event::WindowEvent::Destroyed);
|
self.windows
|
||||||
self.windows.retain(|(window, _event_state)| window.fd as u64 != destroy_id.fd);
|
.retain(|(window, _event_state)| WindowId::from_raw(window.fd) != destroy_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle window events.
|
// Handle window events.
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
// While loop is used here because the same window may be processed more than once.
|
// 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) {
|
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 mut event_buf = [0u8; 16 * mem::size_of::<orbclient::Event>()];
|
||||||
let count =
|
let count =
|
||||||
|
|
@ -604,7 +580,7 @@ impl EventLoop {
|
||||||
} {
|
} {
|
||||||
app.window_event(
|
app.window_event(
|
||||||
&self.window_target,
|
&self.window_target,
|
||||||
RootWindowId(window_id),
|
window_id,
|
||||||
event::WindowEvent::RedrawRequested,
|
event::WindowEvent::RedrawRequested,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,21 +99,6 @@ impl TimeSocket {
|
||||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub(crate) struct PlatformSpecificEventLoopAttributes {}
|
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)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct DeviceId;
|
pub struct DeviceId;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::{Arc, Mutex};
|
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::cursor::Cursor;
|
||||||
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||||
use crate::error::{NotSupportedError, RequestError};
|
use crate::error::{NotSupportedError, RequestError};
|
||||||
use crate::monitor::MonitorHandle as CoreMonitorHandle;
|
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:
|
// 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
|
// https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs
|
||||||
|
|
@ -155,8 +155,8 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoreWindow for Window {
|
impl CoreWindow for Window {
|
||||||
fn id(&self) -> CoreWindowId {
|
fn id(&self) -> WindowId {
|
||||||
CoreWindowId(WindowId { fd: self.window_socket.fd as u64 })
|
WindowId::from_raw(self.window_socket.fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -181,7 +181,7 @@ impl CoreWindow for Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn request_redraw(&self) {
|
fn request_redraw(&self) {
|
||||||
let window_id = self.id().0;
|
let window_id = self.id();
|
||||||
let mut redraws = self.redraws.lock().unwrap();
|
let mut redraws = self.redraws.lock().unwrap();
|
||||||
if !redraws.contains(&window_id) {
|
if !redraws.contains(&window_id) {
|
||||||
redraws.push_back(window_id);
|
redraws.push_back(window_id);
|
||||||
|
|
@ -478,7 +478,7 @@ impl Drop for Window {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
{
|
{
|
||||||
let mut destroys = self.destroys.lock().unwrap();
|
let mut destroys = self.destroys.lock().unwrap();
|
||||||
destroys.push_back(self.id().0);
|
destroys.push_back(self.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.wake_socket.wake().unwrap();
|
self.wake_socket.wake().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{backend, window, HasMonitorPermissionFuture, MonitorPermissionFuture};
|
use super::{backend, HasMonitorPermissionFuture, MonitorPermissionFuture};
|
||||||
use crate::application::ApplicationHandler;
|
use crate::application::ApplicationHandler;
|
||||||
use crate::error::{EventLoopError, NotSupportedError};
|
use crate::error::{EventLoopError, NotSupportedError};
|
||||||
use crate::event::Event;
|
use crate::event::Event;
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ struct Execution {
|
||||||
suspended: Cell<bool>,
|
suspended: Cell<bool>,
|
||||||
event_loop_recreation: Cell<bool>,
|
event_loop_recreation: Cell<bool>,
|
||||||
events: RefCell<VecDeque<EventWrapper>>,
|
events: RefCell<VecDeque<EventWrapper>>,
|
||||||
id: Cell<u64>,
|
id: Cell<usize>,
|
||||||
window: web_sys::Window,
|
window: web_sys::Window,
|
||||||
navigator: Navigator,
|
navigator: Navigator,
|
||||||
document: Document,
|
document: Document,
|
||||||
|
|
@ -438,7 +438,7 @@ impl Shared {
|
||||||
|
|
||||||
// Generate a strictly increasing ID
|
// Generate a strictly increasing ID
|
||||||
// This is used to differentiate windows when handling events
|
// 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();
|
let id = self.0.id.get();
|
||||||
self.0.id.set(id.checked_add(1).expect("exhausted `WindowId`"));
|
self.0.id.set(id.checked_add(1).expect("exhausted `WindowId`"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use web_sys::Element;
|
||||||
use super::super::monitor::MonitorPermissionFuture;
|
use super::super::monitor::MonitorPermissionFuture;
|
||||||
use super::super::{lock, KeyEventExtra};
|
use super::super::{lock, KeyEventExtra};
|
||||||
use super::runner::{EventWrapper, WeakShared};
|
use super::runner::{EventWrapper, WeakShared};
|
||||||
use super::window::WindowId;
|
|
||||||
use super::{backend, runner, EventLoopProxy};
|
use super::{backend, runner, EventLoopProxy};
|
||||||
use crate::error::{NotSupportedError, RequestError};
|
use crate::error::{NotSupportedError, RequestError};
|
||||||
use crate::event::{
|
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::cursor::CustomCursor;
|
||||||
use crate::platform_impl::platform::r#async::Waker;
|
use crate::platform_impl::platform::r#async::Waker;
|
||||||
use crate::platform_impl::Window;
|
use crate::platform_impl::Window;
|
||||||
use crate::window::{
|
use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId};
|
||||||
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId as RootWindowId,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ModifiersShared(Rc<Cell<ModifiersState>>);
|
struct ModifiersShared(Rc<Cell<ModifiersState>>);
|
||||||
|
|
@ -68,14 +65,14 @@ impl ActiveEventLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_id(&self) -> WindowId {
|
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 {
|
pub fn create_custom_cursor_async(&self, source: CustomCursorSource) -> CustomCursorFuture {
|
||||||
CustomCursorFuture(CustomCursor::new_async(self, source.inner))
|
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();
|
let canvas_clone = canvas.clone();
|
||||||
|
|
||||||
canvas.on_touch_start();
|
canvas.on_touch_start();
|
||||||
|
|
@ -89,13 +86,13 @@ impl ActiveEventLoop {
|
||||||
let clear_modifiers = (!modifiers.get().is_empty()).then(|| {
|
let clear_modifiers = (!modifiers.get().is_empty()).then(|| {
|
||||||
modifiers.set(ModifiersState::empty());
|
modifiers.set(ModifiersState::empty());
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(ModifiersState::empty().into()),
|
event: WindowEvent::ModifiersChanged(ModifiersState::empty().into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::Focused(false),
|
event: WindowEvent::Focused(false),
|
||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
|
|
@ -105,7 +102,7 @@ impl ActiveEventLoop {
|
||||||
canvas.on_focus(move || {
|
canvas.on_focus(move || {
|
||||||
if !has_focus.replace(true) {
|
if !has_focus.replace(true) {
|
||||||
runner.send_event(Event::WindowEvent {
|
runner.send_event(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::Focused(true),
|
event: WindowEvent::Focused(true),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -124,10 +121,8 @@ impl ActiveEventLoop {
|
||||||
|
|
||||||
if focused {
|
if focused {
|
||||||
canvas.has_focus.set(true);
|
canvas.has_focus.set(true);
|
||||||
self.runner.send_event(Event::WindowEvent {
|
self.runner
|
||||||
window_id: RootWindowId(id),
|
.send_event(Event::WindowEvent { window_id, event: WindowEvent::Focused(true) })
|
||||||
event: WindowEvent::Focused(true),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let runner = self.runner.clone();
|
let runner = self.runner.clone();
|
||||||
|
|
@ -137,14 +132,14 @@ impl ActiveEventLoop {
|
||||||
let modifiers_changed = (modifiers.get() != active_modifiers).then(|| {
|
let modifiers_changed = (modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.send_events(
|
runner.send_events(
|
||||||
iter::once(Event::WindowEvent {
|
iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::KeyboardInput {
|
event: WindowEvent::KeyboardInput {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
event: KeyEvent {
|
event: KeyEvent {
|
||||||
|
|
@ -171,14 +166,14 @@ impl ActiveEventLoop {
|
||||||
let modifiers_changed = (modifiers.get() != active_modifiers).then(|| {
|
let modifiers_changed = (modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.send_events(
|
runner.send_events(
|
||||||
iter::once(Event::WindowEvent {
|
iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::KeyboardInput {
|
event: WindowEvent::KeyboardInput {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
event: KeyEvent {
|
event: KeyEvent {
|
||||||
|
|
@ -208,13 +203,13 @@ impl ActiveEventLoop {
|
||||||
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent {
|
runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::PointerLeft {
|
event: WindowEvent::PointerLeft {
|
||||||
device_id: device_id.map(RootDeviceId),
|
device_id: device_id.map(RootDeviceId),
|
||||||
position: Some(position),
|
position: Some(position),
|
||||||
|
|
@ -233,13 +228,13 @@ impl ActiveEventLoop {
|
||||||
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent {
|
runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::PointerEntered {
|
event: WindowEvent::PointerEntered {
|
||||||
device_id: device_id.map(RootDeviceId),
|
device_id: device_id.map(RootDeviceId),
|
||||||
position,
|
position,
|
||||||
|
|
@ -263,13 +258,13 @@ impl ActiveEventLoop {
|
||||||
.then(|| {
|
.then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::PointerMoved { device_id, position, source },
|
event: WindowEvent::PointerMoved { device_id, position, source },
|
||||||
}))
|
}))
|
||||||
}));
|
}));
|
||||||
|
|
@ -285,7 +280,7 @@ impl ActiveEventLoop {
|
||||||
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -293,7 +288,7 @@ impl ActiveEventLoop {
|
||||||
let device_id = device_id.map(RootDeviceId);
|
let device_id = device_id.map(RootDeviceId);
|
||||||
|
|
||||||
runner.send_events(modifiers.into_iter().chain([Event::WindowEvent {
|
runner.send_events(modifiers.into_iter().chain([Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::PointerButton { device_id, state, position, button },
|
event: WindowEvent::PointerButton { device_id, state, position, button },
|
||||||
}]));
|
}]));
|
||||||
}
|
}
|
||||||
|
|
@ -308,14 +303,14 @@ impl ActiveEventLoop {
|
||||||
let modifiers = (modifiers.get() != active_modifiers).then(|| {
|
let modifiers = (modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let device_id = pointer_id.map(RootDeviceId);
|
let device_id = pointer_id.map(RootDeviceId);
|
||||||
runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::PointerButton {
|
event: WindowEvent::PointerButton {
|
||||||
device_id,
|
device_id,
|
||||||
state: ElementState::Pressed,
|
state: ElementState::Pressed,
|
||||||
|
|
@ -336,7 +331,7 @@ impl ActiveEventLoop {
|
||||||
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -344,7 +339,7 @@ impl ActiveEventLoop {
|
||||||
let device_id = pointer_id.map(RootDeviceId);
|
let device_id = pointer_id.map(RootDeviceId);
|
||||||
|
|
||||||
runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::PointerButton {
|
event: WindowEvent::PointerButton {
|
||||||
device_id,
|
device_id,
|
||||||
state: ElementState::Released,
|
state: ElementState::Released,
|
||||||
|
|
@ -362,14 +357,14 @@ impl ActiveEventLoop {
|
||||||
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
(has_focus.get() && modifiers.get() != active_modifiers).then(|| {
|
||||||
modifiers.set(active_modifiers);
|
modifiers.set(active_modifiers);
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.send_events(modifiers_changed.into_iter().chain(iter::once(
|
runner.send_events(modifiers_changed.into_iter().chain(iter::once(
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::MouseWheel {
|
event: WindowEvent::MouseWheel {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
delta,
|
delta,
|
||||||
|
|
@ -383,7 +378,7 @@ impl ActiveEventLoop {
|
||||||
canvas.on_dark_mode(move |is_dark_mode| {
|
canvas.on_dark_mode(move |is_dark_mode| {
|
||||||
let theme = if is_dark_mode { Theme::Dark } else { Theme::Light };
|
let theme = if is_dark_mode { Theme::Dark } else { Theme::Light };
|
||||||
runner.send_event(Event::WindowEvent {
|
runner.send_event(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::ThemeChanged(theme),
|
event: WindowEvent::ThemeChanged(theme),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -410,7 +405,7 @@ impl ActiveEventLoop {
|
||||||
if canvas.old_size() != new_size {
|
if canvas.old_size() != new_size {
|
||||||
canvas.set_old_size(new_size);
|
canvas.set_old_size(new_size);
|
||||||
runner.send_event(Event::WindowEvent {
|
runner.send_event(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::SurfaceResized(new_size),
|
event: WindowEvent::SurfaceResized(new_size),
|
||||||
});
|
});
|
||||||
canvas.request_animation_frame();
|
canvas.request_animation_frame();
|
||||||
|
|
@ -426,7 +421,7 @@ impl ActiveEventLoop {
|
||||||
&& !(is_intersecting && canvas_clone.is_intersecting.get().is_none())
|
&& !(is_intersecting && canvas_clone.is_intersecting.get().is_none())
|
||||||
{
|
{
|
||||||
runner.send_event(Event::WindowEvent {
|
runner.send_event(Event::WindowEvent {
|
||||||
window_id: RootWindowId(id),
|
window_id,
|
||||||
event: WindowEvent::Occluded(!is_intersecting),
|
event: WindowEvent::Occluded(!is_intersecting),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -435,7 +430,7 @@ impl ActiveEventLoop {
|
||||||
});
|
});
|
||||||
|
|
||||||
let runner = self.runner.clone();
|
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();
|
canvas.on_context_menu();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,5 +48,5 @@ pub(crate) use self::monitor::{
|
||||||
VideoModeHandle,
|
VideoModeHandle,
|
||||||
};
|
};
|
||||||
use self::web_sys as backend;
|
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;
|
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ use web_sys::{
|
||||||
use super::super::cursor::CursorHandler;
|
use super::super::cursor::CursorHandler;
|
||||||
use super::super::event::DeviceId;
|
use super::super::event::DeviceId;
|
||||||
use super::super::main_thread::MainThreadMarker;
|
use super::super::main_thread::MainThreadMarker;
|
||||||
use super::super::WindowId;
|
|
||||||
use super::animation_frame::AnimationFrameHandler;
|
use super::animation_frame::AnimationFrameHandler;
|
||||||
use super::event_handle::EventListenerHandle;
|
use super::event_handle::EventListenerHandle;
|
||||||
use super::intersection_handle::IntersectionObserverHandle;
|
use super::intersection_handle::IntersectionObserverHandle;
|
||||||
|
|
@ -28,7 +27,7 @@ use crate::event::{
|
||||||
};
|
};
|
||||||
use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey};
|
use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey};
|
||||||
use crate::platform_impl::Fullscreen;
|
use crate::platform_impl::Fullscreen;
|
||||||
use crate::window::{WindowAttributes, WindowId as RootWindowId};
|
use crate::window::{WindowAttributes, WindowId};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Canvas {
|
pub struct Canvas {
|
||||||
|
|
@ -490,7 +489,7 @@ impl Canvas {
|
||||||
let new_size = {
|
let new_size = {
|
||||||
let new_size = Arc::new(Mutex::new(current_size));
|
let new_size = Arc::new(Mutex::new(current_size));
|
||||||
event_handler(crate::event::Event::WindowEvent {
|
event_handler(crate::event::Event::WindowEvent {
|
||||||
window_id: RootWindowId(self.id),
|
window_id: self.id,
|
||||||
event: crate::event::WindowEvent::ScaleFactorChanged {
|
event: crate::event::WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor: scale,
|
scale_factor: scale,
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_size)),
|
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_size)),
|
||||||
|
|
@ -518,7 +517,7 @@ impl Canvas {
|
||||||
// Then we at least send a resized event.
|
// Then we at least send a resized event.
|
||||||
self.set_old_size(new_size);
|
self.set_old_size(new_size);
|
||||||
runner.send_event(crate::event::Event::WindowEvent {
|
runner.send_event(crate::event::Event::WindowEvent {
|
||||||
window_id: RootWindowId(self.id),
|
window_id: self.id,
|
||||||
event: crate::event::WindowEvent::SurfaceResized(new_size),
|
event: crate::event::WindowEvent::SurfaceResized(new_size),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use crate::icon::Icon;
|
||||||
use crate::monitor::MonitorHandle as RootMonitorHandle;
|
use crate::monitor::MonitorHandle as RootMonitorHandle;
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
Cursor, CursorGrabMode, Fullscreen as RootFullscreen, ImePurpose, ResizeDirection, Theme,
|
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,
|
WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ impl Window {
|
||||||
target.register(&canvas, id);
|
target.register(&canvas, id);
|
||||||
|
|
||||||
let runner = target.runner.clone();
|
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 {
|
let inner = Inner {
|
||||||
id,
|
id,
|
||||||
|
|
@ -65,7 +65,7 @@ impl Window {
|
||||||
|
|
||||||
let canvas = Rc::downgrade(&inner.canvas);
|
let canvas = Rc::downgrade(&inner.canvas);
|
||||||
let (dispatcher, runner) = Dispatcher::new(target.runner.main_thread(), inner);
|
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 })
|
Ok(Window { inner: dispatcher })
|
||||||
}
|
}
|
||||||
|
|
@ -91,8 +91,8 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RootWindow for Window {
|
impl RootWindow for Window {
|
||||||
fn id(&self) -> RootWI {
|
fn id(&self) -> WindowId {
|
||||||
RootWI(self.inner.queue(|inner| inner.id))
|
self.inner.queue(|inner| inner.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self) -> f64 {
|
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)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct PlatformSpecificWindowAttributes {
|
pub struct PlatformSpecificWindowAttributes {
|
||||||
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,
|
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ use crate::event::Event;
|
||||||
use crate::platform_impl::platform::definitions::{
|
use crate::platform_impl::platform::definitions::{
|
||||||
IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl,
|
IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl,
|
||||||
};
|
};
|
||||||
use crate::platform_impl::platform::WindowId;
|
use crate::window::WindowId;
|
||||||
use crate::window::WindowId as RootWindowId;
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct FileDropHandlerData {
|
pub struct FileDropHandlerData {
|
||||||
|
|
@ -86,7 +85,7 @@ impl FileDropHandler {
|
||||||
let hdrop = unsafe {
|
let hdrop = unsafe {
|
||||||
Self::iterate_filenames(pDataObj, |filename| {
|
Self::iterate_filenames(pDataObj, |filename| {
|
||||||
drop_handler.send_event(Event::WindowEvent {
|
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),
|
event: HoveredFile(filename),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
@ -120,7 +119,7 @@ impl FileDropHandler {
|
||||||
let drop_handler = unsafe { Self::from_interface(this) };
|
let drop_handler = unsafe { Self::from_interface(this) };
|
||||||
if drop_handler.hovered_is_valid {
|
if drop_handler.hovered_is_valid {
|
||||||
drop_handler.send_event(Event::WindowEvent {
|
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,
|
event: HoveredFileCancelled,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +139,7 @@ impl FileDropHandler {
|
||||||
let hdrop = unsafe {
|
let hdrop = unsafe {
|
||||||
Self::iterate_filenames(pDataObj, |filename| {
|
Self::iterate_filenames(pDataObj, |filename| {
|
||||||
drop_handler.send_event(Event::WindowEvent {
|
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),
|
event: DroppedFile(filename),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,12 @@ use crate::platform_impl::platform::window::InitData;
|
||||||
use crate::platform_impl::platform::window_state::{
|
use crate::platform_impl::platform::window_state::{
|
||||||
CursorFlags, ImeState, WindowFlags, WindowState,
|
CursorFlags, ImeState, WindowFlags, WindowState,
|
||||||
};
|
};
|
||||||
use crate::platform_impl::platform::{
|
use crate::platform_impl::platform::{raw_input, util, wrap_device_id, FingerId, Fullscreen};
|
||||||
raw_input, util, wrap_device_id, FingerId, Fullscreen, WindowId,
|
|
||||||
};
|
|
||||||
use crate::platform_impl::Window;
|
use crate::platform_impl::Window;
|
||||||
use crate::utils::Lazy;
|
use crate::utils::Lazy;
|
||||||
use crate::window::{
|
use crate::window::{
|
||||||
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
|
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
|
||||||
WindowAttributes, WindowId as CoreWindowId,
|
WindowAttributes, WindowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct WindowData {
|
pub(crate) struct WindowData {
|
||||||
|
|
@ -920,7 +918,7 @@ fn update_modifiers(window: HWND, userdata: &WindowData) {
|
||||||
drop(window_state);
|
drop(window_state);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: ModifiersChanged(modifiers.into()),
|
event: ModifiersChanged(modifiers.into()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -932,7 +930,7 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) {
|
||||||
update_modifiers(window, userdata);
|
update_modifiers(window, userdata);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: Focused(true),
|
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.window_state_lock().modifiers_state = ModifiersState::empty();
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: ModifiersChanged(ModifiersState::empty().into()),
|
event: ModifiersChanged(ModifiersState::empty().into()),
|
||||||
});
|
});
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: Focused(false),
|
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);
|
userdata.key_event_builder.process_message(window, msg, wparam, lparam, &mut result);
|
||||||
for event in events {
|
for event in events {
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: KeyboardInput {
|
event: KeyboardInput {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
event: event.event,
|
event: event.event,
|
||||||
|
|
@ -1130,7 +1128,7 @@ unsafe fn public_window_callback_inner(
|
||||||
WM_CLOSE => {
|
WM_CLOSE => {
|
||||||
use crate::event::WindowEvent::CloseRequested;
|
use crate::event::WindowEvent::CloseRequested;
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: CloseRequested,
|
event: CloseRequested,
|
||||||
});
|
});
|
||||||
result = ProcResult::Value(0);
|
result = ProcResult::Value(0);
|
||||||
|
|
@ -1140,7 +1138,7 @@ unsafe fn public_window_callback_inner(
|
||||||
use crate::event::WindowEvent::Destroyed;
|
use crate::event::WindowEvent::Destroyed;
|
||||||
unsafe { RevokeDragDrop(window) };
|
unsafe { RevokeDragDrop(window) };
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: Destroyed,
|
event: Destroyed,
|
||||||
});
|
});
|
||||||
result = ProcResult::Value(0);
|
result = ProcResult::Value(0);
|
||||||
|
|
@ -1161,7 +1159,7 @@ unsafe fn public_window_callback_inner(
|
||||||
// and request a normal redraw with `RedrawWindow`.
|
// and request a normal redraw with `RedrawWindow`.
|
||||||
if !userdata.event_loop_runner.should_buffer() {
|
if !userdata.event_loop_runner.should_buffer() {
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::RedrawRequested,
|
event: WindowEvent::RedrawRequested,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1264,7 +1262,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let physical_position =
|
let physical_position =
|
||||||
unsafe { PhysicalPosition::new((*windowpos).x, (*windowpos).y) };
|
unsafe { PhysicalPosition::new((*windowpos).x, (*windowpos).y) };
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: Moved(physical_position),
|
event: Moved(physical_position),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1280,7 +1278,7 @@ unsafe fn public_window_callback_inner(
|
||||||
|
|
||||||
let physical_size = PhysicalSize::new(w, h);
|
let physical_size = PhysicalSize::new(w, h);
|
||||||
let event = Event::WindowEvent {
|
let event = Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: SurfaceResized(physical_size),
|
event: SurfaceResized(physical_size),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1395,7 +1393,7 @@ unsafe fn public_window_callback_inner(
|
||||||
userdata.window_state_lock().ime_state = ImeState::Enabled;
|
userdata.window_state_lock().ime_state = ImeState::Enabled;
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::Ime(Ime::Enabled),
|
event: WindowEvent::Ime(Ime::Enabled),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1415,7 +1413,7 @@ unsafe fn public_window_callback_inner(
|
||||||
|
|
||||||
if lparam == 0 {
|
if lparam == 0 {
|
||||||
userdata.send_event(Event::WindowEvent {
|
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)),
|
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.window_state_lock().ime_state = ImeState::Enabled;
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
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)),
|
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||||
});
|
});
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::Ime(Ime::Commit(text)),
|
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)));
|
let cursor_range = first.map(|f| (f, last.unwrap_or(f)));
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
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)),
|
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) };
|
let ime_context = unsafe { ImeContext::current(window) };
|
||||||
if let Some(text) = unsafe { ime_context.get_composed_text() } {
|
if let Some(text) = unsafe { ime_context.get_composed_text() } {
|
||||||
userdata.send_event(Event::WindowEvent {
|
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)),
|
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||||
});
|
});
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::Ime(Ime::Commit(text)),
|
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.window_state_lock().ime_state = ImeState::Disabled;
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::Ime(Ime::Disabled),
|
event: WindowEvent::Ime(Ime::Disabled),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1541,7 +1539,7 @@ unsafe fn public_window_callback_inner(
|
||||||
|
|
||||||
drop(w);
|
drop(w);
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerEntered {
|
event: PointerEntered {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
position,
|
position,
|
||||||
|
|
@ -1566,7 +1564,7 @@ unsafe fn public_window_callback_inner(
|
||||||
|
|
||||||
drop(w);
|
drop(w);
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerLeft {
|
event: PointerLeft {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
position: Some(position),
|
position: Some(position),
|
||||||
|
|
@ -1589,7 +1587,7 @@ unsafe fn public_window_callback_inner(
|
||||||
update_modifiers(window, userdata);
|
update_modifiers(window, userdata);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
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 },
|
event: PointerMoved { device_id: None, position, source: PointerSource::Mouse },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1607,7 +1605,7 @@ unsafe fn public_window_callback_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
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 },
|
event: PointerLeft { device_id: None, position: None, kind: Mouse },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1623,7 +1621,7 @@ unsafe fn public_window_callback_inner(
|
||||||
update_modifiers(window, userdata);
|
update_modifiers(window, userdata);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::MouseWheel {
|
event: WindowEvent::MouseWheel {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
delta: LineDelta(0.0, value),
|
delta: LineDelta(0.0, value),
|
||||||
|
|
@ -1643,7 +1641,7 @@ unsafe fn public_window_callback_inner(
|
||||||
update_modifiers(window, userdata);
|
update_modifiers(window, userdata);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::MouseWheel {
|
event: WindowEvent::MouseWheel {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
delta: LineDelta(value, 0.0),
|
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);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Pressed,
|
state: Pressed,
|
||||||
|
|
@ -1707,7 +1705,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Released,
|
state: Released,
|
||||||
|
|
@ -1732,7 +1730,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Pressed,
|
state: Pressed,
|
||||||
|
|
@ -1757,7 +1755,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Released,
|
state: Released,
|
||||||
|
|
@ -1782,7 +1780,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Pressed,
|
state: Pressed,
|
||||||
|
|
@ -1807,7 +1805,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Released,
|
state: Released,
|
||||||
|
|
@ -1833,7 +1831,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Pressed,
|
state: Pressed,
|
||||||
|
|
@ -1864,7 +1862,7 @@ unsafe fn public_window_callback_inner(
|
||||||
let position = PhysicalPosition::new(x as f64, y as f64);
|
let position = PhysicalPosition::new(x as f64, y as f64);
|
||||||
|
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: PointerButton {
|
event: PointerButton {
|
||||||
device_id: None,
|
device_id: None,
|
||||||
state: Released,
|
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 y = position.y as f64 + (input.y % 100) as f64 / 100f64;
|
||||||
let position = PhysicalPosition::new(x, y);
|
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 {
|
let finger_id = RootFingerId(FingerId {
|
||||||
id: input.dwID,
|
id: input.dwID,
|
||||||
primary: util::has_flag(input.dwFlags, TOUCHEVENTF_PRIMARY),
|
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 y = location.y as f64 + y.fract();
|
||||||
let position = PhysicalPosition::new(x, y);
|
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 {
|
let finger_id = RootFingerId(FingerId {
|
||||||
id: pointer_info.pointerId,
|
id: pointer_info.pointerId,
|
||||||
primary: util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_PRIMARY),
|
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));
|
let new_surface_size = Arc::new(Mutex::new(new_physical_surface_size));
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: ScaleFactorChanged {
|
event: ScaleFactorChanged {
|
||||||
scale_factor: new_scale_factor,
|
scale_factor: new_scale_factor,
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)),
|
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;
|
window_state.current_theme = new_theme;
|
||||||
drop(window_state);
|
drop(window_state);
|
||||||
userdata.send_event(Event::WindowEvent {
|
userdata.send_event(Event::WindowEvent {
|
||||||
window_id: CoreWindowId(WindowId(window)),
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: ThemeChanged(new_theme),
|
event: ThemeChanged(new_theme),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ pub(crate) enum RunnerState {
|
||||||
|
|
||||||
enum BufferedEvent {
|
enum BufferedEvent {
|
||||||
Event(Event),
|
Event(Event),
|
||||||
ScaleFactorChanged(WindowId, f64, PhysicalSize<u32>),
|
ScaleFactorChanged(HWND, f64, PhysicalSize<u32>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventLoopRunner {
|
impl EventLoopRunner {
|
||||||
|
|
@ -360,7 +360,7 @@ impl BufferedEvent {
|
||||||
event: WindowEvent::ScaleFactorChanged { scale_factor, surface_size_writer },
|
event: WindowEvent::ScaleFactorChanged { scale_factor, surface_size_writer },
|
||||||
window_id,
|
window_id,
|
||||||
} => BufferedEvent::ScaleFactorChanged(
|
} => BufferedEvent::ScaleFactorChanged(
|
||||||
window_id,
|
window_id.into_raw() as HWND,
|
||||||
scale_factor,
|
scale_factor,
|
||||||
*surface_size_writer.new_surface_size.upgrade().unwrap().lock().unwrap(),
|
*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)) {
|
pub fn dispatch_event(self, dispatch: impl FnOnce(Event)) {
|
||||||
match self {
|
match self {
|
||||||
Self::Event(event) => dispatch(event),
|
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));
|
let user_new_surface_size = Arc::new(Mutex::new(new_surface_size));
|
||||||
dispatch(Event::WindowEvent {
|
dispatch(Event::WindowEvent {
|
||||||
window_id,
|
window_id: WindowId::from_raw(window as usize),
|
||||||
event: WindowEvent::ScaleFactorChanged {
|
event: WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor,
|
scale_factor,
|
||||||
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
|
surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(
|
||||||
|
|
@ -388,12 +388,11 @@ impl BufferedEvent {
|
||||||
|
|
||||||
if surface_size != new_surface_size {
|
if surface_size != new_surface_size {
|
||||||
let window_flags = unsafe {
|
let window_flags = unsafe {
|
||||||
let userdata =
|
let userdata = get_window_long(window, GWL_USERDATA) as *mut WindowData;
|
||||||
get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData;
|
|
||||||
(*userdata).window_state_lock().window_flags
|
(*userdata).window_state_lock().window_flags
|
||||||
};
|
};
|
||||||
|
|
||||||
window_flags.set_size((window_id.0).0, surface_size);
|
window_flags.set_size(window, surface_size);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,27 +101,6 @@ pub struct KeyEventExtra {
|
||||||
pub key_without_modifiers: Key,
|
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)]
|
#[inline(always)]
|
||||||
const fn get_xbutton_wparam(x: u32) -> u16 {
|
const fn get_xbutton_wparam(x: u32) -> u16 {
|
||||||
hiword(x)
|
hiword(x)
|
||||||
|
|
|
||||||
|
|
@ -66,11 +66,11 @@ use crate::platform_impl::platform::keyboard::KeyEventBuilder;
|
||||||
use crate::platform_impl::platform::window_state::{
|
use crate::platform_impl::platform::window_state::{
|
||||||
CursorFlags, SavedWindow, WindowFlags, WindowState,
|
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::{
|
use crate::window::{
|
||||||
CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
|
CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
|
||||||
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons,
|
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId,
|
||||||
WindowId as CoreWindowId, WindowLevel,
|
WindowLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The Win32 implementation of the main `Window` object.
|
/// The Win32 implementation of the main `Window` object.
|
||||||
|
|
@ -696,8 +696,8 @@ impl CoreWindow for Window {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> CoreWindowId {
|
fn id(&self) -> WindowId {
|
||||||
CoreWindowId(WindowId(self.hwnd()))
|
WindowId::from_raw(self.hwnd() as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_minimized(&self, minimized: bool) {
|
fn set_minimized(&self, minimized: bool) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||||
use crate::error::RequestError;
|
use crate::error::RequestError;
|
||||||
pub use crate::icon::{BadIcon, Icon};
|
pub use crate::icon::{BadIcon, Icon};
|
||||||
use crate::monitor::{MonitorHandle, VideoModeHandle};
|
use crate::monitor::{MonitorHandle, VideoModeHandle};
|
||||||
use crate::platform_impl::{self, PlatformSpecificWindowAttributes};
|
use crate::platform_impl::PlatformSpecificWindowAttributes;
|
||||||
use crate::utils::AsAny;
|
use crate::utils::AsAny;
|
||||||
|
|
||||||
/// Identifier of a window. Unique for each window.
|
/// 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
|
/// 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.
|
/// can then compare to the ids of your windows.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct WindowId(pub(crate) platform_impl::WindowId);
|
pub struct WindowId(usize);
|
||||||
|
|
||||||
impl WindowId {
|
impl WindowId {
|
||||||
/// Convert the `WindowId` into the underlying integer.
|
/// 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.
|
/// 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 {
|
pub const fn into_raw(self) -> usize {
|
||||||
self.0.into_raw()
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a `WindowId` from the underlying integer.
|
/// Construct a `WindowId` from the underlying integer.
|
||||||
///
|
///
|
||||||
/// This should only be called with integers returned from [`WindowId::into_raw`].
|
/// This should only be called with integers returned from [`WindowId::into_raw`].
|
||||||
pub const fn from_raw(id: u64) -> Self {
|
pub const fn from_raw(id: usize) -> Self {
|
||||||
Self(platform_impl::WindowId::from_raw(id))
|
Self(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue