From 896508deee81d091d2d42b0926db4333c61e8145 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Tue, 5 Sep 2023 23:07:18 +0200 Subject: [PATCH] window: Only accept drops of correct type This got lost with having a custom "accept" signal handler since the signal uses g_signal_accumulator_first_wins. Fixing this also works around GTK not properly checking the drops and ending up in criticals. Fixes #234 --- src/window.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/window.rs b/src/window.rs index d909296..f264234 100644 --- a/src/window.rs +++ b/src/window.rs @@ -379,10 +379,14 @@ mod imp { self.drop_target.set_types(&[gdk::FileList::static_type()]); - // Only accept drops from external sources or different windows self.drop_target.connect_accept( clone!(@weak obj => @default-return false, move |_drop_target, drop| { - drop.drag().is_none() || drop.drag() != obj.image_view().drag_source().drag() + // Only accept drops from external sources or different windows + let different_source = drop.drag().is_none() || drop.drag() != obj.image_view().drag_source().drag(); + // We have to do this manually since we are overwriting the default handler + let correct_format = drop.formats().contains_type(gdk::FileList::static_type()); + + different_source && correct_format }), );