diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa.m | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa.m')
-rw-r--r-- | libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa.m | 283 |
1 files changed, 283 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa.m b/libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa.m new file mode 100644 index 0000000..3f6023a --- /dev/null +++ b/libraries/ecore/src/lib/ecore_cocoa/ecore_cocoa.m | |||
@@ -0,0 +1,283 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <Cocoa/Cocoa.h> | ||
6 | |||
7 | #include <Eina.h> | ||
8 | |||
9 | #include <Ecore.h> | ||
10 | #include <ecore_private.h> | ||
11 | #include <Ecore_Input.h> | ||
12 | |||
13 | #include "Ecore_Cocoa.h" | ||
14 | #include "Ecore_Cocoa_Keys.h" | ||
15 | |||
16 | |||
17 | EAPI int ECORE_COCOA_EVENT_GOT_FOCUS = 0; | ||
18 | EAPI int ECORE_COCOA_EVENT_LOST_FOCUS = 0; | ||
19 | EAPI int ECORE_COCOA_EVENT_RESIZE = 0; | ||
20 | EAPI int ECORE_COCOA_EVENT_EXPOSE = 0; | ||
21 | |||
22 | static int _ecore_cocoa_init_count = 0; | ||
23 | |||
24 | static int old_flags; | ||
25 | |||
26 | EAPI int | ||
27 | ecore_cocoa_init(void) | ||
28 | { | ||
29 | if (++_ecore_cocoa_init_count != 1) | ||
30 | return _ecore_cocoa_init_count; | ||
31 | |||
32 | if (!ecore_event_init()) | ||
33 | return --_ecore_cocoa_init_count; | ||
34 | |||
35 | NSApplicationLoad(); | ||
36 | |||
37 | ECORE_COCOA_EVENT_GOT_FOCUS = ecore_event_type_new(); | ||
38 | ECORE_COCOA_EVENT_LOST_FOCUS = ecore_event_type_new(); | ||
39 | ECORE_COCOA_EVENT_RESIZE = ecore_event_type_new(); | ||
40 | ECORE_COCOA_EVENT_EXPOSE = ecore_event_type_new(); | ||
41 | |||
42 | return _ecore_cocoa_init_count; | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Shuts down the Ecore_Cocoa library. | ||
47 | * @return @c The number of times the system has been initialised without | ||
48 | * being shut down. | ||
49 | * @ingroup Ecore_Cocoa_Library_Group | ||
50 | */ | ||
51 | EAPI int | ||
52 | ecore_cocoa_shutdown(void) | ||
53 | { | ||
54 | if (--_ecore_cocoa_init_count != 0) | ||
55 | return _ecore_cocoa_init_count; | ||
56 | |||
57 | ecore_event_shutdown(); | ||
58 | |||
59 | return _ecore_cocoa_init_count; | ||
60 | } | ||
61 | |||
62 | EAPI void | ||
63 | ecore_cocoa_feed_events(void) | ||
64 | { | ||
65 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0.001]; | ||
66 | NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask | ||
67 | untilDate:date | ||
68 | inMode:NSDefaultRunLoopMode | ||
69 | dequeue:YES]; | ||
70 | [date release]; | ||
71 | if (!event) return; // SDL loops until null; maybe we should do that too. or not. | ||
72 | |||
73 | unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff); | ||
74 | |||
75 | switch([event type]) | ||
76 | { | ||
77 | case NSMouseMoved: | ||
78 | case NSLeftMouseDragged: | ||
79 | case NSRightMouseDragged: | ||
80 | case NSOtherMouseDragged: | ||
81 | { | ||
82 | Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)); | ||
83 | if (!ev) return; | ||
84 | ev->x = [event locationInWindow].x; | ||
85 | ev->y = [event locationInWindow].y; | ||
86 | ev->root.x = ev->x; | ||
87 | ev->root.y = ev->y; | ||
88 | ev->timestamp = time; | ||
89 | ev->window = [event window]; | ||
90 | ev->modifiers = 0; /* FIXME: keep modifier around. */ | ||
91 | |||
92 | ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL); | ||
93 | |||
94 | [NSApp sendEvent:event]; // pass along mouse events, for window manager | ||
95 | break; | ||
96 | } | ||
97 | case NSLeftMouseDown: | ||
98 | case NSRightMouseDown: | ||
99 | case NSOtherMouseDown: | ||
100 | { | ||
101 | Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | ||
102 | if (!ev) return; | ||
103 | ev->x = [event locationInWindow].x; | ||
104 | ev->y = [event locationInWindow].y; | ||
105 | ev->root.x = ev->x; | ||
106 | ev->root.y = ev->y; | ||
107 | ev->timestamp = time; | ||
108 | ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0 | ||
109 | |||
110 | if ([event clickCount] == 2) | ||
111 | ev->double_click = 1; | ||
112 | else | ||
113 | ev->double_click = 0; | ||
114 | |||
115 | if ([event clickCount] >= 3) | ||
116 | ev->triple_click = 1; | ||
117 | else | ||
118 | ev->triple_click = 0; | ||
119 | |||
120 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); | ||
121 | |||
122 | [NSApp sendEvent:event]; // pass along mouse events, for window manager | ||
123 | break; | ||
124 | } | ||
125 | case NSLeftMouseUp: | ||
126 | case NSRightMouseUp: | ||
127 | case NSOtherMouseUp: | ||
128 | { | ||
129 | Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | ||
130 | if (!ev) return; | ||
131 | ev->x = [event locationInWindow].x; | ||
132 | ev->y = [event locationInWindow].y; | ||
133 | ev->root.x = ev->x; | ||
134 | ev->root.y = ev->y; | ||
135 | ev->timestamp = time; | ||
136 | ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0 | ||
137 | |||
138 | if ([event clickCount] == 2) | ||
139 | ev->double_click = 1; | ||
140 | else | ||
141 | ev->double_click = 0; | ||
142 | |||
143 | if ([event clickCount] >= 3) | ||
144 | ev->triple_click = 1; | ||
145 | else | ||
146 | ev->triple_click = 0; | ||
147 | |||
148 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); | ||
149 | |||
150 | [NSApp sendEvent:event]; // pass along mouse events, for window manager | ||
151 | break; | ||
152 | } | ||
153 | case NSKeyDown: | ||
154 | { | ||
155 | Ecore_Event_Key *ev; | ||
156 | unsigned int i; | ||
157 | |||
158 | ev = calloc(1, sizeof (Ecore_Event_Key)); | ||
159 | if (!ev) return; | ||
160 | ev->timestamp = time; | ||
161 | |||
162 | for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_cocoa_keys_s); ++i) | ||
163 | { | ||
164 | if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0])) | ||
165 | { | ||
166 | ev->keyname = keystable[i].name; | ||
167 | ev->string = keystable[i].compose; | ||
168 | |||
169 | ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL); | ||
170 | return; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | break; | ||
175 | } | ||
176 | case NSKeyUp: | ||
177 | { | ||
178 | Ecore_Event_Key *ev; | ||
179 | unsigned int i; | ||
180 | |||
181 | ev = calloc(1, sizeof (Ecore_Event_Key)); | ||
182 | if (!ev) return; | ||
183 | ev->timestamp = time; | ||
184 | |||
185 | for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_cocoa_keys_s); ++i) | ||
186 | { | ||
187 | if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0])) | ||
188 | { | ||
189 | ev->keyname = keystable[i].name; | ||
190 | ev->string = keystable[i].compose; | ||
191 | |||
192 | ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL); | ||
193 | return; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | break; | ||
198 | } | ||
199 | case NSFlagsChanged: | ||
200 | { | ||
201 | int flags = [event modifierFlags]; | ||
202 | |||
203 | Ecore_Event_Key *evDown = NULL; | ||
204 | Ecore_Event_Key *evUp = NULL; | ||
205 | |||
206 | evDown = calloc(1, sizeof (Ecore_Event_Key)); | ||
207 | if (!evDown) return; | ||
208 | |||
209 | evUp = calloc(1, sizeof (Ecore_Event_Key)); | ||
210 | if (!evUp) | ||
211 | { | ||
212 | free(evDown); | ||
213 | return; | ||
214 | } | ||
215 | |||
216 | // Turn special key flags on | ||
217 | if (flags & NSShiftKeyMask) | ||
218 | evDown->keyname = "Shift_L"; | ||
219 | else if (flags & NSControlKeyMask) | ||
220 | evDown->keyname = "Control_L"; | ||
221 | else if (flags & NSAlternateKeyMask) | ||
222 | evDown->keyname = "Alt_L"; | ||
223 | else if (flags & NSCommandKeyMask) | ||
224 | evDown->keyname = "Super_L"; | ||
225 | else if (flags & NSAlphaShiftKeyMask) | ||
226 | evDown->keyname = "Caps_Lock"; | ||
227 | |||
228 | if (evDown->keyname) | ||
229 | { | ||
230 | evDown->timestamp = time; | ||
231 | evDown->string = ""; | ||
232 | ecore_event_add(ECORE_EVENT_KEY_DOWN, evDown, NULL, NULL); | ||
233 | old_flags = flags; | ||
234 | break; | ||
235 | } | ||
236 | |||
237 | int changed_flags = flags ^ old_flags; | ||
238 | |||
239 | // Turn special key flags off | ||
240 | if (changed_flags & NSShiftKeyMask) | ||
241 | evUp->keyname = "Shift_L"; | ||
242 | else if (changed_flags & NSControlKeyMask) | ||
243 | evUp->keyname = "Control_L"; | ||
244 | else if (changed_flags & NSAlternateKeyMask) | ||
245 | evUp->keyname = "Alt_L"; | ||
246 | else if (changed_flags & NSCommandKeyMask) | ||
247 | evUp->keyname = "Super_L"; | ||
248 | else if (changed_flags & NSAlphaShiftKeyMask) | ||
249 | evUp->keyname = "Caps_Lock"; | ||
250 | |||
251 | if (evUp->keyname) | ||
252 | { | ||
253 | evUp->timestamp = time; | ||
254 | evUp->string = ""; | ||
255 | ecore_event_add(ECORE_EVENT_KEY_UP, evUp, NULL, NULL); | ||
256 | old_flags = flags; | ||
257 | break; | ||
258 | } | ||
259 | |||
260 | break; | ||
261 | } | ||
262 | case NSAppKitDefined: | ||
263 | { | ||
264 | if ([event subtype] == NSApplicationActivatedEventType) | ||
265 | ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, NULL, NULL, NULL); | ||
266 | else if ([event subtype] == NSApplicationDeactivatedEventType) | ||
267 | ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, NULL, NULL, NULL); | ||
268 | [NSApp sendEvent:event]; // pass along AppKit events, for window manager | ||
269 | break; | ||
270 | } | ||
271 | case NSScrollWheel: | ||
272 | { | ||
273 | break; | ||
274 | } | ||
275 | default: | ||
276 | { | ||
277 | [NSApp sendEvent:event]; | ||
278 | break; | ||
279 | } | ||
280 | } | ||
281 | |||
282 | [event release]; | ||
283 | } | ||