[PATCH 5/5] client: Added wl_registry_bind_id
spitzak at gmail.com
spitzak at gmail.com
Tue May 17 06:18:10 UTC 2016
From: Bill Spitzak <spitzak at gmail.com>
This function assigns the id into an existing wl_proxy structure. Allows
setting of the queue before binding so that events are sent to the correct
thread.
The arguments are purposely swapped around so that just changing wl_registry_bind
to wl_registry_bind_id will not compile.
The display-test modified to test this and show the usage.
Signed-off-by: Bill Spitzak <spitzak at gmail.com>
---
src/scanner.c | 29 +++++++++++++++++++----------
src/wayland-client-core.h | 4 ++++
src/wayland-client.c | 15 ++++++++++++++-
tests/display-test.c | 4 ++++
4 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/src/scanner.c b/src/scanner.c
index fbe8193..3c0db01 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1184,14 +1184,13 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
*/
if (!ret)
continue;
- if (!ret->interface_name)
- continue; /* wl_registry_bind_id nyi */
printf("/**\n"
" * @ingroup iface_%s\n", interface->name);
printf(" *\n"
" * Same as %s_%s() except it uses an existing proxy created by\n"
" * %s_new().\n"
- " */\n", interface->name, m->name, ret->interface_name);
+ " */\n", interface->name, m->name,
+ ret->interface_name ? ret->interface_name : "wl_proxy");
printf("static inline void\n");
printf("%s_%s_id(struct %s *%s",
@@ -1200,23 +1199,33 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
wl_list_for_each(a, &m->arg_list, link) {
printf(", ");
- if (a->type != NEW_ID)
+ if (a->type != NEW_ID) {
emit_type(a);
- else
- printf("struct %s *", ret->interface_name);
- printf("%s", a->name);
+ printf("%s", a->name);
+ } else if (ret->interface_name) {
+ printf("struct %s *proxy", ret->interface_name);
+ } else {
+ printf("uint32_t version, void *proxy");
+ }
}
printf(")\n"
"{\n"
- "\twl_proxy_marshal_id((struct wl_proxy *) %s,\n"
+ "\twl_proxy_marshal_%s((struct wl_proxy *) %s,\n"
"\t\t\t %s_%s",
+ ret->interface_name ? "id" : "bind",
interface->name,
interface->uppercase_name,
m->uppercase_name);
wl_list_for_each(a, &m->arg_list, link) {
- printf(", %s", a->name);
+ if (a->type != NEW_ID) {
+ printf(", %s", a->name);
+ } else if (ret->interface_name) {
+ printf(", proxy");
+ } else {
+ printf(", version, (struct wl_proxy *) proxy");
+ }
}
printf(");\n");
@@ -1398,7 +1407,7 @@ emit_structs(struct wl_list *message_list, struct interface *interface, enum sid
printf("/**\n"
" * @ingroup iface_%s\n"
" *\n"
- " * Create a %s and allocate an id.\n"
+ " * Allocate a new %s.\n"
" */\n"
"static inline struct %s *\n"
"%s_new(void)\n"
diff --git a/src/wayland-client-core.h b/src/wayland-client-core.h
index 8e48cab..84ceb70 100644
--- a/src/wayland-client-core.h
+++ b/src/wayland-client-core.h
@@ -128,6 +128,10 @@ void
wl_proxy_marshal_id(struct wl_proxy *proxy, uint32_t opcode, ...);
void
+wl_proxy_marshal_bind(struct wl_proxy *factory, uint32_t opcode,
+ uint32_t name, uint32_t version, struct wl_proxy *new_proxy);
+
+void
wl_proxy_marshal_array(struct wl_proxy *p, uint32_t opcode,
union wl_argument *args);
diff --git a/src/wayland-client.c b/src/wayland-client.c
index d539bf7..326ca14 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -741,11 +741,24 @@ wl_proxy_marshal_id(struct wl_proxy *factory, uint32_t opcode, ...)
new_proxy->display = factory->display;
if (new_proxy->queue == NULL)
new_proxy->queue = factory->queue;
- new_proxy->version = factory->version;
+ if (new_proxy->version == 0)
+ new_proxy->version = factory->version;
proxy_marshal_array(factory, opcode, args, new_proxy);
}
+/** Same as wl_proxy_marshal_id() except special handling of the new_id.
+ * The message will prefix this with the interface name and the version.
+ * Currently the api only works for the wl_registry_bind argument list.
+ */
+WL_EXPORT void
+wl_proxy_marshal_bind(struct wl_proxy *factory, uint32_t opcode,
+ uint32_t name, uint32_t version, struct wl_proxy *new_proxy)
+{
+ new_proxy->version = version;
+ wl_proxy_marshal_id(factory, opcode, name, wl_proxy_get_class(new_proxy), version, new_proxy);
+}
+
/** Prepare a request to be sent to the compositor
*
* \param factory The proxy object
diff --git a/tests/display-test.c b/tests/display-test.c
index f9f8160..3c82f34 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -141,6 +141,10 @@ registry_handle_globals(void *data, struct wl_registry *registry,
if (hi->use_unversioned)
hi->seat = old_registry_bind(registry, id,
&wl_seat_interface, ver);
+ else if (1) { /* test _id version of bind */
+ hi->seat = wl_seat_new();
+ wl_registry_bind_id(registry, id, ver, hi->seat);
+ }
else
hi->seat = wl_registry_bind(registry, id,
&wl_seat_interface, ver);
--
1.9.1
More information about the wayland-devel
mailing list