From 7f48522286ed6b8de372faa4a19ad511c08df141 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 2 Dec 2024 19:19:36 -0500 Subject: [PATCH 1/2] fix: use dummy window for clipboard This avoids issues with apps like the portal that creates a screenshot, sets the clipboard, and then has the data device destroyed when the window is closed. --- winit/src/program.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/winit/src/program.rs b/winit/src/program.rs index 933c643e0b..8d941b9194 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -245,6 +245,7 @@ where sender: mpsc::UnboundedSender>, receiver: mpsc::UnboundedReceiver, error: Option, + proxy: Proxy, #[cfg(target_arch = "wasm32")] is_booted: std::rc::Rc>, @@ -274,6 +275,7 @@ where sender: event_sender, receiver: control_receiver, error: None, + proxy: proxy.clone(), #[cfg(target_arch = "wasm32")] is_booted: std::rc::Rc::new(std::cell::RefCell::new(false)), @@ -378,6 +380,7 @@ where self.canvas = window.canvas(); } + let proxy = self.proxy.raw.clone(); let finish_boot = async move { let mut compositor = C::new(graphics_settings, window.clone()).await?; @@ -390,6 +393,13 @@ where .send(Boot { compositor, is_wayland, + clipboard: Clipboard::connect( + window, + crate::clipboard::ControlSender { + sender: control_sender, + proxy, + }, + ), }) .ok() .expect("Send boot event"); @@ -636,6 +646,7 @@ where struct Boot { compositor: C, is_wayland: bool, + clipboard: Clipboard, } pub(crate) enum Event { @@ -702,6 +713,7 @@ async fn run_instance<'a, P, C>( let Boot { mut compositor, is_wayland, + mut clipboard, } = boot.await.expect("Receive boot"); let mut platform_specific_handler = @@ -781,7 +793,6 @@ async fn run_instance<'a, P, C>( rustc_hash::FxBuildHasher, >, > = ManuallyDrop::new(FxHashMap::default()); - let mut clipboard = Clipboard::unconnected(); let mut cur_dnd_surface: Option = None; From c4eaf6a8630b8c550a5e6c6737b8df7a1908a261 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 2 Dec 2024 20:31:56 -0500 Subject: [PATCH 2/2] fix(winit): cleanup layer surface dnd surface --- winit/src/platform_specific/wayland/sctk_event.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/winit/src/platform_specific/wayland/sctk_event.rs b/winit/src/platform_specific/wayland/sctk_event.rs index ac655e95d3..c0d552b36e 100755 --- a/winit/src/platform_specific/wayland/sctk_event.rs +++ b/winit/src/platform_specific/wayland/sctk_event.rs @@ -666,16 +666,14 @@ impl SctkEvent { LayerSurfaceEventVariant::Done => { if let Some(id) = surface_ids.remove(&surface.id()) { if let Some(w) = window_manager.remove(id.inner()) { + clipboard.register_dnd_destination( + DndSurface(Arc::new(Box::new(w.raw.clone()))), + Vec::new(), + ); if clipboard .window_id() .is_some_and(|id| w.raw.id() == id) { - clipboard.register_dnd_destination( - DndSurface(Arc::new(Box::new( - w.raw.clone(), - ))), - Vec::new(), - ); *clipboard = Clipboard::unconnected(); } }