diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h index 46a27b6829..96fec957ab 100644 --- a/src/video/cocoa/SDL_cocoawindow.h +++ b/src/video/cocoa/SDL_cocoawindow.h @@ -140,6 +140,7 @@ typedef enum @property(nonatomic) SDL_CocoaVideoData *videodata; @property(nonatomic) SDL_bool send_floating_size; @property(nonatomic) SDL_bool send_floating_position; +@property(nonatomic) SDL_bool border_toggled; @property(nonatomic) BOOL checking_zoom; #ifdef SDL_VIDEO_OPENGL_EGL @property(nonatomic) EGLSurface egl_surface; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 0b0c8113c8..d2745db04c 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -1140,18 +1140,12 @@ static SDL_bool Cocoa_IsZoomed(SDL_Window *window) - (void)windowWillEnterFullScreen:(NSNotification *)aNotification { SDL_Window *window = _data.window; - NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; + const NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskTitled; - /* Don't set the titled flag on a fullscreen window if the windowed-mode window - * is borderless, or the window can wind up in a weird, pseudo-decorated state - * when leaving fullscreen if the border flag was toggled on. + /* For some reason, the fullscreen window won't get any mouse button events + * without the NSWindowStyleMaskTitled flag being set when entering fullscreen, + * so it's needed even if the window is borderless. */ - if (!(window->flags & SDL_WINDOW_BORDERLESS)) { - flags |= NSWindowStyleMaskTitled; - } else { - flags |= NSWindowStyleMaskBorderless; - } - SetWindowStyle(window, flags); _data.was_zoomed = !!(window->flags & SDL_WINDOW_MAXIMIZED); @@ -1212,6 +1206,19 @@ static SDL_bool Cocoa_IsZoomed(SDL_Window *window) - (void)windowWillExitFullScreen:(NSNotification *)aNotification { + SDL_Window *window = _data.window; + + /* If the windowed mode borders were toggled on while in a fullscreen space, + * NSWindowStyleMaskTitled has to be cleared here, or the window can end up + * in a weird, semi-decorated state upon returning to windowed mode. + */ + if (_data.border_toggled && !(window->flags & SDL_WINDOW_BORDERLESS)) { + const NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; + + SetWindowStyle(window, flags); + _data.border_toggled = SDL_FALSE; + } + isFullscreenSpace = NO; inFullscreenTransition = YES; } @@ -1219,17 +1226,11 @@ static SDL_bool Cocoa_IsZoomed(SDL_Window *window) - (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification { SDL_Window *window = _data.window; - NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; + const NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; if (window->is_destroying) { return; } - - if (!(window->flags & SDL_WINDOW_BORDERLESS)) { - flags |= NSWindowStyleMaskTitled; - } else { - flags |= NSWindowStyleMaskBorderless; - } SetWindowStyle(window, flags); @@ -2455,6 +2456,8 @@ void Cocoa_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, SDL_boo Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */ } } + } else { + data.border_toggled = SDL_TRUE; } } }