Skip to content

Commit

Permalink
[linux] Add support for simple xselection pasting
Browse files Browse the repository at this point in the history
02 May 2016 - Don't create an additional window and also don't use
XNextEvent, we already have XNextEvent a different location.
Wait for event SelectionNotify at most for 200 ms and use function
XCheckTypedWindowEvent to check it.

First version: Matthias Kortstiege <mkortstiege@kodi.tv> 4 Jul 2015
https://github.com/mkortstiege/xbmc/tree/linux-paste
mkortstiege@62e56b7
  • Loading branch information
sergiomb2 committed May 2, 2016
1 parent 4015436 commit 9c30d6e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions xbmc/windowing/X11/WinSystemX11.cpp
Expand Up @@ -48,6 +48,8 @@

using namespace KODI::MESSAGING;

#include <limits.h>

#define EGL_NO_CONFIG (EGLConfig)0

CWinSystemX11::CWinSystemX11() : CWinSystemBase()
Expand Down Expand Up @@ -1070,4 +1072,53 @@ void CWinSystemX11::UpdateCrtc()
g_graphicsContext.SetFPS(fps);
}

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

std::string result;
Atom utf8_string = XInternAtom(m_dpy, "UTF8_STRING", False);
Atom clipboard = XInternAtom(m_dpy, "CLIPBOARD", False);
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
int count = 20; // will wait at most for 200 ms
while (--count >= 0)
{
XEvent event;
if (XCheckTypedWindowEvent (m_dpy, m_glWindow, SelectionNotify, &event))
break;
// not very elegant.. we could do a select() or something like that...
// however clipboard content requesting is inherently slow on x11, it
// often takes 50ms or more so...
Sleep(10);
}

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

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)
{
result.append(reinterpret_cast<const char*>(data), items_read);
offset += items_read;
}

XDeleteProperty(m_dpy, m_glWindow, utf8_string);

if(!items_left)
break;
}

return result;
}

#endif
1 change: 1 addition & 0 deletions xbmc/windowing/X11/WinSystemX11.h
Expand Up @@ -68,6 +68,7 @@ class CWinSystemX11 : public CWinSystemBase
bool IsCurrentOutput(std::string output);
void RecreateWindow();
int GetCrtc() { return m_crtc; }
std::string GetClipboardText(void);

protected:
virtual bool SetWindow(int width, int height, bool fullscreen, const std::string &output, int *winstate = NULL) = 0;
Expand Down

0 comments on commit 9c30d6e

Please sign in to comment.