Skip to content

Commit

Permalink
fix: use dummy window for clipboard
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wash2 committed Dec 3, 2024
1 parent 5a38039 commit 7f48522
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ where
sender: mpsc::UnboundedSender<Event<Message>>,
receiver: mpsc::UnboundedReceiver<Control>,
error: Option<Error>,
proxy: Proxy<Message>,

#[cfg(target_arch = "wasm32")]
is_booted: std::rc::Rc<std::cell::RefCell<bool>>,
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -378,6 +380,7 @@ where
self.canvas = window.canvas();

Check failure on line 380 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / web

no method named `canvas` found for struct `std::sync::Arc<dyn winit::window::Window>` in the current scope

Check failure on line 380 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / wasm

no method named `canvas` found for struct `std::sync::Arc<dyn winit::window::Window>` in the current scope

Check failure on line 380 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / web

no method named `canvas` found for struct `std::sync::Arc<dyn winit::window::Window>` in the current scope

Check failure on line 380 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / wasm

no method named `canvas` found for struct `std::sync::Arc<dyn winit::window::Window>` in the current scope
}

let proxy = self.proxy.raw.clone();
let finish_boot = async move {
let mut compositor =
C::new(graphics_settings, window.clone()).await?;
Expand All @@ -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");
Expand Down Expand Up @@ -636,6 +646,7 @@ where
struct Boot<C> {
compositor: C,
is_wayland: bool,
clipboard: Clipboard,
}

pub(crate) enum Event<Message: 'static> {
Expand Down Expand Up @@ -702,6 +713,7 @@ async fn run_instance<'a, P, C>(
let Boot {
mut compositor,
is_wayland,

Check warning on line 715 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / web

unused variable: `is_wayland`

Check warning on line 715 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / wasm

unused variable: `is_wayland`

Check warning on line 715 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / web

unused variable: `is_wayland`

Check warning on line 715 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / wasm

unused variable: `is_wayland`
mut clipboard,
} = boot.await.expect("Receive boot");

let mut platform_specific_handler =
Expand Down Expand Up @@ -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<window::Id> = None;

Expand Down

0 comments on commit 7f48522

Please sign in to comment.