From 48282c7feaa5cc74b40c6e48aca14633764f4027 Mon Sep 17 00:00:00 2001 From: Zi Ree Date: Wed, 5 Oct 2022 00:10:45 +0200 Subject: [PATCH] FIRE-31976 - Linux/X11: fix pasting text being cropped to 64k bytes --- indra/llwindow/llwindowsdl2.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/indra/llwindow/llwindowsdl2.cpp b/indra/llwindow/llwindowsdl2.cpp index cd5d3b362e..5d7d85c912 100644 --- a/indra/llwindow/llwindowsdl2.cpp +++ b/indra/llwindow/llwindowsdl2.cpp @@ -130,7 +130,8 @@ namespace Atom XA_CLIPBOARD; Atom XA_TARGETS; Atom PVT_PASTE_BUFFER; - long const MAX_PASTE_BUFFER_SIZE = 16383; + // Unused in the current clipboard implementation -Zi + // long const MAX_PASTE_BUFFER_SIZE = 16383; void filterSelectionRequest( XEvent aEvent ) { @@ -277,11 +278,23 @@ bool LLWindowSDL::getSelectionText( Atom aSelection, Atom aType, LLWString &text maybe_lock_display(); Atom type; - int format{}; - unsigned long len{},remaining {}; + int format {}; + unsigned long len {}, size {}; unsigned char* data = nullptr; + + // get type and size of the clipboard contents first + XGetWindowProperty( mSDL_Display, mSDL_XWindowID, + PVT_PASTE_BUFFER, 0, 0, False, + AnyPropertyType, &type, &format, &len, + &size, &data); + XFree(data); + + // now get the real data, we don't really have a size limit here, but we need + // to tell the X11 clipboard how much space we have, which happens to be exactly + // the size of the current clipboard contents + unsigned long remaining {}; int res = XGetWindowProperty(mSDL_Display, mSDL_XWindowID, - PVT_PASTE_BUFFER, 0, MAX_PASTE_BUFFER_SIZE, False, + PVT_PASTE_BUFFER, 0, size, False, AnyPropertyType, &type, &format, &len, &remaining, &data); if (data && len)