From f424ef88e2cae6d3fb06041d63902af2b8cffe9b Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Fri, 7 Jan 2022 22:09:13 +0900 Subject: [PATCH] Handle internal events specially on PGTK * src/xgselect.c (xg_select): If there are pending events already, don't sleep. --- src/xgselect.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/xgselect.c b/src/xgselect.c index 674c259db76..d22340fc9bc 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -96,10 +96,17 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds, int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1; int i, nfds, tmo_in_millisec, must_free = 0; bool need_to_dispatch; +#ifdef HAVE_PGTK + bool already_has_events; +#endif context = g_main_context_default (); acquire_select_lock (context); +#ifdef HAVE_PGTK + already_has_events = g_main_context_pending (context); +#endif + if (rfds) all_rfds = *rfds; else FD_ZERO (&all_rfds); if (wfds) all_wfds = *wfds; @@ -146,10 +153,41 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds, tmop = &tmo; } +#ifndef HAVE_PGTK fds_lim = max_fds + 1; nfds = thread_select (pselect, fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL, efds, tmop, sigmask); +#else + /* + On PGTK, when you type a key, the key press event are received, + and one more key press event seems to be received internally. + The second event is not via a socket, so there are weird status: + - socket read buffer is empty + - a key press event is pending + In that case, we should not sleep, and dispatch the event immediately. + Bug#52761 + */ + if (!already_has_events) + { + fds_lim = max_fds + 1; + nfds = thread_select (pselect, fds_lim, + &all_rfds, have_wfds ? &all_wfds : NULL, efds, + tmop, sigmask); + } + else + { + /* Emulate return values */ + nfds = 1; + FD_ZERO (&all_rfds); + if (have_wfds) + FD_ZERO (&all_wfds); + if (efds) + FD_ZERO (efds); + our_fds++; + } +#endif + if (nfds < 0) retval = nfds; else if (nfds > 0) -- 2.39.2