static gboolean grab_guest_clipboard(gpointer data) { SpiceDisplay *display; SpiceDisplayPrivate *d; display = global_display(); if (global_display() == NULL) { return FALSE; } d = SPICE_DISPLAY_GET_PRIVATE(display); if (d->main == NULL) { return FALSE; } /* Grab the guest clipboard, with just one type (text) */ spice_main_clipboard_selection_grab(d->main, VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD, clipboardTypes, ntypes); clipboardOwner = CB_OWNER_HOST; return FALSE; }
static void clipboard_get_targets(GtkClipboard *clipboard, GdkAtom *atoms, gint n_atoms, gpointer user_data) { WeakRef *weakref = user_data; SpiceGtkSession *self = (SpiceGtkSession*)weakref->object; weak_unref(weakref); if (self == NULL) return; g_return_if_fail(SPICE_IS_GTK_SESSION(self)); SpiceGtkSessionPrivate *s = self->priv; guint32 types[SPICE_N_ELEMENTS(atom2agent)]; char *name; int a, m, t; int selection; if (s->main == NULL) return; selection = get_selection_from_clipboard(s, clipboard); g_return_if_fail(selection != -1); SPICE_DEBUG("%s:", __FUNCTION__); if (spice_util_get_debug()) { for (a = 0; a < n_atoms; a++) { name = gdk_atom_name(atoms[a]); SPICE_DEBUG(" \"%s\"", name); g_free(name); } } memset(types, 0, sizeof(types)); for (a = 0; a < n_atoms; a++) { name = gdk_atom_name(atoms[a]); for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) { if (strcasecmp(name, atom2agent[m].xatom) != 0) { continue; } /* found match */ for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) { if (types[t] == atom2agent[m].vdagent) { /* type already in list */ break; } if (types[t] == 0) { /* add type to empty slot */ types[t] = atom2agent[m].vdagent; break; } } break; } g_free(name); } for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) { if (types[t] == 0) { break; } } if (!s->clip_grabbed[selection] && t > 0) { s->clip_grabbed[selection] = TRUE; 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; } }