Mercurial > osx-quasimode
comparison QuasimodalEventTap.m @ 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 |
comparison
equal
deleted
inserted
replaced
19:8053681846ad | 20:58522f82a39e |
---|---|
1 #include <AppKit/NSWorkspace.h> | 1 #include <AppKit/NSWorkspace.h> |
2 #import <Foundation/NSAutoreleasePool.h> | 2 #import <Foundation/NSAutoreleasePool.h> |
3 #import <Foundation/NSString.h> | 3 #import <Foundation/NSString.h> |
4 #import <Foundation/NSArray.h> | |
4 #import <Foundation/NSDictionary.h> | 5 #import <Foundation/NSDictionary.h> |
5 | 6 |
6 #import "QuasimodalEventTap.h" | 7 #import "QuasimodalEventTap.h" |
7 | 8 |
8 #define QUASIMODE_KEY kCGEventFlagMaskAlternate | 9 #define QUASIMODE_KEY kCGEventFlagMaskAlternate |
19 CGEventRef event, | 20 CGEventRef event, |
20 void *refcon); | 21 void *refcon); |
21 | 22 |
22 @implementation QuasimodalEventTap | 23 @implementation QuasimodalEventTap |
23 - (void)sendSomeKeyEvent { | 24 - (void)sendSomeKeyEvent { |
24 // TODO: Send some-key event | 25 NSArray *keys = [NSArray arrayWithObjects: @"event", nil]; |
26 NSArray *values = [NSArray arrayWithObjects: @"someKey", nil]; | |
27 NSDictionary *dict = [NSDictionary dictionaryWithObjects: values | |
28 forKeys: keys]; | |
29 | |
30 [center postNotificationName: @"QuasimodalEventTap" | |
31 object: name | |
32 userInfo: dict]; | |
25 } | 33 } |
26 | 34 |
27 - (CGEventRef)processEventWithProxy: (CGEventTapProxy)proxy | 35 - (CGEventRef)processEventWithProxy: (CGEventTapProxy)proxy |
28 type: (CGEventType)type | 36 type: (CGEventType)type |
29 event: (CGEventRef)event { | 37 event: (CGEventRef)event { |
32 if (type == kCGEventFlagsChanged) { | 40 if (type == kCGEventFlagsChanged) { |
33 CGEventFlags flags = CGEventGetFlags(event); | 41 CGEventFlags flags = CGEventGetFlags(event); |
34 | 42 |
35 if (inQuasimode) { | 43 if (inQuasimode) { |
36 if (!(flags & QUASIMODE_KEY)) { | 44 if (!(flags & QUASIMODE_KEY)) { |
37 // TODO: Send quasimodeend event | 45 NSArray *keys = [NSArray arrayWithObjects: @"event", nil]; |
46 NSArray *values = [NSArray arrayWithObjects: @"quasimodeEnd", nil]; | |
47 NSDictionary *dict = [NSDictionary dictionaryWithObjects: values | |
48 forKeys: keys]; | |
49 | |
50 [center postNotificationName: @"QuasimodalEventTap" | |
51 object: name | |
52 userInfo: dict]; | |
53 | |
38 inQuasimode = NO; | 54 inQuasimode = NO; |
39 if (numQuasimodalKeyDowns == 1) { | 55 if (numQuasimodalKeyDowns == 1) { |
40 CGEventRef event[2]; | 56 CGEventRef event[2]; |
41 | 57 |
42 DEBUG_MSG("Re-posting single keypress\n"); | 58 DEBUG_MSG("Re-posting single keypress\n"); |
64 } | 80 } |
65 DEBUG_MSG("Exit quasimode\n"); | 81 DEBUG_MSG("Exit quasimode\n"); |
66 } | 82 } |
67 } else { | 83 } else { |
68 if (flags & QUASIMODE_KEY) { | 84 if (flags & QUASIMODE_KEY) { |
69 // TODO: Send quasimodestart event | 85 NSArray *keys = [NSArray arrayWithObjects: @"event", nil]; |
86 NSArray *values = [NSArray arrayWithObjects: @"quasimodeStart", nil]; | |
87 NSDictionary *dict = [NSDictionary dictionaryWithObjects: values | |
88 forKeys: keys]; | |
89 | |
90 [center postNotificationName: @"QuasimodalEventTap" | |
91 object: name | |
92 userInfo: dict]; | |
93 | |
70 inQuasimode = YES; | 94 inQuasimode = YES; |
71 passOnEvent = NO; | 95 passOnEvent = NO; |
72 numQuasimodalKeyDowns = 0; | 96 numQuasimodalKeyDowns = 0; |
73 DEBUG_MSG("Enter quasimode\n"); | 97 DEBUG_MSG("Enter quasimode\n"); |
74 } else { | 98 } else { |
106 } else | 130 } else |
107 eventType = @"keyUp"; | 131 eventType = @"keyUp"; |
108 | 132 |
109 NSNumber *keycodeNum = [NSNumber numberWithUnsignedInt: keycode]; | 133 NSNumber *keycodeNum = [NSNumber numberWithUnsignedInt: keycode]; |
110 | 134 |
111 // TODO: Send event | 135 NSArray *keys = [NSArray arrayWithObjects: @"event", @"chars", |
136 @"keycode", nil]; | |
137 NSArray *values = [NSArray arrayWithObjects: eventType, chars, | |
138 keycodeNum, nil]; | |
139 NSDictionary *dict = [NSDictionary dictionaryWithObjects: values | |
140 forKeys: keys]; | |
141 | |
142 [center postNotificationName: @"QuasimodalEventTap" | |
143 object: name | |
144 userInfo: dict]; | |
112 } else { | 145 } else { |
113 [self sendSomeKeyEvent]; | 146 [self sendSomeKeyEvent]; |
114 } | 147 } |
115 } | 148 } |
116 | 149 |
118 return event; | 151 return event; |
119 else | 152 else |
120 return NULL; | 153 return NULL; |
121 } | 154 } |
122 | 155 |
123 - (id)init { | 156 - (id)initWithName:(NSString *)objectName { |
124 if (self = [super init]) { | 157 if (self = [super init]) { |
125 numQuasimodalKeyDowns = 0; | 158 numQuasimodalKeyDowns = 0; |
126 inQuasimode = NO; | 159 inQuasimode = NO; |
160 | |
161 name = [objectName copy]; | |
162 center = [NSNotificationCenter defaultCenter]; | |
127 | 163 |
128 CGEventMask mask = (CGEventMaskBit(kCGEventKeyDown) | | 164 CGEventMask mask = (CGEventMaskBit(kCGEventKeyDown) | |
129 CGEventMaskBit(kCGEventKeyUp) | | 165 CGEventMaskBit(kCGEventKeyUp) | |
130 CGEventMaskBit(kCGEventFlagsChanged)); | 166 CGEventMaskBit(kCGEventFlagsChanged)); |
131 | 167 |