Skip to content

Commit

Permalink
#812:
Browse files Browse the repository at this point in the history
* handle greedy clients
* ignore our own updates to the clipboard using the 'block_owner_change' mechanism

git-svn-id: https://xpra.org/svn/Xpra/trunk@22481 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 20, 2019
1 parent 53013fd commit 4b85338
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/xpra/clipboard/clipboard_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def send_tokens(self, selections=()):
proxy = self._clipboard_proxies.get(selection)
if proxy:
proxy._have_token = False
#after we remove the legacy gtk code, we can directly call:
#proxy.do_emit_token()
self._send_clipboard_token_handler(proxy)

def send_all_tokens(self):
Expand Down
24 changes: 20 additions & 4 deletions src/xpra/platform/win32/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def wnd_proc(self, hwnd, msg, wparam, lparam):
log("clipboard event: %s", CLIPBOARD_EVENTS.get(msg))
if msg==WM_CLIPBOARDUPDATE:
for proxy in self._clipboard_proxies.values():
#TODO: handle greedy clients
self._send_clipboard_token_handler(proxy, packet_data=())
if not proxy._block_owner_change:
proxy.schedule_emit_token()
return r


Expand All @@ -118,7 +118,8 @@ def cleanup_window(self):
UnregisterClassA(wch, GetModuleHandleA(0))

def make_proxy(self, selection):
proxy = Win32ClipboardProxy(self.window, selection, self._send_clipboard_request_handler)
proxy = Win32ClipboardProxy(self.window, selection,
self._send_clipboard_request_handler, self._send_clipboard_token_handler)
proxy.set_want_targets(self._want_targets)
proxy.set_direction(self.can_send, self.can_receive)
return proxy
Expand All @@ -134,9 +135,10 @@ def _munge_wire_selection_to_raw(self, encoding, dtype, dformat, data):


class Win32ClipboardProxy(ClipboardProxyCore):
def __init__(self, window, selection, send_clipboard_request_handler):
def __init__(self, window, selection, send_clipboard_request_handler, send_clipboard_token_handler):
self.window = window
self.send_clipboard_request_handler = send_clipboard_request_handler
self.send_clipboard_token_handler = send_clipboard_token_handler
ClipboardProxyCore.__init__(self, selection)

def set_want_targets(self, want_targets):
Expand Down Expand Up @@ -165,6 +167,17 @@ def clear_error():
log.error("Error: failed to clear the clipboard")
self.with_clipboard_lock(EmptyClipboard, clear_error)

def do_emit_token(self):
#TODO: if contents are not text,
#send just the token
if self._greedy_client:
target = "UTF8_STRING"
def got_contents(dtype, dformat, data):
packet_data = ([target], (target, dtype, dformat, data))
self.send_clipboard_token_handler(self, packet_data)
self.get_contents(target, got_contents)
self.send_clipboard_token_handler(self)

def get_contents(self, target, got_contents):
def got_text(text):
log("got_text(%s)", repr_ellipsized(str(text)))
Expand Down Expand Up @@ -275,12 +288,15 @@ def set_clipboard_text(self, text):

def do_set_data():
try:
self._block_owner_change = True
log("SetClipboardData(..) block_owner_change=%s", self._block_owner_change)
EmptyClipboard()
if not SetClipboardData(win32con.CF_UNICODETEXT, buf):
return
#done!
finally:
GlobalFree(buf)
glib.idle_add(self.remove_block)
def set_error():
GlobalFree(buf)
log.error("Error: failed to set clipboard data")
Expand Down

0 comments on commit 4b85338

Please sign in to comment.