diff --git a/src/platform_impl/apple/appkit/app_state.rs b/src/platform_impl/apple/appkit/app_state.rs index 6c1769ff3b..61694bd1b9 100644 --- a/src/platform_impl/apple/appkit/app_state.rs +++ b/src/platform_impl/apple/appkit/app_state.rs @@ -13,9 +13,9 @@ use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo}; use super::menu; use super::observer::{EventLoopWaker, RunLoop}; use crate::application::ApplicationHandler; -use crate::event::{StartCause, WindowEvent}; +use crate::event::{StartCause, SurfaceEvent}; use crate::event_loop::ControlFlow; -use crate::window::WindowId; +use crate::window::SurfaceId; #[derive(Debug)] pub(super) struct AppState { @@ -40,7 +40,7 @@ pub(super) struct AppState { waker: RefCell, start_time: Cell>, wait_timeout: Cell>, - pending_redraw: RefCell>, + pending_redraw: RefCell>, // NOTE: This is strongly referenced by our `NSWindowDelegate` and our `NSView` subclass, and // as such should be careful to not add fields that, in turn, strongly reference those. } @@ -240,12 +240,12 @@ impl AppState { self.control_flow.get() } - pub fn handle_redraw(self: &Rc, window_id: WindowId) { + pub fn handle_redraw(self: &Rc, window_id: SurfaceId) { // Redraw request might come out of order from the OS. // -> Don't go back into the event handler when our callstack originates from there if !self.event_handler.in_use() { self.with_handler(|app, event_loop| { - app.window_event(event_loop, window_id, WindowEvent::RedrawRequested); + app.window_event(event_loop, window_id, SurfaceEvent::RedrawRequested); }); // `pump_events` will request to stop immediately _after_ dispatching RedrawRequested @@ -258,7 +258,7 @@ impl AppState { } } - pub fn queue_redraw(&self, window_id: WindowId) { + pub fn queue_redraw(&self, window_id: SurfaceId) { let mut pending_redraw = self.pending_redraw.borrow_mut(); if !pending_redraw.contains(&window_id) { pending_redraw.push(window_id); @@ -357,7 +357,7 @@ impl AppState { let redraw = mem::take(&mut *self.pending_redraw.borrow_mut()); for window_id in redraw { self.with_handler(|app, event_loop| { - app.window_event(event_loop, window_id, WindowEvent::RedrawRequested); + app.window_event(event_loop, window_id, SurfaceEvent::RedrawRequested); }); } self.with_handler(|app, event_loop| { diff --git a/src/platform_impl/apple/appkit/view.rs b/src/platform_impl/apple/appkit/view.rs index 357e1cd648..faa15e20d0 100644 --- a/src/platform_impl/apple/appkit/view.rs +++ b/src/platform_impl/apple/appkit/view.rs @@ -27,7 +27,7 @@ use super::window::WinitWindow; use crate::dpi::{LogicalPosition, LogicalSize}; use crate::event::{ DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, PointerKind, - PointerSource, TouchPhase, WindowEvent, + PointerSource, TouchPhase, SurfaceEvent, }; use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey}; use crate::platform::macos::OptionAsAlt; @@ -196,7 +196,7 @@ declare_class!( // 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height). let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64); let size = logical_size.to_physical::(self.scale_factor()); - self.queue_event(WindowEvent::SurfaceResized(size)); + self.queue_event(SurfaceEvent::SurfaceResized(size)); } #[method(drawRect:)] @@ -301,7 +301,7 @@ declare_class!( // Notify IME is active if application still doesn't know it. if self.ivars().ime_state.get() == ImeState::Disabled { *self.ivars().input_source.borrow_mut() = self.current_input_source(); - self.queue_event(WindowEvent::Ime(Ime::Enabled)); + self.queue_event(SurfaceEvent::Ime(Ime::Enabled)); } if unsafe { self.hasMarkedText() } { @@ -324,8 +324,8 @@ declare_class!( Some((lowerbound_utf8, upperbound_utf8)) }; - // Send WindowEvent for updating marked text - self.queue_event(WindowEvent::Ime(Ime::Preedit(string.to_string(), cursor_range))); + // Send SurfaceEvent for updating marked text + self.queue_event(SurfaceEvent::Ime(Ime::Preedit(string.to_string(), cursor_range))); } #[method(unmarkText)] @@ -336,7 +336,7 @@ declare_class!( let input_context = self.inputContext().expect("input context"); input_context.discardMarkedText(); - self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None))); + self.queue_event(SurfaceEvent::Ime(Ime::Preedit(String::new(), None))); if self.is_ime_enabled() { // Leave the Preedit self.ivars() self.ivars().ime_state.set(ImeState::Ground); @@ -403,8 +403,8 @@ declare_class!( // Commit only if we have marked text. if unsafe { self.hasMarkedText() } && self.is_ime_enabled() && !is_control { - self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None))); - self.queue_event(WindowEvent::Ime(Ime::Commit(string))); + self.queue_event(SurfaceEvent::Ime(Ime::Preedit(String::new(), None))); + self.queue_event(SurfaceEvent::Ime(Ime::Commit(string))); self.ivars().ime_state.set(ImeState::Committed); } } @@ -442,7 +442,7 @@ declare_class!( *prev_input_source = current_input_source; drop(prev_input_source); self.ivars().ime_state.set(ImeState::Disabled); - self.queue_event(WindowEvent::Ime(Ime::Disabled)); + self.queue_event(SurfaceEvent::Ime(Ime::Disabled)); } } @@ -483,7 +483,7 @@ declare_class!( if !had_ime_input || self.ivars().forward_key_to_app.get() { let key_event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); - self.queue_event(WindowEvent::KeyboardInput { + self.queue_event(SurfaceEvent::KeyboardInput { device_id: None, event: key_event, is_synthetic: false, @@ -503,7 +503,7 @@ declare_class!( self.ivars().ime_state.get(), ImeState::Ground | ImeState::Disabled ) { - self.queue_event(WindowEvent::KeyboardInput { + self.queue_event(SurfaceEvent::KeyboardInput { device_id: None, event: create_key_event(&event, false, false, None), is_synthetic: false, @@ -554,7 +554,7 @@ declare_class!( self.update_modifiers(&event, false); let event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); - self.queue_event(WindowEvent::KeyboardInput { + self.queue_event(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -642,7 +642,7 @@ declare_class!( let position = self.mouse_view_point(event).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::PointerEntered { + self.queue_event(SurfaceEvent::PointerEntered { device_id: None, position, kind: PointerKind::Mouse, @@ -655,7 +655,7 @@ declare_class!( let position = self.mouse_view_point(event).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::PointerLeft { + self.queue_event(SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: PointerKind::Mouse, @@ -698,7 +698,7 @@ declare_class!( self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| app.device_event(event_loop, None, DeviceEvent::MouseWheel { delta }) ); - self.queue_event(WindowEvent::MouseWheel { + self.queue_event(SurfaceEvent::MouseWheel { device_id: None, delta, phase, @@ -720,7 +720,7 @@ declare_class!( _ => return, }; - self.queue_event(WindowEvent::PinchGesture { + self.queue_event(SurfaceEvent::PinchGesture { device_id: None, delta: unsafe { event.magnification() }, phase, @@ -733,7 +733,7 @@ declare_class!( self.mouse_motion(event); - self.queue_event(WindowEvent::DoubleTapGesture { + self.queue_event(SurfaceEvent::DoubleTapGesture { device_id: None, }); } @@ -753,7 +753,7 @@ declare_class!( _ => return, }; - self.queue_event(WindowEvent::RotationGesture { + self.queue_event(SurfaceEvent::RotationGesture { device_id: None, delta: unsafe { event.rotation() }, phase, @@ -764,7 +764,7 @@ declare_class!( fn pressure_change_with_event(&self, event: &NSEvent) { trace_scope!("pressureChangeWithEvent:"); - self.queue_event(WindowEvent::TouchpadPressure { + self.queue_event(SurfaceEvent::TouchpadPressure { device_id: None, pressure: unsafe { event.pressure() }, stage: unsafe { event.stage() } as i64, @@ -840,7 +840,7 @@ impl WinitView { self.ivars()._ns_window.load().expect("view to have a window") } - fn queue_event(&self, event: WindowEvent) { + fn queue_event(&self, event: SurfaceEvent) { let window_id = self.window().id(); self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| { app.window_event(event_loop, window_id, event); @@ -899,7 +899,7 @@ impl WinitView { if self.ivars().ime_state.get() != ImeState::Disabled { self.ivars().ime_state.set(ImeState::Disabled); - self.queue_event(WindowEvent::Ime(Ime::Disabled)); + self.queue_event(SurfaceEvent::Ime(Ime::Disabled)); } } @@ -914,7 +914,7 @@ impl WinitView { pub(super) fn reset_modifiers(&self) { if !self.ivars().modifiers.get().state().is_empty() { self.ivars().modifiers.set(Modifiers::default()); - self.queue_event(WindowEvent::ModifiersChanged(self.ivars().modifiers.get())); + self.queue_event(SurfaceEvent::ModifiersChanged(self.ivars().modifiers.get())); } } @@ -978,7 +978,7 @@ impl WinitView { let mut event = event.clone(); event.location = KeyLocation::Left; event.physical_key = get_left_modifier_code(&event.logical_key).into(); - events.push_back(WindowEvent::KeyboardInput { + events.push_back(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -987,7 +987,7 @@ impl WinitView { if phys_mod.contains(ModLocationMask::RIGHT) { event.location = KeyLocation::Right; event.physical_key = get_right_modifier_code(&event.logical_key).into(); - events.push_back(WindowEvent::KeyboardInput { + events.push_back(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -1018,7 +1018,7 @@ impl WinitView { event.state = if is_pressed { Pressed } else { Released }; } - events.push_back(WindowEvent::KeyboardInput { + events.push_back(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -1037,7 +1037,7 @@ impl WinitView { return; } - self.queue_event(WindowEvent::ModifiersChanged(self.ivars().modifiers.get())); + self.queue_event(SurfaceEvent::ModifiersChanged(self.ivars().modifiers.get())); } fn mouse_click(&self, event: &NSEvent, button_state: ElementState) { @@ -1046,7 +1046,7 @@ impl WinitView { self.update_modifiers(event, false); - self.queue_event(WindowEvent::PointerButton { + self.queue_event(SurfaceEvent::PointerButton { device_id: None, state: button_state, position, @@ -1072,7 +1072,7 @@ impl WinitView { self.update_modifiers(event, false); - self.queue_event(WindowEvent::PointerMoved { + self.queue_event(SurfaceEvent::PointerMoved { device_id: None, position: view_point.to_physical(self.scale_factor()), source: PointerSource::Mouse, diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 9373042ae8..f74b50dd98 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -12,7 +12,7 @@ use crate::error::RequestError; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::window::{ Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; pub(crate) struct Window { @@ -91,7 +91,7 @@ impl rwh_06::HasWindowHandle for Window { } impl CoreWindow for Window { - fn id(&self) -> crate::window::WindowId { + fn id(&self) -> crate::window::SurfaceId { self.maybe_wait_on_main(|delegate| delegate.id()) } @@ -364,7 +364,7 @@ declare_class!( ); impl WinitWindow { - pub(super) fn id(&self) -> WindowId { - WindowId::from_raw(self as *const Self as usize) + pub(super) fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self as *const Self as usize) } } diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index 10aac698f0..86f507e857 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -36,11 +36,11 @@ use super::window::WinitWindow; use super::{ffi, Fullscreen, MonitorHandle}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{SurfaceSizeWriter, WindowEvent}; +use crate::event::{SurfaceSizeWriter, SurfaceEvent}; use crate::platform::macos::{OptionAsAlt, WindowExtMacOS}; use crate::window::{ Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; #[derive(Clone, Debug, PartialEq)] @@ -145,7 +145,7 @@ declare_class!( #[method(windowShouldClose:)] fn window_should_close(&self, _: Option<&AnyObject>) -> bool { trace_scope!("windowShouldClose:"); - self.queue_event(WindowEvent::CloseRequested); + self.queue_event(SurfaceEvent::CloseRequested); false } @@ -158,13 +158,13 @@ declare_class!( // be called after the window closes. self.window().setDelegate(None); }); - self.queue_event(WindowEvent::Destroyed); + self.queue_event(SurfaceEvent::Destroyed); } #[method(windowDidResize:)] fn window_did_resize(&self, _: Option<&AnyObject>) { trace_scope!("windowDidResize:"); - // NOTE: WindowEvent::SurfaceResized is reported in frameDidChange. + // NOTE: SurfaceEvent::SurfaceResized is reported in frameDidChange. self.emit_move_event(); } @@ -210,7 +210,7 @@ declare_class!( trace_scope!("windowDidBecomeKey:"); // TODO: center the cursor if the window had mouse grab when it // lost focus - self.queue_event(WindowEvent::Focused(true)); + self.queue_event(SurfaceEvent::Focused(true)); } #[method(windowDidResignKey:)] @@ -225,7 +225,7 @@ declare_class!( // a synthetic ModifiersChanged event when we lose focus. self.view().reset_modifiers(); - self.queue_event(WindowEvent::Focused(false)); + self.queue_event(SurfaceEvent::Focused(false)); } /// Invoked when before enter fullscreen @@ -350,7 +350,7 @@ declare_class!( fn window_did_change_occlusion_state(&self, _: Option<&AnyObject>) { trace_scope!("windowDidChangeOcclusionState:"); let visible = self.window().occlusionState().contains(NSWindowOcclusionState::Visible); - self.queue_event(WindowEvent::Occluded(!visible)); + self.queue_event(SurfaceEvent::Occluded(!visible)); } #[method(windowDidChangeScreen:)] @@ -379,7 +379,7 @@ declare_class!( filenames.into_iter().for_each(|file| { let path = PathBuf::from(file.to_string()); - self.queue_event(WindowEvent::HoveredFile(path)); + self.queue_event(SurfaceEvent::HoveredFile(path)); }); true @@ -405,7 +405,7 @@ declare_class!( filenames.into_iter().for_each(|file| { let path = PathBuf::from(file.to_string()); - self.queue_event(WindowEvent::DroppedFile(path)); + self.queue_event(SurfaceEvent::DroppedFile(path)); }); true @@ -421,7 +421,7 @@ declare_class!( #[method(draggingExited:)] fn dragging_exited(&self, _sender: Option<&NSObject>) { trace_scope!("draggingExited:"); - self.queue_event(WindowEvent::HoveredFileCancelled); + self.queue_event(SurfaceEvent::HoveredFileCancelled); } } @@ -469,7 +469,7 @@ declare_class!( return; } - self.queue_event(WindowEvent::ThemeChanged(new)); + self.queue_event(SurfaceEvent::ThemeChanged(new)); } else { panic!("unknown observed keypath {key_path:?}"); } @@ -778,7 +778,7 @@ impl WindowDelegate { // XXX Send `Focused(false)` right after creating the window delegate, so we won't // obscure the real focused events on the startup. - delegate.queue_event(WindowEvent::Focused(false)); + delegate.queue_event(SurfaceEvent::Focused(false)); // Set fullscreen mode after we setup everything delegate.set_fullscreen(attrs.fullscreen.map(Into::into)); @@ -814,11 +814,11 @@ impl WindowDelegate { } #[track_caller] - pub(crate) fn id(&self) -> WindowId { + pub(crate) fn id(&self) -> SurfaceId { self.window().id() } - pub(crate) fn queue_event(&self, event: WindowEvent) { + pub(crate) fn queue_event(&self, event: SurfaceEvent) { let window_id = self.window().id(); self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| { app.window_event(event_loop, window_id, event); @@ -833,7 +833,7 @@ impl WindowDelegate { let suggested_size = content_size.to_physical(scale_factor); let new_surface_size = Arc::new(Mutex::new(suggested_size)); - self.queue_event(WindowEvent::ScaleFactorChanged { + self.queue_event(SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)), }); @@ -845,7 +845,7 @@ impl WindowDelegate { let size = NSSize::new(logical_size.width, logical_size.height); window.setContentSize(size); } - self.queue_event(WindowEvent::SurfaceResized(physical_size)); + self.queue_event(SurfaceEvent::SurfaceResized(physical_size)); } fn emit_move_event(&self) { @@ -857,7 +857,7 @@ impl WindowDelegate { let position = LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::Moved(position)); + self.queue_event(SurfaceEvent::Moved(position)); } fn set_style_mask(&self, mask: NSWindowStyleMask) { diff --git a/src/platform_impl/apple/uikit/app_state.rs b/src/platform_impl/apple/uikit/app_state.rs index 4b5880d170..5776c1f0dc 100644 --- a/src/platform_impl/apple/uikit/app_state.rs +++ b/src/platform_impl/apple/uikit/app_state.rs @@ -27,7 +27,7 @@ use super::window::WinitUIWindow; use super::ActiveEventLoop; use crate::application::ApplicationHandler; use crate::dpi::PhysicalSize; -use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent}; +use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; use crate::event_loop::ControlFlow; macro_rules! bug { @@ -71,7 +71,7 @@ fn handle_event(mtm: MainThreadMarker, event: Event) { let event_loop = &ActiveEventLoop { mtm }; get_handler(mtm).handle(|app| match event { Event::NewEvents(cause) => app.new_events(event_loop, cause), - Event::WindowEvent { window_id, event } => app.window_event(event_loop, window_id, event), + Event::SurfaceEvent { window_id, event } => app.window_event(event_loop, window_id, event), Event::DeviceEvent { device_id, event } => app.device_event(event_loop, device_id, event), Event::UserWakeUp => app.proxy_wake_up(event_loop), Event::Suspended => app.suspended(event_loop), @@ -103,7 +103,7 @@ enum UserCallbackTransitionResult<'a> { impl Event { fn is_redraw(&self) -> bool { - matches!(self, Event::WindowEvent { event: WindowEvent::RedrawRequested, .. }) + matches!(self, Event::SurfaceEvent { event: SurfaceEvent::RedrawRequested, .. }) } } @@ -597,9 +597,9 @@ pub(crate) fn send_occluded_event_for_all_windows(application: &UIApplication, o let ptr: *const WinitUIWindow = ptr.cast(); &*ptr }; - events.push(EventWrapper::StaticEvent(Event::WindowEvent { + events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::Occluded(occluded), + event: SurfaceEvent::Occluded(occluded), })); } } @@ -624,9 +624,9 @@ pub fn handle_main_events_cleared(mtm: MainThreadMarker) { .main_events_cleared_transition() .into_iter() .map(|window| { - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::RedrawRequested, + event: SurfaceEvent::RedrawRequested, }) }) .collect(); @@ -653,9 +653,9 @@ pub(crate) fn terminated(application: &UIApplication) { let ptr: *const WinitUIWindow = ptr.cast(); &*ptr }; - events.push(EventWrapper::StaticEvent(Event::WindowEvent { + events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::Destroyed, + event: SurfaceEvent::Destroyed, })); } } @@ -671,9 +671,9 @@ pub(crate) fn terminated(application: &UIApplication) { fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) { let ScaleFactorChanged { suggested_size, scale_factor, window } = event; let new_surface_size = Arc::new(Mutex::new(suggested_size)); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::ScaleFactorChanged { + event: SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)), }, diff --git a/src/platform_impl/apple/uikit/view.rs b/src/platform_impl/apple/uikit/view.rs index e4c1844006..377fea562d 100644 --- a/src/platform_impl/apple/uikit/view.rs +++ b/src/platform_impl/apple/uikit/view.rs @@ -18,7 +18,7 @@ use super::FingerId; use crate::dpi::PhysicalPosition; use crate::event::{ ButtonSource, ElementState, Event, FingerId as RootFingerId, Force, KeyEvent, PointerKind, - PointerSource, TouchPhase, WindowEvent, + PointerSource, TouchPhase, SurfaceEvent, }; use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKeyCode, PhysicalKey}; use crate::platform_impl::KeyEventExtra; @@ -57,9 +57,9 @@ declare_class!( let window = self.window().unwrap(); app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::RedrawRequested, + event: SurfaceEvent::RedrawRequested, }), ); let _: () = unsafe { msg_send![super(self), drawRect: rect] }; @@ -92,9 +92,9 @@ declare_class!( app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::SurfaceResized(size), + event: SurfaceEvent::SurfaceResized(size), }), ); } @@ -143,9 +143,9 @@ declare_class!( }, )) .chain(std::iter::once(EventWrapper::StaticEvent( - Event::WindowEvent { + Event::SurfaceEvent { window_id, - event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)), + event: SurfaceEvent::SurfaceResized(size.to_physical(scale_factor)), }, ))), ); @@ -196,9 +196,9 @@ declare_class!( state => panic!("unexpected recognizer state: {:?}", state), }; - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::PinchGesture { + event: SurfaceEvent::PinchGesture { device_id: None, delta: delta as f64, phase, @@ -214,9 +214,9 @@ declare_class!( let window = self.window().unwrap(); if recognizer.state() == UIGestureRecognizerState::Ended { - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::DoubleTapGesture { + event: SurfaceEvent::DoubleTapGesture { device_id: None, }, }); @@ -256,9 +256,9 @@ declare_class!( }; // Make delta negative to match macos, convert to degrees - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::RotationGesture { + event: SurfaceEvent::RotationGesture { device_id: None, delta: -delta.to_degrees() as _, phase, @@ -307,9 +307,9 @@ declare_class!( }; - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::PanGesture { + event: SurfaceEvent::PanGesture { device_id: None, delta: PhysicalPosition::new(dx as _, dy as _), phase, @@ -517,9 +517,9 @@ impl WinitView { match phase { UITouchPhase::Began => { - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerEntered { + event: SurfaceEvent::PointerEntered { device_id: None, position, kind: if let UITouchType::Pencil = touch_type { @@ -529,9 +529,9 @@ impl WinitView { }, }, })); - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: ElementState::Pressed, position, @@ -544,9 +544,9 @@ impl WinitView { })); }, UITouchPhase::Moved => { - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id: None, position, source: if let UITouchType::Pencil = touch_type { @@ -560,9 +560,9 @@ impl WinitView { // 2 is UITouchPhase::Stationary and is not expected here UITouchPhase::Ended | UITouchPhase::Cancelled => { if let UITouchPhase::Ended = phase { - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: ElementState::Released, position, @@ -575,9 +575,9 @@ impl WinitView { })); } - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerLeft { + event: SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: if let UITouchType::Pencil = touch_type { @@ -606,9 +606,9 @@ impl WinitView { let text = smol_str::SmolStr::from_iter([c]); // Emit both press and release events [ElementState::Pressed, ElementState::Released].map(|state| { - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { event: KeyEvent { text: if state == ElementState::Pressed { Some(text.clone()) @@ -640,9 +640,9 @@ impl WinitView { app_state::handle_nonuser_events( mtm, [ElementState::Pressed, ElementState::Released].map(|state| { - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { device_id: None, event: KeyEvent { state, diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index e5d1f9d2a5..9e7ac42b8e 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -20,13 +20,13 @@ use super::{app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle}; use crate::cursor::Cursor; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{Event, WindowEvent}; +use crate::event::{Event, SurfaceEvent}; use crate::icon::Icon; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations}; use crate::window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; declare_class!( @@ -48,9 +48,9 @@ declare_class!( let mtm = MainThreadMarker::new().unwrap(); app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: self.id(), - event: WindowEvent::Focused(true), + event: SurfaceEvent::Focused(true), }), ); let _: () = unsafe { msg_send![super(self), becomeKeyWindow] }; @@ -61,9 +61,9 @@ declare_class!( let mtm = MainThreadMarker::new().unwrap(); app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: self.id(), - event: WindowEvent::Focused(false), + event: SurfaceEvent::Focused(false), }), ); let _: () = unsafe { msg_send![super(self), resignKeyWindow] }; @@ -104,8 +104,8 @@ impl WinitUIWindow { this } - pub(crate) fn id(&self) -> WindowId { - WindowId::from_raw(self as *const Self as usize) + pub(crate) fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self as *const Self as usize) } } @@ -416,7 +416,7 @@ impl Inner { Some(MonitorHandle::new(UIScreen::mainScreen(MainThreadMarker::new().unwrap()))) } - pub fn id(&self) -> WindowId { + pub fn id(&self) -> SurfaceId { self.window.id() } @@ -530,9 +530,9 @@ impl Window { suggested_size: size.to_physical(scale_factor), })) .chain(std::iter::once(EventWrapper::StaticEvent( - Event::WindowEvent { + Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)), + event: SurfaceEvent::SurfaceResized(size.to_physical(scale_factor)), }, ))), ); @@ -584,7 +584,7 @@ impl rwh_06::HasWindowHandle for Window { } impl CoreWindow for Window { - fn id(&self) -> crate::window::WindowId { + fn id(&self) -> crate::window::SurfaceId { self.maybe_wait_on_main(|delegate| delegate.id()) } diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 2ab9e5b9e3..7ebb27c706 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -25,7 +25,7 @@ use crate::keyboard::{ }; use crate::platform_impl::Window; use crate::window::{ - CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, WindowId, + CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, SurfaceId, }; fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { @@ -314,7 +314,7 @@ impl EventLoop { } fn process_event( - window_id: WindowId, + window_id: SurfaceId, event_option: EventOption, event_state: &mut EventState, window_target: &ActiveEventLoop, @@ -505,7 +505,7 @@ impl EventLoop { let mut creates = self.window_target.creates.lock().unwrap(); creates.pop_front() } { - let window_id = WindowId::from_raw(window.fd); + let window_id = SurfaceId::from_raw(window.fd); let mut buf: [u8; 4096] = [0; 4096]; let path = window.fpath(&mut buf).expect("failed to read properties"); @@ -529,14 +529,14 @@ impl EventLoop { } { app.window_event(&self.window_target, destroy_id, event::SurfaceEvent::Destroyed); self.windows - .retain(|(window, _event_state)| WindowId::from_raw(window.fd) != destroy_id); + .retain(|(window, _event_state)| SurfaceId::from_raw(window.fd) != destroy_id); } // Handle window events. let mut i = 0; // While loop is used here because the same window may be processed more than once. while let Some((window, event_state)) = self.windows.get_mut(i) { - let window_id = WindowId::from_raw(window.fd); + let window_id = SurfaceId::from_raw(window.fd); let mut event_buf = [0u8; 16 * mem::size_of::()]; let count = @@ -702,8 +702,8 @@ pub struct ActiveEventLoop { control_flow: Cell, exit: Cell, pub(super) creates: Mutex>>, - pub(super) redraws: Arc>>, - pub(super) destroys: Arc>>, + pub(super) redraws: Arc>>, + pub(super) destroys: Arc>>, pub(super) event_socket: Arc, pub(super) wake_socket: Arc, user_events_sender: mpsc::SyncSender<()>, diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 0446a4ecca..7644a6771d 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -6,7 +6,7 @@ use crate::cursor::Cursor; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; use crate::monitor::MonitorHandle as CoreMonitorHandle; -use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId}; +use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, SurfaceId}; // 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 @@ -21,8 +21,8 @@ const ORBITAL_FLAG_TRANSPARENT: char = 't'; pub struct Window { window_socket: Arc, - redraws: Arc>>, - destroys: Arc>>, + redraws: Arc>>, + destroys: Arc>>, wake_socket: Arc, } @@ -155,8 +155,8 @@ impl Window { } impl CoreWindow for Window { - fn id(&self) -> WindowId { - WindowId::from_raw(self.window_socket.fd) + fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self.window_socket.fd) } #[inline]