[weston PATCH v8 1/2] add the set_maximised implementation

Pekka Paalanen ppaalanen at gmail.com
Wed Feb 8 01:44:19 PST 2012


On Wed,  8 Feb 2012 12:02:19 +0800
juan.j.zhao at linux.intel.com wrote:

> From: Juan Zhao <juan.j.zhao at linux.intel.com>
> 
> ---
>  src/shell.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 100 insertions(+), 0 deletions(-)
> 
> diff --git a/src/shell.c b/src/shell.c
> index 53b192c..ae66d3d 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -81,6 +81,7 @@ enum shell_surface_type {
>  	SHELL_SURFACE_TOPLEVEL,
>  	SHELL_SURFACE_TRANSIENT,
>  	SHELL_SURFACE_FULLSCREEN,
> +	SHELL_SURFACE_MAXIMISED,
>  	SHELL_SURFACE_POPUP
>  };
>  
> @@ -366,6 +367,7 @@ reset_shell_surface_type(struct shell_surface *surface)
>  	case SHELL_SURFACE_TOPLEVEL:
>  	case SHELL_SURFACE_TRANSIENT:
>  	case SHELL_SURFACE_POPUP:
> +	case SHELL_SURFACE_MAXIMISED:
>  		break;
>  	}
>  
> @@ -419,6 +421,91 @@ get_default_output(struct weston_compositor *compositor)
>  			    struct weston_output, link);
>  }
>  
> +static struct wl_shell *
> +shell_surface_get_shell(struct shell_surface *shsurf)
> +{
> +	struct weston_surface *es = shsurf->surface;
> +	struct weston_shell *shell=es->compositor->shell;
> +
> +	return (struct wl_shell *)container_of(shell, struct wl_shell, shell);
> +}
> +
> +static int
> +get_output_panel_height(struct wl_shell *wlshell,struct weston_output *output)
> +{
> +	struct shell_surface *priv;
> +	int panel_height = 0;
> +
> +	if(!output)
> +		return 0;
> +
> +	wl_list_for_each(priv, &wlshell->panels, link) {
> +		if (priv->output == output) {
> +			panel_height = priv->surface->geometry.height;
> +			break;
> +		}
> +	}
> +	return panel_height;
> +}
> +
> +static struct weston_output *
> +get_available_output(struct weston_output *output,
> +		       struct weston_compositor *compositor)
> +{
> +	struct weston_output *privo = NULL;
> +	struct weston_output *reto = NULL;
> +
> +	if(!output)
> +		reto = get_default_output(compositor);
> +
> +	if(!reto) {
> +		wl_list_for_each(privo, &compositor->output_list, link){
> +			if ( privo == output ) {
> +				reto = output;
> +				break;
> +			}

You don't need this loop to check if a pointer is in the output_list.
The protocol core code already makes sure a client cannot give you a
bogus pointer (NULL is allowed, though). If a non-NULL output is not
in the output_list, we have a bug somewhere in the compositor.

> +		};
> +	}
> +
> +	return reto;
> +}
> +
> +static void
> +shell_surface_set_maximised(struct wl_client *client,
> +			    struct wl_resource *resource,
> +			    struct wl_resource *output_resource )
> +{
> +	struct shell_surface *shsurf = resource->data;
> +	struct weston_surface *es = shsurf->surface;
> +	struct weston_output *output = output_resource?output_resource->data:NULL;
> +	struct wl_shell *wlshell = NULL;
> +	uint32_t edges = 0, panel_height = 0;
> +
> +	/* get the default output, if the client set it as NULL
> +	   check whether the ouput is available, if no, give a message
> +	    and return */
> +	es->output = get_available_output(output, es->compositor);
> +
> +	if(!es->output) {
> +		fprintf(stderr, "Please provide correct output, \
> +				 or setting that output to NULL");
> +		return;

If you want to signal an error condition, it should be done with
wl_resource_post_error(), which will lead to the client terminating.
But you never need that here, anyway.

> +	}
> +
> +	if (reset_shell_surface_type(shsurf))
> +		return;
> +
> +	wlshell = shell_surface_get_shell(shsurf);
> +	panel_height = get_output_panel_height(wlshell, es->output);
> +	edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
> +	wl_resource_post_event(&shsurf->resource,
> +			       WL_SHELL_SURFACE_CONFIGURE,
> +			       weston_compositor_get_time(), edges,
> +			       es->output->current->width, es->output->current->height-panel_height);
> +
> +	shsurf->type = SHELL_SURFACE_MAXIMISED;
> +}
> +
>  static void
>  shell_surface_set_fullscreen(struct wl_client *client,
>  			     struct wl_resource *resource)
> @@ -572,6 +659,7 @@ static const struct wl_shell_surface_interface shell_surface_implementation = {
>  	shell_surface_set_toplevel,
>  	shell_surface_set_transient,
>  	shell_surface_set_fullscreen,
> +	shell_surface_set_maximised,
>  	shell_surface_set_popup
>  };
>  
> @@ -1320,6 +1408,12 @@ map(struct weston_shell *base,
>  	case SHELL_SURFACE_FULLSCREEN:
>  		center_on_output(surface, surface->fullscreen_output);
>  		break;
> +	case SHELL_SURFACE_MAXIMISED:
> +		/*use surface configure to set the geometry*/
> +		weston_surface_configure(surface, 0,
> +					 get_output_panel_height(shell,surface->output),
> +					 width, height);

To set the surface geometry right, you should use output->x and
output->y as the top-left corner of the chosen output, and add panel
height to that. weston_surface_configure() does not do that for you.

> +		break;
>  	case SHELL_SURFACE_LOCK:
>  		center_on_output(surface, get_default_output(compositor));
>  		break;
> @@ -1396,6 +1490,7 @@ map(struct weston_shell *base,
>  	case SHELL_SURFACE_TOPLEVEL:
>  	case SHELL_SURFACE_TRANSIENT:
>  	case SHELL_SURFACE_FULLSCREEN:
> +	case SHELL_SURFACE_MAXIMISED:
>  		if (!shell->locked)
>  			activate(base, surface,
>  				 (struct weston_input_device *)
> @@ -1434,6 +1529,11 @@ configure(struct weston_shell *base, struct weston_surface *surface,
>  	case SHELL_SURFACE_FULLSCREEN:
>  		center_on_output(surface, surface->fullscreen_output);
>  		break;
> +	case SHELL_SURFACE_MAXIMISED:
> +		/*setting x, y and using configure to change that geometry*/
> +		x = 0;
> +		y = get_output_panel_height(shell,surface->output);

The same comment as above.

> +		break;
>  	default:
>  		break;
>  	}

You can test multi-output easily by running weston under X, using for
instance:
$ weston -o output-count=3


Thanks,
pq


More information about the wayland-devel mailing list