diff --git a/packages/desktop_drop/linux/desktop_drop_plugin.cc b/packages/desktop_drop/linux/desktop_drop_plugin.cc index 118fb38d..a9ccfcc7 100644 --- a/packages/desktop_drop/linux/desktop_drop_plugin.cc +++ b/packages/desktop_drop/linux/desktop_drop_plugin.cc @@ -4,8 +4,6 @@ #include #include -#include - #define DESKTOP_DROP_PLUGIN(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), desktop_drop_plugin_get_type(), \ DesktopDropPlugin)) @@ -14,6 +12,9 @@ struct _DesktopDropPlugin { GObject parent_instance; }; +static gboolean isKDE = FALSE; +static gboolean ignoreNext = FALSE; + G_DEFINE_TYPE(DesktopDropPlugin, desktop_drop_plugin, g_object_get_type()) void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, @@ -31,6 +32,11 @@ void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, void on_drag_motion(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time, gpointer user_data) { + if (ignoreNext) { + ignoreNext = FALSE; + return; + } + auto *channel = static_cast(user_data); double point[] = {double(x), double(y)}; g_autoptr(FlValue) args = fl_value_new_float_list(point, 2); @@ -59,7 +65,23 @@ static void desktop_drop_plugin_class_init(DesktopDropPluginClass *klass) { G_OBJECT_CLASS(klass)->dispose = desktop_drop_plugin_dispose; } -static void desktop_drop_plugin_init(DesktopDropPlugin *self) {} +static void desktop_drop_plugin_init(DesktopDropPlugin *self) { + const char * desktopEnv = std::getenv("XDG_CURRENT_DESKTOP"); + if (desktopEnv) { + const char * lowercaseDesktopEnv = g_ascii_strdown(desktopEnv, -1); + + if (strcmp(lowercaseDesktopEnv, "kde") == 0 || strcmp(lowercaseDesktopEnv, "plasma") == 0) { + isKDE = TRUE; + } + } +} + +static void on_focus_in_event(GtkWidget *widget, GdkEventFocus *event, gpointer user_data) { + if (isKDE) { + ignoreNext = TRUE; + } + return; +} static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data) { @@ -93,6 +115,8 @@ void desktop_drop_plugin_register_with_registrar(FlPluginRegistrar *registrar) { G_CALLBACK(on_drag_data_received), channel); g_signal_connect(GTK_WIDGET(fl_view), "drag-leave", G_CALLBACK(on_drag_leave), channel); + g_signal_connect(fl_view, "focus-in-event", + G_CALLBACK(on_focus_in_event), nullptr); g_object_unref(plugin); }