From e5c6f6cd7a66f2ca7a53da0813b870f69caa37e1 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Fri, 20 Sep 2013 18:44:08 +0200 Subject: [PATCH] Fix Key Released events in fullscreen (close #465) --- src/SFML/Window/OSX/SFApplication.m | 12 ++++++++---- src/SFML/Window/OSX/SFOpenGLView.mm | 9 ++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/SFML/Window/OSX/SFApplication.m b/src/SFML/Window/OSX/SFApplication.m index c46aadbdc..d7b350a9c 100644 --- a/src/SFML/Window/OSX/SFApplication.m +++ b/src/SFML/Window/OSX/SFApplication.m @@ -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]; } diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 4f4ba4c27..bf53059c6 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -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];