From 81b174cace56af924de93b4c32bf18273253b71f Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 31 May 2022 08:47:30 +0800 Subject: [PATCH] Prevent events from being lost waiting for selections on GTK * src/xterm.c (x_wait_for_cell_change): Use GTK to iterate the main loop so events reach the toolkit. --- src/xterm.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/xterm.c b/src/xterm.c index 777a6c4dafc..f6bb97b2f89 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -14858,6 +14858,7 @@ x_wait_for_cell_change (Lisp_Object cell, struct timespec timeout) for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) { +#ifndef USE_GTK if (XPending (dpyinfo->display)) { EVENT_INIT (hold_quit); @@ -14873,6 +14874,7 @@ x_wait_for_cell_change (Lisp_Object cell, struct timespec timeout) if (!NILP (XCAR (cell))) return; } +#endif fd = XConnectionNumber (dpyinfo->display); @@ -14883,6 +14885,33 @@ x_wait_for_cell_change (Lisp_Object cell, struct timespec timeout) FD_SET (XConnectionNumber (dpyinfo->display), &fds); } + /* Prevent events from being lost (from GTK's point of view) by + using GDK to run the event loop. */ +#ifdef USE_GTK + while (gtk_events_pending ()) + { + EVENT_INIT (hold_quit); + current_count = 0; + current_hold_quit = &hold_quit; + current_finish = X_EVENT_NORMAL; + + gtk_main_iteration (); + + current_count = -1; + current_hold_quit = NULL; + + /* Make us quit now. */ + if (hold_quit.kind != NO_EVENT) + kbd_buffer_store_event (&hold_quit); + + if (!NILP (XCAR (cell))) + return; + + if (current_finish == X_EVENT_GOTO_OUT) + break; + } +#endif + eassert (maxfd >= 0); current = current_timespec (); -- 2.39.2