[Take 2][PATCH] Add touch support for wl_shell_surface_move

Jan Arne Petersen janarne at gmail.com
Thu Aug 15 05:12:44 PDT 2013


On 08/15/2013 12:49 AM, Rusty Lynch wrote:
> From 3c68e0e2aa98250c65a5d5e9658299904ccf34f1 Mon Sep 17 00:00:00 2001
> From: Rusty Lynch <rusty.lynch at intel.com>
> Date: Wed, 14 Aug 2013 09:27:44 -0700
> Subject: [PATCH] Add touch support for wl_shell_surface_move
> 
> ---
>  clients/calibrator.c    |   4 +-
>  clients/desktop-shell.c |   9 ++--
>  clients/flower.c        |  11 +++++
>  clients/fullscreen.c    |  12 +++++
>  clients/simple-egl.c    |  50 +++++++++++++++++++
>  clients/smoke.c         |   4 +-
>  clients/transformed.c   |  12 +++++
>  clients/window.c        |  52 +++++++++++++++-----
>  clients/window.h        |  11 ++++-
>  src/shell.c             | 128 +++++++++++++++++++++++++++++++++++++++++++++---
>  10 files changed, 263 insertions(+), 30 deletions(-)

...

> diff --git a/src/shell.c b/src/shell.c
> index 8f2be78..b6af8b0 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -237,11 +237,23 @@ struct shell_grab {
>  	struct wl_listener shsurf_destroy_listener;
>  };
>  
> +struct shell_touch_grab {
> +	struct weston_touch_grab grab;
> +	struct shell_surface *shsurf;
> +	struct wl_listener shsurf_destroy_listener;
> +	struct weston_touch *touch;
> +};
> +
>  struct weston_move_grab {
>  	struct shell_grab base;
>  	wl_fixed_t dx, dy;
>  };
>  
> +struct weston_touch_move_grab {
> +	struct shell_touch_grab base;
> +	wl_fixed_t dx, dy;
> +};
> +
>  struct rotate_grab {
>  	struct shell_grab base;
>  	struct weston_matrix rotation;
> @@ -350,6 +362,36 @@ shell_grab_end(struct shell_grab *grab)
>  }
>  
>  static void
> +shell_touch_grab_start(struct shell_touch_grab *grab,
> +		       const struct weston_touch_grab_interface *interface,
> +		       struct shell_surface *shsurf,
> +		       struct weston_touch *touch)
> +{
> +	struct desktop_shell *shell = shsurf->shell;
> +	
> +	grab->grab.interface = interface;
> +	grab->shsurf = shsurf;
> +	grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
> +	wl_signal_add(&shsurf->destroy_signal,
> +		      &grab->shsurf_destroy_listener);
> +
> +	grab->touch = touch;
> +
> +	weston_touch_start_grab(touch, &grab->grab);
> +	if (shell->child.desktop_shell)
> +		weston_touch_set_focus(touch->seat, shell->grab_surface);
> +}
> +
> +static void
> +shell_touch_grab_end(struct shell_touch_grab *grab)
> +{
> +	if (grab->shsurf)
> +		wl_list_remove(&grab->shsurf_destroy_listener.link);
> +
> +	weston_touch_end_grab(grab->touch);
> +}
> +
> +static void
>  center_on_output(struct weston_surface *surface,
>  		 struct weston_output *output);
>  
> @@ -1035,6 +1077,74 @@ bind_workspace_manager(struct wl_client *client,
>  }
>  
>  static void
> +touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
> +		     int touch_id, wl_fixed_t sx, wl_fixed_t sy)
> +{
> +}
> +
> +static void
> +touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
> +{
> +	struct shell_touch_grab *shell_grab = container_of(grab, 
> +							   struct shell_touch_grab,
> +							   grab);
> +	shell_touch_grab_end(shell_grab);
> +}
> +
> +static void
> +touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
> +		       int touch_id, wl_fixed_t sx, wl_fixed_t sy)
> +{
> +	struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
> +	struct shell_surface *shsurf = move->base.shsurf;
> +	struct weston_surface *es;
> +	int dx = wl_fixed_to_int(sx + move->dx);
> +	int dy = wl_fixed_to_int(sy + move->dy);

that should be global coordinates (touch->grab_x, touch->grab_y instead
of sx an sy).

> +	if (!shsurf)
> +		return;
> +
> +	es = shsurf->surface;
> +
> +	weston_surface_configure(es, dx, dy,
> +				 es->geometry.width, es->geometry.height);
> +
> +	weston_compositor_schedule_repaint(es->compositor);
> +}
> +
> +static const struct weston_touch_grab_interface touch_move_grab_interface = {
> +	touch_move_grab_down,
> +	touch_move_grab_up,
> +	touch_move_grab_motion,
> +};
> +
> +static int
> +surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
> +{
> +	struct weston_touch_move_grab *move;
> +
> +	if (!shsurf)
> +		return -1;
> +
> +	if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
> +		return 0;
> +
> +	move = malloc(sizeof *move);
> +	if (!move)
> +		return -1;
> +
> +	move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
> +			seat->touch->grab_x;
> +	move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
> +			seat->touch->grab_y;
> +
> +	shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
> +			       seat->touch);
> +
> +	return 0;
> +}
> +
> +static void
>  noop_grab_focus(struct weston_pointer_grab *grab)
>  {
>  }
> @@ -1117,13 +1227,17 @@ shell_surface_move(struct wl_client *client, struct wl_resource *resource,
>  	struct weston_surface *surface;
>  
>  	surface = weston_surface_get_main_surface(seat->pointer->focus);
> -	if (seat->pointer->button_count == 0 ||
> -	    seat->pointer->grab_serial != serial ||
> -	    surface != shsurf->surface)
> -		return;
> -
> -	if (surface_move(shsurf, seat) < 0)
> -		wl_resource_post_no_memory(resource);
> +	if (seat->pointer->button_count > 0 && seat->pointer->grab_serial == serial) {
> +		surface = weston_surface_get_main_surface(seat->pointer->focus);
> +		if ((surface == shsurf->surface) && 
> +		    (surface_move(shsurf, seat) < 0))
> +			wl_resource_post_no_memory(resource);
> +	} else if (seat->touch->grab_serial == serial) {
> +		surface = weston_surface_get_main_surface(seat->touch->focus);
> +		if ((surface == shsurf->surface) && 
> +		    (surface_touch_move(shsurf, seat) < 0))
> +			wl_resource_post_no_memory(resource);
> +	}
>  }
>  
>  struct weston_resize_grab {
> 



More information about the wayland-devel mailing list