(x_get_customization_string): Don't use value of strcpy.
[bpt/emacs.git] / src / xterm.c
index e43dba3..30f3403 100644 (file)
@@ -271,6 +271,7 @@ extern Cursor XCreateCursor ();
 extern FONT_TYPE *XOpenFont ();
 
 static void flashback ();
 extern FONT_TYPE *XOpenFont ();
 
 static void flashback ();
+static void redraw_previous_char ();
 
 #ifndef HAVE_X11
 static void dumpqueue ();
 
 #ifndef HAVE_X11
 static void dumpqueue ();
@@ -288,7 +289,7 @@ static int XTclear_end_of_line ();
    of the frame being updated, so that the XT... functions do not
    need to take a frame as argument.  Most of the XT... functions
    should never be called except during an update, the only exceptions
    of the frame being updated, so that the XT... functions do not
    need to take a frame as argument.  Most of the XT... functions
    should never be called except during an update, the only exceptions
-   being XTcursor_to, XTwrite_char and XTreassert_line_highlight.  */
+   being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight.  */
 
 extern int mouse_track_top, mouse_track_left, mouse_track_width;
 
 
 extern int mouse_track_top, mouse_track_left, mouse_track_width;
 
@@ -680,7 +681,9 @@ XTclear_end_of_line (first_unused)
              CHAR_TO_PIXEL_ROW (f, curs_y),
              FONT_WIDTH (f->display.x->font) * (first_unused - curs_x),
              FONT_HEIGHT (f->display.x->font), False);
              CHAR_TO_PIXEL_ROW (f, curs_y),
              FONT_WIDTH (f->display.x->font) * (first_unused - curs_x),
              FONT_HEIGHT (f->display.x->font), False);
-             
+#if 0
+  redraw_previous_char (f, curs_x, curs_y);
+#endif
 #else /* ! defined (HAVE_X11) */
   XPixSet (FRAME_X_WINDOW (f),
           CHAR_TO_PIXEL_COL (f, curs_x),
 #else /* ! defined (HAVE_X11) */
   XPixSet (FRAME_X_WINDOW (f),
           CHAR_TO_PIXEL_COL (f, curs_x),
@@ -693,6 +696,38 @@ XTclear_end_of_line (first_unused)
   UNBLOCK_INPUT;
 }
 
   UNBLOCK_INPUT;
 }
 
+/* Erase the character (if any) at the position just before X, Y in frame F,
+   then redraw it and the character before it.
+   This is necessary when we erase starting at X,
+   in case the character after X overlaps into the one before X.  */
+
+static void
+redraw_previous_char (f, x, y)
+     FRAME_PTR f;
+     int x, y;
+{
+  /* Erase the character before the new ones, in case
+     what was here before overlaps it.
+     Reoutput that character, and the previous character
+     (in case the previous character overlaps it).  */
+  if (x > 0)
+    {
+      int start_x = x - 2;
+      if (start_x < 0)
+       start_x = 0;
+      XClearArea (x_current_display, FRAME_X_WINDOW (f),
+                 CHAR_TO_PIXEL_COL (f, x - 1),
+                 CHAR_TO_PIXEL_ROW (f, y),
+                 FONT_WIDTH (f->display.x->font),
+                 FONT_HEIGHT (f->display.x->font), False);
+
+      dumpglyphs (f, CHAR_TO_PIXEL_COL (f, start_x),
+                 CHAR_TO_PIXEL_ROW (f, y),
+                 &FRAME_CURRENT_GLYPHS (f)->glyphs[y][start_x],
+                 x - start_x, highlight);
+    }
+}
+
 static
 XTclear_frame ()
 {
 static
 XTclear_frame ()
 {
@@ -2861,7 +2896,7 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
              /* The window manager never makes a window invisible
                 ("withdrawn"); all it does is switch between visible
                 and iconified.  Frames get into the invisible state
              /* The window manager never makes a window invisible
                 ("withdrawn"); all it does is switch between visible
                 and iconified.  Frames get into the invisible state
-                only through x_make_frame_invisible.
+                only through x_make_frame_invisible.  */
              if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))
                f->async_iconified = 1;
            }
              if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))
                f->async_iconified = 1;
            }
@@ -2940,7 +2975,16 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
                       || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */
                       || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */
                       || x_is_vendor_fkey (orig_keysym))
                       || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */
                       || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */
                       || x_is_vendor_fkey (orig_keysym))
-                     && ! IsModifierKey (orig_keysym)) /* wherever */
+                     && ! (IsModifierKey (orig_keysym)
+#ifndef HAVE_X11R5
+#ifdef XK_Mode_switch
+                           || ((unsigned)(orig_keysym) == XK_Mode_switch)
+#endif
+#ifdef XK_Num_Lock
+                           || ((unsigned)(orig_keysym) == XK_Num_Lock)
+#endif
+#endif /* not HAVE_X11R5 */
+                           ))
                    {
                      if (temp_index == sizeof temp_buffer / sizeof (short))
                        temp_index = 0;
                    {
                      if (temp_index == sizeof temp_buffer / sizeof (short))
                        temp_index = 0;
@@ -3954,8 +3998,14 @@ x_trace_wire ()
 
 #ifdef HAVE_X11
 
 
 #ifdef HAVE_X11
 
+struct font_info
+{
+  XFontStruct *font;
+  char *name;
+};
+
 /* A table of all the fonts we have already loaded.  */
 /* A table of all the fonts we have already loaded.  */
-static XFontStruct **x_font_table;
+static struct font_info *x_font_table;
 
 /* The current capacity of x_font_table.  */
 static int x_font_table_size;
 
 /* The current capacity of x_font_table.  */
 static int x_font_table_size;
@@ -3978,9 +4028,8 @@ x_new_font (f, fontname)
   /* Get a list of all the fonts that match this name.  Once we
      have a list of matching fonts, we compare them against the fonts
      we already have by comparing font ids.  */
   /* Get a list of all the fonts that match this name.  Once we
      have a list of matching fonts, we compare them against the fonts
      we already have by comparing font ids.  */
-  font_names = (char **) XListFontsWithInfo (x_current_display, fontname,
-                                            1024, &n_matching_fonts,
-                                            &font_info);
+  font_names = (char **) XListFonts (x_current_display, fontname,
+                                    1024, &n_matching_fonts);
   /* Apparently it doesn't set n_matching_fonts to zero when it can't
      find any matches; font_names == 0 is the only clue.  */
   if (! font_names)
   /* Apparently it doesn't set n_matching_fonts to zero when it can't
      find any matches; font_names == 0 is the only clue.  */
   if (! font_names)
@@ -3998,7 +4047,7 @@ x_new_font (f, fontname)
 
       for (i = 0; i < n_fonts; i++)
        for (j = 0; j < n_matching_fonts; j++)
 
       for (i = 0; i < n_fonts; i++)
        for (j = 0; j < n_matching_fonts; j++)
-         if (x_font_table[i]->fid == font_info[j].fid)
+         if (!strcmp (x_font_table[i].name, font_names[j]))
            {
              already_loaded = i;
              fontname = font_names[j];
            {
              already_loaded = i;
              fontname = font_names[j];
@@ -4008,8 +4057,8 @@ x_new_font (f, fontname)
  found_font:
   
   /* If we have, just return it from the table.  */
  found_font:
   
   /* If we have, just return it from the table.  */
-  if (already_loaded > 0)
-    f->display.x->font = x_font_table[already_loaded];
+  if (already_loaded >= 0)
+    f->display.x->font = x_font_table[already_loaded].font;
   
   /* Otherwise, load the font and add it to the table.  */
   else
   
   /* Otherwise, load the font and add it to the table.  */
   else
@@ -4034,9 +4083,9 @@ x_new_font (f, fontname)
       font = (XFontStruct *) XLoadQueryFont (x_current_display, fontname);
       if (! font)
        {
       font = (XFontStruct *) XLoadQueryFont (x_current_display, fontname);
       if (! font)
        {
-         /* Free the information from XListFontsWithInfo.  */
+         /* Free the information from XListFonts.  */
          if (n_matching_fonts)
          if (n_matching_fonts)
-           XFreeFontInfo (font_names, font_info, n_matching_fonts);
+           XFreeFontNames (font_names);
          return Qnil;
        }
 
          return Qnil;
        }
 
@@ -4045,22 +4094,24 @@ x_new_font (f, fontname)
        {
          x_font_table_size = 16;
          x_font_table
        {
          x_font_table_size = 16;
          x_font_table
-           = (XFontStruct **) xmalloc (x_font_table_size
-                                       * sizeof (x_font_table[0]));
+           = (struct font_info *) xmalloc (x_font_table_size
+                                           * sizeof (x_font_table[0]));
        }
       /* Do we need to grow the table?  */
       else if (n_fonts >= x_font_table_size)
        {
          x_font_table_size *= 2;
          x_font_table
        }
       /* Do we need to grow the table?  */
       else if (n_fonts >= x_font_table_size)
        {
          x_font_table_size *= 2;
          x_font_table
-           = (XFontStruct **) xrealloc (x_font_table,
-                                        (x_font_table_size
-                                         * sizeof (x_font_table[0])));
+           = (struct font_info *) xrealloc (x_font_table,
+                                            (x_font_table_size
+                                             * sizeof (x_font_table[0])));
        }
 
        }
 
-      f->display.x->font = x_font_table[n_fonts++] = font;
+      x_font_table[n_fonts].name = (char *) xmalloc (strlen (fontname));
+      bcopy (fontname, x_font_table[n_fonts].name, strlen (fontname) + 1);
+      f->display.x->font = x_font_table[n_fonts++].font = font;
     }
     }
-  
+
   /* Now make the frame display the given font.  */
   if (FRAME_X_WINDOW (f) != 0)
     {
   /* Now make the frame display the given font.  */
   if (FRAME_X_WINDOW (f) != 0)
     {
@@ -4078,9 +4129,9 @@ x_new_font (f, fontname)
     Lisp_Object lispy_name = build_string (fontname);
 
 
     Lisp_Object lispy_name = build_string (fontname);
 
 
-    /* Free the information from XListFontsWithInfo.  The data
+    /* Free the information from XListFonts.  The data
        we actually retain comes from XLoadQueryFont.  */
        we actually retain comes from XLoadQueryFont.  */
-    XFreeFontInfo (font_names, font_info, n_matching_fonts);
+    XFreeFontNames (font_names);
 
     return lispy_name;
   }
 
     return lispy_name;
   }
@@ -4458,6 +4509,14 @@ x_iconify_frame (f)
      IconicState.  */
   x_wm_set_window_state (f, IconicState);
 
      IconicState.  */
   x_wm_set_window_state (f, IconicState);
 
+  if (!FRAME_VISIBLE_P (f))
+    {
+      /* If the frame was withdrawn, before, we must map it.  */
+      XMapWindow (XDISPLAY FRAME_X_WINDOW (f));
+      if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
+       XMapSubwindows (x_current_display, FRAME_X_WINDOW (f));
+    }
+
   f->async_iconified = 1;
 #else /* ! defined (HAVE_X11) */
   XUnmapWindow (XDISPLAY FRAME_X_WINDOW (f));
   f->async_iconified = 1;
 #else /* ! defined (HAVE_X11) */
   XUnmapWindow (XDISPLAY FRAME_X_WINDOW (f));
@@ -4707,15 +4766,18 @@ x_term_init (display_name)
 {
   Lisp_Object frame;
   char *defaultvalue;
 {
   Lisp_Object frame;
   char *defaultvalue;
+#ifndef F_SETOWN_BUG
 #ifdef F_SETOWN
   extern int old_fcntl_owner;
 #endif /* ! defined (F_SETOWN) */
 #ifdef F_SETOWN
   extern int old_fcntl_owner;
 #endif /* ! defined (F_SETOWN) */
+#endif /* F_SETOWN_BUG */
   
   x_focus_frame = x_highlight_frame = 0;
 
   x_current_display = XOpenDisplay (display_name);
   if (x_current_display == 0)
   
   x_focus_frame = x_highlight_frame = 0;
 
   x_current_display = XOpenDisplay (display_name);
   if (x_current_display == 0)
-    fatal ("X server %s not responding; check the DISPLAY environment variable or use \"-d\"\n",
+    fatal ("X server %s not responding.\n\
+Check the DISPLAY environment variable or use \"-d\"\n",
           display_name);
 
 #ifdef HAVE_X11
           display_name);
 
 #ifdef HAVE_X11
@@ -4780,6 +4842,7 @@ x_term_init (display_name)
 
 #endif /* ! defined (HAVE_X11) */
   
 
 #endif /* ! defined (HAVE_X11) */
   
+#ifndef F_SETOWN_BUG
 #ifdef F_SETOWN
   old_fcntl_owner = fcntl (0, F_GETOWN, 0);
 #ifdef F_SETOWN_SOCK_NEG
 #ifdef F_SETOWN
   old_fcntl_owner = fcntl (0, F_GETOWN, 0);
 #ifdef F_SETOWN_SOCK_NEG
@@ -4788,16 +4851,12 @@ x_term_init (display_name)
   fcntl (0, F_SETOWN, getpid ());
 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
 #endif /* ! defined (F_SETOWN) */
   fcntl (0, F_SETOWN, getpid ());
 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
 #endif /* ! defined (F_SETOWN) */
+#endif /* F_SETOWN_BUG */
 
 #ifdef SIGIO
   init_sigio ();
 #endif /* ! defined (SIGIO) */
 
 
 #ifdef SIGIO
   init_sigio ();
 #endif /* ! defined (SIGIO) */
 
-  /* Must use interrupt input because we cannot otherwise
-     arrange for C-g to be noticed immediately.
-     We cannot connect it to SIGINT.  */
-  Fset_input_mode (Qt, Qnil, Qt, Qnil);
-
   expose_all_windows = 0;
 
   clear_frame_hook = XTclear_frame;
   expose_all_windows = 0;
 
   clear_frame_hook = XTclear_frame;
@@ -4832,6 +4891,9 @@ x_term_init (display_name)
                                   off the bottom */
   baud_rate = 19200;
 
                                   off the bottom */
   baud_rate = 19200;
 
+  /* Try to use interrupt input; if we can't, then start polling.  */
+  Fset_input_mode (Qt, Qnil, Qt, Qnil);
+
   /* Note that there is no real way portable across R3/R4 to get the 
      original error handler.  */
   XHandleError (x_error_quitter);
   /* Note that there is no real way portable across R3/R4 to get the 
      original error handler.  */
   XHandleError (x_error_quitter);