summaryrefslogtreecommitdiff
path: root/src/lib/ecore_cocoa/ecore_cocoa.m
diff options
context:
space:
mode:
authorNicolas Aguirre <aguirre.nicolas@gmail.com>2014-01-11 10:17:04 +0100
committerCedric BAIL <c.bail@partner.samsung.com>2014-06-18 11:34:06 +0200
commite4538b94d1a8ed7983c39e44e30df47f8536915c (patch)
tree1b0674aea5fc6facf5d2f17687dff95f1ba09540 /src/lib/ecore_cocoa/ecore_cocoa.m
parent795f97e22a30f62d5b3792c79e2f89d66d0804b9 (diff)
ecore_cocoa: fix button order.
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa.m176
1 files changed, 94 insertions, 82 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m
index 2cc5b73bbf..59bc02814b 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa.m
@@ -23,6 +23,54 @@ static int _ecore_cocoa_init_count = 0;
23 23
24static int old_flags; 24static int old_flags;
25 25
26static unsigned int
27_ecore_cocoa_event_modifiers(int mod)
28{
29 unsigned int modifiers = 0;
30
31 if(mod & NSShiftKeyMask) modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
32 if(mod & NSControlKeyMask) modifiers |= ECORE_EVENT_MODIFIER_CTRL;
33 if(mod & NSAlternateKeyMask) modifiers |= ECORE_EVENT_MODIFIER_ALT;
34 if(mod & NSAlphaShiftKeyMask) modifiers |= ECORE_EVENT_LOCK_CAPS;
35
36 return modifiers;
37}
38
39static Ecore_Event_Key*
40_ecore_cocoa_event_key(NSEvent *nsevent, double timestamp)
41{
42 Ecore_Event_Key *ev;
43 unsigned int i;
44 int flags = [nsevent modifierFlags];
45
46 ev = malloc(sizeof(Ecore_Event_Key));
47 if (!ev) return NULL;
48
49 ev->timestamp = timestamp;
50 ev->window = 0;
51 ev->event_window = 0;
52 ev->modifiers = _ecore_cocoa_event_modifiers(flags);
53 ev->key = NULL;
54 ev->compose = NULL;
55
56 printf("key code : %d\n", [[nsevent charactersIgnoringModifiers] characterAtIndex:0]);
57
58 for (i = 0; i < EINA_C_ARRAY_LENGTH(keystable); ++i)
59 if (keystable[i].code == [[nsevent charactersIgnoringModifiers] characterAtIndex:0])
60 {
61 printf("keycode : %d key pressed : %s\n", keystable[i].code, keystable[i].name);
62 ev->keyname = keystable[i].name;
63 ev->key = ev->keyname;
64 ev->string = keystable[i].compose;
65
66 return ev;
67 }
68 free(ev);
69 return NULL;
70}
71
72
73
26EAPI int 74EAPI int
27ecore_cocoa_init(void) 75ecore_cocoa_init(void)
28{ 76{
@@ -115,7 +163,17 @@ ecore_cocoa_feed_events(void)
115 ev->root.x = ev->x; 163 ev->root.x = ev->x;
116 ev->root.y = ev->y; 164 ev->root.y = ev->y;
117 ev->timestamp = time; 165 ev->timestamp = time;
118 ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0 166
167 if ([event buttonNumber] == 0)
168 ev->buttons = 1;
169 else if ([event buttonNumber] == 2)
170 ev->buttons = 2;
171 else
172 ev->buttons = 3;
173
174 printf("ev buttons : %d - %d\n", ev->buttons, [event buttonNumber]);
175 ev->window = window.ecore_window_data;
176 ev->event_window = ev->window;
119 177
120 if ([event clickCount] == 2) 178 if ([event clickCount] == 2)
121 ev->double_click = 1; 179 ev->double_click = 1;
@@ -148,7 +206,16 @@ ecore_cocoa_feed_events(void)
148 ev->root.x = ev->x; 206 ev->root.x = ev->x;
149 ev->root.y = ev->y; 207 ev->root.y = ev->y;
150 ev->timestamp = time; 208 ev->timestamp = time;
151 ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0 209
210 if ([event buttonNumber] == 0)
211 ev->buttons = 1;
212 else if ([event buttonNumber] == 2)
213 ev->buttons = 2;
214 else
215 ev->buttons = 3;
216
217 ev->window = window.ecore_window_data;
218 ev->event_window = ev->window;
152 219
153 if ([event clickCount] == 2) 220 if ([event clickCount] == 2)
154 ev->double_click = 1; 221 ev->double_click = 1;
@@ -168,115 +235,60 @@ ecore_cocoa_feed_events(void)
168 case NSKeyDown: 235 case NSKeyDown:
169 { 236 {
170 Ecore_Event_Key *ev; 237 Ecore_Event_Key *ev;
171 unsigned int i;
172 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; 238 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window];
173 239
174 ev = calloc(1, sizeof (Ecore_Event_Key)); 240 ev = _ecore_cocoa_event_key(event, time);
175 if (!ev) return; 241 if (!ev) return;
176 ev->timestamp = time;
177 242
178 for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_cocoa_keys_s); ++i) 243 ev->window = window.ecore_window_data;
179 { 244 ev->event_window = ev->window;
180 if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0])) 245 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
181 {
182 printf("Key pressed : %s\n", keystable[i].name);
183 ev->keyname = keystable[i].name;
184 ev->key = keystable[i].name;
185 ev->string = keystable[i].compose;
186 ev->window = window.ecore_window_data;
187 ev->event_window = ev->window;
188 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
189 return;
190 }
191 }
192 246
193 break; 247 break;
194 } 248 }
195 case NSKeyUp: 249 case NSKeyUp:
196 { 250 {
197 Ecore_Event_Key *ev; 251 Ecore_Event_Key *ev;
198 unsigned int i;
199 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; 252 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window];
200 253
201 printf("Key Up\n"); 254 ev = _ecore_cocoa_event_key(event, time);
202
203 ev = calloc(1, sizeof (Ecore_Event_Key));
204 if (!ev) return; 255 if (!ev) return;
205 ev->timestamp = time;
206 256
207 for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_cocoa_keys_s); ++i) 257 ev->window = window.ecore_window_data;
208 { 258 ev->event_window = ev->window;
209 if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0])) 259 ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
210 {
211 ev->keyname = keystable[i].name;
212 ev->key = keystable[i].name;
213 ev->string = keystable[i].compose;
214 ev->window = window.ecore_window_data;
215 ev->event_window = ev->window;
216 ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
217 return;
218 }
219 }
220 260
221 break; 261 break;
222 } 262 }
223 case NSFlagsChanged: 263 case NSFlagsChanged:
224 { 264 {
225 int flags = [event modifierFlags];
226 265
227 Ecore_Event_Key *evDown = NULL; 266 int flags = [event modifierFlags];
228 Ecore_Event_Key *evUp = NULL; 267 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window];
229 268 Ecore_Event_Key *ev;
230 evDown = calloc(1, sizeof (Ecore_Event_Key));
231 if (!evDown) return;
232 269
233 evUp = calloc(1, sizeof (Ecore_Event_Key)); 270 ev = calloc(1, sizeof(Ecore_Event_Key));
234 if (!evUp) 271 if (!ev) return;
235 {
236 free(evDown);
237 return;
238 }
239 272
240 // Turn special key flags on
241 if (flags & NSShiftKeyMask) 273 if (flags & NSShiftKeyMask)
242 evDown->keyname = "Shift_L"; 274 ev->keyname = "Shift_L";
243 else if (flags & NSControlKeyMask) 275 else if (flags & NSControlKeyMask)
244 evDown->keyname = "Control_L"; 276 ev->keyname = "Control_L";
245 else if (flags & NSAlternateKeyMask) 277 else if (flags & NSAlternateKeyMask)
246 evDown->keyname = "Alt_L"; 278 ev->keyname = "Alt_L";
247 else if (flags & NSCommandKeyMask) 279 else if (flags & NSCommandKeyMask)
248 evDown->keyname = "Super_L"; 280 ev->keyname = "Super_L";
249 else if (flags & NSAlphaShiftKeyMask) 281 else if (flags & NSAlphaShiftKeyMask)
250 evDown->keyname = "Caps_Lock"; 282 ev->keyname = "Caps_Lock";
251
252 if (evDown->keyname)
253 {
254 evDown->timestamp = time;
255 evDown->string = "";
256 ecore_event_add(ECORE_EVENT_KEY_DOWN, evDown, NULL, NULL);
257 old_flags = flags;
258 break;
259 }
260 283
261 int changed_flags = flags ^ old_flags; 284 if (ev->keyname)
262
263 // Turn special key flags off
264 if (changed_flags & NSShiftKeyMask)
265 evUp->keyname = "Shift_L";
266 else if (changed_flags & NSControlKeyMask)
267 evUp->keyname = "Control_L";
268 else if (changed_flags & NSAlternateKeyMask)
269 evUp->keyname = "Alt_L";
270 else if (changed_flags & NSCommandKeyMask)
271 evUp->keyname = "Super_L";
272 else if (changed_flags & NSAlphaShiftKeyMask)
273 evUp->keyname = "Caps_Lock";
274
275 if (evUp->keyname)
276 { 285 {
277 evUp->timestamp = time; 286 ev->key = ev->keyname;
278 evUp->string = ""; 287 ev->timestamp = time;
279 ecore_event_add(ECORE_EVENT_KEY_UP, evUp, NULL, NULL); 288 ev->string = "";
289 ev->modifiers = _ecore_cocoa_event_modifiers(flags);
290 printf("Flags changed keyup\n");
291 ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
280 old_flags = flags; 292 old_flags = flags;
281 break; 293 break;
282 } 294 }