diff --git a/glfw/x11_platform.h b/glfw/x11_platform.h index 5c1386b9f..363044951 100644 --- a/glfw/x11_platform.h +++ b/glfw/x11_platform.h @@ -246,7 +246,7 @@ typedef struct AtomArray { typedef struct XIScrollValuator { double increment, value, min, max; int number, resolution, mode; - bool is_vertical, initialized; + bool is_vertical, initialized, has_value; } XIScrollValuator; typedef struct XIScrollDevice { diff --git a/glfw/x11_window.c b/glfw/x11_window.c index d92ea5afe..01ac6c6b2 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -1308,11 +1308,20 @@ handle_xi_motion_event(_GLFWwindow *window, XIDeviceEvent *de) { scroll_valuator_found = true; if (!v->initialized) { v->initialized = true; - v->value = value; - continue; + if (!v->has_value) { + v->has_value = true; + v->value = value; + continue; + } + const double max_plausible_delta = 10. * (v->increment != 0. ? fabs(v->increment) : 1.); + if (fabs(value - v->value) > max_plausible_delta) { + v->value = value; + continue; + } } double delta = value - v->value; v->value = value; + v->has_value = true; delta *= -1; double *off = v->is_vertical ? &yOffset : &xOffset; *off = delta; @@ -2018,7 +2027,7 @@ processEvent(XEvent *event) { } case LeaveNotify: { - resetScrollValuators(); + if (event->xcrossing.mode == NotifyNormal && event->xcrossing.detail != NotifyInferior) resetScrollValuators(); _glfwInputCursorEnter(window, false); return; }