[gtk+/gtk-3-6] Bug 672193 - windows (including menus) shown multiple times don't...



commit 1a0e861fcdb03c724e78e921238e2ea5f37f1685
Author: Michael Natterer <mitch gimp org>
Date:   Tue Nov 20 10:28:58 2012 +0100

    Bug 672193 - windows (including menus) shown multiple times don't...
    
    Based on a patch from Paul Davis, inject synthetic enter events directly
    into the Quartz event stream, instead of trying to synthesize them in GDK.
    
    This seems to magically fix most combo box popup weirdness, I guess
    some code is relying on a specfic order of events, or any other state
    imposed by the "proper" code path of events coming in the usual way.
    
    The patch also removes _gdk_quartz_events_send_enter_notify_event()
    which is now obsolete.
    (cherry picked from commit 2d5ad5f54e7e78fd35ef09b4ce055af9f6d9aa0a)

 gdk/quartz/GdkQuartzNSWindow.c |   40 ++++++++++++++++++++++++++++++++++++++++
 gdk/quartz/GdkQuartzNSWindow.h |    1 +
 gdk/quartz/GdkQuartzView.c     |    9 ---------
 gdk/quartz/gdkevents-quartz.c  |   33 ---------------------------------
 gdk/quartz/gdkprivate-quartz.h |    1 -
 5 files changed, 41 insertions(+), 43 deletions(-)
---
diff --git a/gdk/quartz/GdkQuartzNSWindow.c b/gdk/quartz/GdkQuartzNSWindow.c
index 76a759c..b5eaae2 100644
--- a/gdk/quartz/GdkQuartzNSWindow.c
+++ b/gdk/quartz/GdkQuartzNSWindow.c
@@ -141,6 +141,38 @@
   return inMove;
 }
 
+-(void)checkSendEnterNotify
+{
+  GdkWindow *window = [[self contentView] gdkWindow];
+  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
+
+  /* When a new window has been created, and the mouse
+   * is in the window area, we will not receive an NSMouseEntered
+   * event.  Therefore, we synthesize an enter notify event manually.
+   */
+  if (!initialPositionKnown)
+    {
+      initialPositionKnown = YES;
+
+      if (NSPointInRect ([NSEvent mouseLocation], [self frame]))
+        {
+          NSEvent *event;
+
+          event = [NSEvent enterExitEventWithType: NSMouseEntered
+                                         location: [self mouseLocationOutsideOfEventStream]
+                                    modifierFlags: 0
+                                        timestamp: [[NSApp currentEvent] timestamp]
+                                     windowNumber: [impl->toplevel windowNumber]
+                                          context: NULL
+                                      eventNumber: 0
+                                   trackingNumber: [impl->view trackingRect]
+                                         userData: nil];
+
+          [NSApp postEvent:event atStart:NO];
+        }
+    }
+}
+
 -(void)windowDidMove:(NSNotification *)aNotification
 {
   GdkWindow *window = [[self contentView] gdkWindow];
@@ -157,6 +189,8 @@
   event->configure.height = window->height;
 
   _gdk_event_queue_append (gdk_display_get_default (), event);
+
+  [self checkSendEnterNotify];
 }
 
 -(void)windowDidResize:(NSNotification *)aNotification
@@ -186,6 +220,8 @@
   event->configure.height = window->height;
 
   _gdk_event_queue_append (gdk_display_get_default (), event);
+
+  [self checkSendEnterNotify];
 }
 
 -(id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag screen:(NSScreen *)screen
@@ -283,6 +319,8 @@
     [impl->toplevel orderFront:nil];
 
   inShowOrHide = NO;
+
+  [self checkSendEnterNotify];
 }
 
 - (void)hide
@@ -293,6 +331,8 @@
   inShowOrHide = YES;
   [impl->toplevel orderOut:nil];
   inShowOrHide = NO;
+
+  initialPositionKnown = NO;
 }
 
 - (BOOL)trackManualMove
diff --git a/gdk/quartz/GdkQuartzNSWindow.h b/gdk/quartz/GdkQuartzNSWindow.h
index b456ff7..da9ac58 100644
--- a/gdk/quartz/GdkQuartzNSWindow.h
+++ b/gdk/quartz/GdkQuartzNSWindow.h
@@ -23,6 +23,7 @@
 @interface GdkQuartzNSWindow : NSWindow {
   BOOL    inMove;
   BOOL    inShowOrHide;
+  BOOL    initialPositionKnown;
 
   /* Manually triggered move/resize (not by the window manager) */
   BOOL    inManualMove;
diff --git a/gdk/quartz/GdkQuartzView.c b/gdk/quartz/GdkQuartzView.c
index 0b59119..4058474 100644
--- a/gdk/quartz/GdkQuartzView.c
+++ b/gdk/quartz/GdkQuartzView.c
@@ -167,15 +167,6 @@
                                  owner:self
                               userData:nil
                           assumeInside:NO];
-
-  if (NSPointInRect ([[self window] convertScreenToBase:[NSEvent mouseLocation]], rect))
-    {
-      /* When a new window (and thus view) has been created, and the mouse
-       * is in the window area, we will not receive an NSMouseEntered
-       * event.  Therefore, we synthesize an enter notify event manually.
-       */
-      _gdk_quartz_events_send_enter_notify_event (gdk_window);
-    }
 }
 
 -(void)viewDidMoveToWindow
diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c
index 0d3cdc9..cd05882 100644
--- a/gdk/quartz/gdkevents-quartz.c
+++ b/gdk/quartz/gdkevents-quartz.c
@@ -590,39 +590,6 @@ _gdk_quartz_events_update_focus_window (GdkWindow *window,
 }
 
 void
-_gdk_quartz_events_send_enter_notify_event (GdkWindow *window)
-{
-  NSPoint screen_point;
-  GdkEvent *event;
-  gint x, y, x_root, y_root;
-
-  event = gdk_event_new (GDK_ENTER_NOTIFY);
-  event->any.window = NULL;
-  event->any.send_event = FALSE;
-
-  screen_point = [NSEvent mouseLocation];
-
-  _gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &x_root, &y_root);
-  get_window_point_from_screen_point (window, screen_point, &x, &y);
-
-  event->crossing.window = window;
-  event->crossing.subwindow = NULL;
-  event->crossing.time = GDK_CURRENT_TIME;
-  event->crossing.x = x;
-  event->crossing.y = y;
-  event->crossing.x_root = x_root;
-  event->crossing.y_root = y_root;
-  event->crossing.mode = GDK_CROSSING_NORMAL;
-  event->crossing.detail = GDK_NOTIFY_ANCESTOR;
-  event->crossing.state = _gdk_quartz_events_get_current_keyboard_modifiers () |
-                          _gdk_quartz_events_get_current_mouse_modifiers ();
-
-  gdk_event_set_device (event, _gdk_display->core_pointer);
-
-  append_event (event, TRUE);
-}
-
-void
 _gdk_quartz_events_send_map_event (GdkWindow *window)
 {
   GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (window->impl);
diff --git a/gdk/quartz/gdkprivate-quartz.h b/gdk/quartz/gdkprivate-quartz.h
index 71fdbb9..dcac502 100644
--- a/gdk/quartz/gdkprivate-quartz.h
+++ b/gdk/quartz/gdkprivate-quartz.h
@@ -64,7 +64,6 @@ void         _gdk_quartz_events_send_map_event         (GdkWindow *window);
 GdkModifierType _gdk_quartz_events_get_current_keyboard_modifiers (void);
 GdkModifierType _gdk_quartz_events_get_current_mouse_modifiers    (void);
 
-void         _gdk_quartz_events_send_enter_notify_event (GdkWindow *window);
 void         _gdk_quartz_events_break_all_grabs         (guint32    time);
 
 /* Event loop */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]