Fixed processing mouse and keyboard events in hatari, which uses the old SDLMain.m without creating an SDLApplication instance
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Oct 2016 08:15:39 -0700
changeset 105356fa4430b1f84
parent 10534 dde37ddd81bc
child 10536 a6fa3f38672c
Fixed processing mouse and keyboard events in hatari, which uses the old SDLMain.m without creating an SDLApplication instance
src/video/cocoa/SDL_cocoaevents.m
     1.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Fri Oct 14 06:57:55 2016 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Fri Oct 14 08:15:39 2016 -0700
     1.3 @@ -48,13 +48,12 @@
     1.4      SDL_SendQuit();
     1.5  }
     1.6  
     1.7 -// Dispatch events here so that we can handle events caught by
     1.8 -// nextEventMatchingMask in SDL, as well as events caught by other
     1.9 -// processes (such as CEF) that are passed down to NSApp.
    1.10 -- (void)sendEvent:(NSEvent *)theEvent
    1.11 +static SDL_bool s_bShouldHandleEventsInSDLApplication = SDL_FALSE;
    1.12 +
    1.13 +static void Cocoa_DispatchEvent(NSEvent *theEvent)
    1.14  {
    1.15      SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.16 -    
    1.17 +
    1.18      switch ([theEvent type]) {
    1.19          case NSLeftMouseDown:
    1.20          case NSOtherMouseDown:
    1.21 @@ -77,7 +76,17 @@
    1.22          default:
    1.23              break;
    1.24      }
    1.25 -    
    1.26 +}
    1.27 +
    1.28 +// Dispatch events here so that we can handle events caught by
    1.29 +// nextEventMatchingMask in SDL, as well as events caught by other
    1.30 +// processes (such as CEF) that are passed down to NSApp.
    1.31 +- (void)sendEvent:(NSEvent *)theEvent
    1.32 +{
    1.33 +    if (s_bShouldHandleEventsInSDLApplication) {
    1.34 +        Cocoa_DispatchEvent(theEvent);
    1.35 +    }
    1.36 +
    1.37      [super sendEvent:theEvent];
    1.38  }
    1.39  
    1.40 @@ -348,6 +357,8 @@
    1.41          [SDLApplication sharedApplication];
    1.42          SDL_assert(NSApp != nil);
    1.43  
    1.44 +        s_bShouldHandleEventsInSDLApplication = SDL_TRUE;
    1.45 +
    1.46          if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
    1.47              [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
    1.48              [NSApp activateIgnoringOtherApps:YES];
    1.49 @@ -400,6 +411,10 @@
    1.50              break;
    1.51          }
    1.52  
    1.53 +        if (!s_bShouldHandleEventsInSDLApplication) {
    1.54 +            Cocoa_DispatchEvent(event);
    1.55 +        }
    1.56 +
    1.57          // Pass events down to SDLApplication to be handled in sendEvent:
    1.58          [NSApp sendEvent:event];
    1.59      }