From 2a907bcd4bbcf733931143eb62fe9d7520a011fe Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 5 Dec 2022 19:55:04 +0800 Subject: [PATCH] Don't excessively sync in some other code * 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 | 17 +++-------------- src/frame.h | 1 - src/gtkutil.c | 6 +++--- src/xfns.c | 14 -------------- src/xterm.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 45 insertions(+), 40 deletions(-) diff --git a/configure.ac b/configure.ac index 9f431fc78b2..2770694b9c5 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/frame.h b/src/frame.h index d6fd62b2ac2..dcd32036b86 100644 --- a/src/frame.h +++ b/src/frame.h @@ -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) diff --git a/src/gtkutil.c b/src/gtkutil.c index a6bba096a43..592bb497749 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -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 diff --git a/src/xfns.c b/src/xfns.c index df805d66db9..d713d3c378c 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -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 (); -} - /*********************************************************************** Window properties diff --git a/src/xterm.c b/src/xterm.c index d57830163cb..d3842810c3f 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -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. -- 2.39.2