summaryrefslogtreecommitdiff
path: root/redo/uitask_darwin.m
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-05 14:40:08 -0400
committerPietro Gagliardi <[email protected]>2014-08-05 14:40:08 -0400
commitc6674d1e9e5d3b75328e722b5f1100a479081150 (patch)
treecc14fdcf9fae42edd1ea042cfc9de59659bef207 /redo/uitask_darwin.m
parent6b7660a671419006a3e6f2cce6825bd694f4cf5b (diff)
Re-added the NSApplication support code for Area on Mac OS X.
Diffstat (limited to 'redo/uitask_darwin.m')
-rw-r--r--redo/uitask_darwin.m43
1 files changed, 42 insertions, 1 deletions
diff --git a/redo/uitask_darwin.m b/redo/uitask_darwin.m
index b48d30f..2be4dd5 100644
--- a/redo/uitask_darwin.m
+++ b/redo/uitask_darwin.m
@@ -4,6 +4,46 @@
#import "_cgo_export.h"
#import <Cocoa/Cocoa.h>
+static Class areaClass;
+
+@interface goApplication : NSApplication
+@end
+
+@implementation goApplication
+
+// 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 appDelegateClass : NSObject <NSApplicationDelegate>
@end
@@ -19,8 +59,9 @@ id getAppDelegate(void)
BOOL uiinit(void)
{
+ areaClass = getAreaClass();
appDelegate = [appDelegateClass new];
- [NSApplication sharedApplication];
+ [goApplication sharedApplication];
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
// see https://github.com/andlabs/ui/issues/6
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];