Properly handle toggling fullscreen state when another fullscreen state change is in progress.
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h
index 1ec3d3c..dbe592a 100644
--- a/src/video/cocoa/SDL_cocoawindow.h
+++ b/src/video/cocoa/SDL_cocoawindow.h
@@ -34,12 +34,19 @@ typedef struct SDL_WindowData SDL_WindowData;
BOOL wasVisible;
BOOL isFullscreen;
BOOL inFullscreenTransition;
+
+ enum
+ {
+ PENDING_TRANSITION_NONE,
+ PENDING_TRANSITION_ENTER_FULLSCREEN,
+ PENDING_TRANSITION_LEAVE_FULLSCREEN
+ } pendingFullscreenTransition;
}
-(void) listen:(SDL_WindowData *) data;
-(void) pauseVisibleObservation;
-(void) resumeVisibleObservation;
--(BOOL) isToggledFullscreen;
+-(BOOL) setFullscreenState:(BOOL) state;
-(void) close;
/* Window delegate functionality */
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 20852b2..5ae119f 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -103,6 +103,7 @@ GetWindowStyle(SDL_Window * window)
wasVisible = [window isVisible];
isFullscreen = NO;
inFullscreenTransition = NO;
+ pendingFullscreenTransition = PENDING_TRANSITION_NONE;
center = [NSNotificationCenter defaultCenter];
@@ -183,9 +184,52 @@ GetWindowStyle(SDL_Window * window)
}
}
-- (BOOL) isToggledFullscreen
+-(BOOL) canSetFullscreenState:(BOOL) state;
{
- return isFullscreen;
+}
+
+-(BOOL) setFullscreenState:(BOOL) state;
+{
+ SDL_Window *window = _data->window;
+ NSWindow *nswindow = _data->nswindow;
+ BOOL canSetState = NO;
+
+ /* Make sure we can support this fullscreen style */
+ if (![nswindow respondsToSelector: @selector(toggleFullScreen:)]) {
+ return NO;
+ }
+
+ pendingFullscreenTransition = PENDING_TRANSITION_NONE;
+
+ /* We can enter new style fullscreen mode for "fullscreen desktop" */
+ if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ canSetState = YES;
+ }
+
+ /* We can always leave new style fullscreen mode */
+ if (!state && isFullscreen) {
+ canSetState = YES;
+ }
+
+ if (!canSetState) {
+ return NO;
+ }
+
+ if (state == isFullscreen) {
+ return YES;
+ }
+
+ if (inFullscreenTransition) {
+ if (state) {
+ pendingFullscreenTransition = PENDING_TRANSITION_ENTER_FULLSCREEN;
+ } else {
+ pendingFullscreenTransition = PENDING_TRANSITION_LEAVE_FULLSCREEN;
+ }
+ return YES;
+ }
+
+ [nswindow performSelector: @selector(toggleFullScreen:) withObject:nswindow];
+ return YES;
}
- (void)close
@@ -215,8 +259,7 @@ GetWindowStyle(SDL_Window * window)
[window setDelegate:nil];
}
- [window removeObserver:self
- forKeyPath:@"visible"];
+ [window removeObserver:self forKeyPath:@"visible"];
if ([window nextResponder] == self) {
[window setNextResponder:nil];
@@ -385,11 +428,18 @@ GetWindowStyle(SDL_Window * window)
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
{
inFullscreenTransition = NO;
- [self windowDidResize:aNotification];
+
+ if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
+ pendingFullscreenTransition = PENDING_TRANSITION_NONE;
+ [self setFullscreenState:NO];
+ } else {
+ [self windowDidResize:aNotification];
+ }
}
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
{
+ isFullscreen = NO;
inFullscreenTransition = YES;
}
@@ -401,9 +451,14 @@ GetWindowStyle(SDL_Window * window)
if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
[nswindow setStyleMask:GetWindowStyle(window)];
}
- isFullscreen = NO;
inFullscreenTransition = NO;
- [self windowDidResize:aNotification];
+
+ if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
+ pendingFullscreenTransition = PENDING_TRANSITION_NONE;
+ [self setFullscreenState:YES];
+ } else {
+ [self windowDidResize:aNotification];
+ }
}
/* We'll respond to key events by doing nothing so we don't beep.
@@ -1094,41 +1149,6 @@ Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
[pool release];
}
-static SDL_bool
-Cocoa_CanToggleFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
-{
- SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- NSWindow *nswindow = data->nswindow;
-
- if (![nswindow respondsToSelector: @selector(toggleFullScreen:)]) {
- return SDL_FALSE;
- }
-
- /* We can enter new style fullscreen mode for "fullscreen desktop" */
- if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
- return SDL_TRUE;
- }
-
- /* We can always leave new style fullscreen mode */
- if (!fullscreen && [data->listener isToggledFullscreen]) {
- return SDL_TRUE;
- }
-
- /* Requesting a mode switched fullscreen mode */
- return SDL_FALSE;
-}
-
-static void
-Cocoa_SetWindowFullscreen_NewStyle(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
-{
- SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- NSWindow *nswindow = data->nswindow;
-
- if (fullscreen != [data->listener isToggledFullscreen]) {
- [nswindow performSelector: @selector(toggleFullScreen:) withObject:nswindow];
- }
- ScheduleContextUpdates(data);
-}
static void
Cocoa_SetWindowFullscreen_OldStyle(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
@@ -1212,10 +1232,9 @@ void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
- if (Cocoa_CanToggleFullscreen(_this, window, display, fullscreen)) {
- Cocoa_SetWindowFullscreen_NewStyle(_this, window, display, fullscreen);
- } else {
+ if (![data->listener setFullscreenState:(fullscreen ? YES : NO)]) {
Cocoa_SetWindowFullscreen_OldStyle(_this, window, display, fullscreen);
}