Browse Source

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
Sam Lantinga 2 months ago
parent
commit
ecd089bb69
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/core/unix/SDL_poll.c

+ 2 - 2
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;
         }