cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=c6945c075ec108509a187d7ee1df735afa4bf0ff

commit c6945c075ec108509a187d7ee1df735afa4bf0ff
Author: Romain Perier <romain.per...@openwide.fr>
Date:   Thu Jan 15 17:20:16 2015 +0100

    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 <ced...@osg.samsung.com>
---
 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 ed7f6b0..c93a4b0 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 754caa8..9739220 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
 
 

-- 


Reply via email to