[PATCH 1/2] shell: enable moving and resizing of a surface when clicking on a subsurface

Pekka Paalanen ppaalanen at gmail.com
Tue Feb 26 02:19:32 PST 2013


On Mon, 25 Feb 2013 18:59:50 +0100
Giulio Camuffo <giuliocamuffo at gmail.com> wrote:

> ---
>  src/shell.c | 36 ++++++++++++++++++++++++++++++++----
>  1 file changed, 32 insertions(+), 4 deletions(-)
> 
> diff --git a/src/shell.c b/src/shell.c
> index c8f20ec..5273bc1 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -1092,10 +1092,24 @@ shell_surface_move(struct wl_client *client, struct wl_resource *resource,
>  {
>  	struct weston_seat *ws = seat_resource->data;
>  	struct shell_surface *shsurf = resource->data;
> +	int focus_is_surface;
> +	struct weston_subsurface *subsurface;
>  
>  	if (ws->seat.pointer->button_count == 0 ||
> -	    ws->seat.pointer->grab_serial != serial ||
> -	    ws->seat.pointer->focus != &shsurf->surface->surface)
> +	    ws->seat.pointer->grab_serial != serial)
> +		return;
> +
> +	focus_is_surface = ws->seat.pointer->focus == &shsurf->surface->surface;
> +	if (!focus_is_surface) {
> +		wl_list_for_each(subsurface, &shsurf->surface->subsurface_list, parent_link) {
> +			if (ws->seat.pointer->focus == &subsurface->surface->surface) {
> +				focus_is_surface = 1;
> +				break;
> +			}
> +		}
> +	}
> +
> +	if (!focus_is_surface)
>  		return;
>  
>  	if (surface_move(shsurf, ws) < 0)
> @@ -1215,13 +1229,27 @@ shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
>  {
>  	struct weston_seat *ws = seat_resource->data;
>  	struct shell_surface *shsurf = resource->data;
> +	int focus_is_surface;
> +	struct weston_subsurface *subsurface;
>  
>  	if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
>  		return;
>  
>  	if (ws->seat.pointer->button_count == 0 ||
> -	    ws->seat.pointer->grab_serial != serial ||
> -	    ws->seat.pointer->focus != &shsurf->surface->surface)
> +		ws->seat.pointer->grab_serial != serial)
> +		return;
> +
> +	focus_is_surface = ws->seat.pointer->focus == &shsurf->surface->surface;
> +	if (!focus_is_surface) {
> +		wl_list_for_each(subsurface, &shsurf->surface->subsurface_list, parent_link) {
> +			if (ws->seat.pointer->focus == &subsurface->surface->surface) {
> +				focus_is_surface = 1;
> +				break;
> +			}
> +		}
> +	}
> +
> +	if (!focus_is_surface)
>  		return;
>  
>  	if (surface_resize(shsurf, ws, edges) < 0)

Hi Giulio,

I think these two list traversals could be replaced by calling
weston_surface_get_parent() unconditionally on the current pointer
focus. That will give you a weston_surface that is the main surface of
the window, which is what the shell should only be interested in. You
can then compare that to shsurf->surface.

Personally I prefer container_of() for going from wl_surface to
weston_surface rather than just a cast, but I guess both forms are
found in weston.

If the argument of weston_surface_get_parent() is not a
sub-surface, it just returns the same pointer as passed in.

For example:
http://cgit.collabora.com/git/user/pq/weston.git/commit/?h=subsurface-v2&id=744fad86ed419aa75d56507121154068b74ebb8c


Thanks,
pq


More information about the wayland-devel mailing list