[PATCH weston v3] libweston-desktop: add signal for title/app-id changes

Quentin Glidic sardemff7+wayland at sardemff7.net
Fri Dec 8 10:26:56 UTC 2017


On 12/8/17 11:22 AM, Quentin Glidic wrote:
> From: Matt Hoosier <matt.hoosier at gmail.com>
> 
> As discussed on
> https://lists.freedesktop.org/archives/wayland-devel/2017-August/034720.html,
> it's useful for the shell implementation to know when these change,
> for example to relay the information on to taskbars or similar.
> 
> To avoid ABI changes or the need to make the weston_desktop_surface
> definition public, new functions are introduced for attaching
> listeners to these signals.
> 
> Signed-off-by: Matt Hoosier <matt.hoosier at gmail.com>
> Reviewed-by: Quentin Glidic <sardemff7+git at sardemff7.net>
> Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
> ---

(Err, wanted to drop the Sob send-email added via command line and I 
just closed vim…)

I made this v3 to rename the signal to "metadata" instead of "title", 
but also to tweak a tiny bit the signal sending. I wanted the shell not 
to have to strdup() these, so now, it can listen to the signal, and 
compare old and new values (and even use both) without extra cost.
Do you ack that change?

Still not sure I prefer a signal to just adding to the callbacks struct, 
but we can always break API/ABI again later if we need to. :-)

Cheers,


>   libweston-desktop/libweston-desktop.h |  3 +++
>   libweston-desktop/surface.c           | 22 ++++++++++++++++++----
>   2 files changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/libweston-desktop/libweston-desktop.h b/libweston-desktop/libweston-desktop.h
> index 03b04c7bc..a0fb9381b 100644
> --- a/libweston-desktop/libweston-desktop.h
> +++ b/libweston-desktop/libweston-desktop.h
> @@ -164,6 +164,9 @@ weston_desktop_surface_set_size(struct weston_desktop_surface *surface,
>   				int32_t width, int32_t height);
>   void
>   weston_desktop_surface_close(struct weston_desktop_surface *surface);
> +void
> +weston_desktop_surface_add_metadata_listener(struct weston_desktop_surface *surface,
> +					     struct wl_listener *listener);
>   
>   void *
>   weston_desktop_surface_get_user_data(struct weston_desktop_surface *surface);
> diff --git a/libweston-desktop/surface.c b/libweston-desktop/surface.c
> index d3be93640..cbfa5ee00 100644
> --- a/libweston-desktop/surface.c
> +++ b/libweston-desktop/surface.c
> @@ -64,6 +64,7 @@ struct weston_desktop_surface {
>   		char *title;
>   		char *app_id;
>   		pid_t pid;
> +		struct wl_signal metadata_signal;
>   	};
>   	struct {
>   		struct weston_desktop_surface *parent;
> @@ -287,6 +288,8 @@ weston_desktop_surface_create(struct weston_desktop *desktop,
>   	wl_list_init(&surface->view_list);
>   	wl_list_init(&surface->grab_link);
>   
> +	wl_signal_init(&surface->metadata_signal);
> +
>   	return surface;
>   }
>   
> @@ -511,6 +514,13 @@ weston_desktop_surface_close(struct weston_desktop_surface *surface)
>   					       surface->implementation_data);
>   }
>   
> +WL_EXPORT void
> +weston_desktop_surface_add_metadata_listener(struct weston_desktop_surface *surface,
> +					     struct wl_listener *listener)
> +{
> +	wl_signal_add(&surface->metadata_signal, listener);
> +}
> +
>   struct weston_desktop_surface *
>   weston_desktop_surface_from_client_link(struct wl_list *link)
>   {
> @@ -679,28 +689,32 @@ void
>   weston_desktop_surface_set_title(struct weston_desktop_surface *surface,
>   				 const char *title)
>   {
> -	char *tmp;
> +	char *tmp, *old;
>   
>   	tmp = strdup(title);
>   	if (tmp == NULL)
>   		return;
>   
> -	free(surface->title);
> +	old = surface->title;
>   	surface->title = tmp;
> +	wl_signal_emit(&surface->metadata_signal, surface);
> +	free(old);
>   }
>   
>   void
>   weston_desktop_surface_set_app_id(struct weston_desktop_surface *surface,
>   				  const char *app_id)
>   {
> -	char *tmp;
> +	char *tmp, *old;
>   
>   	tmp = strdup(app_id);
>   	if (tmp == NULL)
>   		return;
>   
> -	free(surface->app_id);
> +	old = surface->app_id;
>   	surface->app_id = tmp;
> +	wl_signal_emit(&surface->metadata_signal, surface);
> +	free(old);
>   }
>   
>   void
> 


-- 

Quentin “Sardem FF7” Glidic


More information about the wayland-devel mailing list