Hi,
I’m trying to create a Drag source in my application. I want to be able to drag an image created in my application to another application (like nautulis). But I just can not manage to find how other people do it. I can find people moving things within their application, but I am not managing to make it work between applications. I already have the current code:
let drag_source = gtk::DragSource::builder()
.actions(gdk::DragAction::COPY)
.build();
drag_source.connect_prepare(clone!(#[weak (rename_to = win)] obj, #[upgrade_or] None, move |drag, x, y| {
win.drag_connect_prepare(drag, x, y)
}));
self.image_view.add_controller(drag_source);
pub fn drag_connect_prepare(&self, source: >k::DragSource, x: f64, y: f64) -> Option<gdk::ContentProvider> {
let icon = self.imp().generated_image.borrow().clone().unwrap();
source.set_icon(Some(&self.dynamic_image_to_texture(&icon)),x as i32 ,y as i32);
Some(gdk::ContentProvider::for_bytes("image/png", &glib::Bytes::from_owned(icon.into_bytes())))
}
This code sucesfully shows an icon at the cursor when i drag the image. But does nothing when I let go of the mouse.
Link to my code
Thank you in advance!