From 124f57eaf4f52603bc4c5e9470e947b1afe87d2f Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 14 May 2024 17:15:53 +0700 Subject: [PATCH] #283 let users choose the prefered clipboard format default to 'text/plain' --- html5/connect.html | 11 ++++++++++- html5/index.html | 3 +++ html5/js/Client.js | 26 +++++++++++++++----------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/html5/connect.html b/html5/connect.html index fc571fc5..b1a7bd4c 100644 --- a/html5/connect.html +++ b/html5/connect.html @@ -431,7 +431,12 @@

Advanced options

  • - Clipboard sharing + Clipboard sharing, preferred format: +
  • Printing @@ -574,6 +579,7 @@

    Advanced options

    "encryption", "scroll_reverse_y", "vrefresh", + "clipboard_preferred_format", ]; const BOOLEAN_PROPERTIES = [ "keyboard", @@ -1537,6 +1543,9 @@

    Advanced options

    }); $('input:radio[value="' + action + '"]').click(); + const clipboard_preferred_format = getparam("clipboard_preferred_format") || "text/plain"; + document.getElementById("clipboard_preferred_format").value = clipboard_preferred_format; + const encoding = getparam("encoding") || "auto"; document.getElementById("encoding").value = encoding; diff --git a/html5/index.html b/html5/index.html index 0e9807bc..b67d491d 100644 --- a/html5/index.html +++ b/html5/index.html @@ -784,6 +784,7 @@

    Xpra Bug Report

    cpoll = !ssl; } const clipboard_poll = getboolparam("clipboard_poll", cpoll); + const clipboard_preferred_format = getparam("clipboard_preferred_format", "text/plain"); const printing = getboolparam("printing", true); const file_transfer = getboolparam("file_transfer", true); const steal = getboolparam("steal", true); @@ -892,6 +893,7 @@

    Xpra Bug Report

    client.insecure = insecure; client.clipboard_enabled = clipboard; client.clipboard_poll = clipboard_poll; + client.clipboard_preferred_format = clipboard_preferred_format; client.printing = printing; client.file_transfer = file_transfer; client.bandwidth_limit = bandwidth_limit; @@ -1072,6 +1074,7 @@

    Xpra Bug Report

    keyboard: keyboard, clipboard: clipboard, clipboard_poll: clipboard_poll, + clipboard_preferred_format: clipboard_preferred_format, printing: printing, file_transfer: file_transfer, exit_with_children: exit_with_children, diff --git a/html5/js/Client.js b/html5/js/Client.js index 54a851a9..b1469be5 100644 --- a/html5/js/Client.js +++ b/html5/js/Client.js @@ -97,6 +97,7 @@ class XpraClient { this.start_new_session = null; this.clipboard_enabled = false; this.clipboard_poll = false; + this.clipboard_preferred_format = "text/plain"; this.file_transfer = false; this.remote_file_size_limit = 0; this.remote_file_chunks = 0; @@ -268,22 +269,12 @@ class XpraClient { this.scroll_reverse_x = false; this.scroll_reverse_y = "auto"; // clipboard - this.clipboard_direction = - default_settings["clipboard_direction"] || "both"; + this.clipboard_direction = default_settings["clipboard_direction"] || "both"; this.clipboard_datatype = null; this.clipboard_buffer = ""; this.clipboard_server_buffers = {}; this.clipboard_pending = false; this.clipboard_targets = [TEXT_HTML, UTF8_STRING, "TEXT", "STRING", TEXT_PLAIN]; - if ( - CLIPBOARD_IMAGES && - navigator.clipboard && - Object.hasOwn(navigator.clipboard, "write") - ) { - this.clipboard_targets.push("image/png"); - } else { - this.log("no clipboard write support: no images, navigator.clipboard=", navigator.clipboard); - } // printing / file-transfer: this.remote_printing = false; this.remote_file_transfer = false; @@ -1664,6 +1655,19 @@ class XpraClient { this.log("legacy clipboard"); } this.log("clipboard polling: ", this.clipboard_poll); + + this.clipboard_targets = [this.clipboard_preferred_format]; + for (const target of [TEXT_HTML, UTF8_STRING, "TEXT", "STRING", TEXT_PLAIN]) { + if (target != this.clipboard_preferred_format) { + this.clipboard_targets.push(target); + } + } + if (CLIPBOARD_IMAGES && navigator.clipboard && Object.hasOwn(navigator.clipboard, "write")) { + this.clipboard_targets.push("image/png"); + } else { + this.log("no clipboard write support: no images, navigator.clipboard=", navigator.clipboard); + } + return { "enabled" : this.clipboard_enabled, "want_targets" : true,