diff --git a/src/main/ios/SDL_sysmain_callbacks.m b/src/main/ios/SDL_sysmain_callbacks.m index ab00d333c4805..439db7a2eacdf 100644 --- a/src/main/ios/SDL_sysmain_callbacks.m +++ b/src/main/ios/SDL_sysmain_callbacks.m @@ -26,6 +26,9 @@ #import +#include "../../video/uikit/SDL_uikitevents.h" // For SDL_UpdateLifecycleObserver() + + @interface SDLIosMainCallbacksDisplayLink : NSObject @property(nonatomic, retain) CADisplayLink *displayLink; - (void)appIteration:(CADisplayLink *)sender; @@ -53,6 +56,7 @@ - (void)appIteration:(CADisplayLink *)sender self.displayLink = nil; globalDisplayLink = nil; SDL_QuitMainCallbacks(); + SDL_UpdateLifecycleObserver(); exit((rc < 0) ? 1 : 0); } } diff --git a/src/video/uikit/SDL_uikitevents.h b/src/video/uikit/SDL_uikitevents.h index 4754110e51b04..683ad02e4fb03 100644 --- a/src/video/uikit/SDL_uikitevents.h +++ b/src/video/uikit/SDL_uikitevents.h @@ -25,6 +25,8 @@ #include "../SDL_sysvideo.h" +extern void SDL_UpdateLifecycleObserver(void); + extern Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp); extern void UIKit_PumpEvents(SDL_VideoDevice *_this); diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m index bba14f13da140..2f45a39e9a805 100644 --- a/src/video/uikit/SDL_uikitevents.m +++ b/src/video/uikit/SDL_uikitevents.m @@ -23,6 +23,7 @@ #ifdef SDL_VIDEO_DRIVER_UIKIT #include "../../events/SDL_events_c.h" +#include "../../main/SDL_main_callbacks.h" #include "SDL_uikitevents.h" #include "SDL_uikitopengles.h" @@ -46,10 +47,10 @@ @interface SDL_LifecycleObserver : NSObject @implementation SDL_LifecycleObserver -- (void)eventPumpChanged +- (void)update { NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter; - if (UIKit_EventPumpEnabled && !self.isObservingNotifications) { + if ((UIKit_EventPumpEnabled || SDL_HasMainCallbacks()) && !self.isObservingNotifications) { self.isObservingNotifications = YES; [notificationCenter addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; [notificationCenter addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil]; @@ -63,7 +64,7 @@ - (void)eventPumpChanged name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; #endif - } else if (!UIKit_EventPumpEnabled && self.isObservingNotifications) { + } else if (!UIKit_EventPumpEnabled && !SDL_HasMainCallbacks() && self.isObservingNotifications) { self.isObservingNotifications = NO; [notificationCenter removeObserver:self]; } @@ -108,6 +109,23 @@ - (void)applicationDidChangeStatusBarOrientation @end +void SDL_UpdateLifecycleObserver(void) +{ + static SDL_LifecycleObserver *lifecycleObserver; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + lifecycleObserver = [SDL_LifecycleObserver new]; + }); + [lifecycleObserver update]; +} + +void SDL_SetiOSEventPump(SDL_bool enabled) +{ + UIKit_EventPumpEnabled = enabled; + + SDL_UpdateLifecycleObserver(); +} + Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp) { static Uint64 timestamp_offset; @@ -126,18 +144,6 @@ Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp) return timestamp; } -void SDL_SetiOSEventPump(SDL_bool enabled) -{ - UIKit_EventPumpEnabled = enabled; - - static SDL_LifecycleObserver *lifecycleObserver; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - lifecycleObserver = [SDL_LifecycleObserver new]; - }); - [lifecycleObserver eventPumpChanged]; -} - void UIKit_PumpEvents(SDL_VideoDevice *_this) { if (!UIKit_EventPumpEnabled) {