diff --git a/examples/pump_events.rs b/examples/pump_events.rs index 8622fe28a2..4de531ac80 100644 --- a/examples/pump_events.rs +++ b/examples/pump_events.rs @@ -9,8 +9,8 @@ fn main() -> std::process::ExitCode { use winit::application::ApplicationHandler; use winit::event::WindowEvent; + use winit::event_loop::pump_events::{EventLoopExtPumpEvents, PumpStatus}; use winit::event_loop::{ActiveEventLoop, EventLoop}; - use winit::platform::pump_events::{EventLoopExtPumpEvents, PumpStatus}; use winit::window::{Window, WindowAttributes, WindowId}; #[path = "util/fill.rs"] diff --git a/examples/run_on_demand.rs b/examples/run_on_demand.rs index 8740b6b66f..f076b43b87 100644 --- a/examples/run_on_demand.rs +++ b/examples/run_on_demand.rs @@ -7,8 +7,8 @@ fn main() -> Result<(), Box> { use winit::application::ApplicationHandler; use winit::event::WindowEvent; + use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand; use winit::event_loop::{ActiveEventLoop, EventLoop}; - use winit::platform::run_on_demand::EventLoopExtRunOnDemand; use winit::window::{Window, WindowAttributes, WindowId}; #[path = "util/fill.rs"] diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 544df68ea3..bf6f2a6ba7 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -199,6 +199,8 @@ changelog entry. - Renamed "super" key to "meta", to match the naming in the W3C specification. `NamedKey::Super` still exists, but it's non-functional and deprecated, `NamedKey::Meta` should be used instead. - Move `IconExtWindows` into `WinIcon`. +- Move `EventLoopExtPumpEvents` and `PumpStatus` from platform module to `winit::event_loop::pump_events`. +- Move `EventLoopExtRunOnDemand` from platform module to `winit::event_loop::run_on_demand`. ### Removed diff --git a/src/event_loop.rs b/src/event_loop.rs index 6b66b814ac..f0044059bf 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -275,7 +275,7 @@ impl AsFd for EventLoop { /// /// [`calloop`]: https://crates.io/crates/calloop /// [`mio`]: https://crates.io/crates/mio - /// [`pump_app_events`]: crate::platform::pump_events::EventLoopExtPumpEvents::pump_app_events + /// [`pump_app_events`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events fn as_fd(&self) -> BorrowedFd<'_> { self.event_loop.as_fd() } @@ -289,8 +289,54 @@ impl AsRawFd for EventLoop { /// /// [`calloop`]: https://crates.io/crates/calloop /// [`mio`]: https://crates.io/crates/mio - /// [`pump_app_events`]: crate::platform::pump_events::EventLoopExtPumpEvents::pump_app_events + /// [`pump_app_events`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events fn as_raw_fd(&self) -> RawFd { self.event_loop.as_raw_fd() } } + +#[cfg(any( + windows_platform, + macos_platform, + android_platform, + x11_platform, + wayland_platform, + docsrs, +))] +impl winit_core::event_loop::pump_events::EventLoopExtPumpEvents for EventLoop { + fn pump_app_events( + &mut self, + timeout: Option, + app: A, + ) -> winit_core::event_loop::pump_events::PumpStatus { + self.event_loop.pump_app_events(timeout, app) + } +} + +#[allow(unused_imports)] +#[cfg(any( + windows_platform, + macos_platform, + android_platform, + x11_platform, + wayland_platform, + docsrs, +))] +impl winit_core::event_loop::run_on_demand::EventLoopExtRunOnDemand for EventLoop { + fn run_app_on_demand(&mut self, app: A) -> Result<(), EventLoopError> { + self.event_loop.run_app_on_demand(app) + } +} + +/// ```compile_error +/// use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand; +/// use winit::event_loop::EventLoop; +/// +/// let mut event_loop = EventLoop::new().unwrap(); +/// event_loop.run_app_on_demand(|_, _| { +/// // Attempt to run the event loop re-entrantly; this must fail. +/// event_loop.run_app_on_demand(|_, _| {}); +/// }); +/// ``` +#[allow(dead_code)] +fn test_run_on_demand_cannot_access_event_loop() {} diff --git a/src/lib.rs b/src/lib.rs index bda19f102e..03e269bf3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,16 +32,8 @@ //! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator`-based event loop //! model, since that can't be implemented properly on some platforms (e.g Web, iOS) and works //! poorly on most other platforms. However, this model can be re-implemented to an extent with -#![cfg_attr( - any(windows_platform, macos_platform, android_platform, x11_platform, wayland_platform), - doc = "[`EventLoopExtPumpEvents::pump_app_events()`][platform::pump_events::EventLoopExtPumpEvents::pump_app_events()]" -)] -#![cfg_attr( - not(any(windows_platform, macos_platform, android_platform, x11_platform, wayland_platform)), - doc = "`EventLoopExtPumpEvents::pump_app_events()`" -)] -//! [^1]. See that method's documentation for more reasons about why -//! it's discouraged beyond compatibility reasons. +//! [`EventLoopExtPumpEvents::pump_app_events()`] [^1]. See that method's documentation for more +//! reasons about why it's discouraged beyond compatibility reasons. //! //! //! ```no_run @@ -276,6 +268,7 @@ //! [`DeviceEvent`]: event::DeviceEvent //! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle //! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle +//! [`EventLoopExtPumpEvents::pump_app_events()`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events() //! [^1]: `EventLoopExtPumpEvents::pump_app_events()` is only available on Windows, macOS, Android, X11 and Wayland. #![deny(rust_2018_idioms)] diff --git a/src/platform/mod.rs b/src/platform/mod.rs index baa7de8026..5d0ca942ef 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -21,26 +21,5 @@ pub mod windows; #[cfg(x11_platform)] pub mod x11; -#[allow(unused_imports)] -#[cfg(any( - windows_platform, - macos_platform, - android_platform, - x11_platform, - wayland_platform, - docsrs, -))] -pub mod run_on_demand; - -#[cfg(any( - windows_platform, - macos_platform, - android_platform, - x11_platform, - wayland_platform, - docsrs, -))] -pub mod pump_events; - #[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, docsrs))] pub mod scancode; diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 029c99c679..bfc8d40937 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -14,6 +14,7 @@ use winit_core::application::ApplicationHandler; use winit_core::cursor::{Cursor, CustomCursor, CustomCursorSource}; use winit_core::error::{EventLoopError, NotSupportedError, RequestError}; use winit_core::event::{self, DeviceId, FingerId, Force, StartCause, SurfaceSizeWriter}; +use winit_core::event_loop::pump_events::PumpStatus; use winit_core::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as CoreEventLoopProxy, EventLoopProxyProvider, @@ -25,8 +26,6 @@ use winit_core::window::{ WindowAttributes, WindowButtons, WindowId, WindowLevel, }; -use crate::platform::pump_events::PumpStatus; - mod keycodes; static HAS_FOCUS: AtomicBool = AtomicBool::new(true); diff --git a/src/platform_impl/apple/appkit/event_loop.rs b/src/platform_impl/apple/appkit/event_loop.rs index 55981982cd..063ed98a1a 100644 --- a/src/platform_impl/apple/appkit/event_loop.rs +++ b/src/platform_impl/apple/appkit/event_loop.rs @@ -18,6 +18,7 @@ use rwh_06::HasDisplayHandle; use winit_core::application::ApplicationHandler; use winit_core::cursor::{CustomCursor as CoreCustomCursor, CustomCursorSource}; use winit_core::error::{EventLoopError, RequestError}; +use winit_core::event_loop::pump_events::PumpStatus; use winit_core::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as CoreEventLoopProxy, OwnedDisplayHandle as CoreOwnedDisplayHandle, @@ -33,7 +34,6 @@ use super::event::dummy_event; use super::monitor; use super::observer::setup_control_flow_observers; use crate::platform::macos::ActivationPolicy; -use crate::platform::pump_events::PumpStatus; use crate::platform_impl::Window; #[derive(Default)] diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index bb51a73550..0336018bb9 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -11,11 +11,11 @@ use std::time::Duration; use dpi::Size; use winit_core::application::ApplicationHandler; use winit_core::error::{EventLoopError, NotSupportedError}; +use winit_core::event_loop::pump_events::PumpStatus; use winit_core::event_loop::ActiveEventLoop; use winit_core::window::ActivationToken; pub(crate) use self::common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey}; -use crate::platform::pump_events::PumpStatus; #[cfg(x11_platform)] use crate::platform::x11::WindowType as XWindowType; diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 4c37550a1b..d24a99a485 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -21,6 +21,7 @@ use winit_core::application::ApplicationHandler; use winit_core::cursor::{CustomCursor as CoreCustomCursor, CustomCursorSource}; use winit_core::error::{EventLoopError, NotSupportedError, OsError, RequestError}; use winit_core::event::{DeviceEvent, StartCause, SurfaceSizeWriter, WindowEvent}; +use winit_core::event_loop::pump_events::PumpStatus; use winit_core::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, OwnedDisplayHandle as CoreOwnedDisplayHandle, @@ -28,7 +29,6 @@ use winit_core::event_loop::{ use winit_core::monitor::MonitorHandle as CoreMonitorHandle; use winit_core::window::Theme; -use crate::platform::pump_events::PumpStatus; use crate::platform_impl::platform::min_timeout; use crate::platform_impl::wayland::types::cursor::WaylandCustomCursor; diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 42d612065b..93f8284d6f 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -19,6 +19,7 @@ use winit_core::application::ApplicationHandler; use winit_core::cursor::{CustomCursor as CoreCustomCursor, CustomCursorSource}; use winit_core::error::{EventLoopError, RequestError}; use winit_core::event::{DeviceId, StartCause, WindowEvent}; +use winit_core::event_loop::pump_events::PumpStatus; use winit_core::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as CoreEventLoopProxy, EventLoopProxyProvider, @@ -33,7 +34,6 @@ use x11rb::protocol::{xkb, xproto}; use x11rb::x11_utils::X11Error as LogicalError; use x11rb::xcb_ffi::ReplyOrIdError; -use crate::platform::pump_events::PumpStatus; use crate::platform::x11::XlibErrorHook; use crate::platform_impl::common::xkb::Context; use crate::platform_impl::platform::min_timeout; diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 810d9e013f..6d0648174c 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -66,6 +66,7 @@ use winit_core::event::{ DeviceEvent, DeviceId, FingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, TouchPhase, WindowEvent, }; +use winit_core::event_loop::pump_events::PumpStatus; use winit_core::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as RootEventLoopProxy, EventLoopProxyProvider, @@ -78,7 +79,6 @@ use winit_core::window::{Theme, Window as CoreWindow, WindowAttributes, WindowId pub(super) use self::runner::{Event, EventLoopRunner}; use super::window::set_skip_taskbar; use super::SelectedCursor; -use crate::platform::pump_events::PumpStatus; use crate::platform_impl::platform::dark_mode::try_theme; use crate::platform_impl::platform::dpi::{become_dpi_aware, dpi_to_scale_factor}; use crate::platform_impl::platform::drop_handler::FileDropHandler; diff --git a/winit-core/src/event_loop.rs b/winit-core/src/event_loop/mod.rs similarity index 99% rename from winit-core/src/event_loop.rs rename to winit-core/src/event_loop/mod.rs index ca82ff62b1..8d35b1180b 100644 --- a/winit-core/src/event_loop.rs +++ b/winit-core/src/event_loop/mod.rs @@ -1,3 +1,6 @@ +pub mod pump_events; +pub mod run_on_demand; + use std::fmt::{self, Debug}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/src/platform/pump_events.rs b/winit-core/src/event_loop/pump_events.rs similarity index 94% rename from src/platform/pump_events.rs rename to winit-core/src/event_loop/pump_events.rs index 2932284ca4..e817d0bc41 100644 --- a/src/platform/pump_events.rs +++ b/winit-core/src/event_loop/pump_events.rs @@ -1,8 +1,8 @@ use std::time::Duration; use crate::application::ApplicationHandler; -use crate::event_loop::EventLoop; +#[allow(rustdoc::broken_intra_doc_links)] // FIXME(madsmtm): Fix these. /// Additional methods on [`EventLoop`] for pumping events within an external event loop pub trait EventLoopExtPumpEvents { /// Pump the `EventLoop` to check for and dispatch pending events. @@ -106,16 +106,6 @@ pub trait EventLoopExtPumpEvents { ) -> PumpStatus; } -impl EventLoopExtPumpEvents for EventLoop { - fn pump_app_events( - &mut self, - timeout: Option, - app: A, - ) -> PumpStatus { - self.event_loop.pump_app_events(timeout, app) - } -} - /// The return status for `pump_events` #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum PumpStatus { diff --git a/src/platform/run_on_demand.rs b/winit-core/src/event_loop/run_on_demand.rs similarity index 80% rename from src/platform/run_on_demand.rs rename to winit-core/src/event_loop/run_on_demand.rs index e24aa7d808..a6e225623f 100644 --- a/src/platform/run_on_demand.rs +++ b/winit-core/src/event_loop/run_on_demand.rs @@ -1,11 +1,12 @@ use crate::application::ApplicationHandler; use crate::error::EventLoopError; -use crate::event_loop::EventLoop; #[cfg(doc)] use crate::{ - event_loop::ActiveEventLoop, platform::pump_events::EventLoopExtPumpEvents, window::Window, + event_loop::{pump_events::EventLoopExtPumpEvents, ActiveEventLoop}, + window::Window, }; +#[allow(rustdoc::broken_intra_doc_links)] // FIXME(madsmtm): Fix these. /// Additional methods on [`EventLoop`] to return control flow to the caller. pub trait EventLoopExtRunOnDemand { /// Run the application with the event loop on the calling thread. @@ -62,22 +63,3 @@ pub trait EventLoopExtRunOnDemand { /// [`set_control_flow()`]: ActiveEventLoop::set_control_flow() fn run_app_on_demand(&mut self, app: A) -> Result<(), EventLoopError>; } - -impl EventLoopExtRunOnDemand for EventLoop { - fn run_app_on_demand(&mut self, app: A) -> Result<(), EventLoopError> { - self.event_loop.run_app_on_demand(app) - } -} - -/// ```compile_fail -/// use winit::event_loop::EventLoop; -/// use winit::platform::run_on_demand::EventLoopExtRunOnDemand; -/// -/// let mut event_loop = EventLoop::new().unwrap(); -/// event_loop.run_on_demand(|_, _| { -/// // Attempt to run the event loop re-entrantly; this must fail. -/// event_loop.run_on_demand(|_, _| {}); -/// }); -/// ``` -#[allow(dead_code)] -fn test_run_on_demand_cannot_access_event_loop() {}