From: Po Lu Date: Mon, 20 Jun 2022 12:56:49 +0000 (+0800) Subject: Fix x-selection-timeout if some keyboard input arrives while waiting X-Git-Tag: emacs-29.0.90~1447^2~1585 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4cc2f820b500ed2f8fad9baa2cf4a057f271a006;p=emacs.git Fix x-selection-timeout if some keyboard input arrives while waiting * src/process.c (wait_reading_process_output): Don't allow skipping calls to select if detect_input_pending when just waiting for a cell. (bug#46935) * src/xselect.c (x_get_foreign_selection): Add more debugging code. --- diff --git a/src/process.c b/src/process.c index 0cbac172fe4..8f654961482 100644 --- a/src/process.c +++ b/src/process.c @@ -5492,7 +5492,17 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, triggered by processing X events). In the latter case, set nfds to 1 to avoid breaking the loop. */ no_avail = 0; - if ((read_kbd || !NILP (wait_for_cell)) + if ((read_kbd + /* The following code doesn't make any sense for just the + wait_or_cell case, because detect_input_pending returns + whether or not the keyboard buffer isn't empty or there + is mouse movement. Any keyboard input that arrives + while waiting for a cell will cause the select call to + be skipped, and gobble_input to be called even when + there is no input available from the terminal itself. + Skipping the call to select also causes the timeout to + be ignored. (bug#46935) */ + /* || !NILP (wait_for_cell) */) && detect_input_pending ()) { nfds = read_kbd ? 0 : 1; diff --git a/src/xselect.c b/src/xselect.c index dd82a906af1..fcf0ee944e2 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -1261,7 +1261,13 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type, intmax_t timeout = max (0, x_selection_timeout); intmax_t secs = timeout / 1000; int nsecs = (timeout % 1000) * 1000000; - TRACE1 (" Start waiting %"PRIdMAX" secs for SelectionNotify", secs); + TRACE1 (" Start waiting %"PRIdMAX" secs for SelectionNotify.", secs); + + if (input_blocked_p ()) + TRACE0 (" Input is blocked."); + else + TRACE1 (" Waiting for %d nsecs in addition.", nsecs); + /* This function can be called with input blocked inside Xt or GTK timeouts run inside popup menus, so use a function that works when input is blocked. Prefer wait_reading_process_output