Skip to content

Commit eab03dc

Browse files
authored
Move EventLoopExt* to winit-core (#4228)
* Move EventLoopExtPumpEvents and PumpStatus to winit-core * Move EventLoopExtRunOnDemand to winit-core
1 parent 59e3dda commit eab03dc

File tree

15 files changed

+68
-74
lines changed

15 files changed

+68
-74
lines changed

examples/pump_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fn main() -> std::process::ExitCode {
99

1010
use winit::application::ApplicationHandler;
1111
use winit::event::WindowEvent;
12+
use winit::event_loop::pump_events::{EventLoopExtPumpEvents, PumpStatus};
1213
use winit::event_loop::{ActiveEventLoop, EventLoop};
13-
use winit::platform::pump_events::{EventLoopExtPumpEvents, PumpStatus};
1414
use winit::window::{Window, WindowAttributes, WindowId};
1515

1616
#[path = "util/fill.rs"]

examples/run_on_demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
77

88
use winit::application::ApplicationHandler;
99
use winit::event::WindowEvent;
10+
use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand;
1011
use winit::event_loop::{ActiveEventLoop, EventLoop};
11-
use winit::platform::run_on_demand::EventLoopExtRunOnDemand;
1212
use winit::window::{Window, WindowAttributes, WindowId};
1313

1414
#[path = "util/fill.rs"]

src/changelog/unreleased.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ changelog entry.
199199
- Renamed "super" key to "meta", to match the naming in the W3C specification.
200200
`NamedKey::Super` still exists, but it's non-functional and deprecated, `NamedKey::Meta` should be used instead.
201201
- Move `IconExtWindows` into `WinIcon`.
202+
- Move `EventLoopExtPumpEvents` and `PumpStatus` from platform module to `winit::event_loop::pump_events`.
203+
- Move `EventLoopExtRunOnDemand` from platform module to `winit::event_loop::run_on_demand`.
202204

203205
### Removed
204206

src/event_loop.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl AsFd for EventLoop {
275275
///
276276
/// [`calloop`]: https://crates.io/crates/calloop
277277
/// [`mio`]: https://crates.io/crates/mio
278-
/// [`pump_app_events`]: crate::platform::pump_events::EventLoopExtPumpEvents::pump_app_events
278+
/// [`pump_app_events`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events
279279
fn as_fd(&self) -> BorrowedFd<'_> {
280280
self.event_loop.as_fd()
281281
}
@@ -289,8 +289,54 @@ impl AsRawFd for EventLoop {
289289
///
290290
/// [`calloop`]: https://crates.io/crates/calloop
291291
/// [`mio`]: https://crates.io/crates/mio
292-
/// [`pump_app_events`]: crate::platform::pump_events::EventLoopExtPumpEvents::pump_app_events
292+
/// [`pump_app_events`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events
293293
fn as_raw_fd(&self) -> RawFd {
294294
self.event_loop.as_raw_fd()
295295
}
296296
}
297+
298+
#[cfg(any(
299+
windows_platform,
300+
macos_platform,
301+
android_platform,
302+
x11_platform,
303+
wayland_platform,
304+
docsrs,
305+
))]
306+
impl winit_core::event_loop::pump_events::EventLoopExtPumpEvents for EventLoop {
307+
fn pump_app_events<A: ApplicationHandler>(
308+
&mut self,
309+
timeout: Option<std::time::Duration>,
310+
app: A,
311+
) -> winit_core::event_loop::pump_events::PumpStatus {
312+
self.event_loop.pump_app_events(timeout, app)
313+
}
314+
}
315+
316+
#[allow(unused_imports)]
317+
#[cfg(any(
318+
windows_platform,
319+
macos_platform,
320+
android_platform,
321+
x11_platform,
322+
wayland_platform,
323+
docsrs,
324+
))]
325+
impl winit_core::event_loop::run_on_demand::EventLoopExtRunOnDemand for EventLoop {
326+
fn run_app_on_demand<A: ApplicationHandler>(&mut self, app: A) -> Result<(), EventLoopError> {
327+
self.event_loop.run_app_on_demand(app)
328+
}
329+
}
330+
331+
/// ```compile_error
332+
/// use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand;
333+
/// use winit::event_loop::EventLoop;
334+
///
335+
/// let mut event_loop = EventLoop::new().unwrap();
336+
/// event_loop.run_app_on_demand(|_, _| {
337+
/// // Attempt to run the event loop re-entrantly; this must fail.
338+
/// event_loop.run_app_on_demand(|_, _| {});
339+
/// });
340+
/// ```
341+
#[allow(dead_code)]
342+
fn test_run_on_demand_cannot_access_event_loop() {}

src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,8 @@
3232
//! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop
3333
//! model, since that can't be implemented properly on some platforms (e.g Web, iOS) and works
3434
//! poorly on most other platforms. However, this model can be re-implemented to an extent with
35-
#![cfg_attr(
36-
any(windows_platform, macos_platform, android_platform, x11_platform, wayland_platform),
37-
doc = "[`EventLoopExtPumpEvents::pump_app_events()`][platform::pump_events::EventLoopExtPumpEvents::pump_app_events()]"
38-
)]
39-
#![cfg_attr(
40-
not(any(windows_platform, macos_platform, android_platform, x11_platform, wayland_platform)),
41-
doc = "`EventLoopExtPumpEvents::pump_app_events()`"
42-
)]
43-
//! [^1]. See that method's documentation for more reasons about why
44-
//! it's discouraged beyond compatibility reasons.
35+
//! [`EventLoopExtPumpEvents::pump_app_events()`] [^1]. See that method's documentation for more
36+
//! reasons about why it's discouraged beyond compatibility reasons.
4537
//!
4638
//!
4739
//! ```no_run
@@ -276,6 +268,7 @@
276268
//! [`DeviceEvent`]: event::DeviceEvent
277269
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle
278270
//! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle
271+
//! [`EventLoopExtPumpEvents::pump_app_events()`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events()
279272
//! [^1]: `EventLoopExtPumpEvents::pump_app_events()` is only available on Windows, macOS, Android, X11 and Wayland.
280273
281274
#![deny(rust_2018_idioms)]

src/platform/mod.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,5 @@ pub mod windows;
2121
#[cfg(x11_platform)]
2222
pub mod x11;
2323

24-
#[allow(unused_imports)]
25-
#[cfg(any(
26-
windows_platform,
27-
macos_platform,
28-
android_platform,
29-
x11_platform,
30-
wayland_platform,
31-
docsrs,
32-
))]
33-
pub mod run_on_demand;
34-
35-
#[cfg(any(
36-
windows_platform,
37-
macos_platform,
38-
android_platform,
39-
x11_platform,
40-
wayland_platform,
41-
docsrs,
42-
))]
43-
pub mod pump_events;
44-
4524
#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, docsrs))]
4625
pub mod scancode;

src/platform_impl/android/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use winit_core::application::ApplicationHandler;
1414
use winit_core::cursor::{Cursor, CustomCursor, CustomCursorSource};
1515
use winit_core::error::{EventLoopError, NotSupportedError, RequestError};
1616
use winit_core::event::{self, DeviceId, FingerId, Force, StartCause, SurfaceSizeWriter};
17+
use winit_core::event_loop::pump_events::PumpStatus;
1718
use winit_core::event_loop::{
1819
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
1920
EventLoopProxy as CoreEventLoopProxy, EventLoopProxyProvider,
@@ -25,8 +26,6 @@ use winit_core::window::{
2526
WindowAttributes, WindowButtons, WindowId, WindowLevel,
2627
};
2728

28-
use crate::platform::pump_events::PumpStatus;
29-
3029
mod keycodes;
3130

3231
static HAS_FOCUS: AtomicBool = AtomicBool::new(true);

src/platform_impl/apple/appkit/event_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rwh_06::HasDisplayHandle;
1818
use winit_core::application::ApplicationHandler;
1919
use winit_core::cursor::{CustomCursor as CoreCustomCursor, CustomCursorSource};
2020
use winit_core::error::{EventLoopError, RequestError};
21+
use winit_core::event_loop::pump_events::PumpStatus;
2122
use winit_core::event_loop::{
2223
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
2324
EventLoopProxy as CoreEventLoopProxy, OwnedDisplayHandle as CoreOwnedDisplayHandle,
@@ -33,7 +34,6 @@ use super::event::dummy_event;
3334
use super::monitor;
3435
use super::observer::setup_control_flow_observers;
3536
use crate::platform::macos::ActivationPolicy;
36-
use crate::platform::pump_events::PumpStatus;
3737
use crate::platform_impl::Window;
3838

3939
#[derive(Default)]

src/platform_impl/linux/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use std::time::Duration;
1111
use dpi::Size;
1212
use winit_core::application::ApplicationHandler;
1313
use winit_core::error::{EventLoopError, NotSupportedError};
14+
use winit_core::event_loop::pump_events::PumpStatus;
1415
use winit_core::event_loop::ActiveEventLoop;
1516
use winit_core::window::ActivationToken;
1617

1718
pub(crate) use self::common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey};
18-
use crate::platform::pump_events::PumpStatus;
1919
#[cfg(x11_platform)]
2020
use crate::platform::x11::WindowType as XWindowType;
2121

src/platform_impl/linux/wayland/event_loop/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ use winit_core::application::ApplicationHandler;
2121
use winit_core::cursor::{CustomCursor as CoreCustomCursor, CustomCursorSource};
2222
use winit_core::error::{EventLoopError, NotSupportedError, OsError, RequestError};
2323
use winit_core::event::{DeviceEvent, StartCause, SurfaceSizeWriter, WindowEvent};
24+
use winit_core::event_loop::pump_events::PumpStatus;
2425
use winit_core::event_loop::{
2526
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
2627
OwnedDisplayHandle as CoreOwnedDisplayHandle,
2728
};
2829
use winit_core::monitor::MonitorHandle as CoreMonitorHandle;
2930
use winit_core::window::Theme;
3031

31-
use crate::platform::pump_events::PumpStatus;
3232
use crate::platform_impl::platform::min_timeout;
3333
use crate::platform_impl::wayland::types::cursor::WaylandCustomCursor;
3434

0 commit comments

Comments
 (0)