Handle internal events specially on PGTK

* src/xgselect.c (xg_select): If there are pending events already,
don't sleep.
This commit is contained in:
Yuuki Harano 2022-01-07 22:09:13 +09:00
parent a263824ae3
commit f424ef88e2

View file

@ -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)