winemac: Dispatch key-up events directly to window to be sure to get them.

For keys pressed in combination with Command, -[NSApplication sendEvent:]
simply doesn't pass the key-up event through to the window.  We have to
track which keys we've told Wine are pressed because Cocoa may consume
key-downs that trigger menus or system behaviors.
This commit is contained in:
Ken Thomases 2013-07-09 02:49:59 -05:00 committed by Alexandre Julliard
parent a723af61ac
commit a39b02c3e7
4 changed files with 36 additions and 1 deletions

View file

@ -54,6 +54,7 @@ @interface WineApplicationController : NSObject <NSApplicationDelegate>
NSEvent* lastFlagsChanged;
BOOL inputSourceIsInputMethod;
BOOL inputSourceIsInputMethodValid;
uint32_t pressedKeyCodes[128 / 32];
CGFloat primaryScreenHeight;
BOOL primaryScreenHeightValid;
@ -105,6 +106,7 @@ - (void) windowGotFocus:(WineWindow*)window;
- (BOOL) waitUntilQueryDone:(int*)done timeout:(NSDate*)timeout processEvents:(BOOL)processEvents;
- (void) keyboardSelectionDidChange;
- (void) noteKey:(uint16_t)keyCode pressed:(BOOL)pressed;
- (void) flipRect:(NSRect*)rect;

View file

@ -1280,6 +1280,25 @@ - (BOOL) stopClippingCursor
return TRUE;
}
- (BOOL) isKeyPressed:(uint16_t)keyCode
{
int bits = sizeof(pressedKeyCodes[0]) * 8;
int index = keyCode / bits;
uint32_t mask = 1 << (keyCode % bits);
return (pressedKeyCodes[index] & mask) != 0;
}
- (void) noteKey:(uint16_t)keyCode pressed:(BOOL)pressed
{
int bits = sizeof(pressedKeyCodes[0]) * 8;
int index = keyCode / bits;
uint32_t mask = 1 << (keyCode % bits);
if (pressed)
pressedKeyCodes[index] |= mask;
else
pressedKeyCodes[index] &= ~mask;
}
- (void) handleMouseMove:(NSEvent*)anEvent
{
WineWindow* targetWindow;
@ -1692,6 +1711,17 @@ - (BOOL) handleEvent:(NSEvent*)anEvent
[self handleScrollWheel:anEvent];
ret = mouseCaptureWindow != nil;
}
else if (type == NSKeyUp)
{
uint16_t keyCode = [anEvent keyCode];
if ([self isKeyPressed:keyCode])
{
WineWindow* window = (WineWindow*)[anEvent window];
[self noteKey:keyCode pressed:FALSE];
if ([window isKindOfClass:[WineWindow class]])
[window postKeyEvent:anEvent];
}
}
return ret;
}

View file

@ -68,4 +68,6 @@ @interface WineWindow : NSPanel <NSWindowDelegate>
- (NSInteger) minimumLevelForActive:(BOOL)active;
- (void) updateFullscreen;
- (void) postKeyEvent:(NSEvent *)theEvent;
@end

View file

@ -1117,6 +1117,8 @@ - (void) postKey:(uint16_t)keyCode
[queue postEvent:event];
macdrv_release_event(event);
[controller noteKey:keyCode pressed:pressed];
}
- (void) postKeyEvent:(NSEvent *)theEvent
@ -1243,7 +1245,6 @@ - (void) updateColorSpace
* ---------- NSResponder method overrides ----------
*/
- (void) keyDown:(NSEvent *)theEvent { [self postKeyEvent:theEvent]; }
- (void) keyUp:(NSEvent *)theEvent { [self postKeyEvent:theEvent]; }
- (void) flagsChanged:(NSEvent *)theEvent
{