From 361672355d6d523efd03672726dc4e7193556163 Mon Sep 17 00:00:00 2001 From: Josh Higgins Date: Thu, 23 Apr 2015 17:06:43 +0000 Subject: [PATCH] #842 clipboard support * off screen text input that is always in focus allows user to paste into the browser page * send a token to server when we get this paste event and store text in clipboard buffer * respond to a clipboard-request packet with the text in clipboard buffer git-svn-id: https://xpra.org/svn/Xpra/trunk@9139 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/html5/include/xpra_client.js | 29 ++++++++++++++++++++++++++++- src/html5/index.html | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/html5/include/xpra_client.js b/src/html5/include/xpra_client.js index 947ff227b9..bdd1a101bd 100644 --- a/src/html5/include/xpra_client.js +++ b/src/html5/include/xpra_client.js @@ -36,6 +36,8 @@ function XpraClient(container) { // audio stuff this.audio_enabled = false; this.audio_ctx = null; + // the "clipboard" + this.clipboard_buffer = ""; // the container div is the "screen" on the HTML page where we // are able to draw our windows in. this.container = document.getElementById(container); @@ -67,7 +69,8 @@ function XpraClient(container) { 'draw': this._process_draw, 'sound-data': this._process_sound_data, 'clipboard-token': this._process_clipboard_token, - 'set-clipboard-enabled': this._process_set_clipboard_enabled + 'set-clipboard-enabled': this._process_set_clipboard_enabled, + 'clipboard-request': this._process_clipboard_request }; // assign callback for window resize event if (window.jQuery) { @@ -219,6 +222,16 @@ XpraClient.prototype._screen_resized = function(event, ctx) { } } +XpraClient.prototype.handle_paste = function(text) { + // set our clipboard buffer + this.clipboard_buffer = text; + // send token + var packet = ["clipboard-token", "CLIPBOARD"]; + this.protocol.send(packet); + // tell user to paste in remote application + alert("Paste acknowledged. Please paste in remote application."); +} + XpraClient.prototype._keyb_get_modifiers = function(event) { /** * Returns the modifiers set for the current event. @@ -802,4 +815,18 @@ XpraClient.prototype._process_clipboard_token = function(packet, ctx) { XpraClient.prototype._process_set_clipboard_enabled = function(packet, ctx) { console.warn("server set clipboard state to "+packet[1]+" reason was: "+packet[2]); +} + +XpraClient.prototype._process_clipboard_request = function(packet, ctx) { + var request_id = packet[1], + selection = packet[2], + target = packet[3]; + + if(this.clipboard_buffer == "") { + packet = ["clipboard-contents-none", request_id, selection]; + } else { + var packet = ["clipboard-contents", request_id, selection, "UTF8_STRING", 8, "bytes", ctx.clipboard_buffer]; + } + + ctx.protocol.send(packet); } \ No newline at end of file diff --git a/src/html5/index.html b/src/html5/index.html index 2eba702994..f54fa05629 100644 --- a/src/html5/index.html +++ b/src/html5/index.html @@ -33,6 +33,11 @@ padding: 0; margin: 0; } + #pasteboard { + position: fixed; + top: -30px; + left: 1px; + } .undecorated { position: absolute; padding: 0; @@ -136,6 +141,8 @@
+ +