diff --git a/src/wayland-client-core.h b/src/wayland-client-core.h index efca7a00..289c43c3 100644 --- a/src/wayland-client-core.h +++ b/src/wayland-client-core.h @@ -228,6 +228,9 @@ wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue); struct wl_event_queue * wl_proxy_get_queue(const struct wl_proxy *proxy); +struct wl_proxy * +wl_proxy_from_object(struct wl_object *object); + const char * wl_event_queue_get_name(const struct wl_event_queue *queue); diff --git a/src/wayland-client.c b/src/wayland-client.c index 8377bc44..6b9d763e 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -2720,6 +2720,28 @@ wl_proxy_wrapper_destroy(void *proxy_wrapper) free(wrapper); } +/** Safely converts an object into its corresponding proxy + * + * \param object object to get the proxy for + * \return A corresponding proxy, or NULL on failure. + * + * Safely converts an object into its corresponding proxy. + * + * This is useful for implementing functions that are given a \c wl_argument + * array, and that need to do further introspection on the ".o" field, as it + * is otherwise an opaque type. + * + * \memberof wl_proxy + */ +WL_EXPORT struct wl_proxy * +wl_proxy_from_object(struct wl_object *object) +{ + struct wl_proxy *proxy; + if (object == NULL) + return NULL; + return wl_container_of(object, proxy, object); +} + WL_EXPORT void wl_log_set_handler_client(wl_log_func_t handler) { diff --git a/tests/protocol-logger-test.c b/tests/protocol-logger-test.c index 93d31858..e3016bea 100644 --- a/tests/protocol-logger-test.c +++ b/tests/protocol-logger-test.c @@ -294,10 +294,11 @@ client_log_to_stderr_demo(void *user_data, enum wl_client_message_type type, break; case 'o': if (args[i].o) { - // Note: server logger should instead cast to - // wl_resource, and use wl_resource_get_class - // and wl_resource_get_id. - arg_proxy = (struct wl_proxy *)(args[i].o); + // Note: server logger should instead use + // wl_resource_from_object, and then + // wl_resource_get_class and + // wl_resource_get_id. + arg_proxy = wl_proxy_from_object(args[i].o); arg_class = wl_proxy_get_class(arg_proxy); fprintf(f, "%s#%u",