From 6d0f3f0724d0b6091500f5673fc759d323fcdecb Mon Sep 17 00:00:00 2001 From: Dusty DeWeese Date: Sat, 4 Sep 2021 11:28:51 -0700 Subject: [PATCH] add Foreground and Background events --- src/event.rs | 12 ++++++++++++ src/platform_impl/ios/view.rs | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/event.rs b/src/event.rs index 6660e00688..dfcf688e84 100644 --- a/src/event.rs +++ b/src/event.rs @@ -76,6 +76,12 @@ pub enum Event<'a, T: 'static> { /// Emitted when the application has been resumed. Resumed, + /// Emitted when the application will enter the foreground. + Foreground, + + /// Emitted when the application has entered the background. + Background, + /// Emitted when all of the event loop's input events have been processed and redraw processing /// is about to begin. /// @@ -138,6 +144,8 @@ impl Clone for Event<'static, T> { LoopDestroyed => LoopDestroyed, Suspended => Suspended, Resumed => Resumed, + Foreground => Foreground, + Background => Background, } } } @@ -156,6 +164,8 @@ impl<'a, T> Event<'a, T> { LoopDestroyed => Ok(LoopDestroyed), Suspended => Ok(Suspended), Resumed => Ok(Resumed), + Foreground => Ok(Foreground), + Background => Ok(Background), } } @@ -176,6 +186,8 @@ impl<'a, T> Event<'a, T> { LoopDestroyed => Some(LoopDestroyed), Suspended => Some(Suspended), Resumed => Some(Resumed), + Foreground => Some(Foreground), + Background => Some(Background), } } } diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index ccdec6bfbf..dc8dfabf7e 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -560,8 +560,13 @@ pub fn create_delegate_class() { unsafe { app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Suspended)) } } - extern "C" fn will_enter_foreground(_: &Object, _: Sel, _: id) {} - extern "C" fn did_enter_background(_: &Object, _: Sel, _: id) {} + extern "C" fn will_enter_foreground(_: &Object, _: Sel, _: id) { + unsafe { app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Foreground)) } + } + + extern "C" fn did_enter_background(_: &Object, _: Sel, _: id) { + unsafe { app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Background)) } + } extern "C" fn will_terminate(_: &Object, _: Sel, _: id) { unsafe {