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.
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
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 3bd5435..068ffec 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -548,6 +548,13 @@ extern "C" {
#define SDL_HINT_MAC_BACKGROUND_APP "SDL_MAC_BACKGROUND_APP"
/**
+ * \brief Allow mouse click events when clicking to focus an SDL window
+ *
+ * This hint only applies to Mac OS X.
+ */
+#define SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH "SDL_MAC_MOUSE_FOCUS_CLICKTHROUGH"
+
+/**
* \brief Android APK expansion main file version. Should be a string number like "1", "2" etc.
*
* Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION.
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 0256525..8874577 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -80,20 +80,20 @@
- (void)sendEvent:(NSEvent *)event
{
- [super sendEvent:event];
+ [super sendEvent:event];
- if ([event type] != NSLeftMouseUp) {
- return;
- }
+ if ([event type] != NSLeftMouseUp) {
+ return;
+ }
- id delegate = [self delegate];
- if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
- return;
- }
+ id delegate = [self delegate];
+ if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
+ return;
+ }
- if ([delegate isMoving]) {
- [delegate windowDidFinishMoving];
- }
+ if ([delegate isMoving]) {
+ [delegate windowDidFinishMoving];
+ }
}
/* We'll respond to selectors by doing nothing so we don't beep.
@@ -1093,6 +1093,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
- (void)rightMouseDown:(NSEvent *)theEvent;
- (BOOL)mouseDownCanMoveWindow;
- (void)drawRect:(NSRect)dirtyRect;
+- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
@end
@implementation SDLView
@@ -1132,6 +1133,12 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
cursor:[NSCursor invisibleCursor]];
}
}
+
+- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
+{
+ const char *hint = SDL_GetHint(SDL_HINT_MAC_MOUSE_FOCUS_CLICKTHROUGH);
+ return hint && *hint != '0';
+}
@end
static int