Skip to content

Commit

Permalink
Handle missing data device manager more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs authored and wez committed May 6, 2024
1 parent 8fa4ba9 commit 0b50725
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions window/src/os/wayland/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ impl DataDeviceHandler for WaylandState {
&mut self,
_conn: &wayland_client::Connection,
_qh: &wayland_client::QueueHandle<Self>,
_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!(
Expand Down Expand Up @@ -91,22 +93,22 @@ impl DataDeviceHandler for WaylandState {
&mut self,
_conn: &wayland_client::Connection,
_qh: &wayland_client::QueueHandle<Self>,
_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);
}
}
}

Expand Down

0 comments on commit 0b50725

Please sign in to comment.