4
4
#include < gtk/gtk.h>
5
5
#include < sys/utsname.h>
6
6
7
- #include < cstring>
8
-
9
7
#define DESKTOP_DROP_PLUGIN (obj ) \
10
8
(G_TYPE_CHECK_INSTANCE_CAST((obj), desktop_drop_plugin_get_type(), \
11
9
DesktopDropPlugin))
@@ -14,6 +12,9 @@ struct _DesktopDropPlugin {
14
12
GObject parent_instance;
15
13
};
16
14
15
+ static gboolean isKDE = FALSE ;
16
+ static gboolean ignoreNext = FALSE ;
17
+
17
18
G_DEFINE_TYPE (DesktopDropPlugin, desktop_drop_plugin, g_object_get_type())
18
19
19
20
void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
@@ -31,6 +32,11 @@ void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
31
32
32
33
void on_drag_motion (GtkWidget *widget, GdkDragContext *drag_context,
33
34
gint x, gint y, guint time, gpointer user_data) {
35
+ if (ignoreNext) {
36
+ ignoreNext = FALSE ;
37
+ return ;
38
+ }
39
+
34
40
auto *channel = static_cast <FlMethodChannel *>(user_data);
35
41
double point[] = {double (x), double (y)};
36
42
g_autoptr (FlValue) args = fl_value_new_float_list (point, 2 );
@@ -59,7 +65,23 @@ static void desktop_drop_plugin_class_init(DesktopDropPluginClass *klass) {
59
65
G_OBJECT_CLASS (klass)->dispose = desktop_drop_plugin_dispose;
60
66
}
61
67
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
+ }
63
85
64
86
static void method_call_cb (FlMethodChannel *channel, FlMethodCall *method_call,
65
87
gpointer user_data) {
@@ -93,6 +115,8 @@ void desktop_drop_plugin_register_with_registrar(FlPluginRegistrar *registrar) {
93
115
G_CALLBACK (on_drag_data_received), channel);
94
116
g_signal_connect (GTK_WIDGET (fl_view), " drag-leave" ,
95
117
G_CALLBACK (on_drag_leave), channel);
118
+ g_signal_connect (fl_view, " focus-in-event" ,
119
+ G_CALLBACK (on_focus_in_event), nullptr );
96
120
97
121
g_object_unref (plugin);
98
122
}
0 commit comments