From: Kruti Pendharkar Date: Wed, 10 Dec 2025 05:31:19 +0000 (-0800) Subject: [GTK4] Workaround for G->H RTF Text DnD by returning Plain Text Only X-Git-Tag: stable-13.1.0~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f20d3df6000a3c5e7ce63b82bef5d2d67d6053c5;p=thirdparty%2Fopen-vm-tools.git [GTK4] Workaround for G->H RTF Text DnD by returning Plain Text Only 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 --- diff --git a/open-vm-tools/services/plugins/dndcp/dndUIX11GTK4.cpp b/open-vm-tools/services/plugins/dndcp/dndUIX11GTK4.cpp index 4e8829c3f..8e5d01f77 100644 --- a/open-vm-tools/services/plugins/dndcp/dndUIX11GTK4.cpp +++ b/open-vm-tools/services/plugins/dndcp/dndUIX11GTK4.cpp @@ -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;