[PATCH weston] input: implement repeat_info event on wl_keyboard

Daniel Stone daniel at fooishbar.org
Thu Jul 25 05:54:46 PDT 2013


Hi,

On 16 July 2013 09:33, Jonny Lamb <jonnylamb at jonnylamb.com> wrote:
> weston-compositor and the weston-info client have also been updated to
> pass on and print these values if present. The rate and delay defaults
> originate from X.

This and the protocol patch both look good to me; in particular I
(surprisingly) can't see a problem with the versioning! The one thing
it's missing though, is integration into clients/window.c where it
sets up the keyboard repeat, inside keyboard_handle_key.  That aside,
I think this is good for merging.

Thanks :)

> ---
>  clients/weston-info.c    | 106 ++++++++++++++++++++++++++++++++++++++++++++---
>  src/compositor-wayland.c |  18 ++++++--
>  src/compositor.c         |   5 +++
>  src/compositor.h         |   3 ++
>  src/input.c              |  12 +++++-
>  5 files changed, 133 insertions(+), 11 deletions(-)
>
> diff --git a/clients/weston-info.c b/clients/weston-info.c
> index 03b4c40..4515bfe 100644
> --- a/clients/weston-info.c
> +++ b/clients/weston-info.c
> @@ -29,6 +29,8 @@
>
>  #include "../shared/os-compatibility.h"
>
> +#define MIN(x,y) (((x) < (y)) ? (x) : (y))
> +
>  typedef void (*print_info_t)(void *info);
>
>  struct global_info {
> @@ -85,6 +87,9 @@ struct seat_info {
>
>         uint32_t capabilities;
>         char *name;
> +
> +       int32_t repeat_rate;
> +       int32_t repeat_delay;
>  };
>
>  struct weston_info {
> @@ -245,22 +250,105 @@ print_seat_info(void *data)
>                 printf(" touch");
>
>         printf("\n");
> +
> +       if (seat->repeat_rate > 0)
> +               printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate);
> +       if (seat->repeat_delay > 0)
> +               printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay);
> +}
> +
> +static void
> +keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
> +                      uint32_t format, int fd, uint32_t size)
> +{
> +}
> +
> +static void
> +keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
> +                     uint32_t serial, struct wl_surface *surface,
> +                     struct wl_array *keys)
> +{
>  }
>
>  static void
> +keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
> +                     uint32_t serial, struct wl_surface *surface)
> +{
> +}
> +
> +static void
> +keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
> +                   uint32_t serial, uint32_t time, uint32_t key,
> +                   uint32_t state)
> +{
> +}
> +
> +static void
> +keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
> +                         uint32_t serial, uint32_t mods_depressed,
> +                         uint32_t mods_latched, uint32_t mods_locked,
> +                         uint32_t group)
> +{
> +}
> +
> +static void
> +keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
> +                           int32_t rate, int32_t delay)
> +{
> +       struct seat_info *seat = data;
> +
> +       seat->repeat_rate = rate;
> +       seat->repeat_delay = delay;
> +}
> +
> +static const struct wl_keyboard_listener keyboard_listener = {
> +       keyboard_handle_keymap,
> +       keyboard_handle_enter,
> +       keyboard_handle_leave,
> +       keyboard_handle_key,
> +       keyboard_handle_modifiers,
> +       keyboard_handle_repeat_info,
> +};
> +
> +/* This is a struct so we don't have to add a (circular) pointer in
> + * seat_info to weston_info just so roundtrip_needed can be set to
> + * true. */
> +struct seat_async_data {
> +       struct seat_info *seat;
> +       struct weston_info *info;
> +};
> +
> +static void
>  seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
>                          enum wl_seat_capability caps)
>  {
> -       struct seat_info *seat = data;
> -       seat->capabilities = caps;
> +       struct seat_async_data *async_data = data;
> +
> +       async_data->seat->capabilities = caps;
> +
> +       /* we want listen for repeat_info from wl_keyboard, but only
> +        * do so if the seat info is >= 3 and if we actually have a
> +        * keyboard */
> +       if (async_data->seat->global.version < 3)
> +               return;
> +
> +       if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
> +               struct wl_keyboard *keyboard;
> +
> +               keyboard = wl_seat_get_keyboard(async_data->seat->seat);
> +               wl_keyboard_add_listener(keyboard, &keyboard_listener,
> +                                        async_data->seat);
> +
> +               async_data->info->roundtrip_needed = true;
> +       }
>  }
>
>  static void
>  seat_handle_name(void *data, struct wl_seat *wl_seat,
>                  const char *name)
>  {
> -       struct seat_info *seat = data;
> -       seat->name = strdup(name);
> +       struct seat_async_data *async_data = data;
> +       async_data->seat->name = strdup(name);
>  }
>
>  static const struct wl_seat_listener seat_listener = {
> @@ -272,13 +360,19 @@ static void
>  add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
>  {
>         struct seat_info *seat = malloc(sizeof *seat);
> +       struct seat_async_data *async_data = malloc(sizeof *async_data);
> +
> +       async_data->seat = seat;
> +       async_data->info = info;
>
>         init_global_info(info, &seat->global, id, "wl_seat", version);
>         seat->global.print = print_seat_info;
>
>         seat->seat = wl_registry_bind(info->registry,
> -                                     id, &wl_seat_interface, 2);
> -       wl_seat_add_listener(seat->seat, &seat_listener, seat);
> +                                     id, &wl_seat_interface, MIN(version, 3));
> +       wl_seat_add_listener(seat->seat, &seat_listener, async_data);
> +
> +       seat->repeat_rate = seat->repeat_delay = -1;
>
>         info->roundtrip_needed = true;
>  }
> diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
> index f3a98a8..6e2998a 100644
> --- a/src/compositor-wayland.c
> +++ b/src/compositor-wayland.c
> @@ -584,12 +584,24 @@ input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
>         notify_modifiers(&input->base, serial_out);
>  }
>
> +static void
> +input_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
> +                        int32_t rate, int32_t delay)
> +{
> +       struct wayland_input *input = data;
> +       struct wayland_compositor *c = input->compositor;
> +
> +       c->base.kb_repeat_rate = rate;
> +       c->base.kb_repeat_delay = delay;
> +}
> +
>  static const struct wl_keyboard_listener keyboard_listener = {
>         input_handle_keymap,
>         input_handle_keyboard_enter,
>         input_handle_keyboard_leave,
>         input_handle_key,
>         input_handle_modifiers,
> +       input_handle_repeat_info,
>  };
>
>  static void
> @@ -625,7 +637,7 @@ static const struct wl_seat_listener seat_listener = {
>  };
>
>  static void
> -display_add_seat(struct wayland_compositor *c, uint32_t id)
> +display_add_seat(struct wayland_compositor *c, uint32_t id, uint32_t version)
>  {
>         struct wayland_input *input;
>
> @@ -638,7 +650,7 @@ display_add_seat(struct wayland_compositor *c, uint32_t id)
>         weston_seat_init(&input->base, &c->base, "default");
>         input->compositor = c;
>         input->seat = wl_registry_bind(c->parent.registry, id,
> -                                      &wl_seat_interface, 1);
> +                                      &wl_seat_interface, MIN(version, 3));
>         wl_list_insert(c->input_list.prev, &input->link);
>
>         wl_seat_add_listener(input->seat, &seat_listener, input);
> @@ -665,7 +677,7 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
>                         wl_registry_bind(registry, name,
>                                          &wl_shell_interface, 1);
>         } else if (strcmp(interface, "wl_seat") == 0) {
> -               display_add_seat(c, name);
> +               display_add_seat(c, name, version);
>         } else if (strcmp(interface, "wl_shm") == 0) {
>                 c->parent.shm =
>                         wl_registry_bind(registry, name, &wl_shm_interface, 1);
> diff --git a/src/compositor.c b/src/compositor.c
> index e9e1166..d916fc3 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -2862,6 +2862,11 @@ weston_compositor_init(struct weston_compositor *ec,
>         if (weston_compositor_xkb_init(ec, &xkb_names) < 0)
>                 return -1;
>
> +       weston_config_section_get_int(s, "repeat-rate",
> +                                     &ec->kb_repeat_rate, 60);
> +       weston_config_section_get_int(s, "repeat-delay",
> +                                     &ec->kb_repeat_delay, 200);
> +
>         ec->ping_handler = NULL;
>
>         screenshooter_create(ec);
> diff --git a/src/compositor.h b/src/compositor.h
> index 84f39e2..f4b85ef 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -586,6 +586,9 @@ struct weston_compositor {
>
>         /* Raw keyboard processing (no libxkbcommon initialization or handling) */
>         int use_xkbcommon;
> +
> +       int32_t kb_repeat_rate;
> +       int32_t kb_repeat_delay;
>  };
>
>  struct weston_buffer {
> diff --git a/src/input.c b/src/input.c
> index 1887e7f..08a9e81 100644
> --- a/src/input.c
> +++ b/src/input.c
> @@ -1232,6 +1232,14 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
>                                           seat->keyboard->focus);
>                 wl_data_device_set_keyboard_focus(seat);
>         }
> +
> +       /* if wl_seat's version is at least 3, the wl_keyboard's
> +        * version must be 2, so we support repeat_info */
> +       if (wl_resource_get_version(resource) >= 3) {
> +               wl_keyboard_send_repeat_info(cr,
> +                                            seat->compositor->kb_repeat_rate,
> +                                            seat->compositor->kb_repeat_delay);
> +       }
>  }
>
>  static void
> @@ -1264,7 +1272,7 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
>         enum wl_seat_capability caps = 0;
>
>         resource = wl_resource_create(client,
> -                                     &wl_seat_interface, MIN(version, 2), id);
> +                                     &wl_seat_interface, MIN(version, 3), id);
>         wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource));
>         wl_resource_set_implementation(resource, &seat_interface, data,
>                                        unbind_resource);
> @@ -1531,7 +1539,7 @@ weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,
>         wl_list_init(&seat->drag_resource_list);
>         wl_signal_init(&seat->destroy_signal);
>
> -       seat->global = wl_global_create(ec->wl_display, &wl_seat_interface, 2,
> +       seat->global = wl_global_create(ec->wl_display, &wl_seat_interface, 3,
>                                         seat, bind_seat);
>
>         seat->compositor = ec;
> --
> 1.8.3.2
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list