]> Pileus Git - ~andy/gtk/commitdiff
Bug 596012 - popup menu position is horribly off on gdk quartz with ...
authorKristian Rietveld <kris@gtk.org>
Sun, 27 Sep 2009 11:36:08 +0000 (13:36 +0200)
committerKristian Rietveld <kris@gtk.org>
Sun, 27 Sep 2009 11:44:10 +0000 (13:44 +0200)
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
gdk/quartz/gdkwindow-quartz.c

index 050267cc9bf0046ea3540dc84cb2e6c6a0cafef4..30cd73edda5dae2eaf73e71f47e13ab5333944ba 100644 (file)
@@ -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);
index 019201969e5cecc295ab8a62bbed131b333bb0b5..86945cd57d31145dcee5a741aa9a5e055592d35d 100644 (file)
@@ -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 *