Skip to content

Commit

Permalink
Fixed processing mouse and keyboard events in hatari, which uses the …
Browse files Browse the repository at this point in the history
…old SDLMain.m without creating an SDLApplication instance
  • Loading branch information
slouken committed Oct 14, 2016
1 parent 83cb2b6 commit 824ecc8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -48,13 +48,12 @@ - (void)terminate:(id)sender
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:
Expand All @@ -77,7 +76,17 @@ - (void)sendEvent:(NSEvent *)theEvent
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];
}

Expand Down Expand Up @@ -348,6 +357,8 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
[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];
Expand Down Expand Up @@ -400,6 +411,10 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
break;
}

if (!s_bShouldHandleEventsInSDLApplication) {
Cocoa_DispatchEvent(event);
}

// Pass events down to SDLApplication to be handled in sendEvent:
[NSApp sendEvent:event];
}
Expand Down

0 comments on commit 824ecc8

Please sign in to comment.