aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2019-07-10 09:13:33 +0200
committerPekka Paalanen <pq@iki.fi>2019-07-29 16:47:36 +0000
commit493ab79bd2cdf8f9f12fb9e5522200dc668b85e0 (patch)
tree2b7d617b2a18f77f8b73b7a70e87182d5e403c62 /src
parentcursor: Use memfd_create() when available (diff)
downloadwayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.tar
wayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.tar.gz
wayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.tar.bz2
wayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.tar.lz
wayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.tar.xz
wayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.tar.zst
wayland-493ab79bd2cdf8f9f12fb9e5522200dc668b85e0.zip
proxy: Add API to tag proxy objects
When an application and a toolkit share the same Wayland connection, it will receive events with each others objects. For example if the toolkit manages a set of surfaces, and the application another set, if both the toolkit and application listen to pointer focus events, they'll receive focus events for each others surfaces. In order for the toolkit and application layers to identify whether a surface is managed by itself or not, it cannot only rely on retrieving the proxy user data, without going through all it's own proxy objects finding whether it's one of them. By adding the ability to "tag" a proxy object, the toolkit and application can use the tag to identify what the user data pointer points to something known. To create a tag, the recommended way is to define a statically allocated constant char array containing some descriptive string. The tag will be the pointer to the non-const pointer to the beginning of the array. For example, to identify whether a focus event is for a surface managed by the code in question: static const char *my_tag = "my tag"; static void pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { struct window *window; const char * const *tag; tag = wl_proxy_get_tag((struct wl_proxy *) surface); if (tag != &my_tag) return; window = wl_surface_get_user_data(surface); ... } ... static void init_window_surface(struct window *window) { struct wl_surface *surface; surface = wl_compositor_create_surface(compositor); wl_surface_set_user_data(surface, window); wl_proxy_set_tag((struct wl_proxy *) surface, &my_tag); } Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/wayland-client-core.h7
-rw-r--r--src/wayland-client.c65
2 files changed, 72 insertions, 0 deletions
diff --git a/src/wayland-client-core.h b/src/wayland-client-core.h
index 03e781b..0cd96e0 100644
--- a/src/wayland-client-core.h
+++ b/src/wayland-client-core.h
@@ -191,6 +191,13 @@ wl_proxy_get_version(struct wl_proxy *proxy);
uint32_t
wl_proxy_get_id(struct wl_proxy *proxy);
+void
+wl_proxy_set_tag(struct wl_proxy *proxy,
+ const char * const *tag);
+
+const char * const *
+wl_proxy_get_tag(struct wl_proxy *proxy);
+
const char *
wl_proxy_get_class(struct wl_proxy *proxy);
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 38756f1..0821af1 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -69,6 +69,7 @@ struct wl_proxy {
void *user_data;
wl_dispatcher_func_t dispatcher;
uint32_t version;
+ const char * const *tag;
};
struct wl_event_queue {
@@ -2059,6 +2060,70 @@ wl_proxy_get_id(struct wl_proxy *proxy)
return proxy->object.id;
}
+/** Set the tag of a proxy object
+ *
+ * A toolkit or application can set a unique tag on a proxy in order to
+ * identify whether an object is managed by itself or some external part.
+ *
+ * To create a tag, the recommended way is to define a statically allocated
+ * constant char array containing some descriptive string. The tag will be the
+ * pointer to the non-const pointer to the beginning of the array.
+ *
+ * For example, to define and set a tag on a surface managed by a certain
+ * subsystem:
+ *
+ * static const char *my_tag = "my tag";
+ *
+ * wl_proxy_set_tag((struct wl_proxy *) surface, &my_tag);
+ *
+ * Then, in a callback with wl_surface as an argument, in order to check
+ * whether it's a surface managed by the same subsystem.
+ *
+ * const char * const *tag;
+ *
+ * tag = wl_proxy_get_tag((struct wl_proxy *) surface);
+ * if (tag != &my_tag)
+ * return;
+ *
+ * ...
+ *
+ * For debugging purposes, a tag should be suitable to be included in a debug
+ * log entry, e.g.
+ *
+ * const char * const *tag;
+ *
+ * tag = wl_proxy_get_tag((struct wl_proxy *) surface);
+ * printf("Got a surface with the tag %p (%s)\n",
+ * tag, (tag && *tag) ? *tag : "");
+ *
+ * \param proxy The proxy object
+ * \param tag The tag
+ *
+ * \memberof wl_proxy
+ * \since 1.17.90
+ */
+WL_EXPORT void
+wl_proxy_set_tag(struct wl_proxy *proxy,
+ const char * const *tag)
+{
+ proxy->tag = tag;
+}
+
+/** Get the tag of a proxy object
+ *
+ * See wl_proxy_set_tag for details.
+ *
+ * \param proxy The proxy object
+ *
+ * \memberof wl_proxy
+ * \since 1.17.90
+ */
+WL_EXPORT const char * const *
+wl_proxy_get_tag(struct wl_proxy *proxy)
+{
+ return proxy->tag;
+}
+
/** Get the interface name (class) of a proxy object
*
* \param proxy The proxy object