Fixed Command key up on Mac OS X. This fix also fixes Help key down, so remove the workaround there.

This commit is contained in:
Pietro Gagliardi 2014-06-07 18:17:29 -04:00
parent fe4d9b992d
commit 9f2669d583
3 changed files with 49 additions and 17 deletions

View File

@ -101,6 +101,13 @@ event(flagsChanged, areaView_flagsChanged)
@end @end
Class areaClass;
void initAreaClass(void)
{
areaClass = [areaView class];
}
id makeArea(void) id makeArea(void)
{ {
return [[areaView alloc] return [[areaView alloc]

View File

@ -35,10 +35,47 @@
#import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSEvent.h> #import <AppKit/NSEvent.h>
#import <AppKit/NSAlert.h> #import <AppKit/NSAlert.h>
#import <AppKit/NSHelpManager.h>
extern NSRect dummyRect; extern NSRect dummyRect;
@interface ourApplication : NSApplication
@end
@implementation ourApplication
// by default, NSApplication eats some key events
// this prevents that from happening with Area
// see http://stackoverflow.com/questions/24099063/how-do-i-detect-keyup-in-my-nsview-with-the-command-key-held and http://lists.apple.com/archives/cocoa-dev/2003/Oct/msg00442.html
- (void)sendEvent:(NSEvent *)e
{
NSEventType type;
type = [e type];
if (type == NSKeyDown || type == NSKeyUp || type == NSFlagsChanged) {
id focused;
focused = [[e window] firstResponder];
// TODO can focused be nil? the isKindOfClass: docs don't say if it handles nil receivers
if ([focused isKindOfClass:areaClass])
switch (type) {
case NSKeyDown:
[focused keyDown:e];
return;
case NSKeyUp:
[focused keyUp:e];
return;
case NSFlagsChanged:
[focused flagsChanged:e];
return;
}
// else fall through
}
// otherwise, let NSApplication do it
[super sendEvent:e];
}
@end
@interface appDelegate : NSObject @interface appDelegate : NSObject
@end @end
@ -75,13 +112,6 @@ extern NSRect dummyRect;
{ {
} }
// see below
// TODO is this the correct signature?
- (void)helpbreaker:(NSNotification *)n
{
[NSHelpManager setContextHelpModeActive:NO];
}
@end @end
id makeAppDelegate(void) id makeAppDelegate(void)
@ -97,19 +127,12 @@ id windowGetContentView(id window)
BOOL initCocoa(id appDelegate) BOOL initCocoa(id appDelegate)
{ {
dummyRect = NSMakeRect(0, 0, 100, 100); dummyRect = NSMakeRect(0, 0, 100, 100);
[NSApplication sharedApplication]; initAreaClass();
[ourApplication sharedApplication]; // makes NSApp an object of type ourApplication
if ([NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] != YES) if ([NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] != YES)
return NO; return NO;
[NSApp activateIgnoringOtherApps:YES]; // TODO actually do C.NO here? Russ Cox does YES in his devdraw; the docs say the Finder does NO [NSApp activateIgnoringOtherApps:YES]; // TODO actually do C.NO here? Russ Cox does YES in his devdraw; the docs say the Finder does NO
[NSApp setDelegate:appDelegate]; [NSApp setDelegate:appDelegate];
// by default, Mac OS X intercepts Help key keyDown events
// we treat Help as Insert, so we don't want this behavior
// this will override it; see http://stackoverflow.com/a/4078542/3408572
// TODO this doesn't send keyDown:
[[NSNotificationCenter defaultCenter] addObserver:appDelegate
selector:@selector(helpbreaker:)
name:NSContextHelpModeDidActivateNotification
object:nil];
return YES; return YES;
} }

View File

@ -43,6 +43,8 @@ extern void giveScrollViewBezelBorder(id);
extern id scrollViewContent(id); extern id scrollViewContent(id);
/* area_darwin.m */ /* area_darwin.m */
extern Class areaClass;
extern void initAreaClass(void);
extern id makeArea(void); extern id makeArea(void);
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t); extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
extern uintptr_t modifierFlags(id); extern uintptr_t modifierFlags(id);