[PATCH weston 3/4] Use versioned versions of wl_client_add/new_object calls

Jason Ekstrand jason at jlekstrand.net
Thu Jun 27 18:17:02 PDT 2013


This commit sets the version numbers for all added/created objects.  The
wl_compositor.create_surface implementation was altered to create a surface
with the same version as the underlying wl_compositor.  Since no other
"child interfaces" have version greater than 1, they were all hard-coded to
version 1.

Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 src/compositor.c        | 41 ++++++++++++++++++++++----------------
 src/data-device.c       | 26 ++++++++++++++-----------
 src/input.c             | 20 ++++++++++++-------
 src/screenshooter.c     |  6 ++++--
 src/shell.c             | 52 ++++++++++++++++++++++++++++---------------------
 src/tablet-shell.c      | 14 +++++++------
 src/text-backend.c      | 36 +++++++++++++++++++---------------
 src/xwayland/launcher.c |  4 ++--
 src/zoom.c              |  5 +++--
 tests/weston-test.c     |  4 ++--
 10 files changed, 121 insertions(+), 87 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 43d8965..6fd6086 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1489,8 +1489,9 @@ surface_frame(struct wl_client *client,
 		return;
 	}
 
-	cb->resource = wl_client_add_object(client, &wl_callback_interface,
-					    NULL, callback, cb);
+	cb->resource = wl_client_add_versioned_object(client,
+						      &wl_callback_interface, 1,
+						      NULL, callback, cb);
 	wl_resource_set_destructor(cb->resource, destroy_frame_callback);
 
 	wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link);
@@ -1688,9 +1689,11 @@ compositor_create_surface(struct wl_client *client,
 		return;
 	}
 
-	surface->resource = wl_client_add_object(client, &wl_surface_interface,
-						 &surface_interface,
-						 id, surface);
+	surface->resource =
+		wl_client_add_versioned_object(client, &wl_surface_interface,
+					       wl_resource_get_version(resource),
+					       &surface_interface,
+					       id, surface);
 	wl_resource_set_destructor(surface->resource, destroy_surface);
 }
 
@@ -1751,8 +1754,9 @@ compositor_create_region(struct wl_client *client,
 
 	pixman_region32_init(&region->region);
 
-	region->resource = wl_client_add_object(client, &wl_region_interface,
-						&region_interface, id, region);
+	region->resource =
+		wl_client_add_versioned_object(client, &wl_region_interface, 1,
+					       &region_interface, id, region);
 	wl_resource_set_destructor(region->resource, destroy_region);
 }
 
@@ -2288,10 +2292,11 @@ weston_subsurface_create(uint32_t id, struct weston_surface *surface,
 	if (!sub)
 		return NULL;
 
-	sub->resource = wl_client_add_object(client,
-					     &wl_subsurface_interface,
-					     &subsurface_implementation,
-					     id, sub);
+	sub->resource =
+		wl_client_add_versioned_object(client,
+					       &wl_subsurface_interface, 1,
+					       &subsurface_implementation,
+					       id, sub);
 	if (!sub->resource) {
 		free(sub);
 		return NULL;
@@ -2409,8 +2414,8 @@ bind_subcompositor(struct wl_client *client,
 {
 	struct weston_compositor *compositor = data;
 
-	wl_client_add_object(client, &wl_subcompositor_interface,
-			     &subcompositor_interface, id, compositor);
+	wl_client_add_versioned_object(client, &wl_subcompositor_interface, 1,
+				       &subcompositor_interface, id, compositor);
 }
 
 static void
@@ -2522,8 +2527,9 @@ bind_output(struct wl_client *client,
 	struct weston_mode *mode;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client,
-					&wl_output_interface, NULL, id, data);
+	resource = wl_client_add_versioned_object(client, &wl_output_interface,
+						  MIN(version, 2),
+						  NULL, id, data);
 
 	wl_list_insert(&output->resource_list, wl_resource_get_link(resource));
 	wl_resource_set_destructor(resource, unbind_resource);
@@ -2743,8 +2749,9 @@ compositor_bind(struct wl_client *client,
 {
 	struct weston_compositor *compositor = data;
 
-	wl_client_add_object(client, &wl_compositor_interface,
-			     &compositor_interface, id, compositor);
+	wl_client_add_versioned_object(client, &wl_compositor_interface,
+				       MIN(version, 3), &compositor_interface,
+				       id, compositor);
 }
 
 static void
diff --git a/src/data-device.c b/src/data-device.c
index 5627884..86789c5 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -117,8 +117,9 @@ wl_data_source_send_offer(struct wl_data_source *source,
 	if (offer == NULL)
 		return NULL;
 
-	offer->resource = wl_client_new_object(wl_resource_get_client(target),
-					       &wl_data_offer_interface,
+	offer->resource =
+		wl_client_new_versioned_object(wl_resource_get_client(target),
+					       &wl_data_offer_interface, 1,
 					       &data_offer_interface, offer);
 	wl_resource_set_destructor(offer->resource, destroy_data_offer);
 
@@ -545,10 +546,11 @@ create_data_source(struct wl_client *client,
 
 	wl_array_init(&source->mime_types);
 
-	source->resource = wl_client_add_object(client,
-						&wl_data_source_interface,
-						&data_source_interface,
-						id, source);
+	source->resource =
+		wl_client_add_versioned_object(client,
+					       &wl_data_source_interface, 1,
+					       &data_source_interface,
+					       id, source);
 	wl_resource_set_destructor(source->resource, destroy_data_source);
 }
 
@@ -565,9 +567,10 @@ get_data_device(struct wl_client *client,
 	struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &wl_data_device_interface,
-					&data_device_interface, id,
-					seat);
+	resource = wl_client_add_versioned_object(client,
+						  &wl_data_device_interface, 1,
+						  &data_device_interface, id,
+						  seat);
 
 	wl_list_insert(&seat->drag_resource_list, wl_resource_get_link(resource));
 	wl_resource_set_destructor(resource, unbind_data_device);
@@ -582,8 +585,9 @@ static void
 bind_manager(struct wl_client *client,
 	     void *data, uint32_t version, uint32_t id)
 {
-	wl_client_add_object(client, &wl_data_device_manager_interface,
-			     &manager_interface, id, NULL);
+	wl_client_add_versioned_object(client,
+				       &wl_data_device_manager_interface, 1,
+				       &manager_interface, id, NULL);
 }
 
 WL_EXPORT void
diff --git a/src/input.c b/src/input.c
index 004d063..663badf 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1163,8 +1163,10 @@ seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
 	if (!seat->pointer)
 		return;
 
-        cr = wl_client_add_object(client, &wl_pointer_interface,
-				  &pointer_interface, id, seat->pointer);
+        cr = wl_client_add_versioned_object(client, &wl_pointer_interface,
+					    wl_resource_get_version(resource),
+					    &pointer_interface, id,
+					    seat->pointer);
 	wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr));
 	wl_resource_set_destructor(cr, unbind_resource);
 
@@ -1196,8 +1198,9 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
 	if (!seat->keyboard)
 		return;
 
-        cr = wl_client_add_object(client, &wl_keyboard_interface, NULL, id,
-				  seat);
+        cr = wl_client_add_versioned_object(client, &wl_keyboard_interface,
+					    wl_resource_get_version(resource),
+					    NULL, id, seat);
 	wl_list_insert(&seat->keyboard->resource_list, wl_resource_get_link(cr));
 	wl_resource_set_destructor(cr, unbind_resource);
 
@@ -1223,7 +1226,9 @@ seat_get_touch(struct wl_client *client, struct wl_resource *resource,
 	if (!seat->touch)
 		return;
 
-        cr = wl_client_add_object(client, &wl_touch_interface, NULL, id, seat);
+        cr = wl_client_add_versioned_object(client, &wl_touch_interface,
+					    wl_resource_get_version(resource),
+					    NULL, id, seat);
 	wl_list_insert(&seat->touch->resource_list, wl_resource_get_link(cr));
 	wl_resource_set_destructor(cr, unbind_resource);
 }
@@ -1241,8 +1246,9 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
 	struct wl_resource *resource;
 	enum wl_seat_capability caps = 0;
 
-	resource = wl_client_add_object(client, &wl_seat_interface,
-					&seat_interface, id, data);
+	resource = wl_client_add_versioned_object(client, &wl_seat_interface,
+						  MIN(version, 2),
+						  &seat_interface, id, data);
 	wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource));
 	wl_resource_set_destructor(resource, unbind_resource);
 
diff --git a/src/screenshooter.c b/src/screenshooter.c
index 8143202..27348f2 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -217,8 +217,10 @@ bind_shooter(struct wl_client *client,
 	struct screenshooter *shooter = data;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &screenshooter_interface,
-			     &screenshooter_implementation, id, data);
+	resource = wl_client_add_versioned_object(client,
+						  &screenshooter_interface, 1,
+						  &screenshooter_implementation,
+						  id, data);
 
 	if (client != shooter->client) {
 		wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
diff --git a/src/shell.c b/src/shell.c
index 9869db5..660580f 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1015,9 +1015,10 @@ bind_workspace_manager(struct wl_client *client,
 	struct desktop_shell *shell = data;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &workspace_manager_interface,
-					&workspace_manager_implementation,
-					id, shell);
+	resource = wl_client_add_versioned_object(client,
+						  &workspace_manager_interface, 1,
+						  &workspace_manager_implementation,
+						  id, shell);
 
 	if (resource == NULL) {
 		weston_log("couldn't add workspace manager object");
@@ -2332,10 +2333,11 @@ shell_get_shell_surface(struct wl_client *client,
 		return;
 	}
 
-	shsurf->resource = wl_client_add_object(client,
-						&wl_shell_surface_interface,
-						&shell_surface_implementation,
-						id, shsurf);
+	shsurf->resource =
+		wl_client_add_versioned_object(client,
+					       &wl_shell_surface_interface, 1,
+					       &shell_surface_implementation,
+					       id, shsurf);
 	wl_resource_set_destructor(shsurf->resource,
 				   shell_destroy_shell_surface);
 }
@@ -3599,8 +3601,8 @@ bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
 {
 	struct desktop_shell *shell = data;
 
-	wl_client_add_object(client, &wl_shell_interface,
-			     &shell_implementation, id, shell);
+	wl_client_add_versioned_object(client, &wl_shell_interface, 1,
+				       &shell_implementation, id, shell);
 }
 
 static void
@@ -3622,9 +3624,11 @@ bind_desktop_shell(struct wl_client *client,
 	struct desktop_shell *shell = data;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &desktop_shell_interface,
-					&desktop_shell_implementation,
-					id, shell);
+	resource = wl_client_add_versioned_object(client,
+						  &desktop_shell_interface,
+						  MIN(version, 2),
+						  &desktop_shell_implementation,
+						  id, shell);
 
 	if (client == shell->child.client) {
 		wl_resource_set_destructor(resource, unbind_desktop_shell);
@@ -3700,9 +3704,10 @@ bind_screensaver(struct wl_client *client,
 	struct desktop_shell *shell = data;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &screensaver_interface,
-					&screensaver_implementation,
-					id, shell);
+	resource = wl_client_add_versioned_object(client,
+						  &screensaver_interface, 1,
+						  &screensaver_implementation,
+						  id, shell);
 
 	if (shell->screensaver.binding == NULL) {
 		wl_resource_set_destructor(resource, unbind_screensaver);
@@ -3894,10 +3899,12 @@ input_panel_get_input_panel_surface(struct wl_client *client,
 		return;
 	}
 
-	ipsurf->resource = wl_client_add_object(client,
-						&wl_input_panel_surface_interface,
-						&input_panel_surface_implementation,
-						id, ipsurf);
+	ipsurf->resource =
+		wl_client_add_versioned_object(client,
+					       &wl_input_panel_surface_interface,
+					       1,
+					       &input_panel_surface_implementation,
+					       id, ipsurf);
 
 	wl_resource_set_destructor(ipsurf->resource,
 				   destroy_input_panel_surface_resource);
@@ -3922,9 +3929,10 @@ bind_input_panel(struct wl_client *client,
 	struct desktop_shell *shell = data;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &wl_input_panel_interface,
-					&input_panel_implementation,
-					id, shell);
+	resource = wl_client_add_versioned_object(client,
+						  &wl_input_panel_interface, 1,
+						  &input_panel_implementation,
+						  id, shell);
 
 	if (shell->input_panel.binding == NULL) {
 		wl_resource_set_destructor(resource, unbind_input_panel);
diff --git a/src/tablet-shell.c b/src/tablet-shell.c
index 91e5110..1619f79 100644
--- a/src/tablet-shell.c
+++ b/src/tablet-shell.c
@@ -350,10 +350,11 @@ tablet_shell_create_client(struct wl_client *client,
 	tablet_client->shell = shell;
 	tablet_client->name = strdup(name);
 
-	tablet_client->resource = wl_client_add_object(client,
-						       &tablet_client_interface,
-						       &tablet_client_implementation,
-						       id, tablet_client);
+	tablet_client->resource =
+		wl_client_add_versioned_object(client,
+					       &tablet_client_interface, 1,
+					       &tablet_client_implementation,
+					       id, tablet_client);
 	wl_resource_set_destructor(tablet_client->resource,
 				   destroy_tablet_client);
 
@@ -498,8 +499,9 @@ bind_tablet_shell(struct wl_client *client, void *data, uint32_t version,
 		 * tries to access the object?. */
 		return;
 
-	shell->resource = wl_client_add_object(client,
-					       &tablet_shell_interface,
+	shell->resource =
+		wl_client_add_versioned_object(client,
+					       &tablet_shell_interface, 1,
 					       &tablet_shell_implementation,
 					       id, shell);
 	wl_resource_set_destructor(shell->resource, destroy_tablet_shell);
diff --git a/src/text-backend.c b/src/text-backend.c
index 38728e9..05560b3 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -358,10 +358,11 @@ static void text_input_manager_create_text_input(struct wl_client *client,
 
 	text_input = calloc(1, sizeof *text_input);
 
-	text_input->resource = wl_client_add_object(client,
-						    &wl_text_input_interface,
-						    &text_input_implementation,
-						    id, text_input);
+	text_input->resource =
+		wl_client_add_versioned_object(client,
+					       &wl_text_input_interface, 1,
+					       &text_input_implementation,
+					       id, text_input);
 	wl_resource_set_destructor(text_input->resource, destroy_text_input);
 
 	text_input->ec = text_input_manager->ec;
@@ -383,9 +384,10 @@ bind_text_input_manager(struct wl_client *client,
 
 	/* No checking for duplicate binding necessary.
 	 * No events have to be sent, so we don't need the return value. */
-	wl_client_add_object(client, &wl_text_input_manager_interface,
-			     &text_input_manager_implementation,
-			     id, text_input_manager);
+	wl_client_add_versioned_object(client,
+				       &wl_text_input_manager_interface, 1,
+				       &text_input_manager_implementation,
+				       id, text_input_manager);
 }
 
 static void
@@ -582,8 +584,8 @@ input_method_context_grab_keyboard(struct wl_client *client,
 	struct weston_seat *seat = context->input_method->seat;
 	struct weston_keyboard *keyboard = seat->keyboard;
 
-	cr = wl_client_add_object(client, &wl_keyboard_interface,
-				  NULL, id, context);
+	cr = wl_client_add_versioned_object(client, &wl_keyboard_interface, 1,
+					    NULL, id, context);
 	wl_resource_set_destructor(cr, unbind_keyboard);
 
 	context->keyboard = cr;
@@ -703,10 +705,12 @@ input_method_context_create(struct text_input *model,
 		return;
 
 	binding = input_method->input_method_binding;
-	context->resource = wl_client_new_object(wl_resource_get_client(binding),
-						 &wl_input_method_context_interface,
-						 &input_method_context_implementation,
-						 context);
+	context->resource =
+		wl_client_new_versioned_object(wl_resource_get_client(binding),
+					       &wl_input_method_context_interface,
+					       1,
+					       &input_method_context_implementation,
+					       context);
 	wl_resource_set_destructor(context->resource,
 				   destroy_input_method_context);
 
@@ -756,9 +760,9 @@ bind_input_method(struct wl_client *client,
 	struct text_backend *text_backend = input_method->text_backend;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &wl_input_method_interface,
-					NULL,
-					id, input_method);
+	resource = wl_client_add_versioned_object(client,
+						  &wl_input_method_interface, 1,
+						  NULL, id, input_method);
 
 	if (input_method->input_method_binding != NULL) {
 		wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
diff --git a/src/xwayland/launcher.c b/src/xwayland/launcher.c
index 7048131..3cde8b3 100644
--- a/src/xwayland/launcher.c
+++ b/src/xwayland/launcher.c
@@ -159,8 +159,8 @@ bind_xserver(struct wl_client *client,
 		return;
 
 	wxs->resource = 
-		wl_client_add_object(client, &xserver_interface,
-				     &xserver_implementation, id, wxs);
+		wl_client_add_versioned_object(client, &xserver_interface, 1,
+					       &xserver_implementation, id, wxs);
 
 	wxs->wm = weston_wm_create(wxs);
 	if (wxs->wm == NULL) {
diff --git a/src/zoom.c b/src/zoom.c
index 267ff31..1164dd3 100644
--- a/src/zoom.c
+++ b/src/zoom.c
@@ -53,8 +53,9 @@ static void
 bind_text_cursor_position(struct wl_client *client,
 	     void *data, uint32_t version, uint32_t id)
 {
-	wl_client_add_object(client, &text_cursor_position_interface,
-			     &text_cursor_position_implementation, id, data);
+	wl_client_add_versioned_object(client, &text_cursor_position_interface,
+				       1, &text_cursor_position_implementation,
+				       id, data);
 }
 
 static void
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 214296e..9822be9 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -191,8 +191,8 @@ bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
 	struct weston_test *test = data;
 	struct wl_resource *resource;
 
-	resource = wl_client_add_object(client, &wl_test_interface,
-					&test_implementation, id, test);
+	resource = wl_client_add_versioned_object(client, &wl_test_interface, 1,
+						  &test_implementation, id, test);
 
 	notify_pointer_position(test, resource);
 }
-- 
1.8.2.1



More information about the wayland-devel mailing list