# HG changeset patch # User Atul Varma # Date 1271056506 25200 # Node ID 58522f82a39e57a820d867e214607dff9f114c76 # Parent 8053681846ad0108f8715c422225a8887d5d594b Brought back the notification center code to QuasimodalEventTap, we can just use the in-process one instead of setting up some complicated observer protocol. diff -r 8053681846ad -r 58522f82a39e QuasimodalEventTap.h --- a/QuasimodalEventTap.h Sun Apr 11 23:53:49 2010 -0700 +++ b/QuasimodalEventTap.h Mon Apr 12 00:15:06 2010 -0700 @@ -1,8 +1,11 @@ #import #import #import +#import @interface QuasimodalEventTap : NSObject { + NSString *name; + NSNotificationCenter *center; CFRunLoopSourceRef rlSrcRef; CFMachPortRef portRef; CGKeyCode lastQuasimodalKeyCode; @@ -10,6 +13,6 @@ int numQuasimodalKeyDowns; BOOL inQuasimode; } -- (id)init; +- (id)initWithName:(NSString *)objectName; - (void)finalize; @end diff -r 8053681846ad -r 58522f82a39e QuasimodalEventTap.m --- a/QuasimodalEventTap.m Sun Apr 11 23:53:49 2010 -0700 +++ b/QuasimodalEventTap.m Mon Apr 12 00:15:06 2010 -0700 @@ -1,6 +1,7 @@ #include #import #import +#import #import #import "QuasimodalEventTap.h" @@ -21,7 +22,14 @@ @implementation QuasimodalEventTap - (void)sendSomeKeyEvent { - // TODO: Send some-key event + NSArray *keys = [NSArray arrayWithObjects: @"event", nil]; + NSArray *values = [NSArray arrayWithObjects: @"someKey", nil]; + NSDictionary *dict = [NSDictionary dictionaryWithObjects: values + forKeys: keys]; + + [center postNotificationName: @"QuasimodalEventTap" + object: name + userInfo: dict]; } - (CGEventRef)processEventWithProxy: (CGEventTapProxy)proxy @@ -34,7 +42,15 @@ if (inQuasimode) { if (!(flags & QUASIMODE_KEY)) { - // TODO: Send quasimodeend event + NSArray *keys = [NSArray arrayWithObjects: @"event", nil]; + NSArray *values = [NSArray arrayWithObjects: @"quasimodeEnd", nil]; + NSDictionary *dict = [NSDictionary dictionaryWithObjects: values + forKeys: keys]; + + [center postNotificationName: @"QuasimodalEventTap" + object: name + userInfo: dict]; + inQuasimode = NO; if (numQuasimodalKeyDowns == 1) { CGEventRef event[2]; @@ -66,7 +82,15 @@ } } else { if (flags & QUASIMODE_KEY) { - // TODO: Send quasimodestart event + NSArray *keys = [NSArray arrayWithObjects: @"event", nil]; + NSArray *values = [NSArray arrayWithObjects: @"quasimodeStart", nil]; + NSDictionary *dict = [NSDictionary dictionaryWithObjects: values + forKeys: keys]; + + [center postNotificationName: @"QuasimodalEventTap" + object: name + userInfo: dict]; + inQuasimode = YES; passOnEvent = NO; numQuasimodalKeyDowns = 0; @@ -108,7 +132,16 @@ NSNumber *keycodeNum = [NSNumber numberWithUnsignedInt: keycode]; - // TODO: Send event + NSArray *keys = [NSArray arrayWithObjects: @"event", @"chars", + @"keycode", nil]; + NSArray *values = [NSArray arrayWithObjects: eventType, chars, + keycodeNum, nil]; + NSDictionary *dict = [NSDictionary dictionaryWithObjects: values + forKeys: keys]; + + [center postNotificationName: @"QuasimodalEventTap" + object: name + userInfo: dict]; } else { [self sendSomeKeyEvent]; } @@ -120,11 +153,14 @@ return NULL; } -- (id)init { +- (id)initWithName:(NSString *)objectName { if (self = [super init]) { numQuasimodalKeyDowns = 0; inQuasimode = NO; + name = [objectName copy]; + center = [NSNotificationCenter defaultCenter]; + CGEventMask mask = (CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged)); diff -r 8053681846ad -r 58522f82a39e TestQuasimodalEventTap.m --- a/TestQuasimodalEventTap.m Sun Apr 11 23:53:49 2010 -0700 +++ b/TestQuasimodalEventTap.m Mon Apr 12 00:15:06 2010 -0700 @@ -6,7 +6,8 @@ { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - QuasimodalEventTap *eventTap = [[QuasimodalEventTap alloc] init]; + QuasimodalEventTap *eventTap = [[QuasimodalEventTap alloc] + initWithName: @"test"]; CFRunLoopRun();