[PATCH 3/6] desktop-shell: split protocol part from shell_surface specific functions

Juan Zhao juan.j.zhao at linux.intel.com
Mon Apr 16 22:31:12 PDT 2012


  On 04/16/2012 10:31 PM, Tiago Vignatti wrote:
> DE operations like toplevel, transiant, fullscreen, maximized, popup and the
> shell_surface constructor are the ones expected to be used in the global scope
> for Weston submodules like xserver-launcher and other shells.
>
> This commit split such procedures into a part that handles the protocol
> request and a part that creates the shell surface and deals with its
> operations. There's no functional changes in this commit.
>
> Signed-off-by: Tiago Vignatti<tiago.vignatti at intel.com>
> ---
>   src/compositor.h |    1 +
>   src/shell.c      |  208 ++++++++++++++++++++++++++++++++++++------------------
>   2 files changed, 140 insertions(+), 69 deletions(-)
>
> diff --git a/src/compositor.h b/src/compositor.h
> index 8fc5ab0..f2860b6 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -168,6 +168,7 @@ struct weston_layer {
>   struct weston_compositor {
>   	struct wl_shm *shm;
>   	struct wl_signal destroy_signal;
> +	void *shell;			/* either desktop or tablet */
>
>   	EGLDisplay display;
>   	EGLContext context;
> diff --git a/src/shell.c b/src/shell.c
> index 02061c6..6026a6c 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -482,27 +482,29 @@ reset_shell_surface_type(struct shell_surface *surface)
>   }
>
>   static void
> +set_toplevel(struct shell_surface *shsurf)
> +{
> +	if (reset_shell_surface_type(shsurf))
> +		return;
> +
> +	shsurf->type = SHELL_SURFACE_TOPLEVEL;
> +}
> +
> +static void
>   shell_surface_set_toplevel(struct wl_client *client,
>   			   struct wl_resource *resource)
>
>   {
>   	struct shell_surface *surface = resource->data;
>
> -	if (reset_shell_surface_type(surface))
> -		return;
> -
> -	surface->type = SHELL_SURFACE_TOPLEVEL;
> +	set_toplevel(surface);
>   }
>
>   static void
> -shell_surface_set_transient(struct wl_client *client,
> -			    struct wl_resource *resource,
> -			    struct wl_resource *parent_resource,
> -			    int x, int y, uint32_t flags)
> +set_transiant(struct shell_surface *shsurf, struct shell_surface *pshsurf,
> +	      int x, int y, uint32_t flags)
>   {
> -	struct shell_surface *shsurf = resource->data;
>   	struct weston_surface *es = shsurf->surface;
> -	struct shell_surface *pshsurf = parent_resource->data;
>   	struct weston_surface *pes = pshsurf->surface;
>
>   	if (reset_shell_surface_type(shsurf))
> @@ -510,12 +512,24 @@ shell_surface_set_transient(struct wl_client *client,
>
>   	/* assign to parents output */
>   	shsurf->output = pes->output;
> - 	weston_surface_set_position(es, pes->geometry.x + x,
> +	weston_surface_set_position(es, pes->geometry.x + x,
>   					pes->geometry.y + y);
>
>   	shsurf->type = SHELL_SURFACE_TRANSIENT;
>   }
>
> +static void
> +shell_surface_set_transient(struct wl_client *client,
> +			    struct wl_resource *resource,
> +			    struct wl_resource *parent_resource,
> +			    int x, int y, uint32_t flags)
> +{
> +	struct shell_surface *shsurf = resource->data;
> +	struct shell_surface *pshsurf = parent_resource->data;
> +
> +	set_transiant(shsurf, pshsurf, x, y, flags);
> +}
> +
>   static struct desktop_shell *
>   shell_surface_get_shell(struct shell_surface *shsurf)
>   {
> @@ -542,25 +556,19 @@ get_output_panel_height(struct desktop_shell *shell,
>   }
>
>   static void
> -shell_surface_set_maximized(struct wl_client *client,
> -			    struct wl_resource *resource,
> -			    struct wl_resource *output_resource )
> +set_maximized(struct shell_surface *shsurf, struct weston_output *output)
>   {
> -	struct shell_surface *shsurf = resource->data;
> +	uint32_t edges = 0, panel_height = 0;
>   	struct weston_surface *es = shsurf->surface;
>   	struct desktop_shell *shell = 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 (output_resource)
> -		shsurf->output = output_resource->data;
> -	else
> -		shsurf->output = get_default_output(es->compositor);
>
>   	if (reset_shell_surface_type(shsurf))
>   		return;
>
> +	if (!output)
> +		output = get_default_output(es->compositor);
> +
> +	shsurf->output = output;
>   	shsurf->saved_x = es->geometry.x;
>   	shsurf->saved_y = es->geometry.y;
>   	shsurf->saved_position_valid = true;
> @@ -577,6 +585,22 @@ shell_surface_set_maximized(struct wl_client *client,
>   }
>
>   static void
> +shell_surface_set_maximized(struct wl_client *client,
> +			    struct wl_resource *resource,
> +			    struct wl_resource *output_resource )
> +{
> +	struct shell_surface *shsurf = resource->data;
> +	struct weston_output *output;
> +
> +	/* get the default output, if the client set it as NULL
> +	   check whether the ouput is available */
The comments should be moved to set_maximized.
Others related to maximized looks OK for me. :)
> +	if (output_resource)
> +		output = output_resource->data;
> +
> +	set_maximized(shsurf, output);
> +}
> +
> +static void
>   black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
>
>   static struct weston_surface *
> @@ -673,23 +697,18 @@ shell_map_fullscreen(struct shell_surface *shsurf)
>   }
>
>   static void
> -shell_surface_set_fullscreen(struct wl_client *client,
> -			     struct wl_resource *resource,
> -			     uint32_t method,
> -			     uint32_t framerate,
> -			     struct wl_resource *output_resource)
> +set_fullscreen(struct shell_surface *shsurf, struct weston_output *output,
> +	       uint32_t method, uint32_t framerate)
>   {
> -	struct shell_surface *shsurf = resource->data;
>   	struct weston_surface *es = shsurf->surface;
>
> -	if (output_resource)
> -		shsurf->output = output_resource->data;
> -	else
> -		shsurf->output = get_default_output(es->compositor);
> -
>   	if (reset_shell_surface_type(shsurf))
>   		return;
>
> +	if (!output)
> +		output = get_default_output(es->compositor);
> +
> +	shsurf->output = output;
>   	shsurf->fullscreen_output = shsurf->output;
>   	shsurf->fullscreen.type = method;
>   	shsurf->fullscreen.framerate = framerate;
> @@ -708,6 +727,22 @@ shell_surface_set_fullscreen(struct wl_client *client,
>   }
>
>   static void
> +shell_surface_set_fullscreen(struct wl_client *client,
> +			     struct wl_resource *resource,
> +			     uint32_t method,
> +			     uint32_t framerate,
> +			     struct wl_resource *output_resource)
> +{
> +	struct shell_surface *shsurf = resource->data;
> +	struct weston_output *output;
> +
> +	if (output_resource)
> +		output = output_resource->data;
> +
> +	set_fullscreen(shsurf, output, method, framerate);
> +}
> +
> +static void
>   popup_grab_focus(struct wl_pointer_grab *grab,
>   		 struct wl_surface *surface, int32_t x, int32_t y)
>   {
> @@ -809,6 +844,18 @@ shell_map_popup(struct shell_surface *shsurf)
>   }
>
>   static void
> +set_popup(struct shell_surface *shsurf, struct shell_surface *pshsurf,
> +	  struct wl_input_device *device, uint32_t serial, int32_t x, int32_t y)
> +{
> +	shsurf->type = SHELL_SURFACE_POPUP;
> +	shsurf->parent = pshsurf;
> +	shsurf->popup.device = device;
> +	shsurf->popup.serial = serial;
> +	shsurf->popup.x = x;
> +	shsurf->popup.y = y;
> +}
> +
> +static void
>   shell_surface_set_popup(struct wl_client *client,
>   			struct wl_resource *resource,
>   			struct wl_resource *input_device_resource,
> @@ -817,13 +864,10 @@ shell_surface_set_popup(struct wl_client *client,
>   			int32_t x, int32_t y, uint32_t flags)
>   {
>   	struct shell_surface *shsurf = resource->data;
> +	struct shell_surface *pshsurf = parent_resource->data;
> +	struct wl_input_device *device = input_device_resource->data;
>
> -	shsurf->type = SHELL_SURFACE_POPUP;
> -	shsurf->parent = parent_resource->data;
> -	shsurf->popup.device = input_device_resource->data;
> -	shsurf->popup.serial = serial;
> -	shsurf->popup.x = x;
> -	shsurf->popup.y = y;
> +	set_popup(shsurf, pshsurf, device, serial, x, y);
>   }
>
>   static const struct wl_shell_surface_interface shell_surface_implementation = {
> @@ -837,10 +881,8 @@ static const struct wl_shell_surface_interface shell_surface_implementation = {
>   };
>
>   static void
> -destroy_shell_surface(struct wl_resource *resource)
> +destroy_shell_surface(struct shell_surface *shsurf)
>   {
> -	struct shell_surface *shsurf = resource->data;
> -
>   	if (shsurf->popup.grab.input_device)
>   		wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device);
>
> @@ -858,6 +900,14 @@ destroy_shell_surface(struct wl_resource *resource)
>   }
>
>   static void
> +shell_destroy_shell_surface(struct wl_resource *resource)
> +{
> +        struct shell_surface *shsurf = resource->data;
> +
> +	destroy_shell_surface(shsurf);
> +}
> +
> +static void
>   shell_handle_surface_destroy(struct wl_listener *listener, void *data)
>   {
>   	struct shell_surface *shsurf = container_of(listener,
> @@ -865,7 +915,11 @@ shell_handle_surface_destroy(struct wl_listener *listener, void *data)
>   						    surface_destroy_listener);
>
>   	shsurf->surface = NULL;
> -	wl_resource_destroy(&shsurf->resource);
> +
> +	if (shsurf->resource.object.implementation != 0)
> +		wl_resource_destroy(&shsurf->resource);
> +	else
> +		destroy_shell_surface(shsurf);
>   }
>
>   static struct shell_surface *
> @@ -886,44 +940,25 @@ static void
>   shell_surface_configure(struct weston_surface *, int32_t, int32_t);
>
>   static void
> -shell_get_shell_surface(struct wl_client *client,
> -			struct wl_resource *resource,
> -			uint32_t id,
> -			struct wl_resource *surface_resource)
> +create_shell_surface(void *shell, struct weston_surface *surface,
> +		     struct shell_surface **ret)
>   {
> -	struct weston_surface *surface = surface_resource->data;
>   	struct shell_surface *shsurf;
>
> -	if (get_shell_surface(surface)) {
> -		wl_resource_post_error(surface_resource,
> -			WL_DISPLAY_ERROR_INVALID_OBJECT,
> -			"wl_shell::get_shell_surface already requested");
> -		return;
> -	}
> -
>   	if (surface->configure) {
> -		wl_resource_post_error(surface_resource,
> -				       WL_DISPLAY_ERROR_INVALID_OBJECT,
> -				       "surface->configure already set");
> +		fprintf(stderr, "surface->configure already set\n");
>   		return;
>   	}
>
>   	shsurf = calloc(1, sizeof *shsurf);
>   	if (!shsurf) {
> -		wl_resource_post_no_memory(resource);
> +		fprintf(stderr, "no memory to allocate shell surface\n");
>   		return;
>   	}
>
>   	surface->configure = shell_surface_configure;
> -
> -	shsurf->resource.destroy = destroy_shell_surface;
> -	shsurf->resource.object.id = id;
> -	shsurf->resource.object.interface =&wl_shell_surface_interface;
> -	shsurf->resource.object.implementation =
> -		(void (**)(void))&shell_surface_implementation;
> -	shsurf->resource.data = shsurf;
> -
> -	shsurf->shell = resource->data;
> +	surface->compositor->shell = shell;
> +	shsurf->shell = (struct desktop_shell *) shell;
>   	shsurf->saved_position_valid = false;
>   	shsurf->surface = surface;
>   	shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
> @@ -944,6 +979,41 @@ shell_get_shell_surface(struct wl_client *client,
>
>   	shsurf->type = SHELL_SURFACE_NONE;
>
> +	*ret = shsurf;
> +}
> +
> +static void
> +shell_get_shell_surface(struct wl_client *client,
> +			struct wl_resource *resource,
> +			uint32_t id,
> +			struct wl_resource *surface_resource)
> +{
> +	struct weston_surface *surface = surface_resource->data;
> +	struct desktop_shell *shell = resource->data;
> +	struct shell_surface *shsurf;
> +
> +	if (get_shell_surface(surface)) {
> +		fprintf(stderr, "get_shell_surface already requested\n");
> +		return;
> +	}
> +
> +	create_shell_surface(shell, surface,&shsurf);
> +	if (!shsurf) {
> +		/* FIXME: break down get_shell_surface to deal separately with
> +		 * the errors, treating ENOMEM as well */
> +		wl_resource_post_error(surface_resource,
> +			WL_DISPLAY_ERROR_INVALID_OBJECT,
> +			"get_shell_surface: surface->configure already set");
> +		return;
> +	}
> +
> +	shsurf->resource.destroy = shell_destroy_shell_surface;
> +	shsurf->resource.object.id = id;
> +	shsurf->resource.object.interface =&wl_shell_surface_interface;
> +	shsurf->resource.object.implementation =
> +		(void (**)(void))&shell_surface_implementation;
> +	shsurf->resource.data = shsurf;
> +
>   	wl_client_add_resource(client,&shsurf->resource);
>   }
>



More information about the wayland-devel mailing list