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; use raw_window_handle::HasRawWindowHandle;
pub use window::{RunningWindow, Window, WindowAttributes, WindowBehavior, WindowBuilder}; pub use window::{RunningWindow, Window, WindowAttributes, WindowBehavior, WindowBuilder};
use winit::error::OsError; use winit::error::{EventLoopError, OsError};
use winit::window::WindowId; use winit::window::WindowId;
use std::collections::HashMap; use std::collections::HashMap;
use std::process::exit;
use std::sync::{mpsc, Arc, Mutex, PoisonError}; use std::sync::{mpsc, Arc, Mutex, PoisonError};
use winit::event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy, EventLoopWindowTarget}; use winit::event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy, EventLoopWindowTarget};
use winit::{event::Event, event_loop::EventLoop}; use winit::{event::Event, event_loop::EventLoop};
@ -82,9 +81,8 @@ where
/// Begins running the application. This function will never return. /// Begins running the application. This function will never return.
/// ///
/// Internally this runs the [`EventLoop`]. /// Internally this runs the [`EventLoop`].
pub fn run(mut self) -> ! { pub fn run(mut self) -> Result<(), EventLoopError> {
self.event_loop self.event_loop.run(move |event, target, control_flow| {
.run(move |event, target, control_flow| {
*control_flow = ControlFlow::Wait; *control_flow = ControlFlow::Wait;
match event { match event {
Event::WindowEvent { window_id, event } => { Event::WindowEvent { window_id, event } => {
@ -131,9 +129,6 @@ where
| Event::AboutToWait => {} | 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 std::time::{Duration, Instant};
use winit::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use winit::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use winit::error::OsError; use winit::error::{EventLoopError, OsError};
use winit::event::{ use winit::event::{
AxisId, DeviceId, ElementState, Ime, KeyEvent, Modifiers, MouseButton, MouseScrollDelta, Touch, AxisId, DeviceId, ElementState, Ime, KeyEvent, Modifiers, MouseButton, MouseScrollDelta, Touch,
TouchPhase, TouchPhase,
@ -774,7 +774,7 @@ where
fn run_with_event_callback( fn run_with_event_callback(
app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response
+ 'static, + 'static,
) -> ! ) -> Result<(), EventLoopError>
where where
Self::Context: Default, Self::Context: Default,
{ {
@ -795,7 +795,7 @@ where
context: Self::Context, context: Self::Context,
app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response app_callback: impl FnMut(AppMessage, &Windows<AppMessage::Window>) -> AppMessage::Response
+ 'static, + 'static,
) -> ! { ) -> Result<(), EventLoopError> {
let app = PendingApp::new_with_event_callback(app_callback); let app = PendingApp::new_with_event_callback(app_callback);
Self::open_with(&app, context).expect("error opening initial window"); Self::open_with(&app, context).expect("error opening initial window");
app.run() app.run()
@ -1020,7 +1020,7 @@ pub trait Run: WindowBehavior<()> {
/// ///
/// This function is shorthand for creating a [`PendingApp`], opening this /// This function is shorthand for creating a [`PendingApp`], opening this
/// window inside of it, and running the pending app. /// window inside of it, and running the pending app.
fn run() -> ! fn run() -> Result<(), EventLoopError>
where where
Self::Context: Default, Self::Context: Default,
{ {
@ -1033,7 +1033,7 @@ pub trait Run: WindowBehavior<()> {
/// ///
/// This function is shorthand for creating a [`PendingApp`], opening this /// This function is shorthand for creating a [`PendingApp`], opening this
/// window inside of it, and running the pending app. /// 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(); let app = PendingApp::new();
Self::open_with(&app, context).expect("error opening initial window"); Self::open_with(&app, context).expect("error opening initial window");
app.run() app.run()