mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 19:38:14 +00:00
Fixed life cycle events on iOS when using main callbacks
This commit is contained in:
@@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#include "../../video/uikit/SDL_uikitevents.h" // For SDL_UpdateLifecycleObserver()
|
||||||
|
|
||||||
|
|
||||||
@interface SDLIosMainCallbacksDisplayLink : NSObject
|
@interface SDLIosMainCallbacksDisplayLink : NSObject
|
||||||
@property(nonatomic, retain) CADisplayLink *displayLink;
|
@property(nonatomic, retain) CADisplayLink *displayLink;
|
||||||
- (void)appIteration:(CADisplayLink *)sender;
|
- (void)appIteration:(CADisplayLink *)sender;
|
||||||
@@ -53,6 +56,7 @@ static SDLIosMainCallbacksDisplayLink *globalDisplayLink;
|
|||||||
self.displayLink = nil;
|
self.displayLink = nil;
|
||||||
globalDisplayLink = nil;
|
globalDisplayLink = nil;
|
||||||
SDL_QuitMainCallbacks();
|
SDL_QuitMainCallbacks();
|
||||||
|
SDL_UpdateLifecycleObserver();
|
||||||
exit((rc < 0) ? 1 : 0);
|
exit((rc < 0) ? 1 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "../SDL_sysvideo.h"
|
#include "../SDL_sysvideo.h"
|
||||||
|
|
||||||
|
extern void SDL_UpdateLifecycleObserver(void);
|
||||||
|
|
||||||
extern Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp);
|
extern Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp);
|
||||||
extern void UIKit_PumpEvents(SDL_VideoDevice *_this);
|
extern void UIKit_PumpEvents(SDL_VideoDevice *_this);
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
||||||
|
|
||||||
#include "../../events/SDL_events_c.h"
|
#include "../../events/SDL_events_c.h"
|
||||||
|
#include "../../main/SDL_main_callbacks.h"
|
||||||
|
|
||||||
#include "SDL_uikitevents.h"
|
#include "SDL_uikitevents.h"
|
||||||
#include "SDL_uikitopengles.h"
|
#include "SDL_uikitopengles.h"
|
||||||
@@ -46,10 +47,10 @@ static BOOL UIKit_EventPumpEnabled = YES;
|
|||||||
|
|
||||||
@implementation SDL_LifecycleObserver
|
@implementation SDL_LifecycleObserver
|
||||||
|
|
||||||
- (void)eventPumpChanged
|
- (void)update
|
||||||
{
|
{
|
||||||
NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
|
NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
|
||||||
if (UIKit_EventPumpEnabled && !self.isObservingNotifications) {
|
if ((UIKit_EventPumpEnabled || SDL_HasMainCallbacks()) && !self.isObservingNotifications) {
|
||||||
self.isObservingNotifications = YES;
|
self.isObservingNotifications = YES;
|
||||||
[notificationCenter addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
[notificationCenter addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
||||||
[notificationCenter addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
|
[notificationCenter addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
|
||||||
@@ -63,7 +64,7 @@ static BOOL UIKit_EventPumpEnabled = YES;
|
|||||||
name:UIApplicationDidChangeStatusBarOrientationNotification
|
name:UIApplicationDidChangeStatusBarOrientationNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
#endif
|
#endif
|
||||||
} else if (!UIKit_EventPumpEnabled && self.isObservingNotifications) {
|
} else if (!UIKit_EventPumpEnabled && !SDL_HasMainCallbacks() && self.isObservingNotifications) {
|
||||||
self.isObservingNotifications = NO;
|
self.isObservingNotifications = NO;
|
||||||
[notificationCenter removeObserver:self];
|
[notificationCenter removeObserver:self];
|
||||||
}
|
}
|
||||||
@@ -108,6 +109,23 @@ static BOOL UIKit_EventPumpEnabled = YES;
|
|||||||
|
|
||||||
@end
|
@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)
|
Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp)
|
||||||
{
|
{
|
||||||
static Uint64 timestamp_offset;
|
static Uint64 timestamp_offset;
|
||||||
@@ -126,18 +144,6 @@ Uint64 UIKit_GetEventTimestamp(NSTimeInterval nsTimestamp)
|
|||||||
return timestamp;
|
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)
|
void UIKit_PumpEvents(SDL_VideoDevice *_this)
|
||||||
{
|
{
|
||||||
if (!UIKit_EventPumpEnabled) {
|
if (!UIKit_EventPumpEnabled) {
|
||||||
|
Reference in New Issue
Block a user