Skip to content

Fail to get text from the clipboard when text is Latin-1 encoded but transfer data type is UTF8_STRING #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

josediazfer
Copy link

@josediazfer josediazfer commented May 13, 2025

It's not possible to paste text data with accented characters (CP-1252) from a Windows VNC connection to a Linux server. Pasting text into other desktop applications works just like gedit. In the code to be merged, each type is attempted (in the order UTF8_STRING, COMPOUND_TEXT, STRING) until the text can be retrieved from the clipboard.

In the gtkclipboard.c file (request_text_received_func function) of the GTK3 native library it does something similar:

static void
request_text_received_func (GtkClipboard     *clipboard,
                            GtkSelectionData *selection_data,
                            gpointer          data)
{
  RequestTextInfo *info = data;
  gchar *result = NULL;

  result = (gchar *) gtk_selection_data_get_text (selection_data);

  if (!result)
    {
      /* If we asked for UTF8 and didn't get it, try compound_text;
       * if we asked for compound_text and didn't get it, try string;
       * If we asked for anything else and didn't get it, give up.
       */
      GdkAtom target = gtk_selection_data_get_target (selection_data);

      if (target == gdk_atom_intern_static_string ("text/plain;charset=utf-8"))
        {
          gtk_clipboard_request_contents (clipboard,
                                          gdk_atom_intern_static_string ("UTF8_STRING"),
                                          request_text_received_func, info);
          return;
        }
      else if (target == gdk_atom_intern_static_string ("UTF8_STRING"))
        {
          gtk_clipboard_request_contents (clipboard,
                                          gdk_atom_intern_static_string ("COMPOUND_TEXT"),
                                          request_text_received_func, info);
          return;
        }
      else if (target == gdk_atom_intern_static_string ("COMPOUND_TEXT"))
        {
          gtk_clipboard_request_contents (clipboard,
                                          GDK_TARGET_STRING,
                                          request_text_received_func, info);
          return;
        }
    }

  info->callback (clipboard, result, info->user_data);
  g_free (info);
  g_free (result);
}

@akurtakov
Copy link
Member

I would appreciate if you split the functional change and reorganization in different PRs in order to make it easier what actually have you changed.

@josediazfer josediazfer changed the title Fail to get text from the clipboard when text is Latin-1 encoded but Fail to get text from the clipboard when text is Latin-1 encoded but transfer data type is UTF8_STRING May 13, 2025
@josediazfer
Copy link
Author

@akurtakov You're right, I just changed it so that the commit only has the functional change

@akurtakov
Copy link
Member

I wonder how can I reproduce this in native Linux environment. Would you please give some hints if you have an idea?

Copy link
Contributor

Test Results

   545 files  ±0     545 suites  ±0   34m 19s ⏱️ - 7m 29s
 4 380 tests ±0   4 362 ✅ ±0   18 💤 ±0  0 ❌ ±0 
16 650 runs  ±0  16 509 ✅ ±0  141 💤 ±0  0 ❌ ±0 

Results for commit b525e2e. ± Comparison against base commit cbf014c.

@josediazfer
Copy link
Author

You can reproduce the problem by establishing a VNC connection with the Remmina client from a Linux machine against a VNC server (x11vnc) as shown below. A connection made from the Windows operating system with other VNC clients (RealVNC, TigerVNC) it also happens.

fail_accents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants