1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Linux: Avoid sending the string terminator to the X11 clipboard

This commit is contained in:
Tom Poole 2022-01-25 10:31:22 +00:00
parent ea5dae4ab6
commit 3366ad4ed4

View file

@ -1351,20 +1351,22 @@ namespace ClipboardHelpers
{ {
auto localContent = XWindowSystem::getInstance()->getLocalClipboardContent(); auto localContent = XWindowSystem::getInstance()->getLocalClipboardContent();
// translate to utf8 // Translate to utf8
numDataItems = localContent.getNumBytesAsUTF8() + 1; numDataItems = localContent.getNumBytesAsUTF8();
data.calloc (numDataItems); auto numBytesRequiredToStore = numDataItems + 1;
localContent.copyToUTF8 (data, numDataItems); data.calloc (numBytesRequiredToStore);
propertyFormat = 8; // bits/item localContent.copyToUTF8 (data, numBytesRequiredToStore);
propertyFormat = 8; // bits per item
} }
else if (evt.target == atoms.targets) else if (evt.target == atoms.targets)
{ {
// another application wants to know what we are able to send // Another application wants to know what we are able to send
numDataItems = 2; numDataItems = 2;
constexpr size_t atomSize = sizeof (Atom); data.calloc (numDataItems * sizeof (Atom));
static_assert (atomSize == 8, "Atoms are 32-bit");
propertyFormat = atomSize * 4; // Atoms are flagged as 32-bit irrespective of sizeof (Atom)
data.calloc (numDataItems * atomSize); propertyFormat = 32;
auto* dataAtoms = unalignedPointerCast<Atom*> (data.getData()); auto* dataAtoms = unalignedPointerCast<Atom*> (data.getData());
@ -1388,7 +1390,7 @@ namespace ClipboardHelpers
{ {
X11Symbols::getInstance()->xChangeProperty (evt.display, evt.requestor, X11Symbols::getInstance()->xChangeProperty (evt.display, evt.requestor,
evt.property, evt.target, evt.property, evt.target,
propertyFormat /* 8 or 32 */, PropModeReplace, propertyFormat, PropModeReplace,
reinterpret_cast<const unsigned char*> (data.getData()), (int) numDataItems); reinterpret_cast<const unsigned char*> (data.getData()), (int) numDataItems);
reply.property = evt.property; // " == success" reply.property = evt.property; // " == success"
} }