proxy: Add API to tag proxy objects
authorJonas Ådahl <jadahl@gmail.com>
Wed, 10 Jul 2019 07:13:33 +0000 (09:13 +0200)
committerPekka Paalanen <pq@iki.fi>
Mon, 29 Jul 2019 16:47:36 +0000 (16:47 +0000)
commit493ab79bd2cdf8f9f12fb9e5522200dc668b85e0
tree2b7d617b2a18f77f8b73b7a70e87182d5e403c62
parent6908c8c85a2e33e5654f64a55cd4f847bf385cae
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>
Makefile.am
src/wayland-client-core.h
src/wayland-client.c
tests/proxy-test.c [new file with mode: 0644]