summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2026-01-23 18:41:19 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2026-01-23 18:41:19 +0100
commitdd9cb9f042ca59875758c7ffedf61d45d915a9c7 (patch)
tree1473e940d98fe44a4e1f23877a43e08decdcca71 /src/drivers
parent05a3f82a5c385e7f00aa2bb8c1971e1cc99225a3 (diff)
Wayland: add support of recoded UTF8 text in clipboard.
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx
index 085f2d5b1..8ded06045 100644
--- a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx
+++ b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx
@@ -1,7 +1,7 @@
//
// Wayland-specific code for clipboard and drag-n-drop support.
//
-// Copyright 1998-2024 by Bill Spitzak and others.
+// Copyright 1998-2026 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -431,6 +431,39 @@ way_out:
fl_selection_length[1] = strlen(fl_selection_buffer[1]);
}
Fl::e_clipboard_type = Fl::clipboard_plain_text;
+ /*
+ UTF8 text from clipboard may encode non-ASCII codepoints as in these examples
+ U+1F431 --> UTF8: 0xF0,0x9F,0x90,0xB1 --> encoded "\F0\9F\90\B1"
+ U+A1 --> UTF8: 0xC2, 0xA1 --> encoded "\C2\A1"
+ Whereas ASCII characters are not encoded.
+ The following decodes that to restore genuine UTF8.
+ */
+ /* for (int i = 0; i < fl_selection_length[1]; i++) {
+ printf("%c[%x] ",fl_selection_buffer[1][i], fl_selection_buffer[1][i]);
+ } puts("");*/
+ int l_input = fl_selection_length[1], l = 0, i = 0, b;
+ char *str = new char[l_input];
+ while (i < l_input) {
+ if (i + 4 < l_input && fl_selection_buffer[1][i] == '\\' &&
+ fl_selection_buffer[1][i+3] == '\\' &&
+ isxdigit(fl_selection_buffer[1][i+1]) && isxdigit(fl_selection_buffer[1][i+1])) {
+ sscanf(fl_selection_buffer[1] + i + 1, "%x", &b);
+ int l_utf8 = fl_utf8len(b);
+ if (i + 3 * l_utf8 <= l_input && fl_selection_buffer[1][i+3*(l_utf8-1)] == '\\') {
+ while (l_utf8-- > 0) {
+ sscanf(fl_selection_buffer[1] + i + 1, "%x", &b);
+ str[l++] = b;
+ i += 3;
+ }
+ continue;
+ }
+ }
+ str[l++] = fl_selection_buffer[1][i++];
+ }
+ memcpy(fl_selection_buffer[1], str, l);
+ delete[] str;
+ fl_selection_length[1] = l;
+ fl_selection_buffer[1][l] = 0;
}