Skip to content

Commit

Permalink
Linux: Avoid sending the string terminator to the X11 clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoole committed Jan 25, 2022
1 parent ea5dae4 commit 3366ad4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
Expand Up @@ -1351,20 +1351,22 @@ namespace ClipboardHelpers
{
auto localContent = XWindowSystem::getInstance()->getLocalClipboardContent();

// translate to utf8
numDataItems = localContent.getNumBytesAsUTF8() + 1;
data.calloc (numDataItems);
localContent.copyToUTF8 (data, numDataItems);
propertyFormat = 8; // bits/item
// Translate to utf8
numDataItems = localContent.getNumBytesAsUTF8();
auto numBytesRequiredToStore = numDataItems + 1;
data.calloc (numBytesRequiredToStore);
localContent.copyToUTF8 (data, numBytesRequiredToStore);
propertyFormat = 8; // bits per item
}
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;
constexpr size_t atomSize = sizeof (Atom);
static_assert (atomSize == 8, "Atoms are 32-bit");
propertyFormat = atomSize * 4;
data.calloc (numDataItems * atomSize);
data.calloc (numDataItems * sizeof (Atom));

// Atoms are flagged as 32-bit irrespective of sizeof (Atom)
propertyFormat = 32;

auto* dataAtoms = unalignedPointerCast<Atom*> (data.getData());

Expand All @@ -1388,7 +1390,7 @@ namespace ClipboardHelpers
{
X11Symbols::getInstance()->xChangeProperty (evt.display, evt.requestor,
evt.property, evt.target,
propertyFormat /* 8 or 32 */, PropModeReplace,
propertyFormat, PropModeReplace,
reinterpret_cast<const unsigned char*> (data.getData()), (int) numDataItems);
reply.property = evt.property; // " == success"
}
Expand Down

0 comments on commit 3366ad4

Please sign in to comment.