Skip to content

Commit 8cbbf9c

Browse files
authored
[desktop_drop] temporary workaround to ignore the redundant signal on KDE (#325)
* temporary workaround to fix the redundant signal on KDE * native workaround * use `g_ascii_strdown` * use `gboolean`
1 parent 1e1579d commit 8cbbf9c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

packages/desktop_drop/linux/desktop_drop_plugin.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <gtk/gtk.h>
55
#include <sys/utsname.h>
66

7-
#include <cstring>
8-
97
#define DESKTOP_DROP_PLUGIN(obj) \
108
(G_TYPE_CHECK_INSTANCE_CAST((obj), desktop_drop_plugin_get_type(), \
119
DesktopDropPlugin))
@@ -14,6 +12,9 @@ struct _DesktopDropPlugin {
1412
GObject parent_instance;
1513
};
1614

15+
static gboolean isKDE = FALSE;
16+
static gboolean ignoreNext = FALSE;
17+
1718
G_DEFINE_TYPE(DesktopDropPlugin, desktop_drop_plugin, g_object_get_type())
1819

1920
void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
@@ -31,6 +32,11 @@ void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
3132

3233
void on_drag_motion(GtkWidget *widget, GdkDragContext *drag_context,
3334
gint x, gint y, guint time, gpointer user_data) {
35+
if (ignoreNext) {
36+
ignoreNext = FALSE;
37+
return;
38+
}
39+
3440
auto *channel = static_cast<FlMethodChannel *>(user_data);
3541
double point[] = {double(x), double(y)};
3642
g_autoptr(FlValue) args = fl_value_new_float_list(point, 2);
@@ -59,7 +65,23 @@ static void desktop_drop_plugin_class_init(DesktopDropPluginClass *klass) {
5965
G_OBJECT_CLASS(klass)->dispose = desktop_drop_plugin_dispose;
6066
}
6167

62-
static void desktop_drop_plugin_init(DesktopDropPlugin *self) {}
68+
static void desktop_drop_plugin_init(DesktopDropPlugin *self) {
69+
const char * desktopEnv = std::getenv("XDG_CURRENT_DESKTOP");
70+
if (desktopEnv) {
71+
const char * lowercaseDesktopEnv = g_ascii_strdown(desktopEnv, -1);
72+
73+
if (strcmp(lowercaseDesktopEnv, "kde") == 0 || strcmp(lowercaseDesktopEnv, "plasma") == 0) {
74+
isKDE = TRUE;
75+
}
76+
}
77+
}
78+
79+
static void on_focus_in_event(GtkWidget *widget, GdkEventFocus *event, gpointer user_data) {
80+
if (isKDE) {
81+
ignoreNext = TRUE;
82+
}
83+
return;
84+
}
6385

6486
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call,
6587
gpointer user_data) {
@@ -93,6 +115,8 @@ void desktop_drop_plugin_register_with_registrar(FlPluginRegistrar *registrar) {
93115
G_CALLBACK(on_drag_data_received), channel);
94116
g_signal_connect(GTK_WIDGET(fl_view), "drag-leave",
95117
G_CALLBACK(on_drag_leave), channel);
118+
g_signal_connect(fl_view, "focus-in-event",
119+
G_CALLBACK(on_focus_in_event), nullptr);
96120

97121
g_object_unref(plugin);
98122
}

0 commit comments

Comments
 (0)