*/
#include "qemu/osdep.h"
-#include "qemu-common.h"
#include "qemu/main-loop.h"
#include "ui/gtk.h"
GtkDisplayState *gd = data;
QemuClipboardSelection s = gd_find_selection(gd, clipboard);
QemuClipboardType type = QEMU_CLIPBOARD_TYPE_TEXT;
- QemuClipboardInfo *info = qemu_clipboard_info_ref(gd->cbinfo[s]);
+ g_autoptr(QemuClipboardInfo) info = NULL;
+
+ info = qemu_clipboard_info_ref(qemu_clipboard_info(s));
qemu_clipboard_request(info, type);
- while (info == gd->cbinfo[s] &&
+ while (info == qemu_clipboard_info(s) &&
info->types[type].available &&
info->types[type].data == NULL) {
main_loop_wait(false);
}
- if (info == gd->cbinfo[s] && gd->cbowner[s]) {
+ if (info == qemu_clipboard_info(s) && gd->cbowner[s]) {
gtk_selection_data_set_text(selection_data,
info->types[type].data,
info->types[type].size);
} else {
/* clipboard owner changed while waiting for the data */
}
-
- qemu_clipboard_info_unref(info);
}
static void gd_clipboard_clear(GtkClipboard *clipboard,
gd->cbowner[s] = false;
}
-static void gd_clipboard_notify(Notifier *notifier, void *data)
+static void gd_clipboard_update_info(GtkDisplayState *gd,
+ QemuClipboardInfo *info)
{
- GtkDisplayState *gd = container_of(notifier, GtkDisplayState, cbpeer.update);
- QemuClipboardInfo *info = data;
QemuClipboardSelection s = info->selection;
bool self_update = info->owner == &gd->cbpeer;
- if (info != gd->cbinfo[s]) {
- qemu_clipboard_info_unref(gd->cbinfo[s]);
- gd->cbinfo[s] = qemu_clipboard_info_ref(info);
+ if (info != qemu_clipboard_info(s)) {
gd->cbpending[s] = 0;
if (!self_update) {
- GtkTargetList *list;
+ g_autoptr(GtkTargetList) list = NULL;
GtkTargetEntry *targets;
gint n_targets;
targets = gtk_target_table_new_from_list(list, &n_targets);
gtk_clipboard_clear(gd->gtkcb[s]);
- gd->cbowner[s] = true;
- gtk_clipboard_set_with_data(gd->gtkcb[s],
- targets, n_targets,
- gd_clipboard_get_data,
- gd_clipboard_clear,
- gd);
-
- gtk_target_table_free(targets, n_targets);
- gtk_target_list_unref(list);
+ if (targets) {
+ gd->cbowner[s] = true;
+ gtk_clipboard_set_with_data(gd->gtkcb[s],
+ targets, n_targets,
+ gd_clipboard_get_data,
+ gd_clipboard_clear,
+ gd);
+
+ gtk_target_table_free(targets, n_targets);
+ }
}
return;
}
*/
}
+static void gd_clipboard_notify(Notifier *notifier, void *data)
+{
+ GtkDisplayState *gd =
+ container_of(notifier, GtkDisplayState, cbpeer.notifier);
+ QemuClipboardNotify *notify = data;
+
+ switch (notify->type) {
+ case QEMU_CLIPBOARD_UPDATE_INFO:
+ gd_clipboard_update_info(gd, notify->info);
+ return;
+ case QEMU_CLIPBOARD_RESET_SERIAL:
+ /* ignore */
+ return;
+ }
+}
+
static void gd_clipboard_request(QemuClipboardInfo *info,
QemuClipboardType type)
{
switch (event->owner_change.reason) {
- case GDK_SETTING_ACTION_NEW:
+ case GDK_OWNER_CHANGE_NEW_OWNER:
info = qemu_clipboard_info_new(&gd->cbpeer, s);
if (gtk_clipboard_wait_is_text_available(clipboard)) {
info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
qemu_clipboard_info_unref(info);
break;
default:
+ qemu_clipboard_peer_release(&gd->cbpeer, s);
+ gd->cbowner[s] = false;
break;
}
}
void gd_clipboard_init(GtkDisplayState *gd)
{
gd->cbpeer.name = "gtk";
- gd->cbpeer.update.notify = gd_clipboard_notify;
+ gd->cbpeer.notifier.notify = gd_clipboard_notify;
gd->cbpeer.request = gd_clipboard_request;
qemu_clipboard_peer_register(&gd->cbpeer);
gd->gtkcb[QEMU_CLIPBOARD_SELECTION_CLIPBOARD] =
- gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE));
+ gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gd->gtkcb[QEMU_CLIPBOARD_SELECTION_PRIMARY] =
- gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
+ gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gd->gtkcb[QEMU_CLIPBOARD_SELECTION_SECONDARY] =
- gtk_clipboard_get(gdk_atom_intern("SECONDARY", FALSE));
+ gtk_clipboard_get(GDK_SELECTION_SECONDARY);
g_signal_connect(gd->gtkcb[QEMU_CLIPBOARD_SELECTION_CLIPBOARD],
"owner-change", G_CALLBACK(gd_owner_change), gd);