ui/clipboard: add qemu_clipboard_peer_release() helper
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 5 Aug 2021 13:57:04 +0000 (17:57 +0400)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 31 Aug 2021 13:25:14 +0000 (17:25 +0400)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20210805135715.857938-8-marcandre.lureau@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
include/ui/clipboard.h
ui/clipboard.c

index 25e0b470c8ecf540b2d5dc9b3b4416332cc68787..6298986b15c3a16be340e8b63748955e52734a71 100644 (file)
@@ -120,6 +120,17 @@ void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer);
 bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer,
                               QemuClipboardSelection selection);
 
+/**
+ * qemu_clipboard_peer_release
+ *
+ * @peer: peer information.
+ * @selection: clipboard selection.
+ *
+ * If the peer owns the clipboard, release it.
+ */
+void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
+                                 QemuClipboardSelection selection);
+
 /**
  * qemu_clipboard_info
  *
index 490c3220f4c48922b619edc333e34605e1418a2b..c277247a7f32e0a8d2b3d3e56dcd729dfbea8fcd 100644 (file)
@@ -24,6 +24,18 @@ bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer,
     return info && info->owner == peer;
 }
 
+void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
+                                 QemuClipboardSelection selection)
+{
+    g_autoptr(QemuClipboardInfo) info = NULL;
+
+    if (qemu_clipboard_peer_owns(peer, selection)) {
+        /* set empty clipboard info */
+        info = qemu_clipboard_info_new(NULL, selection);
+        qemu_clipboard_update(info);
+    }
+}
+
 void qemu_clipboard_update(QemuClipboardInfo *info)
 {
     g_autoptr(QemuClipboardInfo) old = NULL;