[PATCH 1/2] Terminate drag if data source is destroyed

Ander Conselvan de Oliveira conselvan2 at gmail.com
Fri Mar 2 05:45:56 PST 2012


---
 src/data-device.c    |   56 +++++++++++++++++++++++++++++++++++--------------
 src/wayland-server.h |    1 +
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/src/data-device.c b/src/data-device.c
index f0f6baa..be2360c 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -230,6 +230,28 @@ drag_grab_motion(struct wl_pointer_grab *grab,
 }
 
 static void
+data_device_end_drag_grab(struct wl_input_device *device, uint32_t time)
+{
+	struct wl_resource *surface_resource;
+	struct wl_surface_interface *implementation;
+
+	if (device->drag_surface) {
+		surface_resource = &device->drag_surface->resource;
+		implementation = (struct wl_surface_interface *)
+			surface_resource->object.implementation;
+
+		implementation->attach(surface_resource->client,
+				       surface_resource, NULL, 0, 0);
+		wl_list_remove(&device->drag_icon_listener.link);
+	}
+
+	wl_input_device_end_pointer_grab(device, time);
+
+	device->drag_data_source = NULL;
+	device->drag_surface = NULL;
+}
+
+static void
 drag_grab_button(struct wl_pointer_grab *grab,
 		 uint32_t time, int32_t button, int32_t state)
 {
@@ -242,22 +264,8 @@ drag_grab_button(struct wl_pointer_grab *grab,
 				       WL_DATA_DEVICE_DROP);
 
 	if (device->button_count == 0 && state == 0) {
-		wl_input_device_end_pointer_grab(device, time);
-
-		if (device->drag_surface) {
-			struct wl_resource *surface_resource =
-				&device->drag_surface->resource;
-			struct wl_surface_interface *implementation =
-				(struct wl_surface_interface *)
-				surface_resource->object.implementation;
-
-			implementation->attach(surface_resource->client,
-					       surface_resource, NULL, 0, 0);
-			wl_list_remove(&device->drag_icon_listener.link);
-		}
-
-		device->drag_data_source = NULL;
-		device->drag_surface = NULL;
+		data_device_end_drag_grab(device, time);
+		wl_list_remove(&device->drag_data_source_listener.link);
 	}
 }
 
@@ -268,6 +276,18 @@ static const struct wl_pointer_grab_interface drag_grab_interface = {
 };
 
 static void
+destroy_data_device_source(struct wl_listener *listener,
+			   struct wl_resource *resource, uint32_t time)
+{
+	struct wl_input_device *device;
+
+	device = container_of(listener, struct wl_input_device,
+			      drag_data_source_listener);
+
+	data_device_end_drag_grab(device, time);
+}
+
+static void
 destroy_data_device_icon(struct wl_listener *listener,
 			 struct wl_resource *resource, uint32_t time)
 {
@@ -293,7 +313,11 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
 	/* FIXME: Check that the data source type array isn't empty. */
 
 	device->drag_grab.interface = &drag_grab_interface;
+
 	device->drag_data_source = source_resource->data;
+	device->drag_data_source_listener.func = destroy_data_device_source;
+	wl_list_insert(source_resource->destroy_listener_list.prev,
+		       &device->drag_data_source_listener.link);
 
 	if (icon_resource) {
 		device->drag_surface = icon_resource->data;
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 49ab5b1..a1ddc68 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -227,6 +227,7 @@ struct wl_input_device {
 
 	struct wl_list drag_resource_list;
 	struct wl_data_source *drag_data_source;
+	struct wl_listener drag_data_source_listener;
 	struct wl_surface *drag_focus;
 	struct wl_resource *drag_focus_resource;
 	struct wl_listener drag_focus_listener;
-- 
1.7.5.4



More information about the wayland-devel mailing list