diff --git a/redo/area_darwin.m b/redo/area_darwin.m index 3f8e6b5..10fbbd8 100644 --- a/redo/area_darwin.m +++ b/redo/area_darwin.m @@ -98,11 +98,9 @@ event(flagsChanged, areaView_flagsChanged) @end -Class areaClass; - -void initAreaClass(void) +Class getAreaClass(void) { - areaClass = [areaView class]; + return [areaView class]; } id newArea(void *goarea) diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h index 127d3f7..416c319 100644 --- a/redo/objc_darwin.h +++ b/redo/objc_darwin.h @@ -94,6 +94,7 @@ struct xpoint { intptr_t x; intptr_t y; }; +extern Class getAreaClass(void); extern id newArea(void *); extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t); extern uintptr_t modifierFlags(id); 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 +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 @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];