From f7425db87e62b1998c7b27ecfc5f56421be7583a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 16 Oct 2025 17:25:04 +0200 Subject: [PATCH] Avoid redrawing window twice on `RedrawRequested` --- winit/src/lib.rs | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 57b5a6a1..9e690783 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -881,16 +881,16 @@ async fn run_instance

( let mut has_window_resized = false; for action in actions { - has_window_resized = has_window_resized - || matches!( - action, - Action::Window( - runtime::window::Action::Resize( - _, - _ - ) - ) - ); + if let Action::Window( + runtime::window::Action::Resize( + window_id, + _, + ), + ) = action + && window_id == id + { + has_window_resized = true; + } run_action( action, @@ -909,6 +909,17 @@ async fn run_instance

( ); } + for (window_id, window) in + window_manager.iter_mut() + { + // We are already redrawing this window + if window_id == id { + continue; + } + + window.raw.request_redraw(); + } + let Some(next_compositor) = compositor.as_mut() else { continue 'next_event; @@ -1202,6 +1213,10 @@ async fn run_instance

( &mut system_theme, ); } + + for (_id, window) in window_manager.iter_mut() { + window.raw.request_redraw(); + } } if let Some(redraw_at) = window_manager.redraw_at() { @@ -1731,7 +1746,6 @@ where { for (id, window) in window_manager.iter_mut() { window.state.synchronize(program, id, &window.raw); - window.raw.request_redraw(); } debug::theme_changed(|| {