From 6e057f8ca351e16dfd4f8ae98e8e9ee384133723 Mon Sep 17 00:00:00 2001 From: Arnold Loubriat Date: Fri, 14 Nov 2025 16:19:30 +0100 Subject: [PATCH 1/2] fix: Redraw only when needed in the winit examples --- platforms/winit/examples/mixed_handlers.rs | 12 +++++++++--- platforms/winit/examples/simple.rs | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/platforms/winit/examples/mixed_handlers.rs b/platforms/winit/examples/mixed_handlers.rs index 1064d289..d342aec0 100644 --- a/platforms/winit/examples/mixed_handlers.rs +++ b/platforms/winit/examples/mixed_handlers.rs @@ -211,6 +211,9 @@ impl ApplicationHandler for Application { fill::cleanup_window(&window.window); self.window = None; } + WindowEvent::Resized(_) => { + window.window.request_redraw(); + } WindowEvent::RedrawRequested => { fill::fill_window(&window.window); } @@ -231,11 +234,13 @@ impl ApplicationHandler for Application { BUTTON_1_ID }; state.set_focus(adapter, new_focus); + window.window.request_redraw(); } Key::Named(winit::keyboard::NamedKey::Space) => { let mut state = state.lock().unwrap(); let id = state.focus; state.press_button(adapter, id); + window.window.request_redraw(); } _ => (), }, @@ -274,12 +279,13 @@ impl ApplicationHandler for Application { fn resumed(&mut self, event_loop: &ActiveEventLoop) { self.create_window(event_loop) .expect("failed to create initial window"); + if let Some(window) = self.window.as_ref() { + window.window.request_redraw(); + } } fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { - if let Some(window) = self.window.as_ref() { - window.window.request_redraw(); - } else { + if self.window.is_none() { event_loop.exit(); } } diff --git a/platforms/winit/examples/simple.rs b/platforms/winit/examples/simple.rs index 4d4a942c..02a7813d 100644 --- a/platforms/winit/examples/simple.rs +++ b/platforms/winit/examples/simple.rs @@ -188,6 +188,9 @@ impl ApplicationHandler for Application { fill::cleanup_window(&window.window); self.window = None; } + WindowEvent::Resized(_) => { + window.window.request_redraw(); + } WindowEvent::RedrawRequested => { fill::fill_window(&window.window); } @@ -207,10 +210,12 @@ impl ApplicationHandler for Application { BUTTON_1_ID }; state.set_focus(adapter, new_focus); + window.window.request_redraw(); } Key::Named(winit::keyboard::NamedKey::Space) => { let id = state.focus; state.press_button(adapter, id); + window.window.request_redraw(); } _ => (), }, @@ -250,12 +255,13 @@ impl ApplicationHandler for Application { fn resumed(&mut self, event_loop: &ActiveEventLoop) { self.create_window(event_loop) .expect("failed to create initial window"); + if let Some(window) = self.window.as_ref() { + window.window.request_redraw(); + } } fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { - if let Some(window) = self.window.as_ref() { - window.window.request_redraw(); - } else { + if self.window.is_none() { event_loop.exit(); } } From f8f3051bee909fc754a34f517d25ca2799e9d25f Mon Sep 17 00:00:00 2001 From: Arnold Loubriat Date: Wed, 19 Nov 2025 19:40:14 +0100 Subject: [PATCH 2/2] Redraw when receiving action requests --- platforms/winit/examples/mixed_handlers.rs | 1 + platforms/winit/examples/simple.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/platforms/winit/examples/mixed_handlers.rs b/platforms/winit/examples/mixed_handlers.rs index d342aec0..b3a454b3 100644 --- a/platforms/winit/examples/mixed_handlers.rs +++ b/platforms/winit/examples/mixed_handlers.rs @@ -271,6 +271,7 @@ impl ApplicationHandler for Application { _ => (), } } + window.window.request_redraw(); } AccessKitWindowEvent::AccessibilityDeactivated => (), } diff --git a/platforms/winit/examples/simple.rs b/platforms/winit/examples/simple.rs index 02a7813d..f4ab4a63 100644 --- a/platforms/winit/examples/simple.rs +++ b/platforms/winit/examples/simple.rs @@ -247,6 +247,7 @@ impl ApplicationHandler for Application { _ => (), } } + window.window.request_redraw(); } AccessKitWindowEvent::AccessibilityDeactivated => (), }