Skip to content

Commit

Permalink
#1312 improvements:
Browse files Browse the repository at this point in the history
* only verify from server to client
* prevent tray menu initial setup from firing "clipboard-changed" signal
* use set_string wrapper function to deal with gtk3 vs gtk2 differences and weird main loop crashes caused by set_text under gtk2

git-svn-id: https://xpra.org/svn/Xpra/trunk@18248 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 2, 2018
1 parent d45cfcd commit b336932
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/xpra/client/gtk_base/gtk_tray_menu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,17 @@ def set_clipboard_menu(*args):
clipboard_submenu.append(gtk.SeparatorMenuItem())
except:
clipboardlog.error("make_clipboardmenuitem()", exc_info=True)
items = []
for label in CLIPBOARD_DIRECTION_LABELS:
direction_item = CheckMenuItem(label)
d = CLIPBOARD_DIRECTION_LABEL_TO_NAME.get(label)
direction_item.set_active(d==self.client.client_clipboard_direction)
direction_item.connect("toggled", self.clipboard_direction_changed, clipboard_submenu)
clipboard_submenu.append(direction_item)
items.append(direction_item)
clipboard_submenu.show_all()
#connect signals:
for direction_item in items:
direction_item.connect("toggled", self.clipboard_direction_changed, clipboard_submenu)
self.client.after_handshake(set_clipboard_menu)
return self.clipboard_menuitem

Expand Down
3 changes: 0 additions & 3 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,8 +1993,6 @@ def process_ui_capabilities(self):
#(could have been translated, or limited if the client only has one, etc)
clipboardlog("clipboard enabled clipboard helper=%s", self.clipboard_helper)
self.send_clipboard_selections(self.clipboard_helper.remote_clipboards)
if self.clipboard_enabled and self.server_clipboard_loop_uuids:
self.send_clipboard_loop_uuids()
self.set_max_packet_size()
self.send_deflate_level()
c = self.server_capabilities
Expand Down Expand Up @@ -2082,7 +2080,6 @@ def conv(v):
if self.server_clipboard:
#from now on, we will send a message to the server whenever the clipboard flag changes:
self.connect("clipboard-toggled", self.clipboard_toggled)
self.clipboard_toggled()
self.connect("keyboard-sync-toggled", self.send_keyboard_sync_enabled_status)
self.send_ping()
if self.pings>0:
Expand Down
40 changes: 29 additions & 11 deletions src/xpra/clipboard/clipboard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ def _filter_targets(targets):
return f


def set_string(clipboard, thestring):
if is_gtk3():
#no other way?
clipboard.set_text(thestring, len(thestring))
return
value = [thestring]
def get_func(clipboard, selection, info, targets):
log("get_func%s value=%s", (clipboard, selection, info, targets), value[0])
s = value[0]
if s:
selection.set("STRING", 8, s)
else:
clipboard.clear()
def clear_func(*args):
log("clear_func%s value=%s", args, value[0])
value[0] = ""
clipboard.set_with_data([("STRING", 0, 0)], get_func, clear_func)


class ClipboardProtocolHelperBase(object):
def __init__(self, send_packet_cb, progress_cb=None, **kwargs):
d = typedict(kwargs)
Expand All @@ -107,6 +126,7 @@ def __init__(self, send_packet_cb, progress_cb=None, **kwargs):
self.can_send = d.boolget("can-send", True)
self.can_receive = d.boolget("can-receive", True)
self.max_clipboard_packet_size = MAX_CLIPBOARD_PACKET_SIZE
self.disabled_by_loop = []
self.filter_res = []
filter_res = d.strlistget("filters")
if filter_res:
Expand All @@ -124,8 +144,6 @@ def __init__(self, send_packet_cb, progress_cb=None, **kwargs):
remote_loop_uuids = d.dictget("remote-loop-uuids", {})
self.verify_remote_loop_uuids(remote_loop_uuids)
self.remote_clipboards = d.strlistget("clipboards.remote", CLIPBOARDS)
self.disabled_by_loop = []
self.init_proxies_uuid()

def __repr__(self):
return "ClipboardProtocolHelperBase"
Expand Down Expand Up @@ -184,10 +202,11 @@ def _verify_remote_loop_uuids(self, clipboard, value, user_data):
proxy, uuids = user_data
if value:
for selection, rvalue in uuids.items():
log("%s=%s", proxy._selection, value)
if rvalue==proxy._loop_uuid:
clipboard.set_text("")
set_string(clipboard, "")
if rvalue and value==rvalue:
clipboard.set_text("")
set_string(clipboard, "")
if selection==proxy._selection:
log.warn("Warning: loop detected for %s clipboard", selection)
else:
Expand Down Expand Up @@ -584,8 +603,8 @@ def __init__(self, selection):

def init_uuid(self):
self._loop_uuid = LOOP_PREFIX+get_hex_uuid()
log("init_uuid() %s set_text(%s)", self._selection, self._loop_uuid)
self._clipboard.set_text(self._loop_uuid, -1)
log("init_uuid() %s uuid=%s", self._selection, self._loop_uuid)
set_string(self._clipboard, self._loop_uuid)

def set_direction(self, can_send, can_receive):
self._can_send = can_send
Expand Down Expand Up @@ -763,9 +782,7 @@ def nodata():
if is_gtk3() and dtype in (b"UTF8_STRING", b"STRING") and dformat==8:
s = bytestostr(data)
self._clipboard.set_text(s, len(s))
#problem here is that we know own the selection...
#this doesn't work either:
#selection_data.set_text(s, len(s))
#problem here is that we now own the selection...
else:
boc = self._block_owner_change
self._block_owner_change = True
Expand Down Expand Up @@ -812,7 +829,7 @@ def got_token(self, targets, target_data, claim=True, synchronous_client=False):
if text_target in target_data:
text_data = target_data.get(text_target)
log("clipboard %s set to '%s'", self._selection, repr_ellipsized(text_data))
self._clipboard.set_text(text_data, len=len(text_data))
set_string(self._clipboard, text_data)
if not claim:
log("token packet without claim, not setting the token flag")
#the other end is just telling us to send the token again next time something changes,
Expand Down Expand Up @@ -869,7 +886,8 @@ def unpack(clipboard, selection_data, _user_data=None):
log("unpack %s: %s", clipboard, type(selection_data))
global sanitize_gtkselectiondata
if selection_data and sanitize_gtkselectiondata(selection_data):
self._clipboard.set_text("")
selection_data = None
return
if selection_data is None:
cb(None, None, None)
return
Expand Down
1 change: 1 addition & 0 deletions src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ def parse_hello_ui_clipboard(self, ss, c):
clipboardlog("another client already owns the clipboard")
return
self._clipboard_client = ss
self._clipboard_helper.init_proxies_uuid()
#deal with buggy win32 clipboards:
if "clipboard.greedy" not in c:
#old clients without the flag: take a guess based on platform:
Expand Down

0 comments on commit b336932

Please sign in to comment.