changeset 106753:16b52378e95a

NS fixes for Bug#3233. * nsfns.m (ns_get_screen): Rewrite, returning NULL for non-NS. (Fns_display_usable_bounds): Rewrite, computing bounds properly (Bug#3233).
author Chong Yidong <cyd@stupidchicken.com>
date Wed, 06 Jan 2010 09:41:59 -0700
parents 06b47f571086
children 53e52339f8c2 0865d6c0506d
files src/ChangeLog src/nsfns.m
diffstat 2 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Jan 06 16:57:43 2010 +0100
+++ b/src/ChangeLog	Wed Jan 06 09:41:59 2010 -0700
@@ -1,3 +1,9 @@
+2010-01-06  David Reitter  <david.reitter@gmail.com>
+
+	* nsfns.m (ns_get_screen): Rewrite, returning NULL for non-NS.
+	(Fns_display_usable_bounds): Rewrite, computing bounds properly
+	(Bug#3233).
+
 2010-01-06  Jan Djärv  <jan.h.d@swipnet.se>
 
 	* xterm.c (x_clear_frame): Queue draw for scroll bars.
--- a/src/nsfns.m	Wed Jan 06 16:57:43 2010 +0100
+++ b/src/nsfns.m	Wed Jan 06 09:41:59 2010 -0700
@@ -206,30 +206,28 @@
 static NSScreen *
 ns_get_screen (Lisp_Object screen)
 {
-  struct terminal *terminal = get_terminal (screen, 1);
+  struct frame *f;
+  struct terminal *terminal;
+
+  if (EQ (Qt, screen)) /* not documented */
+    return [NSScreen mainScreen];
+
+  terminal = get_terminal (screen, 1);
   if (terminal->type != output_ns)
-    // Not sure if this special case for nil is needed.  It does seem to be
-    // important in xfns.c for the make-frame call in frame-initialize,
-    // so let's keep it here for now.
-    return (NILP (screen) ? [NSScreen mainScreen] : NULL);
+    return NULL;
+
+  if (NILP (screen))
+    f = SELECTED_FRAME ();
+  else if (FRAMEP (screen))
+    f = XFRAME (screen);
   else
     {
       struct ns_display_info *dpyinfo = terminal->display_info.ns;
-      struct frame *f = dpyinfo->x_focus_frame;
-      if (!f)
-	f = dpyinfo->x_highlight_frame;
-      if (!f)
-	return NULL;
-      else
-	{
-	  id window = nil;
-	  Lisp_Object frame;
-	  eassert (FRAME_NS_P (f));
-	  XSETFRAME (frame, f);
-	  window = ns_get_window (frame);
-	  return window ? [window screen] : NULL;
-	}
+      f = (dpyinfo->x_focus_frame || dpyinfo->x_highlight_frame);
     }
+
+  return ((f && FRAME_NS_P (f)) ? [[FRAME_NS_VIEW (f) window] screen]
+	  : NULL);
 }
 
 
@@ -2325,15 +2323,21 @@
      Lisp_Object display;
 {
   int top;
+  NSScreen *screen;
   NSRect vScreen;
 
   check_ns ();
-  vScreen = [ns_get_screen (display) visibleFrame];
-  top = vScreen.origin.y == 0.0 ?
-    (int) [ns_get_screen (display) frame].size.height - vScreen.size.height : 0;
-
+  screen = ns_get_screen (display);
+  if (!screen)
+    return Qnil;
+
+  vScreen = [screen visibleFrame];
+
+  /* NS coordinate system is upside-down.
+     Transform to screen-specific coordinates. */
   return list4 (make_number ((int) vScreen.origin.x),
-                make_number (top),
+		make_number ((int) [screen frame].size.height
+			     - vScreen.size.height - vScreen.origin.y),
                 make_number ((int) vScreen.size.width),
                 make_number ((int) vScreen.size.height));
 }