wayland: Create drop contexts on demand
authorBenjamin Otte <otte@redhat.com>
Fri, 27 Apr 2018 10:25:59 +0000 (12:25 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 27 Apr 2018 12:32:28 +0000 (14:32 +0200)
Instead of creating and reusing the same one from start to finish.

gdk/wayland/gdkdevice-wayland.c
gdk/wayland/gdkselection-wayland.c

index faa41a5d4678796e233e4d5fd655b4a85ba47d51..22ae09aec87796198d543da40912b0470dfd11be 100644 (file)
@@ -1093,6 +1093,13 @@ data_device_enter (void                  *data,
   seat->pointer_info.surface_x = wl_fixed_to_double (x);
   seat->pointer_info.surface_y = wl_fixed_to_double (y);
 
+  seat->drop_context = _gdk_wayland_drop_context_new (seat->display,
+                                                      seat->data_device);
+  if (seat->master_pointer)
+    gdk_drag_context_set_device (seat->drop_context, seat->master_pointer);
+  else if (seat->touch_master)
+    gdk_drag_context_set_device (seat->drop_context, seat->touch_master);
+
   gdk_wayland_drop_context_update_targets (seat->drop_context);
 
   dnd_owner = seat->foreign_dnd_surface;
@@ -1119,7 +1126,7 @@ data_device_leave (void                  *data,
   GDK_DISPLAY_NOTE (seat->display, EVENTS,
             g_message ("data device leave, data device %p", data_device));
 
-  if (!gdk_drag_context_get_dest_surface (seat->drop_context))
+  if (seat->drop_context == NULL)
     return;
 
   g_object_unref (seat->pointer_info.focus);
@@ -1129,6 +1136,8 @@ data_device_leave (void                  *data,
   _gdk_wayland_drag_context_emit_event (seat->drop_context, GDK_DRAG_LEAVE,
                                         GDK_CURRENT_TIME);
   _gdk_wayland_drag_context_set_dest_surface (seat->drop_context, NULL, 0);
+
+  g_clear_object (&seat->drop_context);
 }
 
 static void
@@ -1144,7 +1153,7 @@ data_device_motion (void                  *data,
             g_message ("data device motion, data_device = %p, time = %d, x = %f, y = %f",
                        data_device, time, wl_fixed_to_double (x), wl_fixed_to_double (y)));
 
-  if (!gdk_drag_context_get_dest_surface (seat->drop_context))
+  if (seat->drop_context == NULL)
     return;
 
   /* Update pointer state, so device state queries work during DnD */
@@ -3014,11 +3023,6 @@ seat_handle_capabilities (void                    *data,
       g_clear_object (&seat->touch_master);
       g_clear_object (&seat->touch);
     }
-
-  if (seat->master_pointer)
-    gdk_drag_context_set_device (seat->drop_context, seat->master_pointer);
-  else if (seat->touch_master)
-    gdk_drag_context_set_device (seat->drop_context, seat->touch_master);
 }
 
 static GdkDevice *
@@ -4816,8 +4820,6 @@ _gdk_wayland_display_create_seat (GdkWaylandDisplay *display_wayland,
     wl_data_device_manager_get_data_device (display_wayland->data_device_manager,
                                             seat->wl_seat);
   seat->clipboard = gdk_wayland_clipboard_new (display);
-  seat->drop_context = _gdk_wayland_drop_context_new (display,
-                                                      seat->data_device);
   wl_data_device_add_listener (seat->data_device,
                                &data_device_listener, seat);
 
index 757748dd7fee2185d1dcfb55d05858f5e3d44557..66e5cc3b63143161f203d45ef231b910a92a6541 100644 (file)
@@ -156,15 +156,16 @@ data_offer_source_actions (void                 *data,
   seat = gdk_display_get_default_seat (display);
   device = gdk_seat_get_pointer (seat);
   drop_context = gdk_wayland_device_get_drop_context (device);
+  if (drop_context == NULL)
+    return;
 
   drop_context->actions = _wl_to_gdk_actions (source_actions);
 
   GDK_DISPLAY_NOTE (display, EVENTS,
             g_message ("data offer source actions, offer %p, actions %d", wl_data_offer, source_actions));
 
-  if (gdk_drag_context_get_dest_surface (drop_context))
-    _gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
-                                          GDK_CURRENT_TIME);
+  _gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
+                                        GDK_CURRENT_TIME);
 }
 
 static void
@@ -181,12 +182,13 @@ data_offer_action (void                 *data,
   seat = gdk_display_get_default_seat (display);
   device = gdk_seat_get_pointer (seat);
   drop_context = gdk_wayland_device_get_drop_context (device);
+  if (drop_context == NULL)
+    return;
 
   drop_context->action = _wl_to_gdk_actions (action);
 
-  if (gdk_drag_context_get_dest_surface (drop_context))
-    _gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
-                                          GDK_CURRENT_TIME);
+  _gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
+                                        GDK_CURRENT_TIME);
 }
 
 static const struct wl_data_offer_listener data_offer_listener = {