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.
This commit is contained in:
Sophie Herold 2022-11-28 18:27:40 +01:00
parent b202c1d2d2
commit d6ab100062
3 changed files with 6 additions and 18 deletions

View file

@ -905,21 +905,9 @@ impl LpImage {
} }
/// Drag and drop content provider /// Drag and drop content provider
pub fn content_provider(&self) -> gdk::ContentProvider { pub fn content_provider(&self) -> Option<gdk::ContentProvider> {
let imp = self.imp(); let file = self.file()?;
let mut contents = vec![]; let list = gdk::FileList::from_array(&[file]);
Some(gdk::ContentProvider::for_value(&list.to_value()))
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())
} }
} }

View file

@ -159,7 +159,7 @@ impl LpImagePage {
self.imp().image.texture() self.imp().image.texture()
} }
pub fn content_provider(&self) -> gdk::ContentProvider { pub fn content_provider(&self) -> Option<gdk::ContentProvider> {
self.imp().image.content_provider() self.imp().image.content_provider()
} }

View file

@ -126,7 +126,7 @@ mod imp {
gesture.set_state(gtk::EventSequenceState::Denied); gesture.set_state(gtk::EventSequenceState::Denied);
None None
} else { } else {
obj.current_page().map(|p| p.content_provider()) obj.current_page().and_then(|p| p.content_provider())
} }
}), }),
); );