annotate QuasimodalEventTap.m @ 19:8053681846ad

Refactored event tap C code into an Objective-C class.
author Atul Varma <avarma@mozilla.com>
date Sun, 11 Apr 2010 23:53:49 -0700
parents 78807eea31b7
children 58522f82a39e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
1 #include <AppKit/NSWorkspace.h>
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
2 #import <Foundation/NSAutoreleasePool.h>
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
3 #import <Foundation/NSString.h>
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
4 #import <Foundation/NSDictionary.h>
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
5
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
6 #import "QuasimodalEventTap.h"
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
7
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
8 #define QUASIMODE_KEY kCGEventFlagMaskAlternate
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
9 #define MAX_STR_LEN 10
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
10
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
11 #ifdef DEBUG
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
12 #define DEBUG_MSG(msg) printf(msg);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
13 #else
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
14 #define DEBUG_MSG(msg)
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
15 #endif
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
16
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
17 static CGEventRef eventTapCallback(CGEventTapProxy proxy,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
18 CGEventType type,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
19 CGEventRef event,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
20 void *refcon);
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
21
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
22 @implementation QuasimodalEventTap
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
23 - (void)sendSomeKeyEvent {
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
24 // TODO: Send some-key event
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
25 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
26
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
27 - (CGEventRef)processEventWithProxy: (CGEventTapProxy)proxy
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
28 type: (CGEventType)type
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
29 event: (CGEventRef)event {
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
30 BOOL passOnEvent = !inQuasimode;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
31
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
32 if (type == kCGEventFlagsChanged) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
33 CGEventFlags flags = CGEventGetFlags(event);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
34
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
35 if (inQuasimode) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
36 if (!(flags & QUASIMODE_KEY)) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
37 // TODO: Send quasimodeend event
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
38 inQuasimode = NO;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
39 if (numQuasimodalKeyDowns == 1) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
40 CGEventRef event[2];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
41
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
42 DEBUG_MSG("Re-posting single keypress\n");
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
43
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
44 event[0] = CGEventCreateKeyboardEvent(
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
45 NULL,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
46 (CGKeyCode) lastQuasimodalKeyCode,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
47 true
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
48 );
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
49
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
50 event[1] = CGEventCreateKeyboardEvent(
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
51 NULL,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
52 (CGKeyCode) lastQuasimodalKeyCode,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
53 false
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
54 );
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
55
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
56 CGEventSetFlags(event[0], lastQuasimodalKeyFlags);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
57 CGEventSetFlags(event[1], lastQuasimodalKeyFlags);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
58
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
59 CGEventTapPostEvent(proxy, event[0]);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
60 CGEventTapPostEvent(proxy, event[1]);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
61
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
62 CFRelease(event[0]);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
63 CFRelease(event[1]);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
64 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
65 DEBUG_MSG("Exit quasimode\n");
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
66 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
67 } else {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
68 if (flags & QUASIMODE_KEY) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
69 // TODO: Send quasimodestart event
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
70 inQuasimode = YES;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
71 passOnEvent = NO;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
72 numQuasimodalKeyDowns = 0;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
73 DEBUG_MSG("Enter quasimode\n");
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
74 } else {
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
75 [self sendSomeKeyEvent];
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
76 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
77 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
78 } else {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
79 /* Key up/down event */
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
80
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
81 if (inQuasimode) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
82 UniChar strbuf[MAX_STR_LEN];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
83 UniCharCount charsCopied;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
84
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
85 CGEventKeyboardGetUnicodeString(
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
86 event,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
87 MAX_STR_LEN,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
88 &charsCopied,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
89 strbuf
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
90 );
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
91
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
92 NSString *chars = [NSString stringWithCharacters: strbuf
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
93 length: charsCopied];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
94 NSString *eventType;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
95
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
96 int64_t keycode = CGEventGetIntegerValueField(
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
97 event,
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
98 kCGKeyboardEventKeycode
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
99 );
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
100
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
101 if (type == kCGEventKeyDown) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
102 numQuasimodalKeyDowns += 1;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
103 lastQuasimodalKeyCode = keycode;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
104 lastQuasimodalKeyFlags = CGEventGetFlags(event);
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
105 eventType = @"keyDown";
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
106 } else
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
107 eventType = @"keyUp";
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
108
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
109 NSNumber *keycodeNum = [NSNumber numberWithUnsignedInt: keycode];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
110
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
111 // TODO: Send event
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
112 } else {
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
113 [self sendSomeKeyEvent];
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
114 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
115 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
116
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
117 if (passOnEvent)
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
118 return event;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
119 else
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
120 return NULL;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
121 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
122
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
123 - (id)init {
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
124 if (self = [super init]) {
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
125 numQuasimodalKeyDowns = 0;
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
126 inQuasimode = NO;
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
127
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
128 CGEventMask mask = (CGEventMaskBit(kCGEventKeyDown) |
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
129 CGEventMaskBit(kCGEventKeyUp) |
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
130 CGEventMaskBit(kCGEventFlagsChanged));
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
131
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
132 portRef = CGEventTapCreate(kCGHIDEventTap,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
133 kCGHeadInsertEventTap,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
134 0,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
135 mask,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
136 eventTapCallback,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
137 self);
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
138
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
139 if (portRef == NULL)
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
140 printf( "CGEventTapCreate() failed.\n" );
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
141
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
142 rlSrcRef = CFMachPortCreateRunLoopSource(kCFAllocatorDefault,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
143 portRef,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
144 0);
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
145
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
146 CFRunLoopAddSource(CFRunLoopGetCurrent(),
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
147 rlSrcRef,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
148 kCFRunLoopDefaultMode);
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
149 }
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
150 return self;
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
151 }
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
152
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
153 - (void)finalize {
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
154 CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
155 rlSrcRef,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
156 kCFRunLoopDefaultMode);
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
157
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
158 CFRelease(rlSrcRef);
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
159 CFRelease(portRef);
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
160 }
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
161 @end
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
162
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
163 static CGEventRef eventTapCallback(CGEventTapProxy proxy,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
164 CGEventType type,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
165 CGEventRef event,
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
166 void *refcon)
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
167
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
168 {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
169 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
170 CGEventRef retval;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
171 NSString *bundleId = [
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
172 [[NSWorkspace sharedWorkspace] activeApplication]
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
173 objectForKey: @"NSApplicationBundleIdentifier"
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
174 ];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
175
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
176 if (bundleId &&
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
177 [bundleId isEqualToString: @"com.blizzard.worldofwarcraft"]) {
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
178 retval = event;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
179 } else {
19
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
180 QuasimodalEventTap *tap = (QuasimodalEventTap *) refcon;
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
181 retval = [tap processEventWithProxy: proxy
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
182 type: type
8053681846ad Refactored event tap C code into an Objective-C class.
Atul Varma <avarma@mozilla.com>
parents: 18
diff changeset
183 event: event];
18
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
184 }
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
185
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
186 [pool release];
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
187
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
188 return retval;
78807eea31b7 Added EnsoKeyNotifier.m from Enso source, renamed to QuasimodalEventTap.m w/ some notification center stuff removed and formatting fixed to match this codebase.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
189 }