Skip to content

Commit

Permalink
Set proper window target on clipboard query x11
Browse files Browse the repository at this point in the history
  • Loading branch information
edo9300 committed Mar 8, 2020
1 parent d158440 commit 714022e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions source/Irrlicht/CIrrDeviceLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,15 +1880,16 @@ const c8* CIrrDeviceLinux::getTextFromClipboard()
Clipboard = "";
if (ownerWindow != None )
{
XConvertSelection (display, X_ATOM_CLIPBOARD, X_ATOM_UTF8_STRING, XA_PRIMARY, ownerWindow, CurrentTime);
XConvertSelection (display, X_ATOM_CLIPBOARD, X_ATOM_UTF8_STRING, XA_PRIMARY, window, CurrentTime);
ClipboardWaiting = true;
u32 startTime = getTimer()->getRealTime();
u32 elapsedTime = 0;
while(ClipboardWaiting) {
run();
elapsedTime = getTimer()->getRealTime() - startTime;
if(!ClipboardWaiting) break;
elapsedTime = getTimer()->getRealTime() - startTime;
if(elapsedTime > 1000) {
os::Printer::log("Error: Timeout while querying clipboard.", ELL_ERROR);
ClipboardWaiting = false;
copyToClipboard("");
return Clipboard.c_str();
Expand All @@ -1900,7 +1901,7 @@ const c8* CIrrDeviceLinux::getTextFromClipboard()
int format;
unsigned long numItems, bytesLeft, dummy;
unsigned char *data;
XGetWindowProperty (display, ownerWindow,
XGetWindowProperty (display, window,
XA_PRIMARY, // property name
0, // offset
0, // length (we only check for data, so 0)
Expand All @@ -1911,16 +1912,17 @@ const c8* CIrrDeviceLinux::getTextFromClipboard()
&numItems, // number items
&bytesLeft, // remaining bytes for partial reads
&data); // data
XFree(data);

// there is some data to get
int result = XGetWindowProperty (display, ownerWindow, XA_PRIMARY, 0,
bytesLeft, 0, AnyPropertyType, &type, &format,
&numItems, &dummy, &data);
if (result == Success)
Clipboard = (irr::c8*)data;
XFree (data);

if ( bytesLeft > 0 )
{
// there is some data to get
int result = XGetWindowProperty (display, window, XA_PRIMARY, 0,
bytesLeft, 0, AnyPropertyType, &type, &format,
&numItems, &dummy, &data);
if (result == Success)
Clipboard = (irr::c8*)data;
XFree (data);
}
}

return Clipboard.c_str();
Expand Down

0 comments on commit 714022e

Please sign in to comment.