summaryrefslogtreecommitdiff
path: root/src/lib/ecore_cocoa
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2018-06-22 12:41:05 -0400
committerMike Blumenkrantz <zmike@samsung.com>2018-06-22 12:41:05 -0400
commit9d3b5079dbb135d1750f0754febc509e328eeaac (patch)
treebff5bff2a483cb79b0595b7ba8f0d3ed76611dff /src/lib/ecore_cocoa
parent8f95b17f39cb87cb4627150b0761fc95376bd026 (diff)
ecore_cocoa: explicity allocate for keyname and key
Summary: Allocate memory for keyname and key. Also refactor unnecessary calloc and free. Reviewers: #committers, zmike, devilhorns Reviewed By: zmike Subscribers: cedric Tags: #efl Differential Revision: https://phab.enlightenment.org/D6366
Diffstat (limited to 'src/lib/ecore_cocoa')
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa.m64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m
index cfd56d397a..d8ce7a6cf6 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa.m
@@ -258,29 +258,37 @@ _ecore_cocoa_feed_events(void *anEvent)
258 258
259 Ecore_Event_Key *evDown = NULL; 259 Ecore_Event_Key *evDown = NULL;
260 Ecore_Event_Key *evUp = NULL; 260 Ecore_Event_Key *evUp = NULL;
261 261 const char *key = NULL;
262 evDown = calloc(1, sizeof (Ecore_Event_Key)); 262 int keylen;
263 if (!evDown) return pass;
264 263
265 // Turn special key flags on 264 // Turn special key flags on
266 if (flags & NSEventModifierFlagShift) 265 if (flags & NSEventModifierFlagShift)
267 evDown->key = "Shift_L"; 266 key = "Shift_L";
268 else if (flags & NSEventModifierFlagControl) 267 else if (flags & NSEventModifierFlagControl)
269 evDown->key = "Control_L"; 268 key = "Control_L";
270 else if (flags & NSEventModifierFlagOption) 269 else if (flags & NSEventModifierFlagOption)
271 evDown->key = "Alt_L"; 270 key = "Alt_L";
272 else if (flags & NSEventModifierFlagCommand) 271 else if (flags & NSEventModifierFlagCommand)
273 evDown->key = "Super_L"; 272 key = "Super_L";
274 else if (flags & NSEventModifierFlagCapsLock) 273 else if (flags & NSEventModifierFlagCapsLock)
275 evDown->key = "Caps_Lock"; 274 key = "Caps_Lock";
276 else if (flags & NSEventModifierFlagNumericPad) 275 else if (flags & NSEventModifierFlagNumericPad)
277 evDown->key = "Num_Lock"; 276 key = "Num_Lock";
278 277
279 if (evDown->key) 278 if (key)
280 { 279 {
280 keylen = strlen(key);
281 evDown = calloc(1, sizeof (Ecore_Event_Key) + (keylen * 2) + 2);
282 if (!evDown) return pass;
283
284 evDown->keyname = (char *)(evDown + 1);
285 evDown->key = evDown->keyname + keylen + 1;
286
287 strcpy((char *) evDown->keyname, key);
288 strcpy((char *) evDown->key, key);
289
281 evDown->window = (Ecore_Window)window.ecore_window_data; 290 evDown->window = (Ecore_Window)window.ecore_window_data;
282 evDown->event_window = evDown->window; 291 evDown->event_window = evDown->window;
283 evDown->keyname = evDown->key;
284 evDown->timestamp = time; 292 evDown->timestamp = time;
285 evDown->string = NULL; 293 evDown->string = NULL;
286 ecore_event_add(ECORE_EVENT_KEY_DOWN, evDown, NULL, NULL); 294 ecore_event_add(ECORE_EVENT_KEY_DOWN, evDown, NULL, NULL);
@@ -288,42 +296,44 @@ _ecore_cocoa_feed_events(void *anEvent)
288 break; 296 break;
289 } 297 }
290 298
291 free(evDown); 299 key = NULL;
292
293 evUp = calloc(1, sizeof (Ecore_Event_Key));
294 if (!evUp)
295 {
296 return pass;
297 }
298 300
299 NSUInteger changed_flags = flags ^ old_flags; 301 NSUInteger changed_flags = flags ^ old_flags;
300 302
301 // Turn special key flags off 303 // Turn special key flags off
302 if (changed_flags & NSEventModifierFlagShift) 304 if (changed_flags & NSEventModifierFlagShift)
303 evUp->key = "Shift_L"; 305 key = "Shift_L";
304 else if (changed_flags & NSEventModifierFlagControl) 306 else if (changed_flags & NSEventModifierFlagControl)
305 evUp->key = "Control_L"; 307 key = "Control_L";
306 else if (changed_flags & NSEventModifierFlagOption) 308 else if (changed_flags & NSEventModifierFlagOption)
307 evUp->key = "Alt_L"; 309 key = "Alt_L";
308 else if (changed_flags & NSEventModifierFlagCommand) 310 else if (changed_flags & NSEventModifierFlagCommand)
309 evUp->key = "Super_L"; 311 key = "Super_L";
310 else if (changed_flags & NSEventModifierFlagCapsLock) 312 else if (changed_flags & NSEventModifierFlagCapsLock)
311 evUp->key = "Caps_Lock"; 313 key = "Caps_Lock";
312 else if (changed_flags & NSEventModifierFlagNumericPad) 314 else if (changed_flags & NSEventModifierFlagNumericPad)
313 evUp->key = "Num_Lock"; 315 key = "Num_Lock";
314 316
315 if (evUp->key) 317 if (key)
316 { 318 {
319 keylen = strlen(key);
320 evUp = calloc(1, sizeof (Ecore_Event_Key) + (keylen * 2) + 2);
321 if (!evUp) return pass;
322
323 evUp->keyname = (char *)(evUp + 1);
324 evUp->key = evUp->keyname + keylen + 1;
325
326 strcpy((char *) evUp->keyname, key);
327 strcpy((char *) evUp->key, key);
328
317 evUp->window = (Ecore_Window)window.ecore_window_data; 329 evUp->window = (Ecore_Window)window.ecore_window_data;
318 evUp->event_window = evUp->window; 330 evUp->event_window = evUp->window;
319 evUp->keyname = evUp->key;
320 evUp->timestamp = time; 331 evUp->timestamp = time;
321 evUp->string = NULL; 332 evUp->string = NULL;
322 ecore_event_add(ECORE_EVENT_KEY_UP, evUp, NULL, NULL); 333 ecore_event_add(ECORE_EVENT_KEY_UP, evUp, NULL, NULL);
323 old_flags = flags; 334 old_flags = flags;
324 break; 335 break;
325 } 336 }
326 free(evUp);
327 337
328 break; 338 break;
329 } 339 }