changeset 20:58522f82a39e

Brought back the notification center code to QuasimodalEventTap, we can just use the in-process one instead of setting up some complicated observer protocol.
author Atul Varma <avarma@mozilla.com>
date Mon, 12 Apr 2010 00:15:06 -0700
parents 8053681846ad
children cdc615772d43
files QuasimodalEventTap.h QuasimodalEventTap.m TestQuasimodalEventTap.m
diffstat 3 files changed, 47 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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 <ApplicationServices/ApplicationServices.h>
 #import <CoreFoundation/CoreFoundation.h>
 #import <Foundation/NSObject.h>
+#import <Foundation/NSNotification.h>
 
 @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
--- 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 <AppKit/NSWorkspace.h>
 #import <Foundation/NSAutoreleasePool.h>
 #import <Foundation/NSString.h>
+#import <Foundation/NSArray.h>
 #import <Foundation/NSDictionary.h>
 
 #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));
--- 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();