Pārlūkot izejas kodu

cocoa: Set the titled flag on fullscreen space windows

For some reason, fullscreen space windows won't get any mouse button events unless the NSWindowStyleMaskTitled flag is set when entering fullscreen, even though they successfully become key and receive mouse motion events. Make sure the flag is always set when entering fullscreen space state.
Frank Praznik 1 gadu atpakaļ
vecāks
revīzija
ed62d6e7de
2 mainītis faili ar 21 papildinājumiem un 17 dzēšanām
  1. 1 0
      src/video/cocoa/SDL_cocoawindow.h
  2. 20 17
      src/video/cocoa/SDL_cocoawindow.m

+ 1 - 0
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;

+ 20 - 17
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;
         }
     }
 }