From f725961c8714b3e7f9257c70f44d9a5fb1589a07 Mon Sep 17 00:00:00 2001 From: Ilia Malanin Date: Tue, 9 Jun 2026 13:56:32 +0200 Subject: [PATCH] fix: reuse wgpu compositor across windows --- winit/src/lib.rs | 53 +++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 735d73aa..95df205b 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -864,28 +864,30 @@ async fn run_instance

( platform_specific_handler.send_wayland( platform_specific::Action::TrackWindow(window.clone(), id), ); - match create_compositor::

( - window.clone(), - CreateCompositor { - proxy: &proxy, - runtime: &mut runtime, - display_handle: &display_handle, - graphics_settings: &graphics_settings, - default_fonts: &default_fonts, - }, - ) - .await - { - Ok(comp) => { - compositor = Some(comp); - } - Err(error) => { - control_sender - .start_send(Control::Crash( - Error::GraphicsCreationFailed(error), - )) - .expect("Send control message"); - continue; + if compositor.is_none() { + match create_compositor::

( + window.clone(), + CreateCompositor { + proxy: &proxy, + runtime: &mut runtime, + display_handle: &display_handle, + graphics_settings: &graphics_settings, + default_fonts: &default_fonts, + }, + ) + .await + { + Ok(comp) => { + compositor = Some(comp); + } + Err(error) => { + control_sender + .start_send(Control::Crash( + Error::GraphicsCreationFailed(error), + )) + .expect("Send control message"); + continue; + } } } @@ -1014,6 +1016,7 @@ async fn run_instance

( &mut is_window_opening, &mut system_theme, &mut platform_specific_handler, + is_daemon, ); if exited { runtime.track(None.into_iter()); @@ -1171,6 +1174,7 @@ async fn run_instance

( &mut is_window_opening, &mut system_theme, &mut platform_specific_handler, + is_daemon, ); } @@ -1369,6 +1373,7 @@ async fn run_instance

( &mut is_window_opening, &mut system_theme, &mut platform_specific_handler, + is_daemon, ); } else { window.state.update(&program, window.raw.as_ref(), &event); @@ -1562,6 +1567,7 @@ async fn run_instance

( &mut is_window_opening, &mut system_theme, &mut platform_specific_handler, + is_daemon, ); if exited { runtime.track(None.into_iter()); @@ -2106,6 +2112,7 @@ fn run_action<'a, P, C>( is_window_opening: &mut bool, system_theme: &mut theme::Mode, platform_specific: &mut crate::platform_specific::PlatformSpecific, + is_daemon: bool, ) -> bool where P: Program, @@ -2190,7 +2197,7 @@ where )); } - if window_manager.is_empty() { + if window_manager.is_empty() && !is_daemon { *compositor = None; } }