diff --git a/CHANGELOG.md b/CHANGELOG.md index eab253a6d2e..9fba27739dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Unreleased` header. # Unreleased +- **Breaking:** Removed unnecessary generic parameter `T` from `EventLoopWindowTarget`. - On Wayland, fix resize not issued when scale changes - On X11 and Wayland, fix arrow up on keypad reported as `ArrowLeft`. - On Windows, macOS, X11, Wayland and Web, implement setting images as cursors. See the `custom_cursors.rs` example. diff --git a/examples/child_window.rs b/examples/child_window.rs index 9234d9e4e64..2693dbdc089 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 4c47f362d78..3122135ae9a 100644 --- a/examples/custom_cursors.rs +++ b/examples/custom_cursors.rs @@ -9,7 +9,7 @@ use winit::{ window::{CursorIcon, 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 b11104ee3e7..5090af5d683 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -111,7 +111,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), } @@ -213,10 +213,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)) } } @@ -296,7 +293,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 b719e1d9966..fa50bdd901b 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -48,9 +48,9 @@ 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, + pub(crate) _marker: PhantomData<*mut ()>, // Not Send nor Sync } /// Object that allows building the event loop. @@ -142,7 +142,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 { .. }") } @@ -241,7 +241,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) } @@ -298,13 +298,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 { @@ -370,7 +370,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. @@ -379,7 +379,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 88b241030e9..9bdcb03528a 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 b043f47728e..869c9bf3fb1 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -388,7 +388,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 ccaf1485860..403c52d9781 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 f7d1d525004..b877a657ca6 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,14 +74,14 @@ 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.window_target().clear_exit(); self.event_loop.run_on_demand(event_handler) } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { /// Clear exit status. pub(crate) fn clear_exit(&self) { self.p.clear_exit() diff --git a/src/platform/startup_notify.rs b/src/platform/startup_notify.rs index 323c2fe6244..207aff86cb5 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 b58d929d5b2..587c3805e1c 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -12,7 +12,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 f24eb512873..d118eded3d9 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -165,7 +165,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 { @@ -173,7 +173,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) } @@ -195,7 +195,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 c481e937429..608cb2f392b 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -95,7 +95,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 450138f276e..426fd9bdbf4 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -4,6 +4,7 @@ use std::{ cell::Cell, collections::VecDeque, hash::Hash, + marker::PhantomData, sync::{ atomic::{AtomicBool, Ordering}, mpsc, Arc, Mutex, RwLock, @@ -140,7 +141,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 @@ -187,9 +188,8 @@ impl EventLoop { &redraw_flag, android_app.create_waker(), ), - _marker: std::marker::PhantomData, }, - _marker: std::marker::PhantomData, + _marker: PhantomData, }, redraw_flag, user_events_sender, @@ -205,7 +205,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"); @@ -377,7 +377,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 { @@ -482,14 +482,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); @@ -512,7 +512,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; @@ -545,7 +545,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(); @@ -621,7 +621,7 @@ impl EventLoop { }); } - pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { + pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { &self.window_target } @@ -665,15 +665,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())) } @@ -763,8 +762,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 434111b6bec..e08776dc215 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -34,12 +34,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 +89,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,10 +122,7 @@ impl EventLoop { sender, receiver, window_target: RootEventLoopWindowTarget { - p: EventLoopWindowTarget { - mtm, - p: PhantomData, - }, + p: EventLoopWindowTarget { mtm }, _marker: PhantomData, }, }) @@ -134,7 +130,7 @@ impl EventLoop { 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 +142,7 @@ impl EventLoop { ); let event_handler = std::mem::transmute::< - Box, &RootEventLoopWindowTarget)>, + Box, &RootEventLoopWindowTarget)>, Box>, >(Box::new(event_handler)); @@ -175,7 +171,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 +342,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 +352,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 6e3f1550ea2..ceb01b48259 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -398,8 +398,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 7f310fb4bd9..8f94bce7ab0 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -286,8 +286,8 @@ impl VideoModeHandle { impl Window { #[inline] - pub(crate) fn new( - window_target: &EventLoopWindowTarget, + pub(crate) fn new( + window_target: &EventLoopWindowTarget, attribs: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { @@ -781,26 +781,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()) } } @@ -823,14 +823,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 fca2a912baa..f881cba3a9d 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -63,7 +63,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 +167,6 @@ impl EventLoop { control_flow: Cell::new(ControlFlow::default()), exit: Cell::new(None), state: RefCell::new(winit_state), - _marker: PhantomData, }; let event_loop = Self { @@ -191,7 +190,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 +221,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 +248,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 +324,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 +529,7 @@ impl EventLoop { } #[inline] - pub fn window_target(&self) -> &RootEventLoopWindowTarget { + pub fn window_target(&self) -> &RootEventLoopWindowTarget { &self.window_target } @@ -602,7 +601,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 +623,9 @@ pub struct EventLoopWindowTarget { /// Connection to the wayland server. pub connection: Connection, - - _marker: std::marker::PhantomData, } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub(crate) fn set_control_flow(&self, control_flow: ControlFlow) { self.control_flow.set(control_flow) } diff --git a/src/platform_impl/linux/wayland/output.rs b/src/platform_impl/linux/wayland/output.rs index c54cc2cf11b..d8a9303a332 100644 --- a/src/platform_impl/linux/wayland/output.rs +++ b/src/platform_impl/linux/wayland/output.rs @@ -8,7 +8,7 @@ use crate::platform_impl::platform::VideoModeHandle as PlatformVideoModeHandle; 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 8074920259e..50975919804 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -81,8 +81,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 ce6413a92c1..08bc4e2d9e8 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, @@ -61,7 +61,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(); @@ -136,7 +136,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), { @@ -1370,7 +1370,11 @@ impl EventProcessor { /// Send modifiers for the active window. /// /// The event won't be send when the `modifiers` match the previosly `sent` modifiers value. - fn send_modifiers)>(&self, modifiers: ModifiersState, callback: &mut F) { + fn send_modifiers)>( + &self, + modifiers: ModifiersState, + callback: &mut F, + ) { let window_id = match self.active_window { Some(window) => mkwid(window), None => return, @@ -1384,8 +1388,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, @@ -1415,7 +1419,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 395668c37a8..81ebd0924e9 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -27,6 +27,7 @@ use std::{ collections::{HashMap, HashSet}, ffi::CStr, fmt, + marker::PhantomData, mem::MaybeUninit, ops::Deref, os::{ @@ -142,7 +143,7 @@ impl PeekableReceiver { } } -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { xconn: Arc, wm_delete_window: xproto::Atom, net_wm_ping: xproto::Atom, @@ -155,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, @@ -307,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, @@ -328,7 +327,7 @@ impl EventLoop { let target = Rc::new(RootELW { p: super::EventLoopWindowTarget::X(window_target), - _marker: ::std::marker::PhantomData, + _marker: PhantomData, }); let event_processor = EventProcessor { @@ -397,13 +396,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); @@ -437,7 +436,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; @@ -470,7 +469,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(); @@ -548,7 +547,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); @@ -622,7 +621,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(); @@ -673,7 +672,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)] @@ -681,7 +680,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 { @@ -840,8 +839,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 ddf96542b2a..4829b001ba2 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -152,8 +152,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 6ef6aec5e11..aaa4b94cecf 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -46,18 +46,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 @@ -375,7 +375,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 e252080539c..6ce9383a6a5 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 9a36783d68b..8464bd0da4b 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -74,12 +74,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() @@ -131,7 +130,7 @@ impl EventLoopWindowTarget { } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { pub(crate) fn hide_application(&self) { NSApplication::sharedApplication(self.mtm).hide(None) } @@ -163,7 +162,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 @@ -232,10 +231,7 @@ impl EventLoop { sender, receiver: Rc::new(receiver), window_target: Rc::new(RootWindowTarget { - p: EventLoopWindowTarget { - mtm, - p: PhantomData, - }, + p: EventLoopWindowTarget { mtm }, _marker: PhantomData, }), panic_info, @@ -243,13 +239,13 @@ impl EventLoop { }) } - 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) } @@ -260,7 +256,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); @@ -277,8 +273,8 @@ impl EventLoop { let callback = unsafe { mem::transmute::< - Rc, &RootWindowTarget)>>, - Rc, &RootWindowTarget)>>, + Rc, &RootWindowTarget)>>, + Rc, &RootWindowTarget)>>, >(Rc::new(RefCell::new(callback))) }; @@ -344,7 +340,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 @@ -357,8 +353,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 ab890cafe5b..7f8266a4d09 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -69,8 +69,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 385081d4001..62c85d19bc1 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -272,9 +272,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, } @@ -315,7 +315,6 @@ impl EventLoop { destroys: Arc::new(Mutex::new(VecDeque::new())), event_socket, wake_socket, - p: PhantomData, }, _marker: PhantomData, }, @@ -467,10 +466,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); }; @@ -677,7 +676,7 @@ impl EventLoop { Ok(()) } - pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { + pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { &self.window_target } @@ -717,7 +716,7 @@ impl Clone for EventLoopProxy { impl Unpin for EventLoopProxy {} -pub struct EventLoopWindowTarget { +pub struct EventLoopWindowTarget { control_flow: Cell, exit: Cell, pub(super) creates: Mutex>>, @@ -725,10 +724,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 9a153307817..0ff23e30d4a 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -34,8 +34,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 e077429740d..d9ff33531f4 100644 --- a/src/platform_impl/web/cursor.rs +++ b/src/platform_impl/web/cursor.rs @@ -72,9 +72,9 @@ impl CustomCursor { ))) } - pub(crate) fn build( + pub(crate) fn build( builder: CustomCursorBuilder, - window_target: &EventLoopWindowTarget, + window_target: &EventLoopWindowTarget, ) -> Self { let main_thread = window_target.runner.main_thread(); diff --git a/src/platform_impl/web/event_loop/mod.rs b/src/platform_impl/web/event_loop/mod.rs index d0b7f5d37b9..79e3abf21ee 100644 --- a/src/platform_impl/web/event_loop/mod.rs +++ b/src/platform_impl/web/event_loop/mod.rs @@ -16,7 +16,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, } @@ -40,7 +40,7 @@ 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(), @@ -77,7 +77,7 @@ 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(), @@ -105,7 +105,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 f586643d44b..c3f9edde3e2 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 1e82f21f3d1..9d9db02143a 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -28,8 +28,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 3f3344ef44a..ef5da8baaa5 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -158,7 +158,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 +178,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,7 +222,6 @@ impl EventLoop { thread_id, thread_msg_target, runner_shared, - _marker: PhantomData, }, _marker: PhantomData, }, @@ -231,20 +229,20 @@ impl EventLoop { }) } - 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 +307,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 +527,7 @@ impl EventLoop { } } -impl EventLoopWindowTarget { +impl EventLoopWindowTarget { #[inline(always)] pub(crate) fn create_thread_executor(&self) -> EventLoopThreadExecutor { EventLoopThreadExecutor { @@ -983,7 +981,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, @@ -994,7 +992,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 { @@ -1012,7 +1010,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 b4995ca4a07..d831160dea3 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -96,8 +96,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 { @@ -1074,9 +1074,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, @@ -1084,7 +1084,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 { @@ -1269,18 +1269,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); @@ -1375,11 +1372,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 bdede37ce5a..a0d55bb01f9 100644 --- a/src/window.rs +++ b/src/window.rs @@ -531,10 +531,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()); @@ -558,7 +555,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) }