浏览代码

ui/clipboard: add qemu_clipboard_check_serial()

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Marc-André Lureau 4 年之前
父节点
当前提交
349504e5a1
共有 2 个文件被更改,包括 25 次插入0 次删除
  1. 10 0
      include/ui/clipboard.h
  2. 15 0
      ui/clipboard.c

+ 10 - 0
include/ui/clipboard.h

@@ -172,6 +172,16 @@ void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
  */
  */
 QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection);
 QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection);
 
 
+/**
+ * qemu_clipboard_check_serial
+ *
+ * @info: clipboard info.
+ * @client: whether to check from the client context and priority.
+ *
+ * Return TRUE if the @info has a higher serial than the current clipboard.
+ */
+bool qemu_clipboard_check_serial(QemuClipboardInfo *info, bool client);
+
 /**
 /**
  * qemu_clipboard_info_new
  * qemu_clipboard_info_new
  *
  *

+ 15 - 0
ui/clipboard.c

@@ -41,6 +41,21 @@ void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
     }
     }
 }
 }
 
 
+bool qemu_clipboard_check_serial(QemuClipboardInfo *info, bool client)
+{
+    if (!info->has_serial ||
+        !cbinfo[info->selection] ||
+        !cbinfo[info->selection]->has_serial) {
+        return true;
+    }
+
+    if (client) {
+        return cbinfo[info->selection]->serial >= info->serial;
+    } else {
+        return cbinfo[info->selection]->serial > info->serial;
+    }
+}
+
 void qemu_clipboard_update(QemuClipboardInfo *info)
 void qemu_clipboard_update(QemuClipboardInfo *info)
 {
 {
     QemuClipboardNotify notify = {
     QemuClipboardNotify notify = {