Commit 996bfb48 authored by Jakub Janků's avatar Jakub Janků Committed by Frediano Ziglio
Browse files

spice-gtk-session: cache atoms



At the moment, spice-gtk only sends a grab message to the vdagent
based on the retrieved atoms.

With the upcoming changes, spice-gtk will have to know which
targets were advertised outside of clipboard_get_targets() callback.

We could use gtk_clipboard_wait_for_targets() or
gtk_clipboard_wait_is_*_available(), but the targets are not cached
by GTK+ on wayland for some reason. So let's cache them in spice-gtk
to avoid having to talk to the clipboard owner.
Signed-off-by: Jakub Janků's avatarJakub Janků <jjanku@redhat.com>
Acked-by: Frediano Ziglio's avatarFrediano Ziglio <fziglio@redhat.com>
parent 852b847c
......@@ -55,6 +55,8 @@ struct _SpiceGtkSessionPrivate {
GtkClipboard *clipboard_primary;
GtkTargetEntry *clip_targets[CLIPBOARD_LAST];
guint nclip_targets[CLIPBOARD_LAST];
GdkAtom *atoms[CLIPBOARD_LAST];
guint n_atoms[CLIPBOARD_LAST];
gboolean clip_hasdata[CLIPBOARD_LAST];
gboolean clip_grabbed[CLIPBOARD_LAST];
gboolean clipboard_by_guest[CLIPBOARD_LAST];
......@@ -284,6 +286,8 @@ static void spice_gtk_session_finalize(GObject *gobject)
for (i = 0; i < CLIPBOARD_LAST; ++i) {
g_clear_pointer(&s->clip_targets[i], g_free);
clipboard_release_delay_remove(self, i, true);
g_clear_pointer(&s->atoms[i], g_free);
s->n_atoms[i] = 0;
}
/* Chain up to the parent class */
......@@ -589,6 +593,16 @@ static SpiceWebdavChannel *clipboard_get_open_webdav(SpiceSession *session)
g_list_free(list);
return open ? SPICE_WEBDAV_CHANNEL(channel) : NULL;
}
static GdkAtom clipboard_find_atom(SpiceGtkSessionPrivate *s, guint selection, GdkAtom a)
{
for (int i = 0; i < s->n_atoms[selection]; i++) {
if (s->atoms[selection][i] == a) {
return a;
}
}
return GDK_NONE;
}
#endif
static void clipboard_get_targets(GtkClipboard *clipboard,
......@@ -622,6 +636,11 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
selection = get_selection_from_clipboard(s, clipboard);
g_return_if_fail(selection != -1);
/* GTK+ does seem to cache atoms, but not for Wayland */
g_free(s->atoms[selection]);
s->atoms[selection] = g_memdup(atoms, n_atoms * sizeof(GdkAtom));
s->n_atoms[selection] = n_atoms;
if (s->clip_grabbed[selection]) {
SPICE_DEBUG("Clipboard is already grabbed, re-grab: %d atoms", n_atoms);
}
......@@ -705,6 +724,9 @@ static void clipboard_owner_change(GtkClipboard *clipboard,
return;
}
g_clear_pointer(&s->atoms[selection], g_free);
s->n_atoms[selection] = 0;
if (event->reason != GDK_OWNER_CHANGE_NEW_OWNER) {
if (s->clip_grabbed[selection]) {
/* grab was sent to the agent, so release it */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment