[PATCH 2/2] compositor-wayland: Add touch support

Jason Ekstrand jason at jlekstrand.net
Wed May 7 18:55:23 PDT 2014


Boyan,
By and large, this looks really good!  I have just a few comments below.
As I said in another e-mail, I don't have any touch hardware I can test
this on, so I wasn't able to actually test it.


On Tue, May 6, 2014 at 9:46 PM, Boyan Ding <stu_dby at 126.com> wrote:

> Adding touch support to weston's nested wayland backend to make testing
> easier.
>
> https://bugs.freedesktop.org/show_bug.cgi?id=77769
> ---
>  src/compositor-wayland.c | 95
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 95 insertions(+)
>
> diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
> index a08b71a..45040d4 100644
> --- a/src/compositor-wayland.c
> +++ b/src/compositor-wayland.c
> @@ -1582,6 +1582,91 @@ static const struct wl_keyboard_listener
> keyboard_listener = {
>  };
>
>  static void
> +input_handle_touch_down(void *data, struct wl_touch *touch, uint32_t
> serial,
> +                       uint32_t time, struct wl_surface *surface, int32_t
> id,
> +                       wl_fixed_t x, wl_fixed_t y)
> +{
> +       struct wayland_input *input = data;
> +       int32_t fx, fy;
> +
> +       if (input->output->frame) {
> +               frame_touch_down(input->output->frame, input, id,
> +                                wl_fixed_to_int(x), wl_fixed_to_int(y));
> +               frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
> +               x -= wl_fixed_from_int(fx);
> +               y -= wl_fixed_from_int(fy);
>

You probably want to handle FRAME_STATUS_MOVE here.  See also
input_handle_button.


> +
> +               if (frame_status(input->output->frame) &
> FRAME_STATUS_REPAINT)
> +
> weston_output_schedule_repaint(&input->output->base);
> +       }
> +
> +       weston_output_transform_coordinate(&input->output->base, x, y, &x,
> &y);
> +
> +       notify_touch(&input->base, time, id, x, y, WL_TOUCH_DOWN);
> +}
> +
> +static void
> +input_handle_touch_up(void *data, struct wl_touch *touch, uint32_t serial,
> +                     uint32_t time, int32_t id)
> +{
> +       struct wayland_input *input = data;
> +
> +       if (input->output->frame) {
> +               frame_touch_up(input->output->frame, input, id);
> +
>

You need to handle FRAME_STATUS_CLOSE here.  See also input_handle_button.

Perhaps, we want to add a wayland_output_handle_frame_status function to
handle all of these so they can all be put in one place.  If we want to do
that, then it should probably be in it's own patch.


> +               if (frame_status(input->output->frame) &
> FRAME_STATUS_REPAINT)
> +
> weston_output_schedule_repaint(&input->output->base);
> +       }
> +
> +       notify_touch(&input->base, time, id, 0, 0, WL_TOUCH_UP);
> +}
> +
> +static void
> +input_handle_touch_motion(void *data, struct wl_touch *touch, uint32_t
> time,
> +                         int32_t id, wl_fixed_t x, wl_fixed_t y)
> +{
> +       struct wayland_input *input = data;
> +       int32_t fx, fy;
> +
> +       if (input->output->frame) {
> +               frame_touch_motion(input->output->frame, input, id,
> +                                wl_fixed_to_int(x), wl_fixed_to_int(y));
> +
> +               frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
> +               x -= wl_fixed_from_int(fx);
> +               y -= wl_fixed_from_int(fy);
> +
> +               if (frame_status(input->output->frame) &
> FRAME_STATUS_REPAINT)
> +
> weston_output_schedule_repaint(&input->output->base);
> +       }
> +
> +       weston_output_transform_coordinate(&input->output->base, x, y, &x,
> &y);
> +
> +       notify_touch(&input->base, time, id, x, y, WL_TOUCH_MOTION);
> +}
> +
> +static void
> +input_handle_touch_frame(void *data, struct wl_touch *touch)
> +{
> +       struct wayland_input *input = data;
> +
> +       notify_touch_frame(&input->base);
> +}
> +
> +static void
> +input_handle_touch_cancel(void *data, struct wl_touch *touch)
> +{
>

We should add a frame_touch_cancel function to frame.c and call it here.

Also, we should probably add support for WL_TOUCH_CANCEL in notify_touch in
input.c and call it here.  If that's a little too involved for now, that's
ok.  Just call notify_touch(&input->base, 0, -1, 0, 0, WL_TOUCH_CANCEL)
here and we can implement it in notify_touch later.  It's just a big switch
statement, so this won't hurt anything.


> +}
> +
> +static const struct wl_touch_listener touch_listener = {
> +       input_handle_touch_down,
> +       input_handle_touch_up,
> +       input_handle_touch_motion,
> +       input_handle_touch_frame,
> +       input_handle_touch_cancel
> +};
> +
> +static void
>  input_handle_capabilities(void *data, struct wl_seat *seat,
>                           enum wl_seat_capability caps)
>  {
> @@ -1607,6 +1692,16 @@ input_handle_capabilities(void *data, struct
> wl_seat *seat,
>                 wl_keyboard_destroy(input->parent.keyboard);
>                 input->parent.keyboard = NULL;
>         }
> +
> +       if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->parent.touch) {
> +               input->parent.touch = wl_seat_get_touch(seat);
> +               wl_touch_set_user_data(input->parent.touch, input);
> +               wl_touch_add_listener(input->parent.touch,
> +                                        &touch_listener, input);
> +       } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) &&
> input->parent.touch) {
> +               wl_touch_destroy(input->parent.touch);
> +               input->parent.touch = NULL;
> +       }
>  }
>
>  static const struct wl_seat_listener seat_listener = {
> --
> 1.9.2
>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140507/988b58d8/attachment.html>


More information about the wayland-devel mailing list