From 3b06f647f19edde57a1c717f4b98545ec6874325 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 24 Dec 2023 01:49:47 +0100 Subject: [PATCH] Remove generic parameter T from EventLoopWindowTarget --- CHANGELOG.md | 1 + examples/child_window.rs | 2 +- examples/custom_cursors.rs | 2 +- src/cursor.rs | 9 ++---- src/event_loop.rs | 19 ++++++----- src/platform/android.rs | 2 +- src/platform/macos.rs | 2 +- src/platform/pump_events.rs | 4 +-- src/platform/run_on_demand.rs | 4 +-- src/platform/startup_notify.rs | 2 +- src/platform/wayland.rs | 2 +- src/platform/web.rs | 6 ++-- src/platform/x11.rs | 2 +- src/platform_impl/android/mod.rs | 27 +++++++--------- src/platform_impl/ios/event_loop.rs | 24 ++++++-------- src/platform_impl/ios/window.rs | 4 +-- src/platform_impl/linux/mod.rs | 20 ++++++------ .../linux/wayland/event_loop/mod.rs | 21 +++++------- src/platform_impl/linux/wayland/output.rs | 2 +- src/platform_impl/linux/wayland/window/mod.rs | 4 +-- .../linux/x11/event_processor.rs | 14 ++++---- src/platform_impl/linux/x11/mod.rs | 29 ++++++++--------- src/platform_impl/linux/x11/window.rs | 4 +-- src/platform_impl/macos/app_state.rs | 8 ++--- src/platform_impl/macos/cursor.rs | 5 +-- src/platform_impl/macos/event_loop.rs | 32 ++++++++----------- src/platform_impl/macos/window.rs | 4 +-- src/platform_impl/orbital/event_loop.rs | 18 ++++------- src/platform_impl/orbital/window.rs | 4 +-- src/platform_impl/web/cursor.rs | 4 +-- src/platform_impl/web/event_loop/mod.rs | 12 +++---- .../web/event_loop/window_target.rs | 18 ++--------- src/platform_impl/web/window.rs | 4 +-- src/platform_impl/windows/event_loop.rs | 24 ++++++-------- src/platform_impl/windows/window.rs | 25 +++++++-------- src/window.rs | 7 ++-- 36 files changed, 156 insertions(+), 215 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d222094316..7069c88f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Unreleased` header. # Unreleased +- **Breaking:** Removed unnecessary generic parameter `T` from `EventLoopWindowTarget`. - On Windows, macOS, X11, Wayland and Web, implement setting images as cursors. See the `custom_cursors.rs` example. - Add `Window::set_custom_cursor` - Add `CustomCursor` diff --git a/examples/child_window.rs b/examples/child_window.rs index 9234d9e4e6..2693dbdc08 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -23,7 +23,7 @@ fn main() -> Result<(), impl std::error::Error> { fn spawn_child_window( parent: &Window, - event_loop: &EventLoopWindowTarget<()>, + event_loop: &EventLoopWindowTarget, windows: &mut HashMap, ) { let parent = parent.raw_window_handle().unwrap(); diff --git a/examples/custom_cursors.rs b/examples/custom_cursors.rs index c29dd863f2..4ffac80ae2 100644 --- a/examples/custom_cursors.rs +++ b/examples/custom_cursors.rs @@ -9,7 +9,7 @@ use winit::{ window::{CustomCursor, WindowBuilder}, }; -fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomCursor { +fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomCursor { let img = image::load_from_memory(bytes).unwrap().to_rgba8(); let samples = img.into_flat_samples(); let (_, w, h) = samples.extents(); diff --git a/src/cursor.rs b/src/cursor.rs index 08ac912d53..a821486485 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -87,7 +87,7 @@ pub struct CustomCursorBuilder { } impl CustomCursorBuilder { - pub fn build(self, window_target: &EventLoopWindowTarget) -> CustomCursor { + pub fn build(self, window_target: &EventLoopWindowTarget) -> CustomCursor { CustomCursor { inner: PlatformCustomCursor::build(self.inner, &window_target.p), } @@ -189,10 +189,7 @@ impl Eq for OnlyCursorImage {} #[allow(dead_code)] impl OnlyCursorImage { - fn build( - builder: OnlyCursorImageBuilder, - _: &platform_impl::EventLoopWindowTarget, - ) -> Self { + fn build(builder: OnlyCursorImageBuilder, _: &platform_impl::EventLoopWindowTarget) -> Self { Self(Arc::new(builder.0)) } } @@ -272,7 +269,7 @@ impl NoCustomCursor { Ok(Self) } - fn build(self, _: &platform_impl::EventLoopWindowTarget) -> NoCustomCursor { + fn build(self, _: &platform_impl::EventLoopWindowTarget) -> NoCustomCursor { self } } diff --git a/src/event_loop.rs b/src/event_loop.rs index e2591aa51e..15bf05c84b 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -48,9 +48,8 @@ pub struct EventLoop { /// your callback. [`EventLoop`] will coerce into this type (`impl Deref for /// EventLoop`), so functions that take this as a parameter can also take /// `&EventLoop`. -pub struct EventLoopWindowTarget { - pub(crate) p: platform_impl::EventLoopWindowTarget, - pub(crate) _marker: PhantomData<*mut T>, // Not Send nor Sync + invariant over T +pub struct EventLoopWindowTarget { + pub(crate) p: platform_impl::EventLoopWindowTarget, } /// Object that allows building the event loop. @@ -142,7 +141,7 @@ impl fmt::Debug for EventLoop { } } -impl fmt::Debug for EventLoopWindowTarget { +impl fmt::Debug for EventLoopWindowTarget { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("EventLoopWindowTarget { .. }") } @@ -244,7 +243,7 @@ impl EventLoop { #[cfg(not(all(wasm_platform, target_feature = "exception-handling")))] pub fn run(self, event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &EventLoopWindowTarget), + F: FnMut(Event, &EventLoopWindowTarget), { self.event_loop.run(event_handler) } @@ -301,13 +300,13 @@ impl AsRawFd for EventLoop { } impl Deref for EventLoop { - type Target = EventLoopWindowTarget; - fn deref(&self) -> &EventLoopWindowTarget { + type Target = EventLoopWindowTarget; + fn deref(&self) -> &EventLoopWindowTarget { self.event_loop.window_target() } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { /// Returns the list of all the monitors available on the system. #[inline] pub fn available_monitors(&self) -> impl Iterator { @@ -373,7 +372,7 @@ impl EventLoopWindowTarget { } #[cfg(feature = "rwh_06")] -impl rwh_06::HasDisplayHandle for EventLoopWindowTarget { +impl rwh_06::HasDisplayHandle for EventLoopWindowTarget { fn display_handle(&self) -> Result, rwh_06::HandleError> { let raw = self.p.raw_display_handle_rwh_06()?; // SAFETY: The display will never be deallocated while the event loop is alive. @@ -382,7 +381,7 @@ impl rwh_06::HasDisplayHandle for EventLoopWindowTarget { } #[cfg(feature = "rwh_05")] -unsafe impl rwh_05::HasRawDisplayHandle for EventLoopWindowTarget { +unsafe impl rwh_05::HasRawDisplayHandle for EventLoopWindowTarget { /// Returns a [`rwh_05::RawDisplayHandle`] for the event loop. fn raw_display_handle(&self) -> rwh_05::RawDisplayHandle { self.p.raw_display_handle_rwh_05() diff --git a/src/platform/android.rs b/src/platform/android.rs index b5fde4ad49..c80fbeac29 100644 --- a/src/platform/android.rs +++ b/src/platform/android.rs @@ -30,7 +30,7 @@ impl WindowExtAndroid for Window { } } -impl EventLoopWindowTargetExtAndroid for EventLoopWindowTarget {} +impl EventLoopWindowTargetExtAndroid for EventLoopWindowTarget {} /// Additional methods on [`WindowBuilder`] that are specific to Android. pub trait WindowBuilderExtAndroid {} diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 65cfbe8992..ac7b0a6fb4 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -386,7 +386,7 @@ pub trait EventLoopWindowTargetExtMacOS { fn allows_automatic_window_tabbing(&self) -> bool; } -impl EventLoopWindowTargetExtMacOS for EventLoopWindowTarget { +impl EventLoopWindowTargetExtMacOS for EventLoopWindowTarget { fn hide_application(&self) { self.p.hide_application() } diff --git a/src/platform/pump_events.rs b/src/platform/pump_events.rs index ccaf148586..403c52d978 100644 --- a/src/platform/pump_events.rs +++ b/src/platform/pump_events.rs @@ -174,7 +174,7 @@ pub trait EventLoopExtPumpEvents { /// callback. fn pump_events(&mut self, timeout: Option, event_handler: F) -> PumpStatus where - F: FnMut(Event, &EventLoopWindowTarget); + F: FnMut(Event, &EventLoopWindowTarget); } impl EventLoopExtPumpEvents for EventLoop { @@ -182,7 +182,7 @@ impl EventLoopExtPumpEvents for EventLoop { fn pump_events(&mut self, timeout: Option, event_handler: F) -> PumpStatus where - F: FnMut(Event, &EventLoopWindowTarget), + F: FnMut(Event, &EventLoopWindowTarget), { self.event_loop.pump_events(timeout, event_handler) } diff --git a/src/platform/run_on_demand.rs b/src/platform/run_on_demand.rs index 5326e92c74..03e49a961a 100644 --- a/src/platform/run_on_demand.rs +++ b/src/platform/run_on_demand.rs @@ -66,7 +66,7 @@ pub trait EventLoopExtRunOnDemand { /// [`set_control_flow()`]: EventLoopWindowTarget::set_control_flow() fn run_on_demand(&mut self, event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &EventLoopWindowTarget); + F: FnMut(Event, &EventLoopWindowTarget); } impl EventLoopExtRunOnDemand for EventLoop { @@ -74,7 +74,7 @@ impl EventLoopExtRunOnDemand for EventLoop { fn run_on_demand(&mut self, event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &EventLoopWindowTarget), + F: FnMut(Event, &EventLoopWindowTarget), { self.event_loop.run_on_demand(event_handler) } diff --git a/src/platform/startup_notify.rs b/src/platform/startup_notify.rs index 323c2fe624..207aff86cb 100644 --- a/src/platform/startup_notify.rs +++ b/src/platform/startup_notify.rs @@ -55,7 +55,7 @@ pub trait WindowBuilderExtStartupNotify { fn with_activation_token(self, token: ActivationToken) -> Self; } -impl EventLoopExtStartupNotify for EventLoopWindowTarget { +impl EventLoopExtStartupNotify for EventLoopWindowTarget { fn read_token_from_env(&self) -> Option { match self.p { #[cfg(wayland_platform)] diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index ba87651858..99ae6b295a 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -14,7 +14,7 @@ pub trait EventLoopWindowTargetExtWayland { fn is_wayland(&self) -> bool; } -impl EventLoopWindowTargetExtWayland for EventLoopWindowTarget { +impl EventLoopWindowTargetExtWayland for EventLoopWindowTarget { #[inline] fn is_wayland(&self) -> bool { self.p.is_wayland() diff --git a/src/platform/web.rs b/src/platform/web.rs index 2d79914924..f0f8d2e9ac 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -136,7 +136,7 @@ pub trait EventLoopExtWebSys { /// [^1]: `run()` is _not_ available on WASM when the target supports `exception-handling`. fn spawn(self, event_handler: F) where - F: 'static + FnMut(Event, &EventLoopWindowTarget); + F: 'static + FnMut(Event, &EventLoopWindowTarget); } impl EventLoopExtWebSys for EventLoop { @@ -144,7 +144,7 @@ impl EventLoopExtWebSys for EventLoop { fn spawn(self, event_handler: F) where - F: 'static + FnMut(Event, &EventLoopWindowTarget), + F: 'static + FnMut(Event, &EventLoopWindowTarget), { self.event_loop.spawn(event_handler) } @@ -166,7 +166,7 @@ pub trait EventLoopWindowTargetExtWebSys { fn poll_strategy(&self) -> PollStrategy; } -impl EventLoopWindowTargetExtWebSys for EventLoopWindowTarget { +impl EventLoopWindowTargetExtWebSys for EventLoopWindowTarget { #[inline] fn set_poll_strategy(&self, strategy: PollStrategy) { self.p.set_poll_strategy(strategy); diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 5cbd2fe32a..194f02145f 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -48,7 +48,7 @@ pub trait EventLoopWindowTargetExtX11 { fn is_x11(&self) -> bool; } -impl EventLoopWindowTargetExtX11 for EventLoopWindowTarget { +impl EventLoopWindowTargetExtX11 for EventLoopWindowTarget { #[inline] fn is_x11(&self) -> bool { !self.p.is_wayland() diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index cf28c21bbe..159ab8448c 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -138,7 +138,7 @@ pub struct KeyEventExtra {} pub struct EventLoop { android_app: AndroidApp, - window_target: event_loop::EventLoopWindowTarget, + window_target: event_loop::EventLoopWindowTarget, redraw_flag: SharedFlag, user_events_sender: mpsc::Sender, user_events_receiver: PeekableReceiver, //must wake looper whenever something gets sent @@ -185,9 +185,7 @@ impl EventLoop { &redraw_flag, android_app.create_waker(), ), - _marker: std::marker::PhantomData, }, - _marker: std::marker::PhantomData, }, redraw_flag, user_events_sender, @@ -203,7 +201,7 @@ impl EventLoop { fn single_iteration(&mut self, main_event: Option>, callback: &mut F) where - F: FnMut(event::Event, &RootELW), + F: FnMut(event::Event, &RootELW), { trace!("Mainloop iteration"); @@ -375,7 +373,7 @@ impl EventLoop { callback: &mut F, ) -> InputStatus where - F: FnMut(event::Event, &RootELW), + F: FnMut(event::Event, &RootELW), { let mut input_status = InputStatus::Handled; match event { @@ -480,14 +478,14 @@ impl EventLoop { pub fn run(mut self, event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(event::Event, &event_loop::EventLoopWindowTarget), + F: FnMut(event::Event, &event_loop::EventLoopWindowTarget), { self.run_on_demand(event_handler) } pub fn run_on_demand(&mut self, mut event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(event::Event, &event_loop::EventLoopWindowTarget), + F: FnMut(event::Event, &event_loop::EventLoopWindowTarget), { if self.loop_running { return Err(EventLoopError::AlreadyRunning); @@ -510,7 +508,7 @@ impl EventLoop { pub fn pump_events(&mut self, timeout: Option, mut callback: F) -> PumpStatus where - F: FnMut(event::Event, &RootELW), + F: FnMut(event::Event, &RootELW), { if !self.loop_running { self.loop_running = true; @@ -543,7 +541,7 @@ impl EventLoop { fn poll_events_with_timeout(&mut self, mut timeout: Option, mut callback: F) where - F: FnMut(event::Event, &RootELW), + F: FnMut(event::Event, &RootELW), { let start = Instant::now(); @@ -619,7 +617,7 @@ impl EventLoop { }); } - pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { + pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { &self.window_target } @@ -663,15 +661,14 @@ impl EventLoopProxy { } } -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { app: AndroidApp, control_flow: Cell, exit: Cell, redraw_requester: RedrawRequester, - _marker: std::marker::PhantomData, } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub fn primary_monitor(&self) -> Option { Some(MonitorHandle::new(self.app.clone())) } @@ -757,8 +754,8 @@ pub(crate) struct Window { } impl Window { - pub(crate) fn new( - el: &EventLoopWindowTarget, + pub(crate) fn new( + el: &EventLoopWindowTarget, _window_attrs: window::WindowAttributes, _: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index a260f78aec..029f2200e2 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -2,7 +2,6 @@ use std::{ collections::VecDeque, ffi::c_void, fmt::{self, Debug}, - marker::PhantomData, ptr, sync::mpsc::{self, Receiver, Sender}, }; @@ -34,12 +33,11 @@ use super::{ }; #[derive(Debug)] -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { pub(super) mtm: MainThreadMarker, - p: PhantomData, } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub fn available_monitors(&self) -> VecDeque { monitor::uiscreens(self.mtm) } @@ -90,7 +88,7 @@ pub struct EventLoop { mtm: MainThreadMarker, sender: Sender, receiver: Receiver, - window_target: RootEventLoopWindowTarget, + window_target: RootEventLoopWindowTarget, } #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -123,18 +121,14 @@ impl EventLoop { sender, receiver, window_target: RootEventLoopWindowTarget { - p: EventLoopWindowTarget { - mtm, - p: PhantomData, - }, - _marker: PhantomData, + p: EventLoopWindowTarget { mtm }, }, }) } pub fn run(self, event_handler: F) -> ! where - F: FnMut(Event, &RootEventLoopWindowTarget), + F: FnMut(Event, &RootEventLoopWindowTarget), { unsafe { let application = UIApplication::shared(self.mtm); @@ -146,7 +140,7 @@ impl EventLoop { ); let event_handler = std::mem::transmute::< - Box, &RootEventLoopWindowTarget)>, + Box, &RootEventLoopWindowTarget)>, Box>, >(Box::new(event_handler)); @@ -175,7 +169,7 @@ impl EventLoop { EventLoopProxy::new(self.sender.clone()) } - pub fn window_target(&self) -> &RootEventLoopWindowTarget { + pub fn window_target(&self) -> &RootEventLoopWindowTarget { &self.window_target } } @@ -346,7 +340,7 @@ fn setup_control_flow_observers() { #[derive(Debug)] pub enum Never {} -type EventHandlerCallback = dyn FnMut(Event, &RootEventLoopWindowTarget) + 'static; +type EventHandlerCallback = dyn FnMut(Event, &RootEventLoopWindowTarget) + 'static; pub trait EventHandler: Debug { fn handle_nonuser_event(&mut self, event: Event); @@ -356,7 +350,7 @@ pub trait EventHandler: Debug { struct EventLoopHandler { f: Box>, receiver: Receiver, - event_loop: RootEventLoopWindowTarget, + event_loop: RootEventLoopWindowTarget, } impl Debug for EventLoopHandler { diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index e34801696e..19bc78be2b 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -409,8 +409,8 @@ pub struct Window { } impl Window { - pub(crate) fn new( - event_loop: &EventLoopWindowTarget, + pub(crate) fn new( + event_loop: &EventLoopWindowTarget, window_attributes: WindowAttributes, platform_attributes: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 0cfd3cb8ba..98f32595c3 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -291,8 +291,8 @@ impl VideoMode { impl Window { #[inline] - pub(crate) fn new( - window_target: &EventLoopWindowTarget, + pub(crate) fn new( + window_target: &EventLoopWindowTarget, attribs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { @@ -816,26 +816,26 @@ impl EventLoop { pub fn run(mut self, callback: F) -> Result<(), EventLoopError> where - F: FnMut(crate::event::Event, &RootELW), + F: FnMut(crate::event::Event, &RootELW), { self.run_on_demand(callback) } pub fn run_on_demand(&mut self, callback: F) -> Result<(), EventLoopError> where - F: FnMut(crate::event::Event, &RootELW), + F: FnMut(crate::event::Event, &RootELW), { x11_or_wayland!(match self; EventLoop(evlp) => evlp.run_on_demand(callback)) } pub fn pump_events(&mut self, timeout: Option, callback: F) -> PumpStatus where - F: FnMut(crate::event::Event, &RootELW), + F: FnMut(crate::event::Event, &RootELW), { x11_or_wayland!(match self; EventLoop(evlp) => evlp.pump_events(timeout, callback)) } - pub fn window_target(&self) -> &crate::event_loop::EventLoopWindowTarget { + pub fn window_target(&self) -> &crate::event_loop::EventLoopWindowTarget { x11_or_wayland!(match self; EventLoop(evlp) => evlp.window_target()) } } @@ -858,14 +858,14 @@ impl EventLoopProxy { } } -pub enum EventLoopWindowTarget { +pub enum EventLoopWindowTarget { #[cfg(wayland_platform)] - Wayland(wayland::EventLoopWindowTarget), + Wayland(wayland::EventLoopWindowTarget), #[cfg(x11_platform)] - X(x11::EventLoopWindowTarget), + X(x11::EventLoopWindowTarget), } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { #[inline] pub fn is_wayland(&self) -> bool { match *self { diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index e0d6a36d78..099f176ed4 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -2,7 +2,6 @@ use std::cell::{Cell, RefCell}; use std::io::Result as IOResult; -use std::marker::PhantomData; use std::mem; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; use std::rc::Rc; @@ -63,7 +62,7 @@ pub struct EventLoop { connection: Connection, /// Event loop window target. - window_target: RootEventLoopWindowTarget, + window_target: RootEventLoopWindowTarget, // XXX drop after everything else, just to be safe. /// Calloop's event loop. @@ -167,7 +166,6 @@ impl EventLoop { control_flow: Cell::new(ControlFlow::default()), exit: Cell::new(None), state: RefCell::new(winit_state), - _marker: PhantomData, }; let event_loop = Self { @@ -182,7 +180,6 @@ impl EventLoop { event_loop, window_target: RootEventLoopWindowTarget { p: PlatformEventLoopWindowTarget::Wayland(window_target), - _marker: PhantomData, }, }; @@ -191,7 +188,7 @@ impl EventLoop { pub fn run_on_demand(&mut self, mut event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &RootEventLoopWindowTarget), + F: FnMut(Event, &RootEventLoopWindowTarget), { if self.loop_running { return Err(EventLoopError::AlreadyRunning); @@ -222,7 +219,7 @@ impl EventLoop { pub fn pump_events(&mut self, timeout: Option, mut callback: F) -> PumpStatus where - F: FnMut(Event, &RootEventLoopWindowTarget), + F: FnMut(Event, &RootEventLoopWindowTarget), { if !self.loop_running { self.loop_running = true; @@ -249,7 +246,7 @@ impl EventLoop { pub fn poll_events_with_timeout(&mut self, mut timeout: Option, mut callback: F) where - F: FnMut(Event, &RootEventLoopWindowTarget), + F: FnMut(Event, &RootEventLoopWindowTarget), { let cause = loop { let start = Instant::now(); @@ -325,7 +322,7 @@ impl EventLoop { fn single_iteration(&mut self, callback: &mut F, cause: StartCause) where - F: FnMut(Event, &RootEventLoopWindowTarget), + F: FnMut(Event, &RootEventLoopWindowTarget), { // NOTE currently just indented to simplify the diff @@ -530,7 +527,7 @@ impl EventLoop { } #[inline] - pub fn window_target(&self) -> &RootEventLoopWindowTarget { + pub fn window_target(&self) -> &RootEventLoopWindowTarget { &self.window_target } @@ -602,7 +599,7 @@ impl AsRawFd for EventLoop { } } -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { /// The event loop wakeup source. pub event_loop_awakener: calloop::ping::Ping, @@ -624,11 +621,9 @@ pub struct EventLoopWindowTarget { /// Connection to the wayland server. pub connection: Connection, - - _marker: std::marker::PhantomData, } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { #[inline] pub fn listen_device_events(&self, _allowed: DeviceEvents) {} diff --git a/src/platform_impl/linux/wayland/output.rs b/src/platform_impl/linux/wayland/output.rs index 4e288cdc06..7ac316ae58 100644 --- a/src/platform_impl/linux/wayland/output.rs +++ b/src/platform_impl/linux/wayland/output.rs @@ -9,7 +9,7 @@ use crate::platform_impl::platform::VideoMode as PlatformVideoMode; use super::event_loop::EventLoopWindowTarget; -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { #[inline] pub fn available_monitors(&self) -> impl Iterator { self.state diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 74ff1baf11..ad80e37a56 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -79,8 +79,8 @@ pub struct Window { } impl Window { - pub(crate) fn new( - event_loop_window_target: &EventLoopWindowTarget, + pub(crate) fn new( + event_loop_window_target: &EventLoopWindowTarget, attributes: WindowAttributes, platform_attributes: PlatformAttributes, ) -> Result { diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 6395d35828..6702422580 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -36,7 +36,7 @@ use crate::{ /// The X11 documentation states: "Keycodes lie in the inclusive range `[8, 255]`". const KEYCODE_OFFSET: u8 = 8; -pub(super) struct EventProcessor { +pub(super) struct EventProcessor { pub(super) dnd: Dnd, pub(super) ime_receiver: ImeReceiver, pub(super) ime_event_receiver: ImeEventReceiver, @@ -44,7 +44,7 @@ pub(super) struct EventProcessor { pub(super) devices: RefCell>, pub(super) xi2ext: ExtensionInformation, pub(super) xkbext: ExtensionInformation, - pub(super) target: Rc>, + pub(super) target: Rc, pub(super) kb_state: KbdState, // Number of touch events currently in progress pub(super) num_touch: u32, @@ -59,7 +59,7 @@ pub(super) struct EventProcessor { pub(super) is_composing: bool, } -impl EventProcessor { +impl EventProcessor { pub(super) fn init_device(&self, device: xinput::DeviceId) { let wt = get_xtarget(&self.target); let mut devices = self.devices.borrow_mut(); @@ -134,7 +134,7 @@ impl EventProcessor { result != 0 } - pub(super) fn process_event(&mut self, xev: &mut ffi::XEvent, mut callback: F) + pub(super) fn process_event(&mut self, xev: &mut ffi::XEvent, mut callback: F) where F: FnMut(Event), { @@ -1377,8 +1377,8 @@ impl EventProcessor { } } - fn handle_pressed_keys( - wt: &super::EventLoopWindowTarget, + fn handle_pressed_keys( + wt: &super::EventLoopWindowTarget, window_id: crate::window::WindowId, state: ElementState, kb_state: &mut KbdState, @@ -1408,7 +1408,7 @@ impl EventProcessor { } } - fn process_dpi_change(&self, callback: &mut F) + fn process_dpi_change(&self, callback: &mut F) where F: FnMut(Event), { diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 6d8d9fd305..f1d9ae2cea 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -143,7 +143,7 @@ impl PeekableReceiver { } } -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { xconn: Arc, wm_delete_window: xproto::Atom, net_wm_ping: xproto::Atom, @@ -156,19 +156,18 @@ pub struct EventLoopWindowTarget { redraw_sender: WakeSender, activation_sender: WakeSender, device_events: Cell, - _marker: ::std::marker::PhantomData, } pub struct EventLoop { loop_running: bool, event_loop: Loop<'static, EventLoopState>, waker: calloop::ping::Ping, - event_processor: EventProcessor, + event_processor: EventProcessor, redraw_receiver: PeekableReceiver, user_receiver: PeekableReceiver, activation_receiver: PeekableReceiver, user_sender: Sender, - target: Rc>, + target: Rc, /// The current state of the event loop. state: EventLoopState, @@ -308,7 +307,6 @@ impl EventLoop { control_flow: Cell::new(ControlFlow::default()), exit: Cell::new(None), windows: Default::default(), - _marker: ::std::marker::PhantomData, ime_sender, xconn, wm_delete_window, @@ -329,7 +327,6 @@ impl EventLoop { let target = Rc::new(RootELW { p: super::EventLoopWindowTarget::X(window_target), - _marker: ::std::marker::PhantomData, }); let event_processor = EventProcessor { @@ -395,13 +392,13 @@ impl EventLoop { } } - pub(crate) fn window_target(&self) -> &RootELW { + pub(crate) fn window_target(&self) -> &RootELW { &self.target } pub fn run_on_demand(&mut self, mut event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { if self.loop_running { return Err(EventLoopError::AlreadyRunning); @@ -435,7 +432,7 @@ impl EventLoop { pub fn pump_events(&mut self, timeout: Option, mut callback: F) -> PumpStatus where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { if !self.loop_running { self.loop_running = true; @@ -468,7 +465,7 @@ impl EventLoop { pub fn poll_events_with_timeout(&mut self, mut timeout: Option, mut callback: F) where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { let start = Instant::now(); @@ -546,7 +543,7 @@ impl EventLoop { fn single_iteration(&mut self, callback: &mut F, cause: StartCause) where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { callback(crate::event::Event::NewEvents(cause), &self.target); @@ -620,7 +617,7 @@ impl EventLoop { fn drain_events(&mut self, callback: &mut F) where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { let target = &self.target; let mut xev = MaybeUninit::uninit(); @@ -671,7 +668,7 @@ impl AsRawFd for EventLoop { } } -pub(crate) fn get_xtarget(target: &RootELW) -> &EventLoopWindowTarget { +pub(crate) fn get_xtarget(target: &RootELW) -> &EventLoopWindowTarget { match target.p { super::EventLoopWindowTarget::X(ref target) => target, #[cfg(wayland_platform)] @@ -679,7 +676,7 @@ pub(crate) fn get_xtarget(target: &RootELW) -> &EventLoopWindowTarget { } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { /// Returns the `XConnection` of this events loop. #[inline] pub(crate) fn x_connection(&self) -> &Arc { @@ -834,8 +831,8 @@ impl Deref for Window { } impl Window { - pub(crate) fn new( - event_loop: &EventLoopWindowTarget, + pub(crate) fn new( + event_loop: &EventLoopWindowTarget, attribs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index b7ea8e1a12..5da2d0d035 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -150,8 +150,8 @@ macro_rules! leap { impl UnownedWindow { #[allow(clippy::unnecessary_cast)] - pub(crate) fn new( - event_loop: &EventLoopWindowTarget, + pub(crate) fn new( + event_loop: &EventLoopWindowTarget, window_attrs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 3630b06b8c..75e37b6d71 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -45,18 +45,18 @@ pub trait EventHandler: Debug { fn handle_user_events(&mut self); } -pub(crate) type Callback = RefCell, &RootWindowTarget)>; +pub(crate) type Callback = RefCell, &RootWindowTarget)>; struct EventLoopHandler { callback: Weak>, - window_target: Rc>, + window_target: Rc, receiver: Rc>, } impl EventLoopHandler { fn with_callback(&mut self, f: F) where - F: FnOnce(&mut EventLoopHandler, RefMut<'_, dyn FnMut(Event, &RootWindowTarget)>), + F: FnOnce(&mut EventLoopHandler, RefMut<'_, dyn FnMut(Event, &RootWindowTarget)>), { // `NSApplication` and our `HANDLER` are global state and so it's possible // that we could get a delegate callback after the application has exit an @@ -370,7 +370,7 @@ impl AppState { /// a call to `clear_callback` before returning to avoid undefined behaviour. pub unsafe fn set_callback( callback: Weak>, - window_target: Rc>, + window_target: Rc, receiver: Rc>, ) { *HANDLER.callback.lock().unwrap() = Some(Box::new(EventLoopHandler { diff --git a/src/platform_impl/macos/cursor.rs b/src/platform_impl/macos/cursor.rs index 8f84b5e88d..4f5a06cbe4 100644 --- a/src/platform_impl/macos/cursor.rs +++ b/src/platform_impl/macos/cursor.rs @@ -24,10 +24,7 @@ unsafe impl Send for CustomCursor {} unsafe impl Sync for CustomCursor {} impl CustomCursor { - pub(crate) fn build( - cursor: OnlyCursorImageBuilder, - _: &EventLoopWindowTarget, - ) -> CustomCursor { + pub(crate) fn build(cursor: OnlyCursorImageBuilder, _: &EventLoopWindowTarget) -> CustomCursor { Self(cursor_from_image(&cursor.0)) } } diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 7bce3aba05..08597a3d4f 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -2,7 +2,6 @@ use std::{ any::Any, cell::{Cell, RefCell}, collections::VecDeque, - marker::PhantomData, mem, os::raw::c_void, panic::{catch_unwind, resume_unwind, AssertUnwindSafe, RefUnwindSafe, UnwindSafe}, @@ -74,12 +73,11 @@ impl PanicInfo { } #[derive(Debug)] -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { mtm: MainThreadMarker, - p: PhantomData, } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { #[inline] pub fn available_monitors(&self) -> VecDeque { monitor::available_monitors() @@ -127,7 +125,7 @@ impl EventLoopWindowTarget { } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub(crate) fn hide_application(&self) { NSApplication::sharedApplication(self.mtm).hide(None) } @@ -159,7 +157,7 @@ pub struct EventLoop { sender: mpsc::Sender, receiver: Rc>, - window_target: Rc>, + window_target: Rc, panic_info: Rc, /// We make sure that the callback closure is dropped during a panic @@ -228,24 +226,20 @@ impl EventLoop { sender, receiver: Rc::new(receiver), window_target: Rc::new(RootWindowTarget { - p: EventLoopWindowTarget { - mtm, - p: PhantomData, - }, - _marker: PhantomData, + p: EventLoopWindowTarget { mtm }, }), panic_info, _callback: None, }) } - pub fn window_target(&self) -> &RootWindowTarget { + pub fn window_target(&self) -> &RootWindowTarget { &self.window_target } pub fn run(mut self, callback: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &RootWindowTarget), + F: FnMut(Event, &RootWindowTarget), { self.run_on_demand(callback) } @@ -256,7 +250,7 @@ impl EventLoop { // redundant wake ups. pub fn run_on_demand(&mut self, callback: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &RootWindowTarget), + F: FnMut(Event, &RootWindowTarget), { if AppState::is_running() { return Err(EventLoopError::AlreadyRunning); @@ -273,8 +267,8 @@ impl EventLoop { let callback = unsafe { mem::transmute::< - Rc, &RootWindowTarget)>>, - Rc, &RootWindowTarget)>>, + Rc, &RootWindowTarget)>>, + Rc, &RootWindowTarget)>>, >(Rc::new(RefCell::new(callback))) }; @@ -340,7 +334,7 @@ impl EventLoop { pub fn pump_events(&mut self, timeout: Option, callback: F) -> PumpStatus where - F: FnMut(Event, &RootWindowTarget), + F: FnMut(Event, &RootWindowTarget), { // # Safety // We are erasing the lifetime of the application callback here so that we @@ -353,8 +347,8 @@ impl EventLoop { let callback = unsafe { mem::transmute::< - Rc, &RootWindowTarget)>>, - Rc, &RootWindowTarget)>>, + Rc, &RootWindowTarget)>>, + Rc, &RootWindowTarget)>>, >(Rc::new(RefCell::new(callback))) }; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 790a0ba196..719b46e3be 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -68,8 +68,8 @@ impl Drop for Window { } impl Window { - pub(crate) fn new( - _window_target: &EventLoopWindowTarget, + pub(crate) fn new( + _window_target: &EventLoopWindowTarget, attributes: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 6dd06c3a9c..86b796eb53 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -1,7 +1,6 @@ use std::{ cell::Cell, collections::VecDeque, - marker::PhantomData, mem, slice, sync::{mpsc, Arc, Mutex}, time::Instant, @@ -271,9 +270,9 @@ impl EventState { } } -pub struct EventLoop { +pub struct EventLoop { windows: Vec<(Arc, EventState)>, - window_target: event_loop::EventLoopWindowTarget, + window_target: event_loop::EventLoopWindowTarget, user_events_sender: mpsc::Sender, user_events_receiver: mpsc::Receiver, } @@ -314,9 +313,7 @@ impl EventLoop { destroys: Arc::new(Mutex::new(VecDeque::new())), event_socket, wake_socket, - p: PhantomData, }, - _marker: PhantomData, }, user_events_sender, user_events_receiver, @@ -466,10 +463,10 @@ impl EventLoop { pub fn run(mut self, mut event_handler_inner: F) -> Result<(), EventLoopError> where - F: FnMut(event::Event, &event_loop::EventLoopWindowTarget), + F: FnMut(event::Event, &event_loop::EventLoopWindowTarget), { let mut event_handler = - move |event: event::Event, window_target: &event_loop::EventLoopWindowTarget| { + move |event: event::Event, window_target: &event_loop::EventLoopWindowTarget| { event_handler_inner(event, window_target); }; @@ -676,7 +673,7 @@ impl EventLoop { Ok(()) } - pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { + pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { &self.window_target } @@ -716,7 +713,7 @@ impl Clone for EventLoopProxy { impl Unpin for EventLoopProxy {} -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { control_flow: Cell, exit: Cell, pub(super) creates: Mutex>>, @@ -724,10 +721,9 @@ pub struct EventLoopWindowTarget { pub(super) destroys: Arc>>, pub(super) event_socket: Arc, pub(super) wake_socket: Arc, - p: PhantomData, } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub fn primary_monitor(&self) -> Option { Some(MonitorHandle) } diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 3a5c74b7e1..8e509f04d7 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -33,8 +33,8 @@ pub struct Window { } impl Window { - pub(crate) fn new( - el: &EventLoopWindowTarget, + pub(crate) fn new( + el: &EventLoopWindowTarget, attrs: window::WindowAttributes, _: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/web/cursor.rs b/src/platform_impl/web/cursor.rs index cd8922ecc8..7780064608 100644 --- a/src/platform_impl/web/cursor.rs +++ b/src/platform_impl/web/cursor.rs @@ -68,9 +68,9 @@ impl PartialEq for CustomCursor { impl Eq for CustomCursor {} impl CustomCursor { - pub(crate) fn build( + pub(crate) fn build( builder: CustomCursorBuilder, - window_target: &EventLoopWindowTarget, + window_target: &EventLoopWindowTarget, ) -> Self { Lazy::force(&DROP_HANDLER); diff --git a/src/platform_impl/web/event_loop/mod.rs b/src/platform_impl/web/event_loop/mod.rs index d0b7f5d37b..a1db32f9ee 100644 --- a/src/platform_impl/web/event_loop/mod.rs +++ b/src/platform_impl/web/event_loop/mod.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use std::sync::mpsc::{self, Receiver, Sender}; use crate::error::EventLoopError; @@ -16,7 +15,7 @@ pub use proxy::EventLoopProxy; pub use window_target::EventLoopWindowTarget; pub struct EventLoop { - elw: RootEventLoopWindowTarget, + elw: RootEventLoopWindowTarget, user_event_sender: Sender, user_event_receiver: Receiver, } @@ -29,7 +28,6 @@ impl EventLoop { let (user_event_sender, user_event_receiver) = mpsc::channel(); let elw = RootEventLoopWindowTarget { p: EventLoopWindowTarget::new(), - _marker: PhantomData, }; Ok(EventLoop { elw, @@ -40,11 +38,10 @@ impl EventLoop { pub fn run(self, mut event_handler: F) -> ! where - F: FnMut(Event, &RootEventLoopWindowTarget), + F: FnMut(Event, &RootEventLoopWindowTarget), { let target = RootEventLoopWindowTarget { p: self.elw.p.clone(), - _marker: PhantomData, }; // SAFETY: Don't use `move` to make sure we leak the `event_handler` and `target`. @@ -77,11 +74,10 @@ impl EventLoop { pub fn spawn(self, mut event_handler: F) where - F: 'static + FnMut(Event, &RootEventLoopWindowTarget), + F: 'static + FnMut(Event, &RootEventLoopWindowTarget), { let target = RootEventLoopWindowTarget { p: self.elw.p.clone(), - _marker: PhantomData, }; self.elw.p.run( @@ -105,7 +101,7 @@ impl EventLoop { EventLoopProxy::new(self.elw.p.waker(), self.user_event_sender.clone()) } - pub fn window_target(&self) -> &RootEventLoopWindowTarget { + pub fn window_target(&self) -> &RootEventLoopWindowTarget { &self.elw } } diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 1921c6a732..e29c03df2b 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -2,7 +2,6 @@ use std::cell::{Cell, RefCell}; use std::clone::Clone; use std::collections::{vec_deque::IntoIter as VecDequeIter, VecDeque}; use std::iter; -use std::marker::PhantomData; use std::rc::{Rc, Weak}; use super::runner::{EventWrapper, Execution}; @@ -41,28 +40,17 @@ impl Clone for ModifiersShared { } } -pub struct EventLoopWindowTarget { +#[derive(Clone)] +pub struct EventLoopWindowTarget { pub(crate) runner: runner::Shared, modifiers: ModifiersShared, - _marker: PhantomData, } -impl Clone for EventLoopWindowTarget { - fn clone(&self) -> Self { - Self { - runner: self.runner.clone(), - modifiers: self.modifiers.clone(), - _marker: PhantomData, - } - } -} - -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub fn new() -> Self { Self { runner: runner::Shared::new(), modifiers: ModifiersShared::default(), - _marker: PhantomData, } } diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index f3845dc810..7ff5240ba6 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -30,8 +30,8 @@ pub struct Inner { } impl Window { - pub(crate) fn new( - target: &EventLoopWindowTarget, + pub(crate) fn new( + target: &EventLoopWindowTarget, attr: WindowAttributes, platform_attr: PlatformSpecificWindowBuilderAttributes, ) -> Result { diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 6a3035bc9c..0ab23bb95a 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -6,7 +6,6 @@ use std::{ cell::Cell, collections::VecDeque, ffi::c_void, - marker::PhantomData, mem, panic, ptr, rc::Rc, sync::{ @@ -158,7 +157,7 @@ pub(crate) enum ProcResult { pub struct EventLoop { user_event_sender: Sender, user_event_receiver: Receiver, - window_target: RootELW, + window_target: RootELW, msg_hook: Option bool + 'static>>, } @@ -178,11 +177,10 @@ impl Default for PlatformSpecificEventLoopAttributes { } } -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { thread_id: u32, thread_msg_target: HWND, pub(crate) runner_shared: EventLoopRunnerShared, - _marker: PhantomData, } impl EventLoop { @@ -223,28 +221,26 @@ impl EventLoop { thread_id, thread_msg_target, runner_shared, - _marker: PhantomData, }, - _marker: PhantomData, }, msg_hook: attributes.msg_hook.take(), }) } - pub fn window_target(&self) -> &RootELW { + pub fn window_target(&self) -> &RootELW { &self.window_target } pub fn run(mut self, event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { self.run_on_demand(event_handler) } pub fn run_on_demand(&mut self, mut event_handler: F) -> Result<(), EventLoopError> where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { { let runner = &self.window_target.p.runner_shared; @@ -309,7 +305,7 @@ impl EventLoop { pub fn pump_events(&mut self, timeout: Option, mut event_handler: F) -> PumpStatus where - F: FnMut(Event, &RootELW), + F: FnMut(Event, &RootELW), { { let runner = &self.window_target.p.runner_shared; @@ -529,7 +525,7 @@ impl EventLoop { } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { #[inline(always)] pub(crate) fn create_thread_executor(&self) -> EventLoopThreadExecutor { EventLoopThreadExecutor { @@ -979,7 +975,7 @@ unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) { // // Returning 0 tells the Win32 API that the message has been processed. // FIXME: detect WM_DWMCOMPOSITIONCHANGED and call DwmEnableBlurBehindWindow if necessary -pub(super) unsafe extern "system" fn public_window_callback( +pub(super) unsafe extern "system" fn public_window_callback( window: HWND, msg: u32, wparam: WPARAM, @@ -990,7 +986,7 @@ pub(super) unsafe extern "system" fn public_window_callback( let userdata_ptr = match (userdata, msg) { (0, WM_NCCREATE) => { let createstruct = unsafe { &mut *(lparam as *mut CREATESTRUCTW) }; - let initdata = unsafe { &mut *(createstruct.lpCreateParams as *mut InitData<'_, T>) }; + let initdata = unsafe { &mut *(createstruct.lpCreateParams as *mut InitData<'_>) }; let result = match unsafe { initdata.on_nccreate(window) } { Some(userdata) => unsafe { @@ -1008,7 +1004,7 @@ pub(super) unsafe extern "system" fn public_window_callback( (_, WM_CREATE) => unsafe { let createstruct = &mut *(lparam as *mut CREATESTRUCTW); let initdata = createstruct.lpCreateParams; - let initdata = &mut *(initdata as *mut InitData<'_, T>); + let initdata = &mut *(initdata as *mut InitData<'_>); initdata.on_create(); return DefWindowProcW(window, msg, wparam, lparam); diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 91e205628e..2e46efc7e5 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -94,8 +94,8 @@ pub(crate) struct Window { } impl Window { - pub(crate) fn new( - event_loop: &EventLoopWindowTarget, + pub(crate) fn new( + event_loop: &EventLoopWindowTarget, w_attr: WindowAttributes, pl_attr: PlatformSpecificWindowBuilderAttributes, ) -> Result { @@ -1069,9 +1069,9 @@ impl Drop for Window { } } -pub(super) struct InitData<'a, T: 'static> { +pub(super) struct InitData<'a> { // inputs - pub event_loop: &'a EventLoopWindowTarget, + pub event_loop: &'a EventLoopWindowTarget, pub attributes: WindowAttributes, pub pl_attribs: PlatformSpecificWindowBuilderAttributes, pub window_flags: WindowFlags, @@ -1079,7 +1079,7 @@ pub(super) struct InitData<'a, T: 'static> { pub window: Option, } -impl<'a, T: 'static> InitData<'a, T> { +impl<'a> InitData<'a> { unsafe fn create_window(&self, window: HWND) -> Window { // Register for touch events if applicable { @@ -1262,18 +1262,15 @@ impl<'a, T: 'static> InitData<'a, T> { } } } -unsafe fn init( +unsafe fn init( attributes: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, - event_loop: &EventLoopWindowTarget, -) -> Result -where - T: 'static, -{ + event_loop: &EventLoopWindowTarget, +) -> Result { let title = util::encode_wide(&attributes.title); let class_name = util::encode_wide(&pl_attribs.class_name); - unsafe { register_window_class::(&class_name) }; + unsafe { register_window_class(&class_name) }; let mut window_flags = WindowFlags::empty(); window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations); @@ -1368,11 +1365,11 @@ where Ok(initdata.window.unwrap()) } -unsafe fn register_window_class(class_name: &[u16]) { +unsafe fn register_window_class(class_name: &[u16]) { let class = WNDCLASSEXW { cbSize: mem::size_of::() as u32, style: CS_HREDRAW | CS_VREDRAW, - lpfnWndProc: Some(super::event_loop::public_window_callback::), + lpfnWndProc: Some(super::event_loop::public_window_callback), cbClsExtra: 0, cbWndExtra: 0, hInstance: util::get_instance_handle(), diff --git a/src/window.rs b/src/window.rs index 8786435272..77f95dece9 100644 --- a/src/window.rs +++ b/src/window.rs @@ -506,10 +506,7 @@ impl WindowBuilder { /// - **Web:** The window is created but not inserted into the web page automatically. Please /// see the web platform module for more information. #[inline] - pub fn build( - self, - window_target: &EventLoopWindowTarget, - ) -> Result { + pub fn build(self, window_target: &EventLoopWindowTarget) -> Result { let window = platform_impl::Window::new(&window_target.p, self.window, self.platform_specific)?; window.maybe_queue_on_main(|w| w.request_redraw()); @@ -533,7 +530,7 @@ impl Window { /// /// [`WindowBuilder::new().build(event_loop)`]: WindowBuilder::build #[inline] - pub fn new(event_loop: &EventLoopWindowTarget) -> Result { + pub fn new(event_loop: &EventLoopWindowTarget) -> Result { let builder = WindowBuilder::new(); builder.build(event_loop) }