From 5a5b6dcde001fe93cd840fc5b935b7ba36ae3633 Mon Sep 17 00:00:00 2001 From: Jia Wang Date: Tue, 25 Jul 2017 06:36:19 +0800 Subject: [PATCH] Workaround to allow pasting unicode characters from X selection. Fixes #2491. Fixes #9787. --- platform/x11/os_x11.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 742767bdde6..148bd0d7653 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1661,7 +1661,7 @@ void OS_X11::set_clipboard(const String &p_text) { XSetSelectionOwner(x11_display, XInternAtom(x11_display, "CLIPBOARD", 0), x11_window, CurrentTime); }; -static String _get_clipboard(Atom p_source, Window x11_window, ::Display *x11_display, String p_internal_clipboard) { +static String _get_clipboard_impl(Atom p_source, Window x11_window, ::Display *x11_display, String p_internal_clipboard, Atom target) { String ret; @@ -1678,7 +1678,7 @@ static String _get_clipboard(Atom p_source, Window x11_window, ::Display *x11_di }; if (Sown != None) { - XConvertSelection(x11_display, p_source, XA_STRING, selection, + XConvertSelection(x11_display, p_source, target, selection, x11_window, CurrentTime); XFlush(x11_display); while (true) { @@ -1718,6 +1718,18 @@ static String _get_clipboard(Atom p_source, Window x11_window, ::Display *x11_di return ret; } +static String _get_clipboard(Atom p_source, Window x11_window, ::Display *x11_display, String p_internal_clipboard) { + String ret; + Atom utf8_atom = XInternAtom(x11_display, "UTF8_STRING", True); + if (utf8_atom != None) { + ret = _get_clipboard_impl(p_source, x11_window, x11_display, p_internal_clipboard, utf8_atom); + } + if (ret == "") { + ret = _get_clipboard_impl(p_source, x11_window, x11_display, p_internal_clipboard, XA_STRING); + } + return ret; +} + String OS_X11::get_clipboard() const { String ret;