]> code.delx.au - gnu-emacs/blobdiff - src/xfns.c
Reformat copyright line.
[gnu-emacs] / src / xfns.c
index 572cf38e0c73cfd888f59357e17581bf5c0f384b..6f18e4e813a5780b94d2344334d3e88bb2a75bb5 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions for the X window system.
    Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -1317,7 +1317,43 @@ x_set_menu_bar_lines (f, value, oldval)
 #else /* not USE_X_TOOLKIT && not USE_GTK */
   FRAME_MENU_BAR_LINES (f) = nlines;
   change_window_heights (f->root_window, nlines - olines);
-#endif /* not USE_X_TOOLKIT */
+
+  /* If the menu bar height gets changed, the internal border below
+     the top margin has to be cleared.  Also, if the menu bar gets
+     larger, the area for the added lines has to be cleared except for
+     the first menu bar line that is to be drawn later.  */
+  if (nlines != olines)
+    {
+      int height = FRAME_INTERNAL_BORDER_WIDTH (f);
+      int width = FRAME_PIXEL_WIDTH (f);
+      int y;
+
+      /* height can be zero here. */
+      if (height > 0 && width > 0)
+       {
+         y = FRAME_TOP_MARGIN_HEIGHT (f);
+
+         BLOCK_INPUT;
+         x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+                       0, y, width, height, False);
+         UNBLOCK_INPUT;
+       }
+
+      if (nlines > 1 && nlines > olines)
+       {
+         y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f);
+         height = nlines * FRAME_LINE_HEIGHT (f) - y;
+
+         BLOCK_INPUT;
+         x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+                       0, y, width, height, False);
+         UNBLOCK_INPUT;
+       }
+
+      if (nlines == 0 && WINDOWP (f->menu_bar_window))
+       clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
+    }
+#endif /* not USE_X_TOOLKIT && not USE_GTK */
   adjust_glyphs (f);
 }
 
@@ -3109,6 +3145,91 @@ If FRAME is nil, use the selected frame.  */)
   return Qnil;
 }
 
+/* Return current desktop index for the display where frame F is.
+   If we can't find out the current desktop, return 0.  */
+
+static int
+x_get_current_desktop (f)
+     struct frame *f;
+{
+  Atom actual_type;
+  unsigned long actual_size, bytes_remaining;
+  int rc, actual_format;
+  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  long max_len = 10;
+  Display *dpy = FRAME_X_DISPLAY (f);
+  long *data = NULL;
+  int current_desktop;
+
+  BLOCK_INPUT;
+  x_catch_errors (dpy);
+  rc = XGetWindowProperty (dpy, dpyinfo->root_window,
+                           XInternAtom (dpy, "_NET_CURRENT_DESKTOP", False),
+                           0, max_len, False, XA_CARDINAL,
+                           &actual_type, &actual_format, &actual_size,
+                           &bytes_remaining, (unsigned char **)&data);
+
+  if (rc != Success || actual_type != XA_CARDINAL || x_had_errors_p (dpy)
+      || actual_size == 0 || actual_format != 32)
+    current_desktop = 0;
+  else
+    current_desktop = (int)*data;
+
+  if (data) XFree (data);
+  x_uncatch_errors ();
+  UNBLOCK_INPUT;
+  return current_desktop;
+}
+
+/* Return current size for DESKTOP_INDEX on the display where frame F is.
+   If we can't find out the size, return 0, otherwise 1.  */
+
+static int
+x_get_desktop_workarea (f, desktop_index, deskw, deskh)
+     struct frame *f;
+     int desktop_index;
+     int *deskw, *deskh;
+{
+  Atom actual_type;
+  unsigned long actual_size, bytes_remaining;
+  int rc, actual_format;
+  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  long max_len = 1000; /* This handles 250 desktops, who has that many?  */
+  Display *dpy = FRAME_X_DISPLAY (f);
+  long *data = NULL;
+  int retval;
+
+  BLOCK_INPUT;
+  x_catch_errors (dpy);
+  rc = XGetWindowProperty (dpy, dpyinfo->root_window,
+                           XInternAtom (dpy, "_NET_WORKAREA", False),
+                           0, max_len, False, XA_CARDINAL,
+                           &actual_type, &actual_format, &actual_size,
+                           &bytes_remaining, (unsigned char **)&data);
+
+  if (rc != Success || actual_type != XA_CARDINAL || x_had_errors_p (dpy)
+      || actual_size < 3 || actual_format != 32)
+    retval = 0;
+  else
+    {
+      int idx;
+      
+      if (actual_size == 4 /* Only one info for all desktops.  */
+          || desktop_index*4 > actual_size) /* destop_index out of range.  */
+        desktop_index = 0;
+
+      idx = desktop_index*4;
+      *deskw = data[idx+2] - data[idx];
+      *deskh = data[idx+3] - data[idx+1];
+      retval = 1;
+    }
+  
+  if (data) XFree (data);
+  x_uncatch_errors ();
+  UNBLOCK_INPUT;
+  return retval;
+}
+
 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
        1, 1, 0,
        doc: /* Make a new X window, which is called a "frame" in Emacs terms.
@@ -3128,7 +3249,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
   Lisp_Object name;
   int minibuffer_only = 0;
   long window_prompting = 0;
-  int width, height;
+  int width, height, deskw = -1, deskh = -1, current_desktop = -1;
   int count = SPECPDL_INDEX ();
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   Lisp_Object display;
@@ -3396,6 +3517,58 @@ This function is an internal primitive--use `make-frame' instead.  */)
   /* Compute the size of the X window.  */
   window_prompting = x_figure_window_size (f, parms, 1);
 
+  /* Don't make height higher than display height unless the user asked
+     for it.  */
+  height = FRAME_LINES (f);
+  tem = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
+  if (EQ (tem, Qunbound))
+    {
+      int ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
+      int dph = DisplayHeight (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f));
+      /* Some desktops have fixed menus above and/or panels below.  Try to
+         figure out the usable size we have for emacs.  */
+      current_desktop = x_get_current_desktop (f);
+      x_get_desktop_workarea (f, current_desktop, &deskw, &deskh);
+      if (deskh > 0 && deskh < dph) dph = deskh;
+      
+      if (ph > dph)
+        {
+          height = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, dph) -
+            FRAME_TOOL_BAR_LINES (f) - FRAME_MENU_BAR_LINES (f);
+          if (FRAME_EXTERNAL_TOOL_BAR (f))
+            height -= 2; /* We can't know how big it will be.  */
+          if (FRAME_EXTERNAL_MENU_BAR (f))
+            height -= 2; /* We can't know how big it will be.  */
+        }
+    }
+
+  /* Don't make width wider than display width unless the user asked
+     for it.  */
+  width = FRAME_COLS (f);
+  tem = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
+  if (EQ (tem, Qunbound))
+    {
+      int pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
+      int dpw = DisplayWidth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f));
+      if (deskw == -1)
+        {
+          current_desktop = x_get_current_desktop (f);
+          x_get_desktop_workarea (f, current_desktop, &deskw, &deskh);
+        }
+      if (deskw > 0 && deskw < dpw) dpw = deskw;
+      
+      if (pw > dpw)
+        width = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, dpw);
+    }
+
+  if (height != FRAME_LINES (f) || width != FRAME_COLS (f))
+    {
+      check_frame_size (f, &height, &width);
+      FRAME_LINES (f) = height;
+      SET_FRAME_COLS (f, width);
+    }
+  
+
   tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || EQ (tem, Qt);