From d6ab1000624375c940cc6cab47b21b3f36f5723f Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Mon, 28 Nov 2022 18:27:40 +0100 Subject: [PATCH] image: Use FileList in ContentProvider Makes dragging an image out of Loupe work in most cases. There seems to be an issue with dragging from flatpak to host. Removing the png from the provider seems to avoid gdk crashes but not 100% sure that was the cause. --- src/widgets/image.rs | 20 ++++---------------- src/widgets/image_page.rs | 2 +- src/widgets/image_view.rs | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/widgets/image.rs b/src/widgets/image.rs index 7b9a721..e1f7315 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -905,21 +905,9 @@ impl LpImage { } /// Drag and drop content provider - pub fn content_provider(&self) -> gdk::ContentProvider { - let imp = self.imp(); - let mut contents = vec![]; - - if let Some(file) = imp.file.borrow().as_ref() { - let content = gdk::ContentProvider::for_value(&file.to_value()); - contents.push(content); - } - - if let Some(texture) = imp.texture.borrow().as_ref() { - let bytes = texture.save_to_png_bytes(); - let content = gdk::ContentProvider::for_bytes("image/png", &bytes); - contents.push(content); - } - - gdk::ContentProvider::new_union(contents.as_slice()) + pub fn content_provider(&self) -> Option { + let file = self.file()?; + let list = gdk::FileList::from_array(&[file]); + Some(gdk::ContentProvider::for_value(&list.to_value())) } } diff --git a/src/widgets/image_page.rs b/src/widgets/image_page.rs index 1a24873..074fee8 100644 --- a/src/widgets/image_page.rs +++ b/src/widgets/image_page.rs @@ -159,7 +159,7 @@ impl LpImagePage { self.imp().image.texture() } - pub fn content_provider(&self) -> gdk::ContentProvider { + pub fn content_provider(&self) -> Option { self.imp().image.content_provider() } diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index c2d6ae3..af36079 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -126,7 +126,7 @@ mod imp { gesture.set_state(gtk::EventSequenceState::Denied); None } else { - obj.current_page().map(|p| p.content_provider()) + obj.current_page().and_then(|p| p.content_provider()) } }), );