On Fri, 26 Jan 2018 18:48:01 +0200
Alexandros Frantzis <alexandros.frant...@collabora.com> wrote:

> The current test client code completely ignores removal of globals.
> This commit updates the code to properly handle removal of globals in
> general, and of seat globals in particular. This ensures that the test
> client objects are in sync with the server and any relevant resources
> are released accordingly.
> 
> This update will be used by upcoming tests to check that seat removal
> and re-addition is working properly.
> 
> Signed-off-by: Alexandros Frantzis <alexandros.frant...@collabora.com>
> ---
>  tests/weston-test-client-helper.c | 71 
> +++++++++++++++++++++++++++++++++++++--
>  tests/weston-test-client-helper.h |  1 +
>  2 files changed, 70 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/weston-test-client-helper.c 
> b/tests/weston-test-client-helper.c
> index 854978d0..6dc72213 100644
> --- a/tests/weston-test-client-helper.c
> +++ b/tests/weston-test-client-helper.c
> @@ -541,8 +541,23 @@ static const struct weston_test_listener test_listener = 
> {
>  static void
>  input_destroy(struct input *inp)
>  {
> +     if (inp->pointer) {
> +             if (inp->pointer->wl_pointer)
> +                     wl_pointer_release(inp->pointer->wl_pointer);
> +             free(inp->pointer);
> +     }
> +     if (inp->keyboard) {
> +             if (inp->keyboard->wl_keyboard)
> +                     wl_keyboard_release(inp->keyboard->wl_keyboard);
> +             free(inp->keyboard);
> +     }
> +     if (inp->touch) {
> +             if (inp->touch->wl_touch)
> +                     wl_touch_release(inp->touch->wl_touch);
> +             free(inp->touch);
> +     }
>       wl_list_remove(&inp->link);
> -     wl_seat_destroy(inp->wl_seat);
> +     wl_seat_release(inp->wl_seat);
>       free(inp);
>  }
>  
> @@ -748,6 +763,7 @@ handle_global(void *data, struct wl_registry *registry,
>       } else if (strcmp(interface, "wl_seat") == 0) {
>               input = xzalloc(sizeof *input);
>               input->client = client;
> +             input->global_name = global->name;
>               input->wl_seat =
>                       wl_registry_bind(registry, id,
>                                        &wl_seat_interface, version);
> @@ -778,8 +794,59 @@ handle_global(void *data, struct wl_registry *registry,
>       }
>  }
>  
> +static struct global *
> +client_find_global_with_name(struct client *client, uint32_t name)
> +{
> +     struct global *global;
> +
> +     wl_list_for_each(global, &client->global_list, link) {
> +             if (global->name == name)
> +                     return global;
> +     }
> +
> +     return NULL;
> +}
> +
> +static struct input *
> +client_find_input_with_name(struct client *client, uint32_t name)
> +{
> +     struct input *input;
> +
> +     wl_list_for_each(input, &client->inputs, link) {
> +             if (input->global_name == name)
> +                     return input;
> +     }
> +
> +     return NULL;
> +}
> +
> +static void
> +handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
> +{
> +     struct client *client = data;
> +     struct global *global;
> +     struct input *input;
> +
> +     global = client_find_global_with_name(client, name);
> +     assert(global && "Request to remove unknown global");
> +
> +     if (strcmp(global->interface, "wl_seat") == 0) {
> +             input = client_find_input_with_name(client, name);
> +             if (input) {
> +                     if (client->input == input)
> +                             client->input = NULL;
> +                     input_destroy(input);
> +             }
> +     }
> +
> +     wl_list_remove(&global->link);
> +     free(global->interface);
> +     free(global);
> +}
> +
>  static const struct wl_registry_listener registry_listener = {
> -     handle_global
> +     handle_global,
> +     handle_global_remove,
>  };
>  
>  void
> diff --git a/tests/weston-test-client-helper.h 
> b/tests/weston-test-client-helper.h
> index f16356e5..255bbf66 100644
> --- a/tests/weston-test-client-helper.h
> +++ b/tests/weston-test-client-helper.h
> @@ -75,6 +75,7 @@ struct test {
>  
>  struct input {
>       struct client *client;
> +     uint32_t global_name;
>       struct wl_seat *wl_seat;
>       struct pointer *pointer;
>       struct keyboard *keyboard;

Seems to do the job.

Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>

This also does not hinder the testing of removed wl_seats, because a
test can do stuff with them after sending the device_remove(seat) but
before processing any events.


Thanks,
pq

Attachment: pgpRN2MM9Y4b2.pgp
Description: OpenPGP digital signature

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to