Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wl_data_device): drop and leave event handling #409

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

wash2
Copy link
Member

@wash2 wash2 commented Sep 22, 2023

While the spec says to destroy the wl_data_offer after wl_data_device::leave, I think compositors often send the leave event right away after a drop. This is a bit problematic if an application hasn't finished receiving the data and then the data offer is destroyed before it can make the finish request. I believe this can currently be recreated in the data_device example. The source never receives a finish event because the offer was destroyed and isn't alive by the time we make the request.

This PR tries to avoid destroying an offer after the leave event if a drop event already occurred. It also tries to avoid making request besides finish or destroy.

@wash2 wash2 force-pushed the fix-data-device-leave branch 2 times, most recently from 43321ba to 251321d Compare September 22, 2023 13:29
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably document that the users should destroy the offer? It would also be nice to get which compositors do what you say in particular, but just for the reference.

@@ -860,6 +862,7 @@ impl DataSourceHandler for DataDeviceWindow {
_qh: &QueueHandle<Self>,
source: &wayland_client::protocol::wl_data_source::WlDataSource,
) {
println!("FINISHED");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a debug leftover, given how it's written compared to other logging we have around.

Copy link
Member Author

@wash2 wash2 Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the message above it, but I can change how both messages are written.

src/data_device_manager/data_offer.rs Outdated Show resolved Hide resolved
@wash2
Copy link
Member Author

wash2 commented Sep 22, 2023

It would also be nice to get which compositors do what you say in particular, but just for the reference.

So far I was able to recreate the issue in Cosmic, sway, and Pop on wayland (Gnome), but I can double check vanilla Gnome too

@kchibisov
Copy link
Member

So far I was able to recreate the issue in Cosmic, sway, and Pop on wayland (Gnome), but I can double check vanilla Gnome too

That's more than enough I guess, just mention that in the commit. We could probably use some RAII so users won't worry about that, but I'm not familiar with dnd myself much and can just look into the code.

Comment on lines 314 to 320
pub(crate) fn drop_performed(&self) {
let mut inner = self.inner.lock().unwrap();

if let DataDeviceOffer::Drag(ref mut o) = inner.deref_mut().offer {
o.dropped = true;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this as a separate function if it's used only once in Drop handler?

Comment on lines +115 to +117
if !self.left || self.dropped {
receive(&self.data_offer, mime_type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you document why it's like that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment that explains why

I was able to recreate the issue in Cosmic, sway, and Pop on wayland (Gnome)

refactor(data-device): merge both cases in leave

Co-authored-by: Kirill Chibisov <contact@kchibisov.com>

chore(data-device): document that the offer may need to be manually destroyed after leave

cleanup(data-device): example println capitalization
@wash2 wash2 merged commit dc8c4a0 into Smithay:master Sep 23, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants