macOS: Prevent unwanted native fullscreen (Spaces) toggles when the window is in fullscreen or isn't resizable. Fixes bug #3691.
authorAlex Szpakowski <slime73@gmail.com>
Thu, 31 Aug 2017 21:13:32 -0300
changeset 11434fffd7c61e077
parent 11433 b5e2b88d5193
child 11435 181eadbddae2
macOS: Prevent unwanted native fullscreen (Spaces) toggles when the window is in fullscreen or isn't resizable. Fixes bug #3691.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Aug 31 15:17:59 2017 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Aug 31 21:13:32 2017 -0300
     1.3 @@ -65,10 +65,31 @@
     1.4  - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
     1.5  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
     1.6  - (BOOL)wantsPeriodicDraggingUpdates;
     1.7 +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
     1.8 +
     1.9 +- (SDL_Window*)findSDLWindow;
    1.10  @end
    1.11  
    1.12  @implementation SDLWindow
    1.13  
    1.14 +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
    1.15 +{
    1.16 +    /* Only allow using the macOS native fullscreen toggle menubar item if the
    1.17 +     * window is resizable and not in a SDL fullscreen mode.
    1.18 +     */
    1.19 +    if ([menuItem action] == @selector(toggleFullScreen:)) {
    1.20 +        SDL_Window *window = [self findSDLWindow];
    1.21 +        if (window == NULL) {
    1.22 +            return YES;
    1.23 +        } else if ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0) {
    1.24 +            return NO;
    1.25 +        } else if ((window->flags & SDL_WINDOW_RESIZABLE) == 0) {
    1.26 +            return NO;
    1.27 +        }
    1.28 +    }
    1.29 +    return YES;
    1.30 +}
    1.31 +
    1.32  - (BOOL)canBecomeKeyWindow
    1.33  {
    1.34      return YES;
    1.35 @@ -117,11 +138,10 @@
    1.36  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
    1.37  { @autoreleasepool
    1.38  {
    1.39 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.40      NSPasteboard *pasteboard = [sender draggingPasteboard];
    1.41      NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
    1.42      NSString *desiredType = [pasteboard availableTypeFromArray:types];
    1.43 -    SDL_Window *sdlwindow = nil;
    1.44 +    SDL_Window *sdlwindow = [self findSDLWindow];
    1.45  
    1.46      if (desiredType == nil) {
    1.47          return NO;  /* can't accept anything that's being dropped here. */
    1.48 @@ -158,16 +178,6 @@
    1.49              }
    1.50          }
    1.51  
    1.52 -        /* !!! FIXME: is there a better way to do this? */
    1.53 -        if (_this) {
    1.54 -            for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
    1.55 -                NSWindow *nswindow = ((SDL_WindowData *) sdlwindow->driverdata)->nswindow;
    1.56 -                if (nswindow == self) {
    1.57 -                    break;
    1.58 -                }
    1.59 -            }
    1.60 -        }
    1.61 -
    1.62          if (!SDL_SendDropFile(sdlwindow, [[fileURL path] UTF8String])) {
    1.63              return NO;
    1.64          }
    1.65 @@ -182,6 +192,24 @@
    1.66      return NO;
    1.67  }
    1.68  
    1.69 +- (SDL_Window*)findSDLWindow
    1.70 +{
    1.71 +    SDL_Window *sdlwindow = NULL;
    1.72 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.73 +
    1.74 +    /* !!! FIXME: is there a better way to do this? */
    1.75 +    if (_this) {
    1.76 +        for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
    1.77 +            NSWindow *nswindow = ((SDL_WindowData *) sdlwindow->driverdata)->nswindow;
    1.78 +            if (nswindow == self) {
    1.79 +                break;
    1.80 +            }
    1.81 +        }
    1.82 +    }
    1.83 +
    1.84 +    return sdlwindow;
    1.85 +}
    1.86 +
    1.87  @end
    1.88  
    1.89