Skip to content

Commit

Permalink
#272: rather than (wrongly) claiming ownership of the selection clien…
Browse files Browse the repository at this point in the history
…t-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
  • Loading branch information
totaam committed Apr 4, 2013
1 parent dbe2b3b commit 1ece151
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/xpra/platform/clipboard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -273,20 +272,23 @@ 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):
return "ClipboardProxy(%s)" % self._selection

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)
Expand Down Expand Up @@ -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
Expand All @@ -382,13 +380,17 @@ 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:
log.warn("Failed to acquire local clipboard %s; "
% (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:
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/platform/translated_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ece151

Please sign in to comment.