Skip to content

Commit

Permalink
keep it simple
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomb2 committed May 3, 2016
1 parent 5df157f commit af49c34
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions xbmc/windowing/X11/WinSystemX11.cpp
Expand Up @@ -1077,41 +1077,39 @@ std::string CWinSystemX11::GetClipboardText(void)
if (!m_dpy)
return "";

std::string result;
Atom utf8_string = XInternAtom(m_dpy, "UTF8_STRING", False);
if (utf8_string == None)
return "";

Atom clipboard = XInternAtom(m_dpy, "CLIPBOARD", False);
if (clipboard == None)
return "";

// if no selection or there is no owner for the selection (ancient X ?!)
if (XGetSelectionOwner(m_dpy, clipboard) == None)
return "";

std::string result = "";
XConvertSelection(m_dpy, clipboard, utf8_string, None, m_glWindow, CurrentTime);
// Wait for clipboard event (SelectionNotify) sync, code copied from
// https://github.com/vinniefalco/SimpleDJ/blob/master/Extern/JUCE/modules/juce_gui_basics/native/juce_linux_Clipboard.cpp
// clipboard content requesting is inherently slow on x11, it
// often takes 50ms or more so...
int count = 20; // will wait at most for 200 ms
while (--count >= 0)
{
if (CWinEventsX11Imp::MessagePump())
break;
Sleep(10);
}
CWinEventsX11Imp::MessagePump();

for(unsigned long offset = 0;;)
{
Atom real_type = None;
unsigned char *data;
unsigned long items_read, items_left = 0;
int real_format = 0;
unsigned long items_read, items_left = 0;
unsigned char *data;

Atom utf8_string = XInternAtom(m_dpy, "UTF8_STRING", False);
XGetWindowProperty(m_dpy, m_glWindow, utf8_string, offset, INT_MAX, False,
AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &data);

if(items_read)
if (XGetWindowProperty(m_dpy, m_glWindow, utf8_string, offset, INT_MAX,
False, AnyPropertyType, &real_type, &real_format, &items_read,
&items_left, &data) == Success)
{
result.append(reinterpret_cast<const char*>(data), items_read);
offset += items_read;
}

XDeleteProperty(m_dpy, m_glWindow, utf8_string);

XFree(data);
} else
break;
if(!items_left)
break;
}
Expand Down

0 comments on commit af49c34

Please sign in to comment.