Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.
authorAlex Szpakowski <slime73@gmail.com>
Sat, 02 Apr 2016 11:54:05 -0300
changeset 101406dd5f49e4a77
parent 10139 bb54e1e47110
child 10141 fe9cf7c678f4
Add a new hint SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH, which allows mouse click events to occur when clicking to focus a window in Mac OS X.

Fixes bug #3300.
include/SDL_hints.h
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/include/SDL_hints.h	Fri Apr 01 19:18:50 2016 -0300
     1.2 +++ b/include/SDL_hints.h	Sat Apr 02 11:54:05 2016 -0300
     1.3 @@ -548,6 +548,13 @@
     1.4  #define SDL_HINT_MAC_BACKGROUND_APP    "SDL_MAC_BACKGROUND_APP"
     1.5  
     1.6  /**
     1.7 + *  \brief Allow mouse click events when clicking to focus an SDL window
     1.8 + *
     1.9 + *  This hint only applies to Mac OS X.
    1.10 + */
    1.11 +#define SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH "SDL_MAC_MOUSE_FOCUS_CLICKTHROUGH"
    1.12 +
    1.13 +/**
    1.14   * \brief Android APK expansion main file version. Should be a string number like "1", "2" etc.
    1.15   *
    1.16   * Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION.
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Fri Apr 01 19:18:50 2016 -0300
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Apr 02 11:54:05 2016 -0300
     2.3 @@ -80,20 +80,20 @@
     2.4  
     2.5  - (void)sendEvent:(NSEvent *)event
     2.6  {
     2.7 -  [super sendEvent:event];
     2.8 +    [super sendEvent:event];
     2.9  
    2.10 -  if ([event type] != NSLeftMouseUp) {
    2.11 -      return;
    2.12 -  }
    2.13 +    if ([event type] != NSLeftMouseUp) {
    2.14 +        return;
    2.15 +    }
    2.16  
    2.17 -  id delegate = [self delegate];
    2.18 -  if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
    2.19 -      return;
    2.20 -  }
    2.21 +    id delegate = [self delegate];
    2.22 +    if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
    2.23 +        return;
    2.24 +    }
    2.25  
    2.26 -  if ([delegate isMoving]) {
    2.27 -      [delegate windowDidFinishMoving];
    2.28 -  }
    2.29 +    if ([delegate isMoving]) {
    2.30 +        [delegate windowDidFinishMoving];
    2.31 +    }
    2.32  }
    2.33  
    2.34  /* We'll respond to selectors by doing nothing so we don't beep.
    2.35 @@ -1093,6 +1093,7 @@
    2.36  - (void)rightMouseDown:(NSEvent *)theEvent;
    2.37  - (BOOL)mouseDownCanMoveWindow;
    2.38  - (void)drawRect:(NSRect)dirtyRect;
    2.39 +- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
    2.40  @end
    2.41  
    2.42  @implementation SDLView
    2.43 @@ -1132,6 +1133,12 @@
    2.44                       cursor:[NSCursor invisibleCursor]];
    2.45      }
    2.46  }
    2.47 +
    2.48 +- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
    2.49 +{
    2.50 +    const char *hint = SDL_GetHint(SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH);
    2.51 +    return hint && *hint != '0';
    2.52 +}
    2.53  @end
    2.54  
    2.55  static int