Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linux] support for simple xselection pasting #9631

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions xbmc/windowing/WinEventsX11.cpp
Expand Up @@ -344,6 +344,10 @@ bool CWinEventsX11Imp::MessagePump()

switch (xevent.type)
{
case SelectionNotify:
ret = true;
break;

case MapNotify:
{
g_application.SetRenderGUI(true);
Expand Down
58 changes: 58 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,60 @@ void CWinSystemX11::UpdateCrtc()
g_graphicsContext.SetFPS(fps);
}

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

Atom utf8_string = XInternAtom(m_dpy, "UTF8_STRING", False);
if (utf8_string == None)
return "";

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

This comment was marked as spam.

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)

This comment was marked as spam.

This comment was marked as spam.

{
CLog::Log(LOGNOTICE, "GetClipboardText calls MessagePump count = %d ", count);
if (CWinEventsX11Imp::MessagePump())

This comment was marked as spam.

break;
Sleep(10);
}

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

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;
XFree(data);
} else
break;
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