Skip to content

Commit 05f779f

Browse files
committed
wayland: Cap the max key repeat elapsed time
Cap the elapsed time to something sane in case the compositor sends a bad timestamp, which can result it in it looking like the key has been pressed for a *very* long time, bringing everything to a halt while it tries to enqueue all the repeat events.
1 parent 20e8ac0 commit 05f779f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/video/wayland/SDL_waylandevents.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ void Wayland_DisplayInitCursorShapeManager(SDL_VideoData *display)
308308
static bool keyboard_repeat_handle(SDL_WaylandKeyboardRepeat *repeat_info, Uint64 elapsed)
309309
{
310310
bool ret = false;
311+
312+
/* Cap the elapsed time to something sane in case the compositor sends a bad timestamp,
313+
* which can result it in it looking like the key has been pressed for a *very* long time,
314+
* bringing everything to a halt while it tries to enqueue all the repeat events.
315+
*
316+
* 3 seconds seems reasonable.
317+
*/
318+
elapsed = SDL_min(elapsed, SDL_MS_TO_NS(3000));
319+
311320
while (elapsed >= repeat_info->next_repeat_ns) {
312321
if (repeat_info->scancode != SDL_SCANCODE_UNKNOWN) {
313322
const Uint64 timestamp = repeat_info->wl_press_time_ns + repeat_info->next_repeat_ns;

0 commit comments

Comments
 (0)