1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-31 18:41:20 +00:00

Lower timeout in X11 event thread to fix input delay issue

This commit is contained in:
Chestnut45
2025-12-03 22:07:12 -04:00
parent 8a6408c1ce
commit 3be85a8614
2 changed files with 6 additions and 5 deletions

View File

@@ -4519,7 +4519,7 @@ Bool DisplayServerX11::_predicate_all_events(Display *display, XEvent *event, XP
return True; return True;
} }
bool DisplayServerX11::_wait_for_events() const { bool DisplayServerX11::_wait_for_events(int timeout_seconds, int timeout_microseconds) const {
int x11_fd = ConnectionNumber(x11_display); int x11_fd = ConnectionNumber(x11_display);
fd_set in_fds; fd_set in_fds;
@@ -4529,8 +4529,8 @@ bool DisplayServerX11::_wait_for_events() const {
FD_SET(x11_fd, &in_fds); FD_SET(x11_fd, &in_fds);
struct timeval tv; struct timeval tv;
tv.tv_usec = 0; tv.tv_sec = timeout_seconds;
tv.tv_sec = 1; tv.tv_usec = timeout_microseconds;
// Wait for next event or timeout. // Wait for next event or timeout.
int num_ready_fds = select(x11_fd + 1, &in_fds, nullptr, nullptr, &tv); int num_ready_fds = select(x11_fd + 1, &in_fds, nullptr, nullptr, &tv);
@@ -4549,7 +4549,8 @@ bool DisplayServerX11::_wait_for_events() const {
void DisplayServerX11::_poll_events() { void DisplayServerX11::_poll_events() {
while (!events_thread_done.is_set()) { while (!events_thread_done.is_set()) {
_wait_for_events(); // Wait with a shorter timeout from the events thread to avoid delayed inputs.
_wait_for_events(0, 1000);
// Process events from the queue. // Process events from the queue.
{ {

View File

@@ -379,7 +379,7 @@ class DisplayServerX11 : public DisplayServer {
SafeFlag events_thread_done; SafeFlag events_thread_done;
LocalVector<XEvent> polled_events; LocalVector<XEvent> polled_events;
static void _poll_events_thread(void *ud); static void _poll_events_thread(void *ud);
bool _wait_for_events() const; bool _wait_for_events(int timeout_seconds = 1, int timeout_microseconds = 0) const;
void _poll_events(); void _poll_events();
void _check_pending_events(LocalVector<XEvent> &r_events); void _check_pending_events(LocalVector<XEvent> &r_events);