mirror of
https://github.com/godotengine/godot.git
synced 2024-11-25 21:52:51 +00:00
Merge pull request #54326 from nekomatata/x11-fix-input-delay
This commit is contained in:
commit
d4067e661c
@ -2725,30 +2725,37 @@ void DisplayServerX11::_poll_events() {
|
|||||||
{
|
{
|
||||||
MutexLock mutex_lock(events_mutex);
|
MutexLock mutex_lock(events_mutex);
|
||||||
|
|
||||||
// Non-blocking wait for next event and remove it from the queue.
|
_check_pending_events(polled_events);
|
||||||
XEvent ev;
|
|
||||||
while (XCheckIfEvent(x11_display, &ev, _predicate_all_events, nullptr)) {
|
|
||||||
// Check if the input manager wants to process the event.
|
|
||||||
if (XFilterEvent(&ev, None)) {
|
|
||||||
// Event has been filtered by the Input Manager,
|
|
||||||
// it has to be ignored and a new one will be received.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle selection request events directly in the event thread, because
|
|
||||||
// communication through the x server takes several events sent back and forth
|
|
||||||
// and we don't want to block other programs while processing only one each frame.
|
|
||||||
if (ev.type == SelectionRequest) {
|
|
||||||
_handle_selection_request_event(&(ev.xselectionrequest));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
polled_events.push_back(ev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
// Check if the input manager wants to process the event.
|
||||||
|
if (XFilterEvent(&ev, None)) {
|
||||||
|
// Event has been filtered by the Input Manager,
|
||||||
|
// it has to be ignored and a new one will be received.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle selection request events directly in the event thread, because
|
||||||
|
// communication through the x server takes several events sent back and forth
|
||||||
|
// and we don't want to block other programs while processing only one each frame.
|
||||||
|
if (ev.type == SelectionRequest) {
|
||||||
|
_handle_selection_request_event(&(ev.xselectionrequest));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
r_events.push_back(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DisplayServerX11::process_events() {
|
void DisplayServerX11::process_events() {
|
||||||
_THREAD_SAFE_METHOD_
|
_THREAD_SAFE_METHOD_
|
||||||
|
|
||||||
@ -2798,6 +2805,9 @@ void DisplayServerX11::process_events() {
|
|||||||
MutexLock mutex_lock(events_mutex);
|
MutexLock mutex_lock(events_mutex);
|
||||||
events = polled_events;
|
events = polled_events;
|
||||||
polled_events.clear();
|
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) {
|
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);
|
static void _poll_events_thread(void *ud);
|
||||||
bool _wait_for_events() const;
|
bool _wait_for_events() const;
|
||||||
void _poll_events();
|
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_all_events(Display *display, XEvent *event, XPointer arg);
|
||||||
static Bool _predicate_clipboard_selection(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