Skip to content

Commit

Permalink
#283 let users choose the prefered clipboard format
Browse files Browse the repository at this point in the history
default to 'text/plain'
  • Loading branch information
totaam committed May 14, 2024
1 parent 5271a4f commit 124f57e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
11 changes: 10 additions & 1 deletion html5/connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ <h4 class="panel-title">Advanced options</h4>

<li class="list-group-item clipboard">
<input type="checkbox" id="clipboard" />
<span>Clipboard sharing</span>
<span>Clipboard sharing, preferred format:</span>
<select id="clipboard_preferred_format">
<option value="text/plain">text/plain</option>
<option value="UTF8_STRING">UTF8</option>
<option value="text/html">text/html</option>
</select>
</li>
<li class="list-group-item printing">
<input type="checkbox" id="printing" /> <span>Printing</span>
Expand Down Expand Up @@ -574,6 +579,7 @@ <h4 class="panel-title">Advanced options</h4>
"encryption",
"scroll_reverse_y",
"vrefresh",
"clipboard_preferred_format",
];
const BOOLEAN_PROPERTIES = [
"keyboard",
Expand Down Expand Up @@ -1537,6 +1543,9 @@ <h4 class="panel-title">Advanced options</h4>
});
$('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;

Expand Down
3 changes: 3 additions & 0 deletions html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ <h2>Xpra Bug Report</h2>
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);
Expand Down Expand Up @@ -892,6 +893,7 @@ <h2>Xpra Bug Report</h2>
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;
Expand Down Expand Up @@ -1072,6 +1074,7 @@ <h2>Xpra Bug Report</h2>
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,
Expand Down
26 changes: 15 additions & 11 deletions html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 124f57e

Please sign in to comment.