Don't return short waits from SDL_IOReady()

The Wayland keyboard repeat code assumes that if we have a certain timeout then we'll wait at least that long, and generate a key repeat event on timeout. If we wait a shorter time, we won't generate a key repeat event and then return 0, even if we were supposed to wait indefinitely.

Fixes https://github.com/libsdl-org/SDL/issues/12239
This commit is contained in:
Sam Lantinga
2025-02-10 10:23:22 -08:00
parent 4fd0b2a85c
commit ecd089bb69

View File

@@ -54,7 +54,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
} }
// FIXME: Add support for ppoll() for nanosecond precision // FIXME: Add support for ppoll() for nanosecond precision
if (timeoutNS > 0) { if (timeoutNS > 0) {
timeoutMS = (int)SDL_NS_TO_MS(timeoutNS); timeoutMS = (int)SDL_NS_TO_MS(timeoutNS + (SDL_NS_PER_MS - 1));
} else if (timeoutNS == 0) { } else if (timeoutNS == 0) {
timeoutMS = 0; timeoutMS = 0;
} else { } else {
@@ -82,7 +82,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
if (timeoutNS >= 0) { if (timeoutNS >= 0) {
tv.tv_sec = (timeoutNS / SDL_NS_PER_SECOND); tv.tv_sec = (timeoutNS / SDL_NS_PER_SECOND);
tv.tv_usec = SDL_NS_TO_US(timeoutNS % SDL_NS_PER_SECOND); tv.tv_usec = SDL_NS_TO_US((timeoutNS % SDL_NS_PER_SECOND) + (SDL_NS_PER_US - 1));
tvp = &tv; tvp = &tv;
} }