Fix the X11 clipboard code so that it now waits for a response before attempting to fetch the data; also make it request a UFT-8 string.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5949 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
85b9e9b164
commit
19345a8d2e
|
@ -172,15 +172,52 @@ char *widgetGetClipboardText()
|
||||||
// If there is a selection (and therefore owner) fetch it
|
// If there is a selection (and therefore owner) fetch it
|
||||||
if (selectionOwner != None)
|
if (selectionOwner != None)
|
||||||
{
|
{
|
||||||
// Convert the selection to a string
|
SDL_Event event;
|
||||||
XConvertSelection(info.info.x11.display, XA_CLIPBOARD, XA_STRING, None,
|
bool response = false;
|
||||||
selectionOwner, CurrentTime);
|
|
||||||
|
/*
|
||||||
|
* Ask the window whom current owns the clipboard to convert it to an
|
||||||
|
* XA_UTF8_STRING and place it into the XA_CLIPBOARD property of our
|
||||||
|
* window.
|
||||||
|
*/
|
||||||
|
XConvertSelection(info.info.x11.display, XA_CLIPBOARD, XA_UTF8_STRING,
|
||||||
|
XA_CLIPBOARD, info.info.x11.window, CurrentTime);
|
||||||
XFlush(info.info.x11.display);
|
XFlush(info.info.x11.display);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We now need to wait for a response from the window that owns the
|
||||||
|
* clipboard.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Unlock the connection so that the SDL event loop may function
|
||||||
|
info.info.x11.unlock_func();
|
||||||
|
|
||||||
|
while (!response)
|
||||||
|
{
|
||||||
|
// Wait for an event
|
||||||
|
SDL_WaitEvent(&event);
|
||||||
|
|
||||||
|
// If the event is a window manager event
|
||||||
|
if (event.type == SDL_SYSWMEVENT)
|
||||||
|
{
|
||||||
|
XEvent xevent = event.syswm.msg->event.xevent;
|
||||||
|
|
||||||
|
// See if it is a response to our request
|
||||||
|
if (xevent.type == SelectionNotify
|
||||||
|
&& xevent.xselection.requestor == info.info.x11.window)
|
||||||
|
{
|
||||||
|
response = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock the connection once again
|
||||||
|
info.info.x11.lock_func();
|
||||||
|
|
||||||
// See how much data is there
|
// See how much data is there
|
||||||
XGetWindowProperty(info.info.x11.display, selectionOwner, XA_STRING, 0,
|
XGetWindowProperty(info.info.x11.display, info.info.x11.window,
|
||||||
0, False, AnyPropertyType, &type, &format, &len,
|
XA_CLIPBOARD, 0, 0, False, AnyPropertyType, &type,
|
||||||
&bytesLeft, &data);
|
&format, &len, &bytesLeft, &data);
|
||||||
|
|
||||||
// If any 0-length data was returned, free it
|
// If any 0-length data was returned, free it
|
||||||
if (data)
|
if (data)
|
||||||
|
@ -192,10 +229,11 @@ char *widgetGetClipboardText()
|
||||||
// If there is any data
|
// If there is any data
|
||||||
if (bytesLeft)
|
if (bytesLeft)
|
||||||
{
|
{
|
||||||
result = XGetWindowProperty(info.info.x11.display, selectionOwner,
|
// Fetch the data
|
||||||
XA_STRING, 0, bytesLeft, False,
|
result = XGetWindowProperty(info.info.x11.display,
|
||||||
AnyPropertyType, &type, &format, &len,
|
info.info.x11.window, XA_CLIPBOARD, 0,
|
||||||
&dummy, &data);
|
bytesLeft, False, AnyPropertyType,
|
||||||
|
&type, &format, &len, &dummy, &data);
|
||||||
|
|
||||||
// If we got some data, duplicate it
|
// If we got some data, duplicate it
|
||||||
if (result == Success)
|
if (result == Success)
|
||||||
|
@ -206,7 +244,8 @@ char *widgetGetClipboardText()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the property now that we are finished with it
|
// Delete the property now that we are finished with it
|
||||||
XDeleteProperty(info.info.x11.display, selectionOwner, XA_STRING);
|
XDeleteProperty(info.info.x11.display, info.info.x11.window,
|
||||||
|
XA_CLIPBOARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock the connection
|
// Unlock the connection
|
||||||
|
|
Loading…
Reference in New Issue