How to properly keep track of wl/xdg output?

ferreiradaselva ferreiradaselva at protonmail.com
Sat May 12 10:34:36 UTC 2018


Hi,

Excuse me if this is something that is already explained in the protocols, but I couldn't find the solution by myown.

I'm working on a client-side library, and I need to keep track of wl (or xdg in the future) outputs. My first idea was:
- Have a `wl_list` in my context
- In the global listener, add the `wl_output` to the list
- In the global remove listener, remove the `wl_output` from the list

However, in the global remove listener, we only have a "uint32_t id" parameter. How am I supposed to know that the type of the object being removed is a `wl_output`? In the global listener we at least have a "const char *interface" that let us know that.

This is what I have (some parts omitted for brevity):

```
static void wl_registry_listener_global(void *data, struct wl_registry *registry,uint32_t name, const char *interface, uint32_t version)
{
    struct mycontext *mycontext = data;
    if (!strcmp(interface, "wl_output")) {
        struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, 1);
        wl_output_add_listener(output, &wl_output_listener, mycontext);
        wl_list_insert(&mycontext->outputs, output);
    }
}

static void wl_registry_listener_global_remove(void *data, struct wl_registry *registry, uint32_t id)
{
    struct mycontext *mycontext = data;
    if (...) {
        wl_list_remove(&mycontext->outputs, output);
    }
}
```

Thanks in advance,
- Felipe

Sent with [ProtonMail](https://protonmail.com) Secure Email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20180512/f6e7266b/attachment.html>


More information about the wayland-devel mailing list