From c6945c075ec108509a187d7ee1df735afa4bf0ff Mon Sep 17 00:00:00 2001 From: Romain Perier Date: Thu, 15 Jan 2015 17:20:16 +0100 Subject: [PATCH] ecore_cocoa: use the right Cocoa notification handlers for focus events Don't use NSAppKitDefined events subtype for focus events, which contain NULL window object most of the time. Use the NSWindowDelegate method designed for that purpose instead. It fixes random focus issues in windows which was caused by incorrect window identifier not found in ecore_evas_cocoa. Signed-off-by: Cedric BAIL --- src/lib/ecore_cocoa/ecore_cocoa.m | 26 ++++++++++++++++++++-- src/lib/ecore_cocoa/ecore_cocoa_window.m | 28 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m index ed7f6b02ae..c93a4b00b7 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa.m +++ b/src/lib/ecore_cocoa/ecore_cocoa.m @@ -379,9 +379,31 @@ ecore_cocoa_feed_events(void *anEvent) case NSAppKitDefined: { if ([event subtype] == NSApplicationActivatedEventType) - ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, NULL, NULL, NULL); + { + Ecore_Cocoa_Event_Window *ev; + + ev = malloc(sizeof(Ecore_Cocoa_Event_Window)); + if (!ev) + { + pass = EINA_FALSE; + break; + } + ev->wid = [event window]; + ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, ev, NULL, NULL); + } else if ([event subtype] == NSApplicationDeactivatedEventType) - ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, NULL, NULL, NULL); + { + Ecore_Cocoa_Event_Window *ev; + + ev = malloc(sizeof(Ecore_Cocoa_Event_Window)); + if (!ev) + { + pass = EINA_FALSE; + break; + } + ev->wid = [event window]; + ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, ev, NULL, NULL); + } pass = EINA_TRUE; // pass along AppKit events, for window manager break; } diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m index 754caa8c0b..9739220b60 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_window.m +++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m @@ -69,6 +69,34 @@ ecore_main_loop_iterate(); } +- (void)windowDidBecomeKey:(NSNotification *)notification +{ + Ecore_Cocoa_Event_Window *e; + + e = malloc(sizeof(Ecore_Cocoa_Event_Window)); + if (!e) + { + printf("GOT_FOCUS: Failed to allocate Ecore_Cocoa_Event_Window\n"); + return; + } + e->wid = [notification object]; + ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, e, NULL, NULL); +} + +- (void)windowDidResignKey:(NSNotification *)notification +{ + Ecore_Cocoa_Event_Window *e; + + e = malloc(sizeof(Ecore_Cocoa_Event_Window)); + if (!e) + { + printf("LOST_FOCUS: Failed to allocate Ecore_Cocoa_Event_Window\n"); + return; + } + e->wid = [notification object]; + ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, e, NULL, NULL); +} + @end