]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
[GTK4] Workaround for G->H RTF Text DnD by returning Plain Text Only
authorKruti Pendharkar <kp025370@broadcom.com>
Wed, 10 Dec 2025 05:31:19 +0000 (21:31 -0800)
committerKruti Pendharkar <kp025370@broadcom.com>
Wed, 10 Dec 2025 05:31:19 +0000 (21:31 -0800)
This change introduces a workaround for G->H Drag and Drop operations involving
RTF text in GTK4.

In GTK4, when performing G->H DnD with RTF text, we are unable retrieve the raw
GValue/Byte data from the DnD Clipboard, unlike with the CopyPaste clipboard.
As a result, the original format info is lost. Additionally, the DnD clipboard
always returns a trailing "_" char for these dnd G->H with RTF, which needs to
be removed.

To address these issues, the following changes have been made:
* Always return plain text for G->H RTF DnD
* Remove the trailing "_" if present

open-vm-tools/services/plugins/dndcp/dndUIX11GTK4.cpp

index 4e8829c3fceb43712a9849546b76479b87e0b646..8e5d01f773a8276fbb72d03978f9fcb45882ce81 100644 (file)
@@ -1543,13 +1543,24 @@ bool DnDUIX11::SetCPClipboardFromGtk_PlainText(utf::string &source)
 
 bool DnDUIX11::SetCPClipboardFromGtk_RTF(utf::string &source)
 {
-   if (source.size() > 0 &&
-       source.size() < DNDMSG_MAX_ARGSZ &&
-       CPClipboard_SetItem(&mClipboard, CPFORMAT_RTF, source.c_str(), source.size() + 1)) {
-      g_debug("%s: Got RTF, size %" FMTSZ "u\n", __FUNCTION__, source.size());
-      return true;
+   if (source.size() > 0 && source.size() < DNDMSG_MAX_ARGSZ) {
+      /*
+       * PR3578465, we could not get raw rtf format info from dnd clipboard
+       * set to plain text as workaround. And removing one trailing "_" char.
+       */
+      if (source[source.size() - 1] == '_') {
+         source.erase(source.size() - 1, 1);
+      }
+      if (CPClipboard_SetItem(&mClipboard, CPFORMAT_TEXT, source.c_str(),
+                              source.size() + 1)) {
+         g_debug("%s: Got RTF and parse as plain text, size %" FMTSZ "u\n",
+                 __FUNCTION__, source.size());
+         return true;
+      } else {
+         g_warning("%s: Failed to set target clipboard\n", __FUNCTION__);
+      }
    } else {
-      g_warning("%s: Failed to get RTF\n", __FUNCTION__);
+      g_warning("%s: wrong RTF size from drag source\n", __FUNCTION__);
    }
 
    return false;