diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-14 14:07:54 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-14 14:07:54 +0100 |
commit | 3a2fb42838f790a90c542113fa2c347202ee2c06 (patch) | |
tree | 0fa56045e90f37a94110258fd5f7f8d23c9be2f4 /platform/ios | |
parent | d3f64bf2d277bfcd3cadbe37106862f9c48feaba (diff) | |
parent | fc7a63cbf3dcec176046b3ba047f40d367213cfb (diff) | |
download | redot-engine-3a2fb42838f790a90c542113fa2c347202ee2c06.tar.gz |
Merge pull request #85100 from ztc0611/fix-ios-focus-mainloop-notifs
Enhance mobile suspend MainLoop notifications
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/app_delegate.mm | 8 | ||||
-rw-r--r-- | platform/ios/os_ios.h | 3 | ||||
-rw-r--r-- | platform/ios/os_ios.mm | 28 |
3 files changed, 39 insertions, 0 deletions
diff --git a/platform/ios/app_delegate.mm b/platform/ios/app_delegate.mm index 8a16f8fcc1..32ebf7be44 100644 --- a/platform/ios/app_delegate.mm +++ b/platform/ios/app_delegate.mm @@ -167,6 +167,14 @@ static ViewController *mainViewController = nil; OS_IOS::get_singleton()->on_focus_in(); } +- (void)applicationDidEnterBackground:(UIApplication *)application { + OS_IOS::get_singleton()->on_enter_background(); +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + OS_IOS::get_singleton()->on_exit_background(); +} + - (void)dealloc { self.window = nil; } diff --git a/platform/ios/os_ios.h b/platform/ios/os_ios.h index 2d985a6c0b..445623f587 100644 --- a/platform/ios/os_ios.h +++ b/platform/ios/os_ios.h @@ -129,6 +129,9 @@ public: void on_focus_out(); void on_focus_in(); + + void on_enter_background(); + void on_exit_background(); }; #endif // IOS_ENABLED diff --git a/platform/ios/os_ios.mm b/platform/ios/os_ios.mm index 6ac21fa9c8..078f8e8494 100644 --- a/platform/ios/os_ios.mm +++ b/platform/ios/os_ios.mm @@ -601,6 +601,10 @@ void OS_IOS::on_focus_out() { DisplayServerIOS::get_singleton()->send_window_event(DisplayServer::WINDOW_EVENT_FOCUS_OUT); } + if (OS::get_singleton()->get_main_loop()) { + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT); + } + [AppDelegate.viewController.godotView stopRendering]; audio_driver.stop(); @@ -615,10 +619,34 @@ void OS_IOS::on_focus_in() { DisplayServerIOS::get_singleton()->send_window_event(DisplayServer::WINDOW_EVENT_FOCUS_IN); } + if (OS::get_singleton()->get_main_loop()) { + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_IN); + } + [AppDelegate.viewController.godotView startRendering]; audio_driver.start(); } } +void OS_IOS::on_enter_background() { + // Do not check for is_focused, because on_focus_out will always be fired first by applicationWillResignActive. + + if (OS::get_singleton()->get_main_loop()) { + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_PAUSED); + } + + on_focus_out(); +} + +void OS_IOS::on_exit_background() { + if (!is_focused) { + on_focus_in(); + + if (OS::get_singleton()->get_main_loop()) { + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_RESUMED); + } + } +} + #endif // IOS_ENABLED |