Don't excessively sync in some other code
authorPo Lu <luangruo@yahoo.com>
Mon, 5 Dec 2022 11:55:04 +0000 (19:55 +0800)
committerPo Lu <luangruo@yahoo.com>
Mon, 5 Dec 2022 11:58:05 +0000 (19:58 +0800)
* configure.ac (USE_XCB): Remove xcb-util dependency.
* src/frame.h: Remove x_sync.
* src/gtkutil.c (xg_frame_restack, xg_update_scrollbar_pos)
(xg_update_horizontal_scrollbar_pos): Call XSync manually
instead of x_sync.
* src/xfns.c (x_sync): Delete unused function.
* src/xterm.c (x_send_hourglass_message): New function.
(x_show_hourglass, x_hide_hourglass): Avoid XSync in these two
pieces of frequently used code.
(handle_one_xevent): Handle hourglass messages.
(x_make_frame_invisible): Stop using x_sync.

configure.ac
src/frame.h
src/gtkutil.c
src/xfns.c
src/xterm.c

index 9f431fc78b2500700e92fd4e086b990e0fa33165..2770694b9c54983e865cfe79c807c412702f6a4d 100644 (file)
@@ -3933,21 +3933,10 @@ if test "${HAVE_X11}" = "yes"; then
   if test "${HAVE_XCB}" = "yes"; then
     AC_CHECK_LIB([X11-xcb], [XGetXCBConnection], [HAVE_X11_XCB=yes])
     if test "${HAVE_X11_XCB}" = "yes"; then
-      AC_CHECK_LIB([xcb-util], [xcb_aux_sync], [HAVE_XCB_UTIL=yes])
-      if test "${HAVE_XCB_UTIL}" = "yes"; then
-       AC_DEFINE([USE_XCB], [1],
+      AC_DEFINE([USE_XCB], [1],
 [Define to 1 if you have the XCB library and X11-XCB library for mixed
-  X11/XCB programming.])
-        XCB_LIBS="-lX11-xcb -lxcb -lxcb-util"
-      else
-       AC_CHECK_LIB([xcb-aux], [xcb_aux_sync], [HAVE_XCB_AUX=yes])
-        if test "${HAVE_XCB_AUX}" = "yes"; then
-         AC_DEFINE([USE_XCB], [1],
-[Define to 1 if you have the XCB library and X11-XCB library for mixed
- X11/XCB programming.])
-          XCB_LIBS="-lX11-xcb -lxcb -lxcb-aux"
-        fi
-      fi
+X11/XCB programming.])
+      XCB_LIBS="-lX11-xcb -lxcb"
     fi
   fi
 fi
index d6fd62b2ac259ee22969046493dd90f3fa49705a..dcd32036b86e0a3fc4a8cbe3524582878dcfe48f 100644 (file)
@@ -1718,7 +1718,6 @@ extern void x_wm_set_icon_position (struct frame *, int, int);
 #if !defined USE_X_TOOLKIT
 extern const char *x_get_resource_string (const char *, const char *);
 #endif
-extern void x_sync (struct frame *);
 #endif /* HAVE_X_WINDOWS */
 
 #if !defined (HAVE_NS) && !defined (HAVE_PGTK)
index a6bba096a43b30a279b8d5a024751e94f366ae45..592bb4977490a50d8792e0f2004269ae684ccdd8 100644 (file)
@@ -2103,7 +2103,7 @@ xg_frame_restack (struct frame *f1, struct frame *f2, bool above_flag)
 
       gdk_window_restack (gwin1, gwin2, above_flag);
 #ifndef HAVE_PGTK
-      x_sync (f1);
+      XSync (FRAME_X_DISPLAY (f1), False);
 #else
       gdk_flush ();
 #endif
@@ -4793,7 +4793,7 @@ xg_update_scrollbar_pos (struct frame *f,
          here to get some events.  */
 
 #ifndef HAVE_PGTK
-      x_sync (f);
+      XSync (FRAME_X_DISPLAY (f), False);
 #else
       gdk_flush ();
 #endif
@@ -4894,7 +4894,7 @@ xg_update_horizontal_scrollbar_pos (struct frame *f,
       }
 
 #ifndef HAVE_PGTK
-      x_sync (f);
+      XSync (FRAME_X_DISPLAY (f), False);
 #else
       gdk_flush ();
 #endif
index df805d66db91cb8b1bf894675ccc643bfb0e8e4e..d713d3c378c707a8594855b85e54ba09ff163828 100644 (file)
@@ -7377,20 +7377,6 @@ If TERMINAL is omitted or nil, that stands for the selected frame's display.  */
   return Qnil;
 }
 
-/* Wait for responses to all X commands issued so far for frame F.  */
-
-void
-x_sync (struct frame *f)
-{
-  block_input ();
-#ifndef USE_XCB
-  XSync (FRAME_X_DISPLAY (f), False);
-#else
-  xcb_aux_sync (FRAME_DISPLAY_INFO (f)->xcb_connection);
-#endif
-  unblock_input ();
-}
-
 \f
 /***********************************************************************
                            Window properties
index d57830163cb66a8a1c29f61d917d5e1960410f73..d3842810c3f02c3c8fd9a86c6725786ddca2510a 100644 (file)
@@ -11005,6 +11005,31 @@ x_clear_frame (struct frame *f)
   unblock_input ();
 }
 
+/* Send a message to frame F telling the event loop to track whether
+   or not an hourglass is being displayed.  This is required to ignore
+   the right events when the hourglass is mapped without callig XSync
+   after displaying or hiding the hourglass.  */
+
+static void
+x_send_hourglass_message (struct frame *f, bool hourglass_enabled)
+{
+  struct x_display_info *dpyinfo;
+  XEvent msg;
+
+  dpyinfo = FRAME_DISPLAY_INFO (f);
+  memset (&msg, 0, sizeof msg);
+
+  msg.xclient.type = ClientMessage;
+  msg.xclient.message_type
+    = dpyinfo->Xatom_EMACS_TMP;
+  msg.xclient.format = 8;
+  msg.xclient.window = FRAME_X_WINDOW (f);
+  msg.xclient.data.b[0] = hourglass_enabled ? 1 : 0;
+
+  XSendEvent (dpyinfo->display, FRAME_X_WINDOW (f),
+             False, NoEventMask, &msg);
+}
+
 /* RIF: Show hourglass cursor on frame F.  */
 
 static void
@@ -11025,14 +11050,14 @@ x_show_hourglass (struct frame *f)
       if (popup_activated ())
        return;
 
+      x_send_hourglass_message (f, true);
+
 #ifdef USE_X_TOOLKIT
       if (x->widget)
 #else
       if (FRAME_OUTER_WINDOW (f))
 #endif
        {
-         x->hourglass_p = true;
-
          if (!x->hourglass_window)
            {
 #ifndef USE_XCB
@@ -11099,15 +11124,11 @@ x_hide_hourglass (struct frame *f)
     {
 #ifndef USE_XCB
       XUnmapWindow (FRAME_X_DISPLAY (f), x->hourglass_window);
-      /* Sync here because XTread_socket looks at the
-        hourglass_p flag that is reset to zero below.  */
-      XSync (FRAME_X_DISPLAY (f), False);
 #else
       xcb_unmap_window (FRAME_DISPLAY_INFO (f)->xcb_connection,
                        (xcb_window_t) x->hourglass_window);
-      xcb_aux_sync (FRAME_DISPLAY_INFO (f)->xcb_connection);
 #endif
-      x->hourglass_p = false;
+      x_send_hourglass_message (f, false);
     }
 }
 
@@ -18620,6 +18641,16 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              }
          }
 
+       if (event->xclient.message_type == dpyinfo->Xatom_EMACS_TMP
+           && event->xclient.format == 8)
+         {
+           /* This is actually an hourglass message.  Set whether or
+              not events from here on have the hourglass enabled.  */
+
+           if (any)
+             FRAME_X_OUTPUT (any)->hourglass_p = event->xclient.data.b[0];
+         }
+
         if (event->xclient.message_type == dpyinfo->Xatom_wm_protocols
             && event->xclient.format == 32)
           {
@@ -28273,7 +28304,7 @@ x_make_frame_invisible (struct frame *f)
        error ("Can't notify window manager of window withdrawal");
       }
 
-  x_sync (f);
+  XSync (FRAME_X_DISPLAY (f), False);
 
   /* We can't distinguish this from iconification
      just by the event that we get from the server.