This commit is contained in:
Roland Fredenhagen 2023-09-02 17:29:56 +02:00
parent e7d01c02bb
commit 272d1c7462
No known key found for this signature in database
GPG key ID: 094AF99241035EB6
2 changed files with 53 additions and 58 deletions

View file

@ -11,11 +11,10 @@ pub use winit;
use raw_window_handle::HasRawWindowHandle;
pub use window::{RunningWindow, Window, WindowAttributes, WindowBehavior, WindowBuilder};
use winit::error::OsError;
use winit::error::{EventLoopError, OsError};
use winit::window::WindowId;
use std::collections::HashMap;
use std::process::exit;
use std::sync::{mpsc, Arc, Mutex, PoisonError};
use winit::event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy, EventLoopWindowTarget};
use winit::{event::Event, event_loop::EventLoop};
@ -82,9 +81,8 @@ where
/// Begins running the application. This function will never return.
///
/// Internally this runs the [`EventLoop`].
pub fn run(mut self) -> ! {
self.event_loop
.run(move |event, target, control_flow| {
pub fn run(mut self) -> Result<(), EventLoopError> {
self.event_loop.run(move |event, target, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::WindowEvent { window_id, event } => {
@ -131,9 +129,6 @@ where
| Event::AboutToWait => {}
}
})
.unwrap();
// TODO do we want to forward the change to a result
exit(0);
}
}

View file

@ -7,7 +7,7 @@ use std::thread;
use std::time::{Duration, Instant};
use winit::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use winit::error::OsError;
use winit::error::{EventLoopError, OsError};
use winit::event::{
AxisId, DeviceId, ElementState, Ime, KeyEvent, Modifiers, MouseButton, MouseScrollDelta, Touch,
TouchPhase,
@ -774,7 +774,7 @@ where
fn run_with_event_callback(
app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response
+ 'static,
) -> !
) -> Result<(), EventLoopError>
where
Self::Context: Default,
{
@ -795,7 +795,7 @@ where
context: Self::Context,
app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response
+ 'static,
) -> ! {
) -> Result<(), EventLoopError> {
let app = PendingApp::new_with_event_callback(app_callback);
Self::open_with(&app, context).expect("error opening initial window");
app.run()
@ -1020,7 +1020,7 @@ pub trait Run: WindowBehavior<()> {
///
/// This function is shorthand for creating a [`PendingApp`], opening this
/// window inside of it, and running the pending app.
fn run() -> !
fn run() -> Result<(), EventLoopError>
where
Self::Context: Default,
{
@ -1033,7 +1033,7 @@ pub trait Run: WindowBehavior<()> {
///
/// This function is shorthand for creating a [`PendingApp`], opening this
/// window inside of it, and running the pending app.
fn run_with(context: Self::Context) -> ! {
fn run_with(context: Self::Context) -> Result<(), EventLoopError> {
let app = PendingApp::new();
Self::open_with(&app, context).expect("error opening initial window");
app.run()