Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the lifecycle observer active while there are windows active #11965

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ extern bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window);
extern bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, bool state, bool blocking);
#endif

#ifdef SDL_VIDEO_DRIVER_UIKIT
extern void SDL_UpdateLifecycleObserver(void);
#endif

static void SDL_CheckWindowDisplayChanged(SDL_Window *window);
static void SDL_CheckWindowDisplayScaleChanged(SDL_Window *window);
static void SDL_CheckWindowSafeAreaChanged(SDL_Window *window);
Expand Down Expand Up @@ -2467,6 +2471,10 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
// Make sure window pixel size is up to date
SDL_CheckWindowPixelSizeChanged(window);

#ifdef SDL_VIDEO_DRIVER_UIKIT
SDL_UpdateLifecycleObserver();
#endif

SDL_ClearError();

return window;
Expand Down Expand Up @@ -4198,6 +4206,10 @@ void SDL_DestroyWindow(SDL_Window *window)
}

SDL_free(window);

#ifdef SDL_VIDEO_DRIVER_UIKIT
SDL_UpdateLifecycleObserver();
#endif
}

bool SDL_ScreenSaverEnabled(void)
Expand Down
13 changes: 11 additions & 2 deletions src/video/uikit/SDL_uikitevents.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ @implementation SDL_LifecycleObserver
- (void)update
{
NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
if ((UIKit_EventPumpEnabled || SDL_HasMainCallbacks()) && !self.isObservingNotifications) {
bool wants_observation = (UIKit_EventPumpEnabled || SDL_HasMainCallbacks());
if (!wants_observation) {
// Make sure no windows have active animation callbacks
int num_windows = 0;
SDL_free(SDL_GetWindows(&num_windows));
if (num_windows > 0) {
wants_observation = true;
}
}
if (wants_observation && !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];
Expand All @@ -58,7 +67,7 @@ - (void)update
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
#endif
} else if (!UIKit_EventPumpEnabled && !SDL_HasMainCallbacks() && self.isObservingNotifications) {
} else if (!wants_observation && self.isObservingNotifications) {
self.isObservingNotifications = NO;
[notificationCenter removeObserver:self];
}
Expand Down
Loading