Skip to content

Commit 8d39dbf

Browse files
committed
event_loop: group core API in EventLoopProvider
This helps with portability and defines some top-level structure around the event loop, so in the future, backends can get an idea of what API to use. This also changes the API to be object safe by using `dyn` throughout.
1 parent 8e39516 commit 8d39dbf

File tree

15 files changed

+288
-245
lines changed

15 files changed

+288
-245
lines changed

examples/application.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use winit::application::ApplicationHandler;
1919
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
2020
use winit::error::RequestError;
2121
use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, WindowEvent};
22-
use winit::event_loop::{ActiveEventLoop, EventLoop};
22+
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProvider};
2323
use winit::icon::RgbaIcon;
2424
use winit::keyboard::{Key, ModifiersState};
2525
use winit::monitor::Fullscreen;

examples/child_window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() -> Result<(), impl std::error::Error> {
66
use winit::application::ApplicationHandler;
77
use winit::dpi::{LogicalPosition, LogicalSize, Position};
88
use winit::event::{ElementState, KeyEvent, WindowEvent};
9-
use winit::event_loop::{ActiveEventLoop, EventLoop};
9+
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProvider};
1010
use winit::raw_window_handle::HasRawWindowHandle;
1111
use winit::window::{Window, WindowAttributes, WindowId};
1212

examples/control_flow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ::tracing::{info, warn};
99
use web_time as time;
1010
use winit::application::ApplicationHandler;
1111
use winit::event::{ElementState, KeyEvent, StartCause, WindowEvent};
12-
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
12+
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop, EventLoopProvider};
1313
use winit::keyboard::{Key, NamedKey};
1414
use winit::window::{Window, WindowAttributes, WindowId};
1515

examples/dnd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22

33
use winit::application::ApplicationHandler;
44
use winit::event::WindowEvent;
5-
use winit::event_loop::{ActiveEventLoop, EventLoop};
5+
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProvider};
66
use winit::window::{Window, WindowAttributes, WindowId};
77

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

examples/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::error::Error;
44

55
use winit::application::ApplicationHandler;
66
use winit::event::WindowEvent;
7-
use winit::event_loop::{ActiveEventLoop, EventLoop};
7+
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProvider};
88
#[cfg(web_platform)]
99
use winit::platform::web::WindowAttributesExtWeb;
1010
use winit::window::{Window, WindowAttributes, WindowId};

examples/x11_embed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::error::Error;
55
fn main() -> Result<(), Box<dyn Error>> {
66
use winit::application::ApplicationHandler;
77
use winit::event::WindowEvent;
8-
use winit::event_loop::{ActiveEventLoop, EventLoop};
8+
use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProvider};
99
use winit::platform::x11::WindowAttributesExtX11;
1010
use winit::window::{Window, WindowAttributes, WindowId};
1111

src/application.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use crate::window::WindowId;
88

99
/// The handler of application-level events.
1010
///
11-
/// See [the top-level docs] for example usage, and [`EventLoop::run_app`] for an overview of when
12-
/// events are delivered.
11+
/// See [the top-level docs] for example usage, and [`EventLoopProvider::run_app`] for an overview
12+
/// of when events are delivered.
1313
///
1414
/// This is [dropped] when the event loop is shut down. Note that this only works if you're passing
15-
/// the entire state to [`EventLoop::run_app`] (passing `&mut app` won't work).
15+
/// the entire state to [`EventLoopProvider::run_app`] (passing `&mut app` won't work).
1616
///
1717
/// [the top-level docs]: crate
18-
/// [`EventLoop::run_app`]: crate::event_loop::EventLoop::run_app
18+
/// [`EventLoopProvider::run_app`]: crate::event_loop::EventLoopProvider::run_app
1919
/// [dropped]: std::ops::Drop
2020
pub trait ApplicationHandler {
2121
/// Emitted when new events arrive from the OS to be processed.
@@ -136,7 +136,7 @@ pub trait ApplicationHandler {
136136
/// use std::time::Duration;
137137
///
138138
/// use winit::application::ApplicationHandler;
139-
/// use winit::event_loop::{ActiveEventLoop, EventLoop};
139+
/// use winit::event_loop::{ActiveEventLoop, EventLoop, EventLoopProvider};
140140
///
141141
/// struct MyApp {
142142
/// receiver: mpsc::Receiver<u64>,
@@ -210,9 +210,9 @@ pub trait ApplicationHandler {
210210

211211
/// Emitted when the OS sends an event to a device.
212212
///
213-
/// For this to be called, it must be enabled with [`EventLoop::listen_device_events`].
213+
/// For this to be called, it must be enabled with [`EventLoopProvider::listen_device_events`].
214214
///
215-
/// [`EventLoop::listen_device_events`]: crate::event_loop::EventLoop::listen_device_events
215+
/// [`EventLoopProvider::listen_device_events`]: crate::event_loop::EventLoopProvider::listen_device_events
216216
fn device_event(
217217
&mut self,
218218
event_loop: &dyn ActiveEventLoop,

src/changelog/unreleased.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ changelog entry.
195195
- Renamed "super" key to "meta", to match the naming in the W3C specification.
196196
`NamedKey::Super` still exists, but it's non-functional and deprecated, `NamedKey::Meta` should be used instead.
197197
- Move `IconExtWindows` into `WinIcon`.
198+
- `run_app_on_demand`/`pump_app_events` now accept `&mut dyn ApplicationHandler` instead of generic.
199+
- Moved common `EventLoop` methods like `run_app` into `EventLoopProvider` trait.
200+
- Moved `event_loop::EventLoop` into `platform::event_loop::EventLoop` keeping the old re-export in place.
201+
- `EventLoopProvider::run_app` now takes `Box<dyn ApplicationHandler` instead of owned generic.
198202

199203
### Removed
200204

0 commit comments

Comments
 (0)