Only watch for display connect/disconnect events while the video subsystem is initialized
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m
index a38f00b..5cc7b1e 100644
--- a/src/video/uikit/SDL_uikitappdelegate.m
+++ b/src/video/uikit/SDL_uikitappdelegate.m
@@ -349,14 +349,6 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
- (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];
@@ -528,18 +520,6 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
#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 */
diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m
index e978c10..98e470c 100644
--- a/src/video/uikit/SDL_uikitmodes.m
+++ b/src/video/uikit/SDL_uikitmodes.m
@@ -181,6 +181,44 @@
@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,
@@ -349,6 +387,8 @@ UIKit_InitModes(_THIS)
#if !TARGET_OS_TV
SDL_OnApplicationDidChangeStatusBarOrientation();
#endif
+
+ [SDL_DisplayWatch start];
}
return 0;
@@ -482,6 +522,8 @@ UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
void
UIKit_QuitModes(_THIS)
{
+ [SDL_DisplayWatch stop];
+
/* Release Objective-C objects, so higher level doesn't free() them. */
int i, j;
@autoreleasepool {