ui: update keycodemapdb submodule commit
[qemu/armbru.git] / ui / clipboard.c
blob3525b30178b9d4b03604961e90ddf22a1d4cac9f
1 #include "qemu/osdep.h"
2 #include "ui/clipboard.h"
4 static NotifierList clipboard_notifiers =
5 NOTIFIER_LIST_INITIALIZER(clipboard_notifiers);
7 void qemu_clipboard_peer_register(QemuClipboardPeer *peer)
9 notifier_list_add(&clipboard_notifiers, &peer->update);
12 void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer)
14 notifier_remove(&peer->update);
17 void qemu_clipboard_update(QemuClipboardInfo *info)
19 notifier_list_notify(&clipboard_notifiers, info);
22 QemuClipboardInfo *qemu_clipboard_info_new(QemuClipboardPeer *owner,
23 QemuClipboardSelection selection)
25 QemuClipboardInfo *info = g_new0(QemuClipboardInfo, 1);
27 info->owner = owner;
28 info->selection = selection;
29 info->refcount = 1;
31 return info;
34 QemuClipboardInfo *qemu_clipboard_info_ref(QemuClipboardInfo *info)
36 info->refcount++;
37 return info;
40 void qemu_clipboard_info_unref(QemuClipboardInfo *info)
42 uint32_t type;
44 if (!info) {
45 return;
48 info->refcount--;
49 if (info->refcount > 0) {
50 return;
53 for (type = 0; type < QEMU_CLIPBOARD_TYPE__COUNT; type++) {
54 g_free(info->types[type].data);
56 g_free(info);
59 void qemu_clipboard_request(QemuClipboardInfo *info,
60 QemuClipboardType type)
62 if (info->types[type].data ||
63 info->types[type].requested ||
64 !info->types[type].available ||
65 !info->owner)
66 return;
68 info->types[type].requested = true;
69 info->owner->request(info, type);
72 void qemu_clipboard_set_data(QemuClipboardPeer *peer,
73 QemuClipboardInfo *info,
74 QemuClipboardType type,
75 uint32_t size,
76 const void *data,
77 bool update)
79 if (!info ||
80 info->owner != peer) {
81 return;
84 g_free(info->types[type].data);
85 info->types[type].data = g_memdup(data, size);
86 info->types[type].size = size;
87 info->types[type].available = true;
89 if (update) {
90 qemu_clipboard_update(info);