(XTread_socket) <KeyPress>: In case XmbLookupString
[bpt/emacs.git] / src / xterm.c
index ba719f7..3b774e3 100644 (file)
@@ -412,7 +412,6 @@ static void set_output_cursor P_ ((struct cursor_pos *));
 static struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int,
                                           int *, int *, int *));
 static void note_mode_line_highlight P_ ((struct window *, int, int));
-static void x_check_font P_ ((struct frame *, XFontStruct *));
 static void note_mouse_highlight P_ ((struct frame *, int, int));
 static void note_tool_bar_highlight P_ ((struct frame *f, int, int));
 static void x_handle_tool_bar_click P_ ((struct frame *, XButtonEvent *));
@@ -1187,7 +1186,7 @@ x_per_char_metric (font, char2b)
     }
 
   return ((pcm == NULL
-          || pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)
+          || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0))
          ? NULL : pcm);
 }
 
@@ -1613,7 +1612,10 @@ x_produce_stretch_glyph (it)
      struct it *it;
 {
   /* (space :width WIDTH :height HEIGHT.  */
-  extern Lisp_Object QCwidth, QCheight, QCascent, Qspace;
+#if GLYPH_DEBUG
+  extern Lisp_Object Qspace;
+#endif
+  extern Lisp_Object QCwidth, QCheight, QCascent;
   extern Lisp_Object QCrelative_width, QCrelative_height;
   extern Lisp_Object QCalign_to;
   Lisp_Object prop, plist;
@@ -2249,8 +2251,9 @@ x_produce_glyphs (it)
   else if (it->what == IT_STRETCH)
     x_produce_stretch_glyph (it);
 
-  /* Accumulate dimensions.  */
-  xassert (it->ascent >= 0 && it->descent > 0);
+  /* Accumulate dimensions.  Note: can't assume that it->descent > 0
+     because this isn't true for images with `:ascent 100'.  */
+  xassert (it->ascent >= 0 && it->descent >= 0);
   if (it->area == TEXT_AREA)
     it->current_x += it->pixel_width;
   
@@ -2490,6 +2493,10 @@ static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int,
 static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *,
                                        enum glyph_row_area));
 
+#if GLYPH_DEBUG
+static void x_check_font P_ ((struct frame *, XFontStruct *));
+#endif
+
 
 /* Append the list of glyph strings with head H and tail T to the list
    with head *HEAD and tail *TAIL.  Set *HEAD and *TAIL to the result.  */
@@ -2849,8 +2856,6 @@ x_get_glyph_overhangs (glyph, f, left, right)
      struct frame *f;
      int *left, *right;
 {
-  int c;
-  
   *left = *right = 0;
   
   if (glyph->type == CHAR_GLYPH)
@@ -3153,21 +3158,20 @@ x_draw_composite_glyph_string_foreground (s)
 
 #ifdef USE_X_TOOLKIT
 
-/* Allocate the color COLOR->pixel on the screen and display of
-   widget WIDGET in colormap CMAP.  If an exact match cannot be
-   allocated, try the nearest color available.  Value is non-zero
-   if successful.  This is called from lwlib.  */
+static struct frame *x_frame_of_widget P_ ((Widget));
 
-int
-x_alloc_nearest_color_for_widget (widget, cmap, color)
+
+/* Return the frame on which widget WIDGET is used.. Abort if frame
+   cannot be determined.  */
+
+struct frame *
+x_frame_of_widget (widget)
      Widget widget;
-     Colormap cmap;
-     XColor *color;
 {
-  struct frame *f;
   struct x_display_info *dpyinfo;
   Lisp_Object tail;
-
+  struct frame *f;
+  
   dpyinfo = x_display_info_for_display (XtDisplay (widget));
   
   /* Find the top-level shell of the widget.  Note that this function
@@ -3185,11 +3189,28 @@ x_alloc_nearest_color_for_widget (widget, cmap, color)
            (f->output_data.nothing != 1
             && FRAME_X_DISPLAY_INFO (f) == dpyinfo))
        && f->output_data.x->widget == widget)
-      return x_alloc_nearest_color (f, cmap, color);
+      return f;
 
   abort ();
 }
 
+
+/* Allocate the color COLOR->pixel on the screen and display of
+   widget WIDGET in colormap CMAP.  If an exact match cannot be
+   allocated, try the nearest color available.  Value is non-zero
+   if successful.  This is called from lwlib.  */
+
+int
+x_alloc_nearest_color_for_widget (widget, cmap, color)
+     Widget widget;
+     Colormap cmap;
+     XColor *color;
+{
+  struct frame *f = x_frame_of_widget (widget);
+  return x_alloc_nearest_color (f, cmap, color);
+}
+
+
 #endif /* USE_X_TOOLKIT */
 
 
@@ -3277,6 +3298,30 @@ x_copy_color (f, pixel)
 }
 
 
+/* Allocate color PIXEL on display DPY.  PIXEL must already be allocated.
+   It's necessary to do this instead of just using PIXEL directly to
+   get color reference counts right.  */
+
+unsigned long
+x_copy_dpy_color (dpy, cmap, pixel)
+     Display *dpy;
+     Colormap cmap;
+     unsigned long pixel;
+{
+  XColor color;
+
+  color.pixel = pixel;
+  BLOCK_INPUT;
+  XQueryColor (dpy, cmap, &color);
+  XAllocColor (dpy, cmap, &color);
+  UNBLOCK_INPUT;
+#ifdef DEBUG_X_COLORS
+  register_color (pixel);
+#endif
+  return color.pixel;
+}
+
+
 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
    or DELTA.  Try a color with RGB values multiplied by FACTOR first.
    If this produces the same color as PIXEL, try a color where all RGB
@@ -3363,8 +3408,6 @@ x_setup_relief_color (f, relief, factor, delta, default_pixel)
   if (relief->gc
       && relief->allocated_p)
     {
-      /* If display has an immutable color map, freeing colors is not
-        necessary and some servers don't allow it.  So don't do it.  */
       x_free_colors (f, &relief->pixel, 1);
       relief->allocated_p = 0;
     }
@@ -4382,7 +4425,7 @@ x_set_glyph_string_background_width (s, start, last_x)
 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
      do                                                                           \
        {                                                                  \
-        int c, charset, face_id;                                          \
+        int c, face_id;                                                   \
         XChar2b *char2b;                                                  \
                                                                           \
         c = (ROW)->glyphs[AREA][START].u.ch;                              \
@@ -6130,7 +6173,7 @@ x_y_to_hpos_vpos (w, x, y, hpos, vpos, area)
      int *hpos, *vpos, *area;
 {
   struct glyph *glyph, *end;
-  struct glyph_row *row;
+  struct glyph_row *row = NULL;
   int x0, i, left_area_width;
 
   /* Find row containing Y.  Give up if some row is not enabled.  */
@@ -7402,7 +7445,7 @@ x_send_scroll_bar_event (window, part, portion, whole)
   ev->display = FRAME_X_DISPLAY (f);
   ev->window = FRAME_X_WINDOW (f);
   ev->format = 32;
-  ev->data.l[0] = (long) window;
+  ev->data.l[0] = (long) XFASTINT (window);
   ev->data.l[1] = (long) part;
   ev->data.l[2] = (long) 0;
   ev->data.l[3] = (long) portion;
@@ -7429,8 +7472,11 @@ x_scroll_bar_to_input_event (event, ievent)
      struct input_event *ievent;
 {
   XClientMessageEvent *ev = (XClientMessageEvent *) event;
-  Lisp_Object window = (Lisp_Object) ev->data.l[0];
-  struct frame *f = XFRAME (XWINDOW (window)->frame);
+  Lisp_Object window;
+  struct frame *f;
+
+  XSETFASTINT (window, ev->data.l[0]);
+  f = XFRAME (XWINDOW (window)->frame);
   
   ievent->kind = scroll_bar_click;
   ievent->frame_or_window = window;
@@ -7884,7 +7930,7 @@ x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
          {
 #ifdef HAVE_XAW3D
            ScrollbarWidget sb = (ScrollbarWidget) widget;
-           int scroll_mode;
+           int scroll_mode = 0;
            
            /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR.  */
            if (xaw3d_arrow_scroll)
@@ -9388,7 +9434,10 @@ XTread_socket (sd, bufp, numchars, expected)
                      if (status_return == XLookupNone)
                        break;
                      else if (status_return == XLookupChars)
-                       keysym = NoSymbol;
+                       {
+                         keysym = NoSymbol;
+                         modifiers = 0;
+                       }
                      else if (status_return != XLookupKeySym
                               && status_return != XLookupBoth)
                        abort ();
@@ -9608,7 +9657,20 @@ XTread_socket (sd, bufp, numchars, expected)
              if (event.xfocus.detail != NotifyPointer)
                dpyinfo->x_focus_event_frame = f;
              if (f)
-               x_new_focus_frame (dpyinfo, f);
+               {
+                 x_new_focus_frame (dpyinfo, f);
+
+                 /* Don't stop displaying the initial startup message
+                    for a switch-frame event we don't need.  */
+                 if (GC_NILP (Vterminal_frame)
+                     && GC_CONSP (Vframe_list)
+                     && !GC_NILP (XCDR (Vframe_list)))
+                   {
+                     bufp->kind = FOCUS_IN_EVENT;
+                     XSETFRAME (bufp->frame_or_window, f);
+                     ++bufp, ++count, --numchars;
+                   }
+               }
 
 #ifdef HAVE_X_I18N
              if (f && FRAME_XIC (f))
@@ -10785,7 +10847,8 @@ x_connection_closed (display, error_message)
 #endif
 #endif
 
-  dpyinfo->display = 0;
+  if (dpyinfo)
+    dpyinfo->display = 0;
 
   /* First delete frames whose mini-buffers are on frames
      that are on the dead display.  */
@@ -10952,7 +11015,6 @@ x_new_fontset (f, fontsetname)
 {
   int fontset = fs_query_fontset (build_string (fontsetname), 0);
   Lisp_Object result;
-  char *fontname;
 
   if (fontset < 0)
     return Qnil;
@@ -11141,7 +11203,10 @@ xim_initialize (dpyinfo, resource_name)
   XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb,
                                  resource_name, EMACS_CLASS,
                                  xim_instantiate_callback,
-                                 (XPointer)xim_inst);
+                                 /* Fixme: This is XPointer in
+                                    XFree86 but (XPointer *) on
+                                    Tru64, at least.  */
+                                 (XPointer) xim_inst);
 #else /* not HAVE_X11R6_XIM */
   dpyinfo->xim = NULL;
   xim_open_dpy (dpyinfo, resource_name);
@@ -11219,7 +11284,7 @@ x_calc_absolute_position (f)
            {
              Window newroot, newparent = 0xdeadbeef;
              Window *newchildren;
-             int nchildren;
+             unsigned int nchildren;
 
              if (! XQueryTree (FRAME_X_DISPLAY (f), this_window, &newroot,
                                &newparent, &newchildren, &nchildren))
@@ -11660,6 +11725,7 @@ x_make_frame_visible (f)
            /* It could be confusing if a real alarm arrives while
               processing the fake one.  Turn it off and let the
               handler reset it.  */
+           extern void poll_for_input_1 P_ ((void));
            int old_poll_suppress_count = poll_suppress_count;
            poll_suppress_count = 1;
            poll_for_input_1 ();
@@ -11891,6 +11957,21 @@ x_destroy_window (f)
       free_frame_menubar (f);
 #endif /* USE_X_TOOLKIT */
 
+      unload_color (f, f->output_data.x->foreground_pixel);
+      unload_color (f, f->output_data.x->background_pixel);
+      unload_color (f, f->output_data.x->cursor_pixel);
+      unload_color (f, f->output_data.x->cursor_foreground_pixel);
+      unload_color (f, f->output_data.x->border_pixel);
+      unload_color (f, f->output_data.x->mouse_pixel);
+      if (f->output_data.x->scroll_bar_background_pixel != -1)
+       unload_color (f, f->output_data.x->scroll_bar_background_pixel);
+      if (f->output_data.x->scroll_bar_foreground_pixel != -1)
+       unload_color (f, f->output_data.x->scroll_bar_foreground_pixel);
+      if (f->output_data.x->white_relief.allocated_p)
+       unload_color (f, f->output_data.x->white_relief.pixel);
+      if (f->output_data.x->black_relief.allocated_p)
+       unload_color (f, f->output_data.x->black_relief.pixel);
+      
       free_frame_faces (f);
       XFlush (FRAME_X_DISPLAY (f));
     }
@@ -12208,7 +12289,7 @@ x_list_fonts (f, pattern, size, maxnames)
   for (; CONSP (patterns); patterns = XCDR (patterns))
     {
       int num_fonts;
-      char **names;
+      char **names = NULL;
 
       pattern = XCAR (patterns);
       /* See if we cached the result for this particular query.