Skip to content

Commit

Permalink
[desktop_drop] temporary workaround to ignore the redundant signal on…
Browse files Browse the repository at this point in the history
… KDE (#325)

* temporary workaround to fix the redundant signal on KDE

* native workaround

* use `g_ascii_strdown`

* use `gboolean`
  • Loading branch information
sun-jiao authored Mar 26, 2024
1 parent 1e1579d commit 8cbbf9c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/desktop_drop/linux/desktop_drop_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <gtk/gtk.h>
#include <sys/utsname.h>

#include <cstring>

#define DESKTOP_DROP_PLUGIN(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), desktop_drop_plugin_get_type(), \
DesktopDropPlugin))
Expand All @@ -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,
Expand All @@ -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<FlMethodChannel *>(user_data);
double point[] = {double(x), double(y)};
g_autoptr(FlValue) args = fl_value_new_float_list(point, 2);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

0 comments on commit 8cbbf9c

Please sign in to comment.