Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-work event loop run APIs: adds run -> Result<>, run_ondemand and pump_events #2767

Merged
merged 15 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Web, remove unnecessary `Window::is_dark_mode()`, which was replaced with `Window::theme()`.
- On Web, add `WindowBuilderExtWebSys::with_append()` to append the canvas element to the web page on creation.
- On Windows, add `drag_resize_window` method support.
- **Breaking** `run() ->!` has been replaced by `run() -> Result<(), RunLoopError>` for returning errors without calling `std::process::exit()` ([#2767](https://github.com/rust-windowing/winit/pull/2767))
- **Breaking** Removed `EventLoopExtRunReturn` / `run_return` in favor of `EventLoopExtPumpEvents` / `pump_events` and `EventLoopExtRunOnDemand` / `run_ondemand` ([#2767](https://github.com/rust-windowing/winit/pull/2767))
- `RedrawRequested` is no longer guaranteed to be emitted after `MainEventsCleared`, it is now platform-specific when the event is emitted after being requested via `redraw_request()`.
- On Windows, `RedrawRequested` is now driven by `WM_PAINT` messages which are requested via `redraw_request()`

# 0.29.0-beta.0

Expand Down
2 changes: 1 addition & 1 deletion examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod fill;

#[cfg(any(x11_platform, macos_platform, windows_platform))]
fn main() {
fn main() -> Result<(), impl std::error::Error> {
use std::collections::HashMap;

use raw_window_handle::HasRawWindowHandle;
Expand Down
4 changes: 2 additions & 2 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum Mode {
const WAIT_TIME: time::Duration = time::Duration::from_millis(100);
const POLL_SLEEP_TIME: time::Duration = time::Duration::from_millis(100);

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();

println!("Press '1' to switch to Wait mode.");
Expand Down Expand Up @@ -122,5 +122,5 @@ fn main() {
}
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() {
}
_ => (),
}
});
})
}

const CURSORS: &[CursorIcon] = &[
Expand Down
4 changes: 2 additions & 2 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -73,5 +73,5 @@ fn main() {
Event::RedrawRequested(_) => fill::fill_window(&window),
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/custom_events.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::single_match)]

#[cfg(not(wasm_platform))]
fn main() {
fn main() -> Result<(), impl std::error::Error> {
use simple_logger::SimpleLogger;
use winit::{
event::{Event, WindowEvent},
Expand Down Expand Up @@ -52,7 +52,7 @@ fn main() {
}
_ => (),
}
});
})
}

#[cfg(wasm_platform)]
Expand Down
4 changes: 2 additions & 2 deletions examples/drag_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -69,7 +69,7 @@ fn main() {
}
}
_ => (),
});
})
}

fn name_windows(window_id: WindowId, switched: bool, window_1: &Window, window_2: &Window) {
Expand Down
4 changes: 2 additions & 2 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use winit::platform::macos::WindowExtMacOS;
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -131,5 +131,5 @@ fn main() {
}
_ => {}
}
});
})
}
4 changes: 2 additions & 2 deletions examples/handling_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -87,5 +87,5 @@ fn main() {
}
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new()
.with_level(LevelFilter::Trace)
.init()
Expand Down Expand Up @@ -105,5 +105,5 @@ fn main() {
}
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/key_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
}

#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
fn main() {
fn main() -> Result<(), impl std::error::Error> {
#[path = "util/fill.rs"]
mod fill;

Expand Down Expand Up @@ -61,5 +61,5 @@ fn main() {
}
_ => (),
};
});
})
}
4 changes: 2 additions & 2 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -64,5 +64,5 @@ In other words, the deltas indicate the direction in which to move the content (
}
_ => (),
}
});
})
}
2 changes: 1 addition & 1 deletion examples/multithreaded.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::single_match)]

#[cfg(not(wasm_platform))]
fn main() {
fn main() -> Result<(), impl std::error::Error> {
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};

use simple_logger::SimpleLogger;
Expand Down
2 changes: 1 addition & 1 deletion examples/multiwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down
4 changes: 2 additions & 2 deletions examples/request_redraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -41,5 +41,5 @@ fn main() {
}
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/request_redraw_threaded.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::single_match)]

#[cfg(not(wasm_platform))]
fn main() {
fn main() -> Result<(), impl std::error::Error> {
use std::{sync::Arc, thread, time};

use simple_logger::SimpleLogger;
Expand Down Expand Up @@ -49,7 +49,7 @@ fn main() {
}
_ => (),
}
});
})
}

#[cfg(wasm_platform)]
Expand Down
4 changes: 2 additions & 2 deletions examples/resizable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -53,5 +53,5 @@ fn main() {
}
_ => (),
};
});
})
}
19 changes: 9 additions & 10 deletions examples/startup_notification.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//! Demonstrates the use of startup notifications on Linux.

fn main() {
example::main();
}

#[cfg(any(x11_platform, wayland_platform))]
#[path = "./util/fill.rs"]
mod fill;
Expand All @@ -21,7 +17,7 @@ mod example {
};
use winit::window::{Window, WindowBuilder, WindowId};

pub(super) fn main() {
pub(super) fn main() -> Result<(), impl std::error::Error> {
// Create the event loop and get the activation token.
let event_loop = EventLoop::new();
let mut current_token = match event_loop.read_token_from_env() {
Expand Down Expand Up @@ -115,13 +111,16 @@ mod example {
}

flow.set_wait();
});
})
}
}

#[cfg(any(x11_platform, wayland_platform))]
fn main() -> Result<(), impl std::error::Error> {
example::main()
}

#[cfg(not(any(x11_platform, wayland_platform)))]
mod example {
pub(super) fn main() {
println!("This example is only supported on X11 and Wayland platforms.");
}
fn main() {
println!("This example is only supported on X11 and Wayland platforms.");
}
4 changes: 2 additions & 2 deletions examples/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -75,5 +75,5 @@ fn main() {
}
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -47,5 +47,5 @@ fn main() {
}
_ => (),
}
});
})
}
4 changes: 2 additions & 2 deletions examples/touchpad_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand Down Expand Up @@ -47,5 +47,5 @@ fn main() {
} else if let Event::RedrawRequested(_) = event {
fill::fill_window(&window);
}
});
})
}
4 changes: 2 additions & 2 deletions examples/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use winit::{
#[path = "util/fill.rs"]
mod fill;

fn main() {
fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

Expand All @@ -36,5 +36,5 @@ fn main() {
}
_ => (),
}
});
})
}
6 changes: 3 additions & 3 deletions examples/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use winit::{
window::{Fullscreen, WindowBuilder},
};

pub fn main() {
pub fn main() -> Result<(), impl std::error::Error> {
let event_loop = EventLoop::new();

let builder = WindowBuilder::new().with_title("A fantastic window!");
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn main() {
}
_ => (),
}
});
})
}

#[cfg(wasm_platform)]
Expand All @@ -72,7 +72,7 @@ mod wasm {
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");

#[allow(clippy::main_recursion)]
super::main();
let _ = super::main();
}

pub fn insert_canvas_and_create_log_list(window: &Window) -> web_sys::Element {
Expand Down
2 changes: 1 addition & 1 deletion examples/web_aspect_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This example demonstrates the desired future functionality which will possibly b
// Render once with the size info we currently have
render_circle(&canvas, window.inner_size());

event_loop.run(move |event, _, control_flow| {
let _ = event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

match event {
Expand Down
Loading