diff --git a/src/html5/index.html b/src/html5/index.html
index bbed6c7a6c..a5be637f96 100644
--- a/src/html5/index.html
+++ b/src/html5/index.html
@@ -719,7 +719,9 @@
Xpra Bug Report
if (navigator.clipboard && navigator.clipboard.readText) {
navigator.clipboard.readText().then(function(text) {
cdebug("clipboard", "paste event, text=", text);
- client.send_clipboard_token(unescape(encodeURIComponent(text)));
+ var paste_data = unescape(encodeURIComponent(text));
+ client.clipboard_buffer = paste_data;
+ client.send_clipboard_token(paste_data);
}, function(err) {
cdebug("clipboard", "paste event failed:", err);
});
@@ -734,10 +736,10 @@ Xpra Bug Report
if (Utilities.isIE()) {
datatype = "Text";
}
- paste_data = clipboardData.getData(datatype);
+ paste_data = unescape(encodeURIComponent(clipboardData.getData(datatype)));
cdebug("clipboard", "paste event, data=", paste_data);
client.clipboard_buffer = paste_data;
- client.send_clipboard_token(unescape(encodeURIComponent(paste_data)));
+ client.send_clipboard_token(paste_data);
}
return false;
});
@@ -763,12 +765,11 @@ Xpra Bug Report
var clipboard_buffer = client.get_clipboard_buffer();
var clipboard_datatype = (client.get_clipboard_datatype() || "").toLowerCase();
var is_text = clipboard_datatype.indexOf("text")>=0 || clipboard_datatype.indexOf("string")>=0;
- if (is_text) {
- pasteboard.text(clipboard_buffer);
- }
- else {
- pasteboard.text("");
+ if (!is_text) {
+ //maybe just abort here instead?
+ clipboard_buffer = "";
}
+ pasteboard.text(clipboard_buffer);
pasteboard.select();
cdebug("clipboard", "click event, with pending clipboard datatype=", clipboard_datatype, ", buffer=", clipboard_buffer);
//for IE:
@@ -794,6 +795,8 @@ Xpra Bug Report
//probably no point in trying again?
}
if (success) {
+ //clipboard_buffer may have been cleared if not set to text:
+ client.clipboard_buffer = clipboard_buffer;
client.clipboard_pending = false;
}
}
diff --git a/src/html5/js/Client.js b/src/html5/js/Client.js
index e9371f7c9d..1afb18e6ac 100644
--- a/src/html5/js/Client.js
+++ b/src/html5/js/Client.js
@@ -1305,6 +1305,7 @@ XpraClient.prototype.do_window_mouse_click = function(e, window, pressed) {
if (this.server_readonly || this.mouse_grabbed || !this.connected) {
return;
}
+ this._poll_clipboard(e);
var mouse = this.getMouse(e, window),
x = Math.round(mouse.x),
y = Math.round(mouse.y);
@@ -1405,6 +1406,49 @@ XpraClient.prototype.do_window_mouse_scroll = function(e, window) {
}
+XpraClient.prototype._poll_clipboard = function(e) {
+ //see if the clipboard contents have changed:
+ this.debug("clipboard", "poll clipboard, navigator.clipboard=", navigator.clipboard);
+ if (navigator.clipboard && navigator.clipboard.readText) {
+ var client = this;
+ //warning: this can take a while,
+ //so we may send the click before the clipboard contents...
+ navigator.clipboard.readText().then(function(text) {
+ client.debug("clipboard", "paste event, text=", text);
+ var clipboard_buffer = unescape(encodeURIComponent(text));
+ if (clipboard_buffer!=client.clipboard_buffer) {
+ client.debug("clipboard", "clipboard contents have changed");
+ client.clipboard_buffer = clipboard_buffer;
+ client.send_clipboard_token();
+ }
+ }, function(err) {
+ client.debug("clipboard", "paste event failed:", err);
+ });
+ }
+ else {
+ var datatype = "text/plain";
+ var clipboardData = (e.originalEvent || e).clipboardData;
+ //IE: must use window.clipboardData because the event clipboardData is null!
+ if (!clipboardData) {
+ clipboardData = window.clipboardData;
+ if (!clipboardData) {
+ return;
+ }
+ }
+ if (Utilities.isIE()) {
+ datatype = "Text";
+ }
+ clipboard_buffer = unescape(encodeURIComponent(clipboardData.getData(datatype)));
+ this.debug("clipboard", "paste event, data=", clipboard_buffer);
+ if (clipboard_buffer!=client.clipboard_buffer) {
+ this.debug("clipboard", "clipboard contents have changed");
+ this.clipboard_buffer = clipboard_buffer;
+ this.send_clipboard_token();
+ }
+ }
+}
+
+
/**
* Focus
*/
@@ -3247,7 +3291,7 @@ XpraClient.prototype.send_clipboard_string = function(request_id, selection, cli
} else {
packet = ["clipboard-contents", request_id, selection, datatype || "UTF8_STRING", 8, "bytes", clipboard_buffer];
}
- this.log("send_clipboard_string: packet=", packet);
+ this.debug("clipboard", "send_clipboard_string: packet=", packet);
this.send(packet);
}