Fixed processing mouse and keyboard events in hatari, which uses the old SDLMain.m without creating an SDLApplication instance
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
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index b604fd7..17a3183 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -48,13 +48,12 @@
SDL_SendQuit();
}
-// Dispatch events here so that we can handle events caught by
-// nextEventMatchingMask in SDL, as well as events caught by other
-// processes (such as CEF) that are passed down to NSApp.
-- (void)sendEvent:(NSEvent *)theEvent
+static SDL_bool s_bShouldHandleEventsInSDLApplication = SDL_FALSE;
+
+static void Cocoa_DispatchEvent(NSEvent *theEvent)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
-
+
switch ([theEvent type]) {
case NSLeftMouseDown:
case NSOtherMouseDown:
@@ -77,7 +76,17 @@
default:
break;
}
-
+}
+
+// Dispatch events here so that we can handle events caught by
+// nextEventMatchingMask in SDL, as well as events caught by other
+// processes (such as CEF) that are passed down to NSApp.
+- (void)sendEvent:(NSEvent *)theEvent
+{
+ if (s_bShouldHandleEventsInSDLApplication) {
+ Cocoa_DispatchEvent(theEvent);
+ }
+
[super sendEvent:theEvent];
}
@@ -348,6 +357,8 @@ Cocoa_RegisterApp(void)
[SDLApplication sharedApplication];
SDL_assert(NSApp != nil);
+ s_bShouldHandleEventsInSDLApplication = SDL_TRUE;
+
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];
@@ -400,6 +411,10 @@ Cocoa_PumpEvents(_THIS)
break;
}
+ if (!s_bShouldHandleEventsInSDLApplication) {
+ Cocoa_DispatchEvent(event);
+ }
+
// Pass events down to SDLApplication to be handled in sendEvent:
[NSApp sendEvent:event];
}