From 3e7c6a6e9efa4f982326333d1383e17043e24778 Mon Sep 17 00:00:00 2001 From: HugoPeters1024 Date: Mon, 31 Mar 2025 20:47:08 +0200 Subject: [PATCH] 0.16 Regression fix: re-expose the display handle via a wrapper resource (#18644) # Objective - In the latest released version (15.3) I am able to obtain this information by getting the actual `EventLoop` via `non_send_resource`. Now that this object has (probably rightfully so) been replaced by the `EventLoopProxy`, I can no longer maintain my custom render backend: https://github.com/HugoPeters1024/bevy_vulkan. I also need the display handle for a custom winit integration, for which I've made patches to bevy before: XREF: https://github.com/bevyengine/bevy/pull/15884 ## Solution - Luckily, all that is required is exposing the `OwnedDisplayHandle` in its own wrapper resource. ## Testing - Aforementioned custom rendering backend works on this commit. --------- Co-authored-by: HugoPeters1024 --- crates/bevy_winit/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index db74825f0f..97943cc14a 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -127,6 +127,7 @@ impl Plugin for WinitPlugin { app.init_non_send_resource::() .init_resource::() .init_resource::() + .insert_resource(DisplayHandleWrapper(event_loop.owned_display_handle())) .add_event::() .set_runner(|app| winit_runner(app, event_loop)) .add_systems( @@ -176,6 +177,15 @@ pub struct RawWinitWindowEvent { #[derive(Resource, Deref)] pub struct EventLoopProxyWrapper(EventLoopProxy); +/// A wrapper around [`winit::event_loop::OwnedDisplayHandle`] +/// +/// The `DisplayHandleWrapper` can be used to build integrations that rely on direct +/// access to the display handle +/// +/// Use `Res` to receive this resource. +#[derive(Resource, Deref)] +pub struct DisplayHandleWrapper(pub winit::event_loop::OwnedDisplayHandle); + trait AppSendEvent { fn send(&mut self, event: impl Into); }