Commit e44c6720 authored by mercury233's avatar mercury233

fix linux paste

parent cffd67d6
...@@ -63,6 +63,7 @@ namespace ...@@ -63,6 +63,7 @@ namespace
Atom X_ATOM_TARGETS; Atom X_ATOM_TARGETS;
Atom X_ATOM_UTF8_STRING; Atom X_ATOM_UTF8_STRING;
Atom X_ATOM_TEXT; Atom X_ATOM_TEXT;
Atom X_ATOM_XSEL_DATA;
}; };
namespace irr namespace irr
...@@ -1875,34 +1876,36 @@ const c8* CIrrDeviceLinux::getTextFromClipboard() const ...@@ -1875,34 +1876,36 @@ const c8* CIrrDeviceLinux::getTextFromClipboard() const
Clipboard = ""; Clipboard = "";
if (ownerWindow != None ) if (ownerWindow != None )
{ {
XConvertSelection (display, X_ATOM_CLIPBOARD, XA_STRING, XA_PRIMARY, ownerWindow, CurrentTime); XConvertSelection (display, X_ATOM_CLIPBOARD, X_ATOM_UTF8_STRING, X_ATOM_XSEL_DATA, window, CurrentTime);
XFlush (display); XSync (display, 0);
XEvent event;
// check for data do nanosleep ((const struct timespec[]){{0, 1L}}, NULL);
Atom type; while (!XCheckTypedEvent (display, SelectionNotify, &event));
int format; if ( (event.xselection.selection == X_ATOM_CLIPBOARD) && event.xselection.property )
unsigned long numItems, bytesLeft, dummy; {
unsigned char *data; Atom type;
XGetWindowProperty (display, ownerWindow, int format;
XA_PRIMARY, // property name unsigned long size, dummy;
0, // offset unsigned char *data;
0, // length (we only check for data, so 0) int result = XGetWindowProperty (event.xselection.display,
event.xselection.requestor,
event.xselection.property,
0L, // offset
(~0L), // length (max)
0, // Delete 0==false 0, // Delete 0==false
AnyPropertyType, // AnyPropertyType or property identifier AnyPropertyType, // AnyPropertyType or property identifier
&type, // return type &type, // return type
&format, // return format &format, // return format
&numItems, // number items &size, // number items
&bytesLeft, // remaining bytes for partial reads &dummy, // remaining bytes for partial reads
&data); // data &data); // data
if ( bytesLeft > 0 ) if ( result == Success
{ && (type == X_ATOM_UTF8_STRING || type == XA_STRING) ) // not implemented: INCR (partial reads)
// there is some data to get {
int result = XGetWindowProperty (display, ownerWindow, XA_PRIMARY, 0, Clipboard = strndup((char*)data, size);
bytesLeft, 0, AnyPropertyType, &type, &format, XFree (data);
&numItems, &dummy, &data); }
if (result == Success) XDeleteProperty (event.xselection.display, event.xselection.requestor, event.xselection.property);
Clipboard = (irr::c8*)data;
XFree (data);
} }
} }
...@@ -1966,6 +1969,7 @@ void CIrrDeviceLinux::initXAtoms() ...@@ -1966,6 +1969,7 @@ void CIrrDeviceLinux::initXAtoms()
X_ATOM_TARGETS = XInternAtom(display, "TARGETS", False); X_ATOM_TARGETS = XInternAtom(display, "TARGETS", False);
X_ATOM_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False); X_ATOM_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
X_ATOM_TEXT = XInternAtom (display, "TEXT", False); X_ATOM_TEXT = XInternAtom (display, "TEXT", False);
X_ATOM_XSEL_DATA = XInternAtom (display, "XSEL_DATA", False);
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment