diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-07 18:17:29 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-07 18:17:29 -0400 |
| commit | 9f2669d583fcd4ed30dbd7313139762d22102036 (patch) | |
| tree | 33786f90321ed02e80a48e6231b30ede79de7232 /delegateuitask_darwin.m | |
| parent | fe4d9b992d9b28c9734d06fb41fb093014c7051d (diff) | |
Fixed Command key up on Mac OS X. This fix also fixes Help key down, so remove the workaround there.
Diffstat (limited to 'delegateuitask_darwin.m')
| -rw-r--r-- | delegateuitask_darwin.m | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/delegateuitask_darwin.m b/delegateuitask_darwin.m index 09dcbfd..39bdaa1 100644 --- a/delegateuitask_darwin.m +++ b/delegateuitask_darwin.m @@ -35,10 +35,47 @@ #import <Foundation/NSAutoreleasePool.h> #import <AppKit/NSEvent.h> #import <AppKit/NSAlert.h> -#import <AppKit/NSHelpManager.h> 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 @end @@ -75,13 +112,6 @@ extern NSRect dummyRect; { } -// see below -// TODO is this the correct signature? -- (void)helpbreaker:(NSNotification *)n -{ - [NSHelpManager setContextHelpModeActive:NO]; -} - @end id makeAppDelegate(void) @@ -97,19 +127,12 @@ id windowGetContentView(id window) BOOL initCocoa(id appDelegate) { dummyRect = NSMakeRect(0, 0, 100, 100); - [NSApplication sharedApplication]; + initAreaClass(); + [ourApplication sharedApplication]; // makes NSApp an object of type ourApplication if ([NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] != YES) 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 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; } |
