]> code.delx.au - gnu-emacs/blobdiff - src/xterm.c
* lisp/emacs-lisp/package.el: Fix selected-package logic
[gnu-emacs] / src / xterm.c
index 3955d027a528c832ab8375659ce47452c7248dcb..06ce7070bcac163fa28cabe1c65aea2b333c100b 100644 (file)
@@ -212,7 +212,7 @@ enum xembed_message
   };
 
 static bool x_alloc_nearest_color_1 (Display *, Colormap, XColor *);
-static void x_set_window_size_1 (struct frame *, bool, int, int, bool);
+static void x_set_window_size_1 (struct frame *, bool, int, int);
 static void x_raise_frame (struct frame *);
 static void x_lower_frame (struct frame *);
 static const XColor *x_color_cells (Display *, int *);
@@ -259,7 +259,7 @@ static int x_dispatch_event (XEvent *, Display *);
 #endif
 /* Don't declare this _Noreturn because we want no
    interference with debugging failing X calls.  */
-static void x_connection_closed (Display *, const char *);
+static void x_connection_closed (Display *, const char *, bool);
 static void x_wm_set_window_state (struct frame *, int);
 static void x_wm_set_icon_pixmap (struct frame *, ptrdiff_t);
 static void x_initialize (void);
@@ -1285,7 +1285,7 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
        {
          sprintf (buf, "%0*X",
                   glyph->u.glyphless.ch < 0x10000 ? 4 : 6,
-                  glyph->u.glyphless.ch);
+                  glyph->u.glyphless.ch + 0u);
          str = buf;
        }
 
@@ -1378,9 +1378,9 @@ x_alloc_lighter_color_for_widget (Widget widget, Display *display, Colormap cmap
 
 static XtConvertArgRec cvt_string_to_pixel_args[] =
   {
-    {XtWidgetBaseOffset, (XtPointer) XtOffset (Widget, core.screen),
+    {XtWidgetBaseOffset, (XtPointer) offsetof (WidgetRec, core.screen),
      sizeof (Screen *)},
-    {XtWidgetBaseOffset, (XtPointer) XtOffset (Widget, core.colormap),
+    {XtWidgetBaseOffset, (XtPointer) offsetof (WidgetRec, core.colormap),
      sizeof (Colormap)}
   };
 
@@ -2896,6 +2896,9 @@ x_draw_glyph_string (struct glyph_string *s)
 static void
 x_shift_glyphs_for_insert (struct frame *f, int x, int y, int width, int height, int shift_by)
 {
+/* Never called on a GUI frame, see
+   http://lists.gnu.org/archive/html/emacs-devel/2015-05/msg00456.html
+*/
   XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), FRAME_X_WINDOW (f),
             f->output_data.x->normal_gc,
             x, y, width, height,
@@ -6575,6 +6578,10 @@ x_net_wm_state (struct frame *f, Window window)
       break;
     }
 
+  frame_size_history_add
+    (f, Qx_net_wm_state, 0, 0,
+     list2 (get_frame_param (f, Qfullscreen), lval));
+
   store_frame_param (f, Qfullscreen, lval);
 /**   store_frame_param (f, Qsticky, sticky ? Qt : Qnil); **/
 }
@@ -7006,11 +7013,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
       goto OTHER;
 
     case MapNotify:
-      if (event->xmap.window == tip_window)
-        /* The tooltip has been drawn already.  Avoid
-           the SET_FRAME_GARBAGED below.  */
-        goto OTHER;
-
       /* We use x_top_window_to_frame because map events can
          come for sub-windows and they don't mean that the
          frame is visible.  */
@@ -7057,17 +7059,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 
       f = any;
 
-#if ! defined (USE_GTK)
       /* If mouse-highlight is an integer, input clears out
         mouse highlighting.  */
       if (!hlinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
+#if ! defined (USE_GTK)
          && (f == 0
-             || !EQ (f->tool_bar_window, hlinfo->mouse_face_window)))
+             || !EQ (f->tool_bar_window, hlinfo->mouse_face_window))
+#endif
+         )
         {
           clear_mouse_face (hlinfo);
           hlinfo->mouse_face_hidden = true;
         }
-#endif
 
 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
       if (f == 0)
@@ -7540,6 +7543,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
         {
          x_net_wm_state (f, event->xconfigure.window);
 
+#ifdef USE_X_TOOLKIT
+          /* Tip frames are pure X window, set size for them.  */
+          if (! NILP (tip_frame) && XFRAME (tip_frame) == f)
+            {
+              if (FRAME_PIXEL_HEIGHT (f) != event->xconfigure.height
+                  || FRAME_PIXEL_WIDTH (f) != event->xconfigure.width)
+                SET_FRAME_GARBAGED (f);
+              FRAME_PIXEL_HEIGHT (f) = event->xconfigure.height;
+              FRAME_PIXEL_WIDTH (f) = event->xconfigure.width;
+            }
+#endif
+
 #ifndef USE_X_TOOLKIT
 #ifndef USE_GTK
           int width = FRAME_PIXEL_TO_TEXT_WIDTH (f, event->xconfigure.width);
@@ -8445,7 +8460,7 @@ static char *error_msg;
    the text of an error message that lead to the connection loss.  */
 
 static void
-x_connection_closed (Display *dpy, const char *error_message)
+x_connection_closed (Display *dpy, const char *error_message, bool ioerror)
 {
   struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
   Lisp_Object frame, tail;
@@ -8464,6 +8479,7 @@ x_connection_closed (Display *dpy, const char *error_message)
       dpyinfo->reference_count++;
       dpyinfo->terminal->reference_count++;
     }
+  if (ioerror) dpyinfo->display = 0;
 
   /* First delete frames whose mini-buffers are on frames
      that are on the dead display.  */
@@ -8601,7 +8617,7 @@ x_error_quitter (Display *display, XErrorEvent *event)
   XGetErrorText (display, event->error_code, buf, sizeof (buf));
   sprintf (buf1, "X protocol error: %s on protocol request %d",
           buf, event->request_code);
-  x_connection_closed (display, buf1);
+  x_connection_closed (display, buf1, false);
 }
 
 
@@ -8616,7 +8632,7 @@ x_io_error_quitter (Display *display)
 
   snprintf (buf, sizeof buf, "Connection lost to X server `%s'",
            DisplayString (display));
-  x_connection_closed (display, buf);
+  x_connection_closed (display, buf, true);
   return 0;
 }
 \f
@@ -9227,30 +9243,86 @@ do_ewmh_fullscreen (struct frame *f)
                           None);
           break;
         case FULLSCREEN_WIDTH:
-          if (cur == FULLSCREEN_BOTH || cur == FULLSCREEN_HEIGHT
-              || cur == FULLSCREEN_MAXIMIZED)
-            set_wm_state (frame, false, dpyinfo->Xatom_net_wm_state_fullscreen,
-                          dpyinfo->Xatom_net_wm_state_maximized_vert);
-          if (cur != FULLSCREEN_MAXIMIZED)
-            set_wm_state (frame, true,
-                         dpyinfo->Xatom_net_wm_state_maximized_horz, None);
+         if (x_frame_normalize_before_maximize && cur == FULLSCREEN_MAXIMIZED)
+           {
+             set_wm_state (frame, false,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert);
+             set_wm_state (frame, true,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz, None);
+           }
+         else
+           {
+             if (cur == FULLSCREEN_BOTH || cur == FULLSCREEN_HEIGHT
+                 || cur == FULLSCREEN_MAXIMIZED)
+               set_wm_state (frame, false, dpyinfo->Xatom_net_wm_state_fullscreen,
+                             dpyinfo->Xatom_net_wm_state_maximized_vert);
+             if (cur != FULLSCREEN_MAXIMIZED || x_frame_normalize_before_maximize)
+               set_wm_state (frame, true,
+                             dpyinfo->Xatom_net_wm_state_maximized_horz, None);
+           }
           break;
         case FULLSCREEN_HEIGHT:
-          if (cur == FULLSCREEN_BOTH || cur == FULLSCREEN_WIDTH
-              || cur == FULLSCREEN_MAXIMIZED)
-            set_wm_state (frame, false, dpyinfo->Xatom_net_wm_state_fullscreen,
-                          dpyinfo->Xatom_net_wm_state_maximized_horz);
-          if (cur != FULLSCREEN_MAXIMIZED)
-            set_wm_state (frame, true,
-                         dpyinfo->Xatom_net_wm_state_maximized_vert, None);
+         if (x_frame_normalize_before_maximize && cur == FULLSCREEN_MAXIMIZED)
+           {
+             set_wm_state (frame, false,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert);
+             set_wm_state (frame, true,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert, None);
+           }
+         else
+           {
+             if (cur == FULLSCREEN_BOTH || cur == FULLSCREEN_WIDTH
+                 || cur == FULLSCREEN_MAXIMIZED)
+               set_wm_state (frame, false, dpyinfo->Xatom_net_wm_state_fullscreen,
+                             dpyinfo->Xatom_net_wm_state_maximized_horz);
+             if (cur != FULLSCREEN_MAXIMIZED || x_frame_normalize_before_maximize)
+               set_wm_state (frame, true,
+                             dpyinfo->Xatom_net_wm_state_maximized_vert, None);
+           }
           break;
         case FULLSCREEN_MAXIMIZED:
-          if (cur == FULLSCREEN_BOTH)
-            set_wm_state (frame, false, dpyinfo->Xatom_net_wm_state_fullscreen,
-                         None);
-          set_wm_state (frame, true,
-                       dpyinfo->Xatom_net_wm_state_maximized_horz,
-                        dpyinfo->Xatom_net_wm_state_maximized_vert);
+         if (x_frame_normalize_before_maximize && cur == FULLSCREEN_BOTH)
+           {
+             set_wm_state (frame, false,
+                           dpyinfo->Xatom_net_wm_state_fullscreen, None);
+             set_wm_state (frame, true,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert);
+           }
+         else if (x_frame_normalize_before_maximize && cur == FULLSCREEN_WIDTH)
+           {
+             set_wm_state (frame, false,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz, None);
+             set_wm_state (frame, true,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert);
+           }
+         else if (x_frame_normalize_before_maximize && cur == FULLSCREEN_HEIGHT)
+           {
+             set_wm_state (frame, false,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert, None);
+             set_wm_state (frame, true,
+                           dpyinfo->Xatom_net_wm_state_maximized_horz,
+                           dpyinfo->Xatom_net_wm_state_maximized_vert);
+           }
+         else
+           {
+             if (cur == FULLSCREEN_BOTH)
+               set_wm_state (frame, false, dpyinfo->Xatom_net_wm_state_fullscreen,
+                             None);
+             else if (cur == FULLSCREEN_HEIGHT)
+               set_wm_state (frame, true,
+                             dpyinfo->Xatom_net_wm_state_maximized_horz, None);
+             else if (cur == FULLSCREEN_WIDTH)
+               set_wm_state (frame, true, None,
+                             dpyinfo->Xatom_net_wm_state_maximized_vert);
+             else
+               set_wm_state (frame, true,
+                             dpyinfo->Xatom_net_wm_state_maximized_horz,
+                             dpyinfo->Xatom_net_wm_state_maximized_vert);
+           }
           break;
         case FULLSCREEN_NONE:
           if (cur == FULLSCREEN_BOTH)
@@ -9307,6 +9379,10 @@ x_handle_net_wm_state (struct frame *f, const XPropertyEvent *event)
       break;
     }
 
+  frame_size_history_add
+    (f, Qx_handle_net_wm_state, 0, 0,
+     list2 (get_frame_param (f, Qfullscreen), lval));
+
   store_frame_param (f, Qfullscreen, lval);
   store_frame_param (f, Qsticky, sticky ? Qt : Qnil);
 
@@ -9343,13 +9419,26 @@ x_check_fullscreen (struct frame *f)
           break;
         case FULLSCREEN_WIDTH:
           width = x_display_pixel_width (dpyinfo);
-          break;
+         height = height + FRAME_MENUBAR_HEIGHT (f);
+         break;
         case FULLSCREEN_HEIGHT:
           height = x_display_pixel_height (dpyinfo);
         }
 
+      frame_size_history_add
+       (f, Qx_check_fullscreen, width, height, Qnil);
+
       XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
-                     width, height);
+                    width, height);
+
+      if (FRAME_VISIBLE_P (f))
+       x_wait_for_event (f, ConfigureNotify);
+      else
+       {
+         change_frame_size (f, width, height - FRAME_MENUBAR_HEIGHT (f),
+                            false, true, false, true);
+         x_sync (f);
+       }
     }
 }
 
@@ -9490,21 +9579,57 @@ x_wait_for_event (struct frame *f, int eventtype)
 
 static void
 x_set_window_size_1 (struct frame *f, bool change_gravity,
-                    int width, int height, bool pixelwise)
+                    int width, int height)
 {
-  int pixelwidth, pixelheight;
-
-  pixelwidth = (pixelwise
-               ? FRAME_TEXT_TO_PIXEL_WIDTH (f, width)
-               : FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width));
-  pixelheight = ((pixelwise
-                 ? FRAME_TEXT_TO_PIXEL_HEIGHT (f, height)
-                 : FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height)));
+  int pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width);
+  int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height);
+  int old_width = FRAME_PIXEL_WIDTH (f);
+  int old_height = FRAME_PIXEL_HEIGHT (f);
+  Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
 
   if (change_gravity) f->win_gravity = NorthWestGravity;
   x_wm_set_size_hint (f, 0, false);
-  XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
-                pixelwidth, pixelheight + FRAME_MENUBAR_HEIGHT (f));
+
+  /* When the frame is fullheight and we only want to change the width
+     or it is fullwidth and we only want to change the height we should
+     be able to preserve the fullscreen property.  However, due to the
+     fact that we have to send a resize request anyway, the window
+     manager will abolish it.  At least the respective size should
+     remain unchanged but giving the frame back its normal size will
+     be broken ... */
+  if (EQ (fullscreen, Qfullwidth) && width == FRAME_TEXT_WIDTH (f))
+    {
+      frame_size_history_add
+       (f, Qxg_frame_set_char_size_1, width, height,
+        list2 (make_number (old_height),
+               make_number (pixelheight + FRAME_MENUBAR_HEIGHT (f))));
+
+      XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                    old_width, pixelheight + FRAME_MENUBAR_HEIGHT (f));
+    }
+  else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f))
+    {
+      frame_size_history_add
+       (f, Qxg_frame_set_char_size_2, width, height,
+        list2 (make_number (old_width), make_number (pixelwidth)));
+
+      XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                    pixelwidth, old_height);
+    }
+
+  else
+    {
+      frame_size_history_add
+       (f, Qxg_frame_set_char_size_3, width, height,
+        list2 (make_number (pixelwidth + FRAME_TOOLBAR_WIDTH (f)),
+               make_number (pixelheight + FRAME_TOOLBAR_HEIGHT (f)
+                            + FRAME_MENUBAR_HEIGHT (f))));
+
+      XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                    pixelwidth, pixelheight + FRAME_MENUBAR_HEIGHT (f));
+      fullscreen = Qnil;
+    }
+
 
 
   /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
@@ -9531,7 +9656,16 @@ x_set_window_size_1 (struct frame *f, bool change_gravity,
      not right if the frame is visible.  Instead wait (with timeout)
      for the ConfigureNotify.  */
   if (FRAME_VISIBLE_P (f))
-    x_wait_for_event (f, ConfigureNotify);
+    {
+      x_wait_for_event (f, ConfigureNotify);
+
+      if (!NILP (fullscreen))
+       /* Try to restore fullscreen state.  */
+       {
+         store_frame_param (f, Qfullscreen, fullscreen);
+         x_set_fullscreen (f, fullscreen, fullscreen);
+       }
+    }
   else
     {
       change_frame_size (f, width, height, false, true, false, true);
@@ -9578,20 +9712,21 @@ x_set_window_size (struct frame *f, bool change_gravity,
     }
 #endif
 
+  /* Pixelize width and height, if necessary.  */
+  if (! pixelwise)
+    {
+      width = width * FRAME_COLUMN_WIDTH (f);
+      height = height * FRAME_LINE_HEIGHT (f);
+    }
+
 #ifdef USE_GTK
   if (FRAME_GTK_WIDGET (f))
-    if (! pixelwise)
-      xg_frame_set_char_size (f, width * FRAME_COLUMN_WIDTH (f),
-                             height * FRAME_LINE_HEIGHT (f));
-    else
-      xg_frame_set_char_size (f, width, height);
+    xg_frame_set_char_size (f, width, height);
   else
-    x_set_window_size_1 (f, change_gravity, width, height, pixelwise);
+    x_set_window_size_1 (f, change_gravity, width, height);
 #else /* not USE_GTK */
-
-  x_set_window_size_1 (f, change_gravity, width, height, pixelwise);
+  x_set_window_size_1 (f, change_gravity, width, height);
   x_clear_under_internal_border (f);
-
 #endif /* not USE_GTK */
 
   /* If cursor was outside the new size, mark it as off.  */
@@ -10561,7 +10696,10 @@ get_bits_and_offset (unsigned long mask, int *bits, int *offset)
 bool
 x_display_ok (const char *display)
 {
+  /* XOpenDisplay fails if it gets a signal.  Block SIGIO which may arrive.  */
+  unrequest_sigio ();
   Display *dpy = XOpenDisplay (display);
+  request_sigio ();
   if (!dpy)
     return false;
   XCloseDisplay (dpy);
@@ -10741,7 +10879,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 
         /* gtk_init does set_locale.  Fix locale before and after.  */
         fixup_locale ();
+        unrequest_sigio (); /* See comment in x_display_ok.  */
         gtk_init (&argc, &argv2);
+        request_sigio ();
         fixup_locale ();
 
         g_log_remove_handler ("GLib", id);
@@ -10791,10 +10931,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
        argv[argc++] = xrm_option;
       }
     turn_on_atimers (false);
+    unrequest_sigio ();  /* See comment in x_display_ok.  */
     dpy = XtOpenDisplay (Xt_app_con, SSDATA (display_name),
                         resource_name, EMACS_CLASS,
                         emacs_options, XtNumber (emacs_options),
                         &argc, argv);
+    request_sigio ();
     turn_on_atimers (true);
 
 #ifdef HAVE_X11XTR6
@@ -10805,7 +10947,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 
 #else /* not USE_X_TOOLKIT */
   XSetLocaleModifiers ("");
+  unrequest_sigio ();  // See comment in x_display_ok.
   dpy = XOpenDisplay (SSDATA (display_name));
+  request_sigio ();
 #endif /* not USE_X_TOOLKIT */
 #endif /* not USE_GTK*/
 
@@ -11309,7 +11453,7 @@ static struct redisplay_interface x_redisplay_interface =
     x_draw_window_cursor,
     x_draw_vertical_window_border,
     x_draw_window_divider,
-    x_shift_glyphs_for_insert,
+    x_shift_glyphs_for_insert, /* Never called; see comment in function.  */
     x_show_hourglass,
     x_hide_hourglass
   };
@@ -11602,4 +11746,17 @@ default is nil, which is the same as `super'.  */);
                                     make_float (DEFAULT_REHASH_SIZE),
                                     make_float (DEFAULT_REHASH_THRESHOLD),
                                     Qnil);
+
+  DEFVAR_BOOL ("x-frame-normalize-before-maximize",
+              x_frame_normalize_before_maximize,
+    doc: /* Non-nil means normalize frame before maximizing.
+If this variable is t, Emacs first asks the window manager to give the
+frame its normal size, and only then the final state, whenever changing
+from a full-height, full-width or full-both state to the maximized one
+or when changing from the maximized to the full-height or full-width
+state.
+
+Set this variable only if your window manager cannot handle the
+transition between the various maximization states.  */);
+  x_frame_normalize_before_maximize = false;
 }