[spice-gtk,1/3] clipboard: do not delay release if agent has "no release on regrab"

Submitted by marcandre.lureau@redhat.com on March 22, 2019, 2:20 p.m.

Details

Message ID 20190322142014.3330-2-marcandre.lureau@redhat.com
State New
Headers show
Series "Clipboard improvements" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

marcandre.lureau@redhat.com March 22, 2019, 2:20 p.m.
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 configure.ac            | 2 +-
 meson.build             | 2 +-
 src/channel-main.c      | 2 ++
 src/spice-gtk-session.c | 9 ++++++++-
 4 files changed, 12 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/configure.ac b/configure.ac
index d234822..12159fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -86,7 +86,7 @@  AC_CHECK_LIBM
 AC_SUBST(LIBM)
 
 AC_CONFIG_SUBDIRS([subprojects/spice-common])
-PKG_CHECK_MODULES([SPICE_PROTOCOL], [spice-protocol >= 0.12.15])
+PKG_CHECK_MODULES([SPICE_PROTOCOL], [spice-protocol >= 0.12.16])
 
 COMMON_CFLAGS='-I${top_builddir}/subprojects/spice-common/ -I${top_srcdir}/subprojects/spice-common/ ${SPICE_PROTOCOL_CFLAGS}'
 AC_SUBST(COMMON_CFLAGS)
diff --git a/meson.build b/meson.build
index e0fba93..3383f26 100644
--- a/meson.build
+++ b/meson.build
@@ -75,7 +75,7 @@  endforeach
 #
 # check for mandatory dependencies
 #
-spice_protocol_version='>= 0.12.15'
+spice_protocol_version='>= 0.12.16'
 
 glib_version = '2.46'
 glib_version_info = '>= @0@'.format(glib_version)
diff --git a/src/channel-main.c b/src/channel-main.c
index 10c31ac..7d4b5c2 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -222,6 +222,7 @@  static const char *agent_caps[] = {
     [ VD_AGENT_CAP_AUDIO_VOLUME_SYNC   ] = "volume-sync",
     [ VD_AGENT_CAP_MONITORS_CONFIG_POSITION ] = "monitors config position",
     [ VD_AGENT_CAP_FILE_XFER_DISABLED ] = "file transfer disabled",
+    [ VD_AGENT_CAP_CLIPBOARD_NO_RELEASE_ON_REGRAB ] = "no release on re-grab",
 };
 #define NAME(_a, _i) ((_i) < SPICE_N_ELEMENTS(_a) ? (_a[(_i)] ?: "?") : "?")
 
@@ -1333,6 +1334,7 @@  static void agent_announce_caps(SpiceMainChannel *channel)
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_SELECTION);
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MONITORS_CONFIG_POSITION);
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_FILE_XFER_DETAILED_ERRORS);
+    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_NO_RELEASE_ON_REGRAB);
 
     agent_msg_queue(channel, VD_AGENT_ANNOUNCE_CAPABILITIES, size, caps);
     g_free(caps);
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index d73a44b..7a7ebb7 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -1101,7 +1101,8 @@  static gboolean clipboard_release_timeout(gpointer user_data)
  * sides, client and remote, racing for the clipboard grab, and
  * believing each other is the owner.
  *
- * Workaround this problem by delaying the release event by 0.5 sec.
+ * Workaround this problem by delaying the release event by 0.5 sec,
+ * unless the no-release-on-regrab capability is present.
  * FIXME: protocol change to solve the conflict and set client priority.
  */
 #define CLIPBOARD_RELEASE_DELAY 500 /* ms */
@@ -1119,6 +1120,12 @@  static void clipboard_release_delay(SpiceMainChannel *main, guint selection,
 
     clipboard_release_delay_remove(self, selection, true);
 
+    if (spice_main_channel_agent_test_capability(s->main,
+                                                 VD_AGENT_CAP_CLIPBOARD_NO_RELEASE_ON_REGRAB)) {
+        clipboard_release(self, selection);
+        return;
+    }
+
     rel = g_new0(SpiceGtkClipboardRelease, 1);
     rel->self = self;
     rel->selection = selection;