From 1ece15189652ba39e951de1aa31643159d099f65 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 4 Apr 2013 12:30:25 +0000 Subject: [PATCH] #272: rather than (wrongly) claiming ownership of the selection client-side, we just re-send the token everytime the selection owner changes - which should force the other end to request the data again, but without clobbering the originating selection git-svn-id: https://xpra.org/svn/Xpra/trunk@3051 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/platform/clipboard_base.py | 24 ++++++++++++----------- src/xpra/platform/translated_clipboard.py | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/xpra/platform/clipboard_base.py b/src/xpra/platform/clipboard_base.py index 51bba7431e..deb01544d2 100644 --- a/src/xpra/platform/clipboard_base.py +++ b/src/xpra/platform/clipboard_base.py @@ -36,7 +36,7 @@ class ClipboardProtocolHelperBase(object): - def __init__(self, send_packet_cb, progress_cb=None, clipboards=CLIPBOARDS, filter_res=None, claim_ownership=False): + def __init__(self, send_packet_cb, progress_cb=None, clipboards=CLIPBOARDS, filter_res=None): self.send = send_packet_cb self.progress_cb = progress_cb self.max_clipboard_packet_size = MAX_CLIPBOARD_PACKET_SIZE @@ -47,7 +47,6 @@ def __init__(self, send_packet_cb, progress_cb=None, clipboards=CLIPBOARDS, filt self.filter_res.append(re.compile(x)) except: log.error("invalid regular expression '%s' in clipboard filter") - self._claim_ownership = claim_ownership self._clipboard_request_counter = 0 self._clipboard_outstanding_requests = {} self.init_packet_handlers() @@ -65,7 +64,7 @@ def init_packet_handlers(self): def init_proxies(self, clipboards): self._clipboard_proxies = {} for clipboard in clipboards: - proxy = ClipboardProxy(clipboard, self._claim_ownership) + proxy = ClipboardProxy(clipboard) proxy.connect("send-clipboard-token", self._send_clipboard_token_handler) proxy.connect("get-clipboard-from-remote", self._get_clipboard_from_remote_handler) proxy.show() @@ -273,13 +272,13 @@ class ClipboardProxy(gtk.Invisible): "send-clipboard-token": n_arg_signal(1), } - def __init__(self, selection, claim_ownership): + def __init__(self, selection): gtk.Invisible.__init__(self) self.add_events(PROPERTY_CHANGE_MASK) self._selection = selection - self._claim_ownership = claim_ownership self._clipboard = gtk.Clipboard(selection=selection) self._have_token = False + self._send_on_owner_change = True self._clipboard.connect("owner-change", self.do_owner_changed) def __str__(self): @@ -287,6 +286,9 @@ def __str__(self): def do_owner_changed(self, *args): debug("do_owner_changed(%s)", args) + if self._send_on_owner_change: + self._have_token = False + self.emit("send-clipboard-token", self._selection) def do_selection_request_event(self, event): debug("do_selection_request_event(%s)", event) @@ -357,15 +359,11 @@ def do_selection_get(self, selection_data, info, time): data = result["data"] dformat = result["format"] dtype = result["type"] - debug("do_selection_get(%s,%s,%s) calling selection_data.set(%s, %s, %s:%s), claim_ownership=%s", - selection_data, info, time, dtype, dformat, type(data), len(data or ""), self._claim_ownership) + debug("do_selection_get(%s,%s,%s) calling selection_data.set(%s, %s, %s:%s)", + selection_data, info, time, dtype, dformat, type(data), len(data or "")) selection_data.set(dtype, dformat, data) else: debug("remote selection fetch timed out or empty") - if self._claim_ownership: - #workaround used in TranslatedClipboard to claim clipboard ownership - self.emit("send-clipboard-token", self._selection) - debug("do_selection_get: claiming %s ownership", self._selection) def do_selection_clear_event(self, event): # Someone else on our side has the selection @@ -382,6 +380,7 @@ def got_token(self): # We got the anti-token. debug("got token, selection=%s", self._selection) self._have_token = True + self._send_on_owner_change = False if not self.selection_owner_set(self._selection): # I don't know how this can actually fail, given that we pass # CurrentTime, but just in case: @@ -389,6 +388,9 @@ def got_token(self): % (self._selection,) + "will not be able to pass local apps " + "contents of remote clipboard") + def reenable_send(*args): + self._send_on_owner_change = True + gobject.idle_add(reenable_send) # This function is called by the xpra core when the peer has requested the # contents of this clipboard: diff --git a/src/xpra/platform/translated_clipboard.py b/src/xpra/platform/translated_clipboard.py index c712c1ea90..d179825efd 100644 --- a/src/xpra/platform/translated_clipboard.py +++ b/src/xpra/platform/translated_clipboard.py @@ -23,7 +23,7 @@ class TranslatedClipboardProtocolHelper(GDKClipboardProtocolHelper): def __init__(self, send_packet_cb, progress_cb=None, local_clipboard="CLIPBOARD", remote_clipboard="CLIPBOARD"): self.local_clipboard = local_clipboard self.remote_clipboard = remote_clipboard - ClipboardProtocolHelperBase.__init__(self, send_packet_cb, progress_cb, [local_clipboard], claim_ownership=True) + ClipboardProtocolHelperBase.__init__(self, send_packet_cb, progress_cb, [local_clipboard]) def local_to_remote(self, selection): debug("local_to_remote(%s) local_clipboard=%s, remote_clipboard=%s", selection, self.local_clipboard, self.remote_clipboard)