From d4ffe043fce3dab1d4e093832ab467b7f7dcf461 Mon Sep 17 00:00:00 2001 From: staruwos Date: Fri, 7 Nov 2025 13:41:56 -0300 Subject: [PATCH 1/3] Fix mouse accumulation logic for x11 --- platform/linuxbsd/x11/display_server_x11.cpp | 26 +++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 674117c63a24..d3a9b8350212 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -5291,23 +5291,31 @@ void DisplayServerX11::process_events() { focused_window_id = MAIN_WINDOW_ID; } - while (true) { - if (mouse_mode == MOUSE_MODE_CAPTURED && event.xmotion.x == windows[focused_window_id].size.width / 2 && event.xmotion.y == windows[focused_window_id].size.height / 2) { - //this is likely the warp event since it was warped here - center = Vector2(event.xmotion.x, event.xmotion.y); - break; - } + // Check for warp event first + if (mouse_mode == MOUSE_MODE_CAPTURED && event.xmotion.x == windows[focused_window_id].size.width / 2 && event.xmotion.y == windows[focused_window_id].size.height / 2) { + center = Vector2(event.xmotion.x, event.xmotion.y); + break; + } - if (event_index + 1 < events.size()) { + // If not a warp, check for accumulation + if (Input::get_singleton()->is_using_accumulated_input()) { + // Accumulate all subsequent motion events, + // but stop if we see a warp event. + while (event_index + 1 < events.size()) { const XEvent &next_event = events[event_index + 1]; if (next_event.type == MotionNotify) { + // Check if the *next* event is a warp. If so, stop accumulating. + if (mouse_mode == MOUSE_MODE_CAPTURED && + next_event.xmotion.x == windows[focused_window_id].size.width / 2 && + next_event.xmotion.y == windows[focused_window_id].size.height / 2) { + break; + } + ++event_index; event = next_event; } else { break; } - } else { - break; } } From 48c1b6b6bf586e2eef2cf78d89f98da55d8b33d9 Mon Sep 17 00:00:00 2001 From: staruwos Date: Fri, 7 Nov 2025 14:15:02 -0300 Subject: [PATCH 2/3] fix code style --- platform/linuxbsd/x11/display_server_x11.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index d3a9b8350212..15e71fd11919 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -5292,7 +5292,9 @@ void DisplayServerX11::process_events() { } // Check for warp event first - if (mouse_mode == MOUSE_MODE_CAPTURED && event.xmotion.x == windows[focused_window_id].size.width / 2 && event.xmotion.y == windows[focused_window_id].size.height / 2) { + if (mouse_mode == MOUSE_MODE_CAPTURED && + event.xmotion.x == windows[focused_window_id].size.width / 2 && + event.xmotion.y == windows[focused_window_id].size.height / 2) { center = Vector2(event.xmotion.x, event.xmotion.y); break; } From d0567de3fcbb0c02474f1086a2cf7f3ac0864cee Mon Sep 17 00:00:00 2001 From: staruwos Date: Fri, 7 Nov 2025 14:28:14 -0300 Subject: [PATCH 3/3] Fix code style using clang-format --- platform/linuxbsd/x11/display_server_x11.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 15e71fd11919..433cb708ca74 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -5292,8 +5292,8 @@ void DisplayServerX11::process_events() { } // Check for warp event first - if (mouse_mode == MOUSE_MODE_CAPTURED && - event.xmotion.x == windows[focused_window_id].size.width / 2 && + if (mouse_mode == MOUSE_MODE_CAPTURED && + event.xmotion.x == windows[focused_window_id].size.width / 2 && event.xmotion.y == windows[focused_window_id].size.height / 2) { center = Vector2(event.xmotion.x, event.xmotion.y); break; @@ -5308,11 +5308,11 @@ void DisplayServerX11::process_events() { if (next_event.type == MotionNotify) { // Check if the *next* event is a warp. If so, stop accumulating. if (mouse_mode == MOUSE_MODE_CAPTURED && - next_event.xmotion.x == windows[focused_window_id].size.width / 2 && - next_event.xmotion.y == windows[focused_window_id].size.height / 2) { + next_event.xmotion.x == windows[focused_window_id].size.width / 2 && + next_event.xmotion.y == windows[focused_window_id].size.height / 2) { break; } - + ++event_index; event = next_event; } else {