[PATCH wayland 07/10] wl_data_offer: don't open-code wl_client_new_object

Daniel Stone daniel at fooishbar.org
Mon Jul 23 11:54:44 PDT 2012


Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/data-device.c    |   32 ++++++++++++++++++--------------
 src/wayland-server.h |    3 ++-
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/data-device.c b/src/data-device.c
index c19e14f..ac3c7fb 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -66,9 +66,12 @@ static const struct wl_data_offer_interface data_offer_interface = {
 };
 
 static void
-destroy_data_offer(struct wl_resource *resource)
+destroy_data_offer(struct wl_listener *listener, void *data)
 {
-	struct wl_data_offer *offer = resource->data;
+	struct wl_data_offer *offer;
+
+	offer = container_of(listener, struct wl_data_offer,
+			     offer_destroy_listener);
 
 	if (offer->source)
 		wl_list_remove(&offer->source_destroy_listener.link);
@@ -97,27 +100,28 @@ wl_data_source_send_offer(struct wl_data_source *source,
 	if (offer == NULL)
 		return NULL;
 
-	offer->resource.destroy = destroy_data_offer;
-	offer->resource.object.id = 0;
-	offer->resource.object.interface = &wl_data_offer_interface;
-	offer->resource.object.implementation =
-		(void (**)(void)) &data_offer_interface;
-	offer->resource.data = offer;
-	wl_signal_init(&offer->resource.destroy_signal);
+	offer->resource =
+		wl_client_new_object(target->client, &wl_data_offer_interface,
+				     &data_offer_interface, offer);
+	if (offer->resource == NULL) {
+		free(offer);
+		return NULL;
+	}
+	offer->offer_destroy_listener.notify = destroy_data_offer;
+	wl_signal_add(&offer->resource->destroy_signal,
+		      &offer->offer_destroy_listener);
 
 	offer->source = source;
 	offer->source_destroy_listener.notify = destroy_offer_data_source;
 	wl_signal_add(&source->resource.destroy_signal,
 		      &offer->source_destroy_listener);
 
-	wl_client_add_resource(target->client, &offer->resource);
-
-	wl_data_device_send_data_offer(target, &offer->resource);
+	wl_data_device_send_data_offer(target, offer->resource);
 
 	wl_array_for_each(p, &source->mime_types)
-		wl_data_offer_send_offer(&offer->resource, *p);
+		wl_data_offer_send_offer(offer->resource, *p);
 
-	return &offer->resource;
+	return offer->resource;
 }
 
 static void
diff --git a/src/wayland-server.h b/src/wayland-server.h
index f7a0957..e1a8a2e 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -223,9 +223,10 @@ struct wl_keyboard_grab {
 };
 
 struct wl_data_offer {
-	struct wl_resource resource;
+	struct wl_resource *resource;
 	struct wl_data_source *source;
 	struct wl_listener source_destroy_listener;
+	struct wl_listener offer_destroy_listener;
 };
 
 struct wl_data_source {
-- 
1.7.10.4



More information about the wayland-devel mailing list