[Spice-devel] [PATCH spice-gtk 1/2] Do not grab/release the clipboard on guest without clipboard support

Hans de Goede hdegoede at redhat.com
Tue Jan 31 23:46:59 PST 2012


Ack series.

Regards,

Hans


On 01/31/2012 11:31 PM, Marc-André Lureau wrote:
> Add an agent capability check before calling those functions from
> gtk-session. Avoid extra warnings.
> ---
>   doc/reference/spice-gtk-sections.txt |    1 +
>   gtk/channel-main.c                   |   22 ++++++++++++++++++++++
>   gtk/channel-main.h                   |    2 ++
>   gtk/map-file                         |    1 +
>   gtk/spice-gtk-session.c              |    7 +++++--
>   5 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
> index 5e3af99..3e5ce0b 100644
> --- a/doc/reference/spice-gtk-sections.txt
> +++ b/doc/reference/spice-gtk-sections.txt
> @@ -50,6 +50,7 @@ SpiceMainChannelClass
>   <SUBSECTION>
>   spice_main_channel
>   spice_main_set_display
> +spice_main_agent_test_capability
>   spice_main_clipboard_selection_grab
>   spice_main_clipboard_selection_notify
>   spice_main_clipboard_selection_release
> diff --git a/gtk/channel-main.c b/gtk/channel-main.c
> index b2df547..0689368 100644
> --- a/gtk/channel-main.c
> +++ b/gtk/channel-main.c
> @@ -736,6 +736,7 @@ static void do_emit_main_context(GObject *object, int signum, gpointer params)
>
>   /* ------------------------------------------------------------------ */
>
> +
>   static void agent_free_msg_queue(SpiceMainChannel *channel)
>   {
>       SpiceMainChannelPrivate *c = channel->priv;
> @@ -1716,6 +1717,27 @@ static gboolean timer_set_display(gpointer data)
>   }
>
>   /**
> + * spice_main_agent_test_capability:
> + * @channel:
> + * @cap: an agent capability identifier
> + *
> + * Test capability of a remote agent.
> + *
> + * Returns: %TRUE if @cap (channel kind capability) is available.
> + **/
> +gboolean spice_main_agent_test_capability(SpiceMainChannel *channel, guint32 cap)
> +{
> +    g_return_val_if_fail(SPICE_IS_MAIN_CHANNEL(channel), FALSE);
> +
> +    SpiceMainChannelPrivate *c = channel->priv;
> +
> +    if (!c->agent_caps_received)
> +        return FALSE;
> +
> +    return VD_AGENT_HAS_CAPABILITY(c->agent_caps, sizeof(c->agent_caps), cap);
> +}
> +
> +/**
>    * spice_main_set_display:
>    * @channel:
>    * @id: display channel ID
> diff --git a/gtk/channel-main.h b/gtk/channel-main.h
> index f1ab6ae..ae3f241 100644
> --- a/gtk/channel-main.h
> +++ b/gtk/channel-main.h
> @@ -83,6 +83,8 @@ void spice_main_clipboard_selection_release(SpiceMainChannel *channel, guint sel
>   void spice_main_clipboard_selection_notify(SpiceMainChannel *channel, guint selection, guint32 type, const guchar *data, size_t size);
>   void spice_main_clipboard_selection_request(SpiceMainChannel *channel, guint selection, guint32 type);
>
> +gboolean spice_main_agent_test_capability(SpiceMainChannel *channel, guint32 cap);
> +
>   G_END_DECLS
>
>   #endif /* __SPICE_CLIENT_MAIN_CHANNEL_H__ */
> diff --git a/gtk/map-file b/gtk/map-file
> index 38f7c26..320dae3 100644
> --- a/gtk/map-file
> +++ b/gtk/map-file
> @@ -48,6 +48,7 @@ spice_inputs_lock_get_type;
>   spice_inputs_motion;
>   spice_inputs_position;
>   spice_inputs_set_key_locks;
> +spice_main_agent_test_capability;
>   spice_main_channel_get_type;
>   spice_main_clipboard_grab;
>   spice_main_clipboard_notify;
> diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
> index e4a36d1..f77296d 100644
> --- a/gtk/spice-gtk-session.c
> +++ b/gtk/spice-gtk-session.c
> @@ -478,7 +478,9 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
>       }
>       if (!s->clip_grabbed[selection]&&  t>  0) {
>           s->clip_grabbed[selection] = TRUE;
> -        spice_main_clipboard_selection_grab(s->main, selection, types, t);
> +
> +        if (spice_main_agent_test_capability(s->main, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
> +            spice_main_clipboard_selection_grab(s->main, selection, types, t);
>           /* Sending a grab causes the agent to do an impicit release */
>           s->nclip_targets[selection] = 0;
>       }
> @@ -502,7 +504,8 @@ static void clipboard_owner_change(GtkClipboard        *clipboard,
>
>       if (s->clip_grabbed[selection]) {
>           s->clip_grabbed[selection] = FALSE;
> -        spice_main_clipboard_selection_release(s->main, selection);
> +        if (spice_main_agent_test_capability(s->main, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
> +            spice_main_clipboard_selection_release(s->main, selection);
>       }
>
>       switch (event->reason) {


More information about the Spice-devel mailing list