mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Add exit code to ControlFlow::Exit (#2100)
* Add exit code to control flow and impl on linux * Fix examples to have an exit code * Fix doc examples to use an exit code * Improve documentation wording on the exit code * Add exit code example * Add exit code on windows * Change i32 as exit code to u8 This avoids nasty surprises with negative numbers on some unix-alikes due to two's complement. * Fix android usages of ControlFlow::Exit * Fix ios usages of ControlFlow::Exit * Fix web usages of ControlFlow::Exit * Add macos exit code * Add changelog note * Document exit code on display server disconnection * Revert "Change i32 as exit code to u8" This reverts commitf88fba0253. * Change Exit to ExitWithCode and make an Exit const * Revert "Add exit code example" This reverts commitfbd3d03de9. * Revert "Fix doc examples to use an exit code" This reverts commitdaabcdf9ef. * Revert "Fix examples to have an exit code" This reverts commit0df486896b. * Fix unix-alike to use ExitWithCode instead of Exit * Fix windows to use ExitWithCode rather than Exit * Silence warning about non-uppercase Exit const * Refactor exit code handling * Fix macos Exit usage and recover original semantic * Fix ios to use ExitWithCode instead of Exit * Update documentation to reflect ExitWithCode * Fix web to use ExitWithCode when needed, not Exit * Fix android to use ExitWithCode, not Exit * Apply documenation nits * Apply even more documentation nits * Move change in CHANGELOG.md under "Unreleased" * Try to use OS error code as exit code on wayland
This commit is contained in:
@@ -73,10 +73,10 @@ pub struct EventLoop<T: 'static> {
|
||||
|
||||
macro_rules! call_event_handler {
|
||||
( $event_handler:expr, $window_target:expr, $cf:expr, $event:expr ) => {{
|
||||
if $cf != ControlFlow::Exit {
|
||||
$event_handler($event, $window_target, &mut $cf);
|
||||
if let ControlFlow::ExitWithCode(code) = $cf {
|
||||
$event_handler($event, $window_target, &mut ControlFlow::ExitWithCode(code));
|
||||
} else {
|
||||
$event_handler($event, $window_target, &mut ControlFlow::Exit);
|
||||
$event_handler($event, $window_target, &mut $cf);
|
||||
}
|
||||
}};
|
||||
}
|
||||
@@ -103,11 +103,11 @@ impl<T: 'static> EventLoop<T> {
|
||||
F: 'static
|
||||
+ FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
self.run_return(event_handler);
|
||||
::std::process::exit(0);
|
||||
let exit_code = self.run_return(event_handler);
|
||||
::std::process::exit(exit_code);
|
||||
}
|
||||
|
||||
pub fn run_return<F>(&mut self, mut event_handler: F)
|
||||
pub fn run_return<F>(&mut self, mut event_handler: F) -> i32
|
||||
where
|
||||
F: FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
@@ -339,7 +339,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
);
|
||||
|
||||
match control_flow {
|
||||
ControlFlow::Exit => {
|
||||
ControlFlow::ExitWithCode(code) => {
|
||||
self.first_event = poll(
|
||||
self.looper
|
||||
.poll_once_timeout(Duration::from_millis(0))
|
||||
@@ -349,7 +349,7 @@ impl<T: 'static> EventLoop<T> {
|
||||
start: Instant::now(),
|
||||
requested_resume: None,
|
||||
};
|
||||
break 'event_loop;
|
||||
break 'event_loop code;
|
||||
}
|
||||
ControlFlow::Poll => {
|
||||
self.first_event = poll(
|
||||
|
||||
Reference in New Issue
Block a user