From df1fda1032cf3b5ff50461acd5f65dfe9ba81e28 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 7 Nov 2026 10:52:51 +0530 Subject: [PATCH] Wayland: Limit rendering to 120 FPS soon after a resize For a second after a resize, render frames are not used, so that the resized buffer is filled immediately. This meant that continuous output was rendered as fast as possible, about 900 FPS, during that second. Now only the first render after the resize is immediate, subsequent renders are limited to 120 FPS, unless a render frame arrives sooner. --- kitty/child-monitor.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index d90dddaeb..777d20eb3 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -130,6 +130,9 @@ set_maximum_wait(monotonic_t val) { } // Frame pacing {{{ +// The minimum interval between renders of an OS Window that are not paced by +// render frames, as happens soon after a resize on Wayland (120 FPS) +#define POST_RESIZE_MIN_RENDER_INTERVAL (MONOTONIC_T_1e9 / 120) // How often to retry rendering an OS Window whose buffers could not be swapped #define SWAP_RETRY_INTERVAL (10 * MONOTONIC_T_1e6) // The minimum interval between redraws used when syncing to the monitor @@ -251,7 +254,15 @@ is_render_deferred_by_frame_pacing(OSWindow *w, monotonic_t now) { if (is_thumbnail) return false; // dont respect render frames soon after a resize on Wayland as they cause flicker because // we want to fill the newly resized buffer ASAP, not at compositors convenience - if (global_state.is_wayland && (now - w->viewport_resized_at) <= s_double_to_monotonic_t(1)) return false; + if (global_state.is_wayland && (now - w->viewport_resized_at) <= s_double_to_monotonic_t(1)) { + // The first render after the resize is immediate, subsequent ones + // are limited to a reasonable rate, otherwise continuous output + // would be rendered as fast as possible during this period. + if (w->last_rendered_at <= w->viewport_resized_at) return false; + const monotonic_t since_last_render = now - w->last_rendered_at; + if (since_last_render >= POST_RESIZE_MIN_RENDER_INTERVAL) return false; + set_maximum_wait(POST_RESIZE_MIN_RENDER_INTERVAL - since_last_render); + } w->tick_on_render_frame = true; return true; }