Fix input events random delay on X11
The new system based on a thread gathering events from the X11 server was causing delays in some scenarios where some events have just been missed at the time of processing and we're waiting for a whole frame to check them again. Solved by flushing again and checking for pending events at the beginning of the process loop, in addition to events already gathered on the event thread.
This commit is contained in:
parent
24fdedfe94
commit
ba96fc6a4d
@ -2725,6 +2725,15 @@ void DisplayServerX11::_poll_events() {
|
||||
{
|
||||
MutexLock mutex_lock(events_mutex);
|
||||
|
||||
_check_pending_events(polled_events);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayServerX11::_check_pending_events(LocalVector<XEvent> &r_events) {
|
||||
// Flush to make sure to gather all pending events.
|
||||
XFlush(x11_display);
|
||||
|
||||
// Non-blocking wait for next event and remove it from the queue.
|
||||
XEvent ev;
|
||||
while (XCheckIfEvent(x11_display, &ev, _predicate_all_events, nullptr)) {
|
||||
@ -2743,9 +2752,7 @@ void DisplayServerX11::_poll_events() {
|
||||
continue;
|
||||
}
|
||||
|
||||
polled_events.push_back(ev);
|
||||
}
|
||||
}
|
||||
r_events.push_back(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2798,6 +2805,9 @@ void DisplayServerX11::process_events() {
|
||||
MutexLock mutex_lock(events_mutex);
|
||||
events = polled_events;
|
||||
polled_events.clear();
|
||||
|
||||
// Check for more pending events to avoid an extra frame delay.
|
||||
_check_pending_events(events);
|
||||
}
|
||||
|
||||
for (uint32_t event_index = 0; event_index < events.size(); ++event_index) {
|
||||
|
@ -268,6 +268,7 @@ class DisplayServerX11 : public DisplayServer {
|
||||
static void _poll_events_thread(void *ud);
|
||||
bool _wait_for_events() const;
|
||||
void _poll_events();
|
||||
void _check_pending_events(LocalVector<XEvent> &r_events);
|
||||
|
||||
static Bool _predicate_all_events(Display *display, XEvent *event, XPointer arg);
|
||||
static Bool _predicate_clipboard_selection(Display *display, XEvent *event, XPointer arg);
|
||||
|
Loading…
Reference in New Issue
Block a user