From ecd089bb6941e0a648c78d0ed8f00676a322f4ff Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 10 Feb 2025 10:23:22 -0800
Subject: [PATCH] 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
---
src/core/unix/SDL_poll.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/core/unix/SDL_poll.c b/src/core/unix/SDL_poll.c
index 9440bff90abd9..572ed5a65b821 100644
--- a/src/core/unix/SDL_poll.c
+++ b/src/core/unix/SDL_poll.c
@@ -54,7 +54,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
}
// FIXME: Add support for ppoll() for nanosecond precision
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) {
timeoutMS = 0;
} else {
@@ -82,7 +82,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
if (timeoutNS >= 0) {
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;
}