From 0b50725f67154664292d83681f3f421c6567e3b5 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Mon, 1 Apr 2024 01:40:15 -0600 Subject: [PATCH] Handle missing data device manager more gracefully --- window/src/os/wayland/data_device.rs | 46 +++++++++++++++------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/window/src/os/wayland/data_device.rs b/window/src/os/wayland/data_device.rs index 8726cb0ecad..d2c9a570a61 100644 --- a/window/src/os/wayland/data_device.rs +++ b/window/src/os/wayland/data_device.rs @@ -22,15 +22,17 @@ impl DataDeviceHandler for WaylandState { &mut self, _conn: &wayland_client::Connection, _qh: &wayland_client::QueueHandle, - _data_device: &WlDataDevice, + data_device: &WlDataDevice, ) { - let offer = self - .data_device - .as_ref() - .unwrap() - .data() - .drag_offer() - .unwrap(); + let data = match self.data_device { + Some(ref dv) if dv.inner() == data_device => dv.data(), + _ => { + log::warn!("No existing device manager for {:?}", data_device); + return; + } + }; + + let offer = data.drag_offer().unwrap(); offer.with_mime_types(|mime_types| { log::trace!( @@ -91,22 +93,22 @@ impl DataDeviceHandler for WaylandState { &mut self, _conn: &wayland_client::Connection, _qh: &wayland_client::QueueHandle, - _data_device: &WlDataDevice, + data_device: &WlDataDevice, ) { - let offer = self - .data_device - .as_ref() - .unwrap() - .data() - .selection_offer() - .unwrap(); - - if !offer.with_mime_types(|mime_types| mime_types.iter().any(|s| s == TEXT_MIME_TYPE)) { - return; - } + let offer = match self.data_device { + Some(ref dv) if dv.inner() == data_device => dv.data().selection_offer(), + _ => { + return; + } + }; + if let Some(offer) = offer { + if !offer.with_mime_types(|mime_types| mime_types.iter().any(|s| s == TEXT_MIME_TYPE)) { + return; + } - if let Some(copy_and_paste) = self.resolve_copy_and_paste() { - copy_and_paste.lock().unwrap().confirm_selection(offer); + if let Some(copy_and_paste) = self.resolve_copy_and_paste() { + copy_and_paste.lock().unwrap().confirm_selection(offer); + } } }