server: verify selection offer is still valid when handling clipboard

Should fix #170, fix #183
This commit is contained in:
Shawn Wallace 2025-06-29 01:37:24 -04:00
parent 2e7c318ac2
commit cf1fae1eae
4 changed files with 49 additions and 14 deletions

View file

@ -1095,16 +1095,18 @@ impl<C: XConnection> ServerState<C> {
}
}
if clipboard.source.is_none() || self.world.selection_cancelled {
if self.world.selection.take().is_some() {
let device = clipboard.device.as_ref().unwrap();
let offer = device.data().selection_offer().unwrap();
let mime_types: Box<[String]> = offer.with_mime_types(|mimes| mimes.into());
let foreign = ForeignSelection {
mime_types,
inner: offer,
};
clipboard.source = Some(CopyPasteData::Foreign(foreign));
if clipboard.source.is_none() {
if let Some(offer) = self.world.selection_offer.take() {
if offer.inner().is_alive() {
let mime_types: Box<[String]> = offer.with_mime_types(|mimes| mimes.into());
let foreign = ForeignSelection {
mime_types,
inner: offer,
};
clipboard.source = Some(CopyPasteData::Foreign(foreign));
} else {
clipboard.source = None;
}
}
self.world.selection_cancelled = false;
}