diff src/frame-x.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents bc4f2511bbea
children d1247f3cc363
line wrap: on
line diff
--- a/src/frame-x.c	Sat Dec 26 00:20:27 2009 -0600
+++ b/src/frame-x.c	Sat Dec 26 21:18:49 2009 -0600
@@ -48,7 +48,7 @@
 				   use XtGetValues(), but ... */
 #include <X11/Shell.h>
 #include <X11/ShellP.h>
-#include "xmu.h"
+#include <X11/Xmu/Editres.h>
 #include "EmacsManager.h"
 #include "EmacsFrameP.h"
 #include "EmacsShell.h"
@@ -60,10 +60,6 @@
 #include "dragdrop.h"
 #endif
 
-#ifdef HAVE_OFFIX_DND
-#include "offix.h"
-#endif
-
 /* Default properties to use when creating frames.  */
 Lisp_Object Vdefault_x_frame_plist;
 
@@ -77,11 +73,17 @@
   { XD_END }
 };
 
+#ifdef NEW_GC
+DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("x-frame", x_frame,
+				      0, x_frame_data_description_1,
+				      Lisp_X_Frame);
+#else /* not NEW_GC */
 extern const struct sized_memory_description x_frame_data_description;
 
 const struct sized_memory_description x_frame_data_description = {
   sizeof (struct x_frame), x_frame_data_description_1
 };
+#endif /* not NEW_GC */
 
 EXFUN (Fx_window_id, 1);
 
@@ -272,8 +274,8 @@
   if (cw <= 0 || ch <= 0)
     ABORT ();
 
-  XtSetArg (al[0], XtNwidthInc,  cw);
-  XtSetArg (al[1], XtNheightInc, ch);
+  Xt_SET_ARG (al[0], XtNwidthInc,  cw);
+  Xt_SET_ARG (al[1], XtNheightInc, ch);
   XtSetValues (wmshell, al, 2);
 }
 
@@ -290,8 +292,8 @@
   fflush (stdout);
 #endif
 
-  XtSetArg (al[0], XtNwidthCells,  width);
-  XtSetArg (al[1], XtNheightCells, height);
+  Xt_SET_ARG (al[0], XtNwidthCells,  width);
+  Xt_SET_ARG (al[1], XtNheightCells, height);
   XtSetValues (wmshell, al, 2);
 }
 
@@ -499,6 +501,7 @@
   defi(Qtop, XtNy);
 
 #undef def
+#undef defi
 }
 
 static Lisp_Object
@@ -659,8 +662,8 @@
   if (!old_XtValue || strcmp (new_XtValue, old_XtValue))
     {
       Arg al[2];
-      XtSetArg (al[0], Xt_resource_name, new_XtValue);
-      XtSetArg (al[1], Xt_resource_encoding_name, encoding);
+      Xt_SET_ARG (al[0], Xt_resource_name, new_XtValue);
+      Xt_SET_ARG (al[1], Xt_resource_encoding_name, encoding);
       XtSetValues (FRAME_X_SHELL_WIDGET (f), al, 2);
     }
 }
@@ -736,7 +739,14 @@
   Bool y_position_specified_p = False;
   Bool internal_border_width_specified = False;
   Lisp_Object tail;
-  Widget w = FRAME_X_TEXT_WIDGET (f);
+  Widget w;
+
+  /* We can be called after the X IO error handler has seen a broken pipe on
+     the relevant display. Don't do anything in that case.  */
+  if (!FRAME_LIVE_P (f) || DEVICE_X_BEING_DELETED (XDEVICE (FRAME_DEVICE (f))))
+    return;
+
+  w = FRAME_X_TEXT_WIDGET (f);
 
   for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
     {
@@ -767,12 +777,12 @@
 			     /* !!#### Verify this + 1 and document
 				as zero-termination */
 			     XtRString, extval, extvallen + 1,
-			     (XtArgVal) NULL);
+			     NULL);
 	    }
 	  else
 	    XtVaSetValues (w, XtVaTypedArg, extprop, XtRInt,
 			   XINT (val), sizeof (int),
-			   (XtArgVal) NULL);
+			   NULL);
 	}
       else if (SYMBOLP (prop))
 	{
@@ -871,7 +881,7 @@
 			     /* !!#### Verify this + 1 and document
 				as zero-termination */
 			     XtRString, extval, extvallen + 1,
-			     (XtArgVal) NULL);
+			     NULL);
 	    }
 
 #ifdef HAVE_SCROLLBARS
@@ -986,7 +996,7 @@
   frame_title_format_already_set = 1;
 }
 
-#if defined (HAVE_CDE) || defined (HAVE_OFFIX_DND)
+#if defined (HAVE_CDE)
 
 static Extbyte *
 start_drag_internal_1 (Lisp_Object event, Lisp_Object data,
@@ -1079,7 +1089,7 @@
   return dnd_data;
 }
 
-#endif /* defined (HAVE_CDE) || defined (HAVE_OFFIX_DND) */
+#endif /* defined (HAVE_CDE) */
 
 #ifdef HAVE_CDE
 #include <Dt/Dt.h>
@@ -1317,46 +1327,6 @@
 }
 #endif /* HAVE_CDE */
 
-#ifdef HAVE_OFFIX_DND
-
-DEFUN ("offix-start-drag-internal", Foffix_start_drag_internal, 2, 3, 0, /*
-Start a OffiX drag from a buffer.
-First arg is the event that started the drag,
-second arg should be some string, and the third
-is the type of the data (this should be an int).
-The type defaults to DndText (4).
-*/
-       (event, data, dtyp))
-{
-  Extbyte *dnd_data;
-  XEvent x_event;
-  Bytecount dnd_len;
-  Widget wid;
-  int num_items;
-  int dnd_type = DndText;
-
-  if (!NILP (dtyp))
-    {
-      CHECK_INT (dtyp);
-      dnd_type = XINT (dtyp);
-    }
-
-  dnd_data = start_drag_internal_1 (event, data, Qoffix_dnd_encoding,
-				    &x_event, dnd_type == DndFiles,
-				    &wid, &dnd_len, &num_items);
-
-  DndSetData (dnd_type, (UExtbyte *) dnd_data, dnd_len);
-  xfree (dnd_data, Extbyte *);
-
-  /* the next thing blocks everything... */
-  if (DndHandleDragging (wid, &x_event))
-    return Qt;
-
-  return Qnil;
-}
-
-#endif /* HAVE_OFFIX_DND */
-
 
 /************************************************************************/
 /*				widget creation				*/
@@ -1523,8 +1493,8 @@
       if (! (frame_flags & (WidthValue | HeightValue)))
 	{
           Arg al[2];
-	  XtSetArg (al [0], XtNwidth,  &frame_w);
-	  XtSetArg (al [1], XtNheight, &frame_h);
+	  Xt_SET_ARG (al [0], XtNwidth,  &frame_w);
+	  Xt_SET_ARG (al [1], XtNheight, &frame_h);
 	  XtGetValues (ew, al, 2);
 	  if (!frame_w && !frame_h)
 	    {
@@ -1538,8 +1508,8 @@
       if (frame_flags & (XValue | YValue))
 	{
           Arg al[2];
-	  XtSetArg (al [0], XtNwidth,  &frame_w);
-	  XtSetArg (al [1], XtNheight, &frame_h);
+	  Xt_SET_ARG (al [0], XtNwidth,  &frame_w);
+	  Xt_SET_ARG (al [1], XtNheight, &frame_h);
 	  XtGetValues (ew, al, 2);
 
 	  if (frame_flags & XNegative)
@@ -1547,8 +1517,8 @@
 	  if (frame_flags & YNegative)
 	    frame_y += frame_h;
 
-	  XtSetArg (al [0], XtNx, frame_x);
-	  XtSetArg (al [1], XtNy, frame_y);
+	  Xt_SET_ARG (al [0], XtNx, frame_x);
+	  Xt_SET_ARG (al [1], XtNy, frame_y);
 	  XtSetValues (ew, al, 2);
 	}
       return;
@@ -1853,40 +1823,40 @@
       FRAME_X_TOP_LEVEL_FRAME_P (f) = 1;
 
   ac = 0;
-  XtSetArg (al[ac], XtNallowShellResize, True); ac++;
+  Xt_SET_ARG (al[ac], XtNallowShellResize, True); ac++;
 #ifdef LWLIB_USES_MOTIF
   /* Motif sucks beans.  Without this in here, it will delete the window
      out from under us when it receives a WM_DESTROY_WINDOW message
      from the WM. */
-  XtSetArg (al[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
+  Xt_SET_ARG (al[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
 #endif
 
 #ifdef EXTERNAL_WIDGET
   if (window_id)
     {
-      XtSetArg (al[ac], XtNwindow, window_id); ac++;
+      Xt_SET_ARG (al[ac], XtNwindow, window_id); ac++;
     }
   else
 #endif /* EXTERNAL_WIDGET */
     {
-      XtSetArg (al[ac], XtNinput, True);       ac++;
-      XtSetArg (al[ac], XtNminWidthCells, 10); ac++;
-      XtSetArg (al[ac], XtNminHeightCells, 1); ac++;
-      XtSetArg (al[ac], XtNvisual, visual);    ac++;
-      XtSetArg (al[ac], XtNdepth, depth);      ac++;
-      XtSetArg (al[ac], XtNcolormap, cmap);    ac++;
+      Xt_SET_ARG (al[ac], XtNinput, True);       ac++;
+      Xt_SET_ARG (al[ac], XtNminWidthCells, 10); ac++;
+      Xt_SET_ARG (al[ac], XtNminHeightCells, 1); ac++;
+      Xt_SET_ARG (al[ac], XtNvisual, visual);    ac++;
+      Xt_SET_ARG (al[ac], XtNdepth, depth);      ac++;
+      Xt_SET_ARG (al[ac], XtNcolormap, cmap);    ac++;
     }
 
   if (!NILP (overridep))
     {
-      XtSetArg (al[ac], XtNoverrideRedirect, True);    ac++;
+      Xt_SET_ARG (al[ac], XtNoverrideRedirect, True);    ac++;
     }
 
   /* #### maybe we should check for FRAMEP instead? */
   if (!NILP (parent))
     {
       parentwid = FRAME_X_SHELL_WIDGET (XFRAME (parent));
-      XtSetArg (al[ac], XtNtransientFor, parentwid); ac++;
+      Xt_SET_ARG (al[ac], XtNtransientFor, parentwid); ac++;
     }
 
   shell = XtCreatePopupShell ("shell",
@@ -1905,9 +1875,9 @@
 
   /* Create the manager widget */
   ac = 0;
-  XtSetArg (al[ac], XtNvisual, visual); ac++;
-  XtSetArg (al[ac], XtNdepth, depth); ac++;
-  XtSetArg (al[ac], XtNcolormap, cmap); ac++;
+  Xt_SET_ARG (al[ac], XtNvisual, visual); ac++;
+  Xt_SET_ARG (al[ac], XtNdepth, depth); ac++;
+  Xt_SET_ARG (al[ac], XtNcolormap, cmap); ac++;
 
   container = XtCreateWidget ("container",
 			      emacsManagerWidgetClass, shell, al, ac);
@@ -1919,11 +1889,11 @@
 
   /* Create the text area */
   ac = 0;
-  XtSetArg (al[ac], XtNvisual, visual); ac++;
-  XtSetArg (al[ac], XtNdepth, depth); ac++;
-  XtSetArg (al[ac], XtNcolormap, cmap); ac++;
-  XtSetArg (al[ac], XtNborderWidth, 0); ac++; /* should this be settable? */
-  XtSetArg (al[ac], XtNemacsFrame,  f); ac++;
+  Xt_SET_ARG (al[ac], XtNvisual, visual); ac++;
+  Xt_SET_ARG (al[ac], XtNdepth, depth); ac++;
+  Xt_SET_ARG (al[ac], XtNcolormap, cmap); ac++;
+  Xt_SET_ARG (al[ac], XtNborderWidth, 0); ac++; /* should this be settable? */
+  Xt_SET_ARG (al[ac], XtNemacsFrame,  f); ac++;
   text = XtCreateWidget (name, emacsFrameClass, container, al, ac);
   FRAME_X_TEXT_WIDGET (f) = text;
 
@@ -2028,7 +1998,6 @@
   XIM_init_frame (f);
 #endif /* HAVE_XIM */
 
-#ifdef HACK_EDITRES
   /* Allow XEmacs to respond to EditRes requests.  See the O'Reilly Xt */
   /* Intrinsics Programming Manual, Motif Edition, Aug 1993, Sect 14.14, */
   /* pp. 483-493. */
@@ -2037,7 +2006,6 @@
 		     True,                   /* called on non-maskable events? */
 		     (XtEventHandler) _XEditResCheckMessages, /* the handler */
 		     NULL);
-#endif /* HACK_EDITRES */
 
 #ifdef HAVE_CDE
   {
@@ -2073,7 +2041,11 @@
 allocate_x_frame_struct (struct frame *f)
 {
   /* zero out all slots. */
+#ifdef NEW_GC
+  f->frame_data = alloc_lrecord_type (struct x_frame, &lrecord_x_frame);
+#else /* not NEW_GC */
   f->frame_data = xnew_and_zero (struct x_frame);
+#endif /* not NEW_GC */
 
   /* yeah, except the lisp ones */
   FRAME_X_LAST_MENUBAR_BUFFER (f) = Qnil;
@@ -2140,6 +2112,15 @@
    *   We'll just  need to be careful in the modeline specs.
    */
   update_frame_title (f);
+  /* Henry S. Thompson:
+   * Must set icon resource before mapping frame, or some WMs may
+   * lose the icon (openbox).  See <f5bhc3efb17@hildegard.inf.ed.ac.uk>.
+   * SJT:
+   * This probably means that the frame-icon library won't work with
+   * that WM.  Late breaking news: it *does* work, so possibly the
+   * problem at initialization is due to a race condition.
+   */
+  update_frame_icon (f);
 }
 
 static void
@@ -2178,8 +2159,8 @@
   /* Store the X data into the widget. */
   {
     Arg al[2];
-    XtSetArg (al[0], XtNiconPixmap, x_pixmap);
-    XtSetArg (al[1], XtNiconMask,   x_mask);
+    Xt_SET_ARG (al[0], XtNiconPixmap, x_pixmap);
+    Xt_SET_ARG (al[1], XtNiconMask,   x_mask);
     XtSetValues (FRAME_X_SHELL_WIDGET (f), al, 2);
   }
 }
@@ -2244,9 +2225,9 @@
   int win_gravity;
   Arg al[3];
 
-  XtSetArg (al[0], XtNwidth,       &shell_w);
-  XtSetArg (al[1], XtNheight,      &shell_h);
-  XtSetArg (al[2], XtNborderWidth, &shell_bord);
+  Xt_SET_ARG (al[0], XtNwidth,       &shell_w);
+  Xt_SET_ARG (al[1], XtNheight,      &shell_h);
+  Xt_SET_ARG (al[2], XtNborderWidth, &shell_bord);
   XtGetValues (w, al, 3);
 
   win_gravity =
@@ -2263,9 +2244,9 @@
      come back at the right place.  We can't look at s->visible to determine
      whether it is iconified because it might not be up-to-date yet (the queue
      might not be processed). */
-  XtSetArg (al[0], XtNwinGravity, win_gravity);
-  XtSetArg (al[1], XtNx, xoff);
-  XtSetArg (al[2], XtNy, yoff);
+  Xt_SET_ARG (al[0], XtNwinGravity, win_gravity);
+  Xt_SET_ARG (al[1], XtNx, xoff);
+  Xt_SET_ARG (al[2], XtNy, yoff);
   XtSetValues (w, al, 3);
 
   /* Sometimes you will find that
@@ -2295,6 +2276,17 @@
 x_set_frame_size (struct frame *f, int cols, int rows)
 {
   EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), cols, rows);
+
+  if (!wedge_metacity)		/* cf. EmacsFrameResize */
+    {
+      /* Kick the manager so that it knows we've changed size. */
+      XtWidgetGeometry req, repl;
+      req.request_mode = 0;
+      XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
+      EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f),
+			      repl.width, repl.height);
+    }
+
 #if 0
     /* this is not correct.  x_set_frame_size() is called from
        Fset_frame_size(), which may or may not have been called
@@ -2589,8 +2581,7 @@
 	  XSetInputFocus (XtDisplay (shell_widget),
 			  XtWindow (shell_widget),
 			  RevertToParent,
-			  DEVICE_X_MOUSE_TIMESTAMP
-			  (XDEVICE (FRAME_DEVICE (f))));
+			  CurrentTime);
 	  XFlush (XtDisplay (shell_widget));
 	}
     }
@@ -2613,6 +2604,19 @@
   DtDndDropUnregister (FRAME_X_TEXT_WIDGET (f));
 #endif /* HAVE_CDE */
 
+#ifdef USE_XFT
+  /* If we have an XftDraw structure, we need to free it here.
+     We can't ever have an XftDraw without a Display, so we are safe
+     to free it in here, and we avoid too much playing around with the 
+     malloc checking hooks this way. */
+  if (FRAME_X_XFTDRAW (f)) 
+    {
+      XftDrawDestroy (FRAME_X_XFTDRAW (f));
+      FRAME_X_XFTDRAW (f) = NULL;
+    }
+#endif
+
+
   assert (FRAME_X_SHELL_WIDGET (f) != 0);
   dpy = XtDisplay (FRAME_X_SHELL_WIDGET (f));
 
@@ -2642,7 +2646,9 @@
 
   if (f->frame_data)
     {
+#ifndef NEW_GC
       xfree (f->frame_data, void *);
+#endif /* not NEW_GC */
       f->frame_data = 0;
     }
 }
@@ -2663,7 +2669,7 @@
      if (!EQ (color, Vthe_null_color_instance))
        {
 	 fgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color));
-	 XtSetArg (al[ac], XtNforeground, (void *) fgc.pixel); ac++;
+	 Xt_SET_ARG (al[ac], XtNforeground, (void *) fgc.pixel); ac++;
        }
    }
   else if (EQ (name, Qbackground))
@@ -2674,7 +2680,7 @@
      if (!EQ (color, Vthe_null_color_instance))
        {
 	 bgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color));
-	 XtSetArg (al[ac], XtNbackground, (void *) bgc.pixel); ac++;
+	 Xt_SET_ARG (al[ac], XtNbackground, (void *) bgc.pixel); ac++;
        }
 
      /* Really crappy way to force the modeline shadows to be
@@ -2686,11 +2692,39 @@
    {
      Lisp_Object font = FACE_FONT (Vdefault_face, frame, Vcharset_ascii);
 
+     /* It may be that instantiating the font has deleted the frame (will
+	happen if the user has specified a charset registry for ASCII that
+	isn't available on the server, and our fallback of iso8859-1 isn't
+	available; something vanishingly rare.) In that case, return from
+	this function without further manipulation of the dead frame. */
+
+     if (!FRAME_LIVE_P(frm))
+       {
+	 return;
+       }
+
+     /* #### what to do about Xft?  I don't think the font is actually used
+	to compute cell size for computing frame pixel dimensions (see call
+	to EmacsFrameRecomputeCellSize() below); where is it used? -- sjt
+        What does XtSetValues() do if that resource isn't present? */
      if (!EQ (font, Vthe_null_font_instance))
        {
-	 XtSetArg (al[ac], XtNfont,
-		   (void *) FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)));
-	 ac++;
+	 if (0)
+	   ;
+#ifdef USE_XFT
+	 else if (FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font)))
+	   {
+	     Xt_SET_ARG (al[ac], XtNxftFont,
+		       (void *) FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font)));
+	     ac++;
+	   }
+#endif
+	 else if (FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)))
+	   {
+	     Xt_SET_ARG (al[ac], XtNfont,
+			 (void *) FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)));
+	     ac++;
+	   }
        }
    }
   else
@@ -2720,6 +2754,10 @@
 void
 syms_of_frame_x (void)
 {
+#ifdef NEW_GC
+  INIT_LISP_OBJECT (x_frame);
+#endif /* NEW_GC */
+
   DEFSYMBOL (Qoverride_redirect);
   DEFSYMBOL (Qx_resource_name);
 
@@ -2727,9 +2765,6 @@
 #ifdef HAVE_CDE
   DEFSUBR (Fcde_start_drag_internal);
 #endif
-#ifdef HAVE_OFFIX_DND
-  DEFSUBR (Foffix_start_drag_internal);
-#endif
 }
 
 void