Fix Key Released events in fullscreen (close #465)

This commit is contained in:
Marco Antognini 2013-09-20 18:44:08 +02:00
parent 1b113c2c22
commit e5c6f6cd7a
2 changed files with 16 additions and 5 deletions

View File

@ -42,7 +42,7 @@
while ((event = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode
dequeue:YES])) // Remove the event from the dequeue
dequeue:YES])) // Remove the event from the queue
{
[NSApp sendEvent:event];
}
@ -50,9 +50,13 @@
-(void)sendEvent:(NSEvent *)anEvent
{
if ([anEvent type] == NSKeyUp) {
[[[self mainWindow] firstResponder] tryToPerform:@selector(keyUp:)
with:anEvent];
// Fullscreen windows have a strange behaviour with key up. To make
// sure the user gets an event we call (if possible) sfKeyUp on our
// custom OpenGL view. See -[SFOpenGLView sfKeyUp:] for more details.
id firstResponder = [[anEvent window] firstResponder];
if ([anEvent type] == NSKeyUp && [firstResponder respondsToSelector:@selector(sfKeyUp:)]) {
[firstResponder sfKeyUp:anEvent];
} else {
[super sendEvent:anEvent];
}

View File

@ -619,8 +619,15 @@ BOOL isValidTextUnicode(NSEvent* event);
////////////////////////////////////////////////////////
-(void)keyUp:(NSEvent *)theEvent
-(void)sfKeyUp:(NSEvent *)theEvent
{
// For some mystic reasons, key released events don't work the same way
// as key pressed events... We somewhat hijack the event chain of response
// in -[SFApplication sendEvent:] and resume this chain with the next
// responder.
// This is workaround to make sure key released events are fired in
// fullscreen window too.
// Transmit to non-SFML responder
[[self nextResponder] keyUp:theEvent];