[gtk+] Bug 596012 - popup menu position is horribly off on gdk quartz with ...



commit 2f782de1b7eb1b3dd778d01867e4e56a77af4a8c
Author: Kristian Rietveld <kris gtk org>
Date:   Sun Sep 27 13:36:08 2009 +0200

    Bug 596012 - popup menu position is horribly off on gdk quartz with ...
    
    Based on first patches by Christian Hergert.  Change
    screen_get_monitor_geometry() so that it translates the layout of the screens
    from Cocoa layout to GDK layout.  In Cocoa, the screen locations
    are specified in Cocoa geometry, as well as that GDK uses a different way
    to place individual monitors in the root window.  For now only monitors
    that are laid out horizontally are supported (see the FIXMEs in the source),
    in bug 596238 we will track future work to get things fully right.
    
    Modify _gdk_quartz_window_get_inverted_screen_y() to take the differences
    in screen layout between Cocoa and GDK into account.  Also this function
    is subject to future work.

 gdk/quartz/gdkscreen-quartz.c |   32 +++++++++++++++++++++++++++++++-
 gdk/quartz/gdkwindow-quartz.c |   11 +++++++++--
 2 files changed, 40 insertions(+), 3 deletions(-)
---
diff --git a/gdk/quartz/gdkscreen-quartz.c b/gdk/quartz/gdkscreen-quartz.c
index 050267c..30cd73e 100644
--- a/gdk/quartz/gdkscreen-quartz.c
+++ b/gdk/quartz/gdkscreen-quartz.c
@@ -82,6 +82,13 @@ gdk_screen_set_default_colormap (GdkScreen   *screen,
     g_object_unref (old_colormap);
 }
 
+/* FIXME: note on the get_width() and the get_height() methods.  For
+ * now we only support screen layouts where the screens are laid out
+ * horizontally.  Mac OS X also supports laying out the screens vertically
+ * and the screens having "non-standard" offsets from eachother.  In the
+ * future we need a much more sophiscated algorithm to translate these
+ * layouts to GDK coordinate space and GDK screen layout.
+ */
 gint
 gdk_screen_get_width (GdkScreen *screen)
 {
@@ -221,6 +228,8 @@ screen_get_monitor_geometry (GdkScreen    *screen,
   NSArray *array;
   NSScreen *nsscreen;
   NSRect rect;
+  NSRect largest_rect;
+  int i;
 
   GDK_QUARTZ_ALLOC_POOL;
 
@@ -229,10 +238,31 @@ screen_get_monitor_geometry (GdkScreen    *screen,
   rect = [nsscreen frame];
   
   dest->x = rect.origin.x;
-  dest->y = rect.origin.y;
   dest->width = rect.size.width;
   dest->height = rect.size.height;
 
+  /* FIXME: as stated above the get_width() and get_height() functions
+   * in this file, we only support horizontal screen layouts for now.
+   */
+
+  /* Find the monitor with the largest height.  All monitors should be
+   * offset to this one in the GDK screen space instead of offset to
+   * the screen with the menu bar.
+   */
+  largest_rect = [[array objectAtIndex:0] frame];
+  for (i = 1; i < [array count]; i++)
+    {
+      NSRect rect = [[array objectAtIndex:i] frame];
+
+      if (rect.size.height > largest_rect.size.height)
+        largest_rect = [[array objectAtIndex:i] frame];
+    }
+
+  if (largest_rect.size.height - rect.size.height == 0)
+    dest->y = 0;
+  else
+    dest->y = largest_rect.size.height - rect.size.height + largest_rect.origin.y;
+
   if (in_mm)
     {
       dest->x = get_mm_from_pixels (nsscreen, dest->x);
diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c
index 0192019..86945cd 100644
--- a/gdk/quartz/gdkwindow-quartz.c
+++ b/gdk/quartz/gdkwindow-quartz.c
@@ -654,9 +654,16 @@ _gdk_quartz_window_is_ancestor (GdkWindow *ancestor,
 gint 
 _gdk_quartz_window_get_inverted_screen_y (gint y)
 {
-  NSRect rect = [[NSScreen mainScreen] frame];
+  int index;
+  GdkRectangle gdk_rect;
+  NSScreen *main_screen = [NSScreen mainScreen];
+  NSRect rect = [main_screen frame];
 
-  return rect.size.height - y;
+  index = [[NSScreen screens] indexOfObject:main_screen];
+
+  gdk_screen_get_monitor_geometry (_gdk_screen, index, &gdk_rect);
+
+  return gdk_rect.height - y + rect.origin.y + gdk_rect.y;
 }
 
 static GdkWindow *



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