aboutsummaryrefslogtreecommitdiff
path: root/ui/clipboard.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2021-05-19 07:39:33 +0200
committerGerd Hoffmann <kraxel@redhat.com>2021-05-21 09:42:44 +0200
commit660e8d0f0be4e87da937ce797973874bb282d498 (patch)
treea05534919b34e871236c328154f8f1c5516e9f20 /ui/clipboard.c
parent58d3f3ff8da8d1f0ea917c661f306c42d0a69e7b (diff)
downloadqemu-660e8d0f0be4e87da937ce797973874bb282d498.zip
qemu-660e8d0f0be4e87da937ce797973874bb282d498.tar.gz
qemu-660e8d0f0be4e87da937ce797973874bb282d498.tar.bz2
ui: add clipboard infrastructure
Add some infrastructure to manage the clipboard in qemu. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-id: 20210519053940.1888907-1-kraxel@redhat.com Message-Id: <20210519053940.1888907-3-kraxel@redhat.com>
Diffstat (limited to 'ui/clipboard.c')
-rw-r--r--ui/clipboard.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/ui/clipboard.c b/ui/clipboard.c
new file mode 100644
index 0000000..abf2b98
--- /dev/null
+++ b/ui/clipboard.c
@@ -0,0 +1,92 @@
+#include "qemu/osdep.h"
+#include "ui/clipboard.h"
+
+static NotifierList clipboard_notifiers =
+ NOTIFIER_LIST_INITIALIZER(clipboard_notifiers);
+
+void qemu_clipboard_peer_register(QemuClipboardPeer *peer)
+{
+ notifier_list_add(&clipboard_notifiers, &peer->update);
+}
+
+void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer)
+{
+ notifier_remove(&peer->update);
+}
+
+void qemu_clipboard_update(QemuClipboardInfo *info)
+{
+ notifier_list_notify(&clipboard_notifiers, info);
+}
+
+QemuClipboardInfo *qemu_clipboard_info_new(QemuClipboardPeer *owner,
+ QemuClipboardSelection selection)
+{
+ QemuClipboardInfo *info = g_new0(QemuClipboardInfo, 1);
+
+ info->owner = owner;
+ info->selection = selection;
+ info->refcount = 1;
+
+ return info;
+}
+
+QemuClipboardInfo *qemu_clipboard_info_ref(QemuClipboardInfo *info)
+{
+ info->refcount++;
+ return info;
+}
+
+void qemu_clipboard_info_unref(QemuClipboardInfo *info)
+{
+ uint32_t type;
+
+ if (!info) {
+ return;
+ }
+
+ info->refcount--;
+ if (info->refcount > 0) {
+ return;
+ }
+
+ for (type = 0; type < QEMU_CLIPBOARD_TYPE__COUNT; type++) {
+ g_free(info->types[type].data);
+ }
+ g_free(info);
+}
+
+void qemu_clipboard_request(QemuClipboardInfo *info,
+ QemuClipboardType type)
+{
+ if (info->types[type].data ||
+ info->types[type].requested ||
+ !info->types[type].available ||
+ !info->owner)
+ return;
+
+ info->types[type].requested = true;
+ info->owner->request(info, type);
+}
+
+void qemu_clipboard_set_data(QemuClipboardPeer *peer,
+ QemuClipboardInfo *info,
+ QemuClipboardType type,
+ uint32_t size,
+ void *data,
+ bool update)
+{
+ if (!info ||
+ info->owner != peer) {
+ return;
+ }
+
+ g_free(info->types[type].data);
+ info->types[type].data = g_memdup(data, size);
+ info->types[type].size = size;
+ info->types[type].available = true;
+
+ if (update) {
+ qemu_clipboard_update(info);
+ }
+}