Skip to content

Commit

Permalink
Only watch for display connect/disconnect events while the video subs…
Browse files Browse the repository at this point in the history
…ystem is initialized
  • Loading branch information
slouken committed Oct 9, 2020
1 parent 7991cc3 commit b546db2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
20 changes: 0 additions & 20 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -349,14 +349,6 @@ - (void)hideLaunchScreen

- (void)postFinishLaunch
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];


/* Hide the launch screen the next time the run loop is run. SDL apps will
* have a chance to load resources while the launch screen is still up. */
[self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
Expand Down Expand Up @@ -528,18 +520,6 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl

#endif

- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification
{
UIScreen *uiscreen = [aNotification object];
UIKit_AddDisplay(uiscreen, SDL_TRUE);
}

- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification
{
UIScreen *uiscreen = [aNotification object];
UIKit_DelDisplay(uiscreen);
}

@end

#endif /* SDL_VIDEO_DRIVER_UIKIT */
Expand Down
42 changes: 42 additions & 0 deletions src/video/uikit/SDL_uikitmodes.m
Expand Up @@ -181,6 +181,44 @@ @implementation SDL_DisplayModeData

@end

@interface SDL_DisplayWatch : NSObject
@end

@implementation SDL_DisplayWatch

+ (void)start
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(screenConnected:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(screenDisconnected:)
name:UIScreenDidDisconnectNotification object:nil];
}

+ (void)stop
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center removeObserver:self
name:UIScreenDidConnectNotification object:nil];
[center removeObserver:self
name:UIScreenDidDisconnectNotification object:nil];
}

+ (void)screenConnected:(NSNotification*)notification
{
UIScreen *uiscreen = [notification object];
UIKit_AddDisplay(uiscreen, SDL_TRUE);
}

+ (void)screenDisconnected:(NSNotification*)notification
{
UIScreen *uiscreen = [notification object];
UIKit_DelDisplay(uiscreen);
}

@end

static int
UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
Expand Down Expand Up @@ -349,6 +387,8 @@ @implementation SDL_DisplayModeData
#if !TARGET_OS_TV
SDL_OnApplicationDidChangeStatusBarOrientation();
#endif

[SDL_DisplayWatch start];
}

return 0;
Expand Down Expand Up @@ -482,6 +522,8 @@ @implementation SDL_DisplayModeData
void
UIKit_QuitModes(_THIS)
{
[SDL_DisplayWatch stop];

/* Release Objective-C objects, so higher level doesn't free() them. */
int i, j;
@autoreleasepool {
Expand Down

0 comments on commit b546db2

Please sign in to comment.