[Spice-devel] [spice-gtk 2/2] clipboard: Use gtk_clipboard_request_text for text data
Christophe Fergeau
cfergeau at redhat.com
Wed Aug 31 08:41:58 UTC 2016
On Mon, Aug 15, 2016 at 12:56:44PM +0200, Pavel Grunt wrote:
> Hi,
>
> On Wed, 2016-08-10 at 12:26 +0200, Christophe Fergeau wrote:
> > Currently, when the agent asks us for VD_AGENT_CLIPBOARD_UTF8_TEXT data,
> > spice-gtk looks up for the first X11 target which would provide it with
> > UTF8_TEXT data, and uses that for the clipboard request. This means we
> > will use UTF8_STRING as the target for gtk_clipboard_request_contents().
> >
> > However, some applications who can copy and paste text do not
> > necessarily support the UTF8_STRING target. This is the case for Motif
> > applications which support the STRING target however. It turns out gtk+
> > also provides a gtk_clipboard_request_text() method which will try
> > several targets (UTF8_TEXT, COMPOUND_TEXT, TEXT), and will ensure the
> > returned string is UTF-8, so we can use that when the agent asks us for
> > some text data.
> >
> Sounds good to me
>
> > This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1348624
> > ---
> > src/spice-gtk-session.c | 65 +++++++++++++++++++++++++++++++++++++++---------
> > -
> > 1 file changed, 52 insertions(+), 13 deletions(-)
> >
> > diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
> > index 1343302..5855610 100644
> > --- a/src/spice-gtk-session.c
> > +++ b/src/spice-gtk-session.c
> > @@ -947,6 +947,40 @@ static char *fixup_clipboard_text(SpiceGtkSession *self,
> > const char *text, int *
> > return conv;
> > }
> >
> > +static void clipboard_received_text_cb(GtkClipboard *clipboard,
> > + const gchar *text,
> > + gpointer user_data)
> > +{
> > + WeakRef *weakref = user_data;
> > + SpiceGtkSession *self = (SpiceGtkSession*)weakref->object;
> > + char *conv = NULL;
> > + int len = 0;
> > + int selection;
> > +
> > + weak_unref(weakref);
> > +
> > + if (self == NULL)
> > + return;
> > +
> > + g_return_if_fail(SPICE_IS_GTK_SESSION(self));
> > +
> > + selection = get_selection_from_clipboard(self->priv, clipboard);
> > + g_return_if_fail(selection != -1);
> > +
> > + len = strlen(text);
> > + if (!check_clipboard_size_limits(self, len)) {
> > + return;
> > + }
> > +
> > + /* gtk+ internal utf8 newline is always LF, even on windows */
> > + conv = fixup_clipboard_text(self, text, &len);
> > +
> > + spice_main_clipboard_selection_notify(self->priv->main, selection,
> > + VD_AGENT_CLIPBOARD_UTF8_TEXT,
> > + (guchar *)conv ?: (guchar*)text,
> or just (guchar *) (conv ?: text)
>
Indeed, I'll change it.
> OT: '?:' is in C or just in gcc ?
Wikipedia implies it's a GCC extension:
« A GNU extension to C allows omitting the second operand, and using
implicitly the first operand as the second »
https://en.wikipedia.org/wiki/%3F:#C
https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Conditionals.html#Conditionals
> > len);
> > + g_free(conv);
> > +}
> > +
> > static void clipboard_received_cb(GtkClipboard *clipboard,
> > GtkSelectionData *selection_data,
> > gpointer user_data)
> > @@ -994,10 +1028,10 @@ static void clipboard_received_cb(GtkClipboard
> > *clipboard,
> > const guchar *data = gtk_selection_data_get_data(selection_data);
> > gpointer conv = NULL;
>
> 'conv' is not used ^, should be removed
Yep, already gone in my local copy actually, not sure when I did that :)
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160831/e556021e/attachment.sig>
More information about the Spice-devel
mailing list