Skip to content

Commit

Permalink
Fixed bug 3107 OSX - Process events in SDLApplication to fix integrat…
Browse files Browse the repository at this point in the history
…ion with CEF.

John Wordsworth

While attempting to integrate CEF (Browser) into an SDL application, we noticed that there were problems on OS X where approximately 50% of the input events were essentially being lost - even when we were using off-screen rendering in CEF and passing through input events manually.

It appears that this problem has been around for a while (see: http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11141).

Please consider the following patch that fixes this issue. Instead of processing events directly after calling [NSApp nextEventMatchingMask:...] we now pass these events down to NSApp, for processing by an overloaded sendEvent: method. Chromium also forwards events to NSApp in the same way, which means we don't miss events, even if they were originally dequeued by CEF.
  • Loading branch information
slouken committed Oct 1, 2016
1 parent c8cfccc commit fae5d0e
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -36,6 +36,7 @@
@interface SDLApplication : NSApplication

- (void)terminate:(id)sender;
- (void)sendEvent:(NSEvent *)theEvent;

@end

Expand All @@ -47,6 +48,39 @@ - (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
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();

switch ([theEvent type]) {
case NSLeftMouseDown:
case NSOtherMouseDown:
case NSRightMouseDown:
case NSLeftMouseUp:
case NSOtherMouseUp:
case NSRightMouseUp:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved:
case NSScrollWheel:
Cocoa_HandleMouseEvent(_this, theEvent);
break;
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
Cocoa_HandleKeyEvent(_this, theEvent);
break;
default:
break;
}

[super sendEvent:theEvent];
}

@end // SDLApplication

/* setAppleMenu disappeared from the headers in 10.4 */
Expand Down Expand Up @@ -367,29 +401,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
break;
}

switch ([event type]) {
case NSLeftMouseDown:
case NSOtherMouseDown:
case NSRightMouseDown:
case NSLeftMouseUp:
case NSOtherMouseUp:
case NSRightMouseUp:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved:
case NSScrollWheel:
Cocoa_HandleMouseEvent(_this, event);
break;
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
Cocoa_HandleKeyEvent(_this, event);
break;
default:
break;
}
/* Pass through to NSApp to make sure everything stays in sync */
// Pass events down to SDLApplication to be handled in sendEvent:
[NSApp sendEvent:event];
}
}}
Expand Down

0 comments on commit fae5d0e

Please sign in to comment.