Skip to content

Commit

Permalink
[linux] support for simple xselection pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkortstiege committed Jul 4, 2015
1 parent e9aa4af commit 62e56b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions xbmc/windowing/X11/WinSystemX11.cpp
Expand Up @@ -45,6 +45,8 @@
#include "../WinEventsX11.h"
#include "input/InputManager.h"

#include <limits.h>

using namespace std;

#define EGL_NO_CONFIG (EGLConfig)0
Expand Down Expand Up @@ -1466,4 +1468,48 @@ void CWinSystemX11::UpdateCrtc()
g_graphicsContext.SetFPS(fps);
}

std::string CWinSystemX11::GetClipboardText(void)
{
if(!m_dpy)
return "";

std::string result;
Window p = DefaultRootWindow(m_dpy);
Window w = XCreateSimpleWindow(m_dpy, p, 0, 0, 1, 1, 0, CopyFromParent, CopyFromParent);
Atom utf8_string = XInternAtom(m_dpy, "UTF8_STRING", False);
XConvertSelection(m_dpy, XA_PRIMARY, utf8_string, None, w, CurrentTime);
XFlush(m_dpy);

for(unsigned long offset = 0;;)
{
XEvent ev;
XNextEvent(m_dpy, &ev);

if(SelectionNotify == ev.type && ev.xselection.property != None)
{
Atom real_type = None;
unsigned char *data;
unsigned long items_read, items_left = 0;
int real_format = 0;

XGetWindowProperty(m_dpy, w, ev.xselection.property, offset, INT_MAX, False,
AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &data);

if(items_read)
{
result.append(reinterpret_cast<const char*>(data), items_read);
offset += items_read;
}

XDeleteProperty(m_dpy, w, ev.xselection.property);

if(!items_left)
break;
}
}

return result;
}


#endif
2 changes: 2 additions & 0 deletions xbmc/windowing/X11/WinSystemX11.h
Expand Up @@ -89,6 +89,8 @@ class CWinSystemX11 : public CWinSystemBase, public ISettingCallback
void RecreateWindow();
int GetCrtc() { return m_crtc; }

std::string GetClipboardText(void);

protected:
bool RefreshGlxContext(bool force);
void OnLostDevice();
Expand Down

0 comments on commit 62e56b7

Please sign in to comment.