From 20b02654b656d1bb3415e50379f62019925074ab Mon Sep 17 00:00:00 2001 From: hn-88 Date: Mon, 29 Sep 2025 14:48:48 +0530 Subject: [PATCH 1/2] take care of MIME types on Linux clipboard fix crash on Linux due to the first MIME type being returned by xclip --- src/misc/clipboard.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/misc/clipboard.cpp b/src/misc/clipboard.cpp index 7e27e145..3eda6391 100644 --- a/src/misc/clipboard.cpp +++ b/src/misc/clipboard.cpp @@ -97,9 +97,31 @@ std::string clipboardText() { return ""; #else std::string text; - if (exec("xclip -o -sel c -f", text)) { - return text.substr(0, text.length()); // remove a line ending + // Try UTF8_STRING first + if (exec("xclip -o -selection clipboard -target UTF8_STRING", text)) { + if (!text.empty() && text.back() == '\n') { + text.pop_back(); + } + return text; + } + + // Fallback: try text/plain;charset=utf-8 + if (exec("xclip -o -selection clipboard -target text/plain;charset=utf-8", text)) { + if (!text.empty() && text.back() == '\n') { + text.pop_back(); + } + return text; } + + // Final fallback: default text/plain + if (exec("xclip -o -selection clipboard -target text/plain", text)) { + if (!text.empty() && text.back() == '\n') { + text.pop_back(); + } + return text; + } + + // If all else fails return ""; #endif } From 731a08fefa734ed87af476352ad1b6d22f11b19f Mon Sep 17 00:00:00 2001 From: hn-88 Date: Mon, 6 Oct 2025 09:33:43 +0530 Subject: [PATCH 2/2] add timeout to xclip execution to prevent it from blocking OpenSpace when pasting content from Chromium / CEF --- src/misc/clipboard.cpp | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/misc/clipboard.cpp b/src/misc/clipboard.cpp index 3eda6391..9a27b0d2 100644 --- a/src/misc/clipboard.cpp +++ b/src/misc/clipboard.cpp @@ -97,31 +97,9 @@ std::string clipboardText() { return ""; #else std::string text; - // Try UTF8_STRING first - if (exec("xclip -o -selection clipboard -target UTF8_STRING", text)) { - if (!text.empty() && text.back() == '\n') { - text.pop_back(); - } - return text; - } - - // Fallback: try text/plain;charset=utf-8 - if (exec("xclip -o -selection clipboard -target text/plain;charset=utf-8", text)) { - if (!text.empty() && text.back() == '\n') { - text.pop_back(); - } - return text; + if (exec("timeout --kill-after=0.2s 0.3s xclip -o -sel c -f", text)) { + return text.substr(0, text.length()); // remove a line ending } - - // Final fallback: default text/plain - if (exec("xclip -o -selection clipboard -target text/plain", text)) { - if (!text.empty() && text.back() == '\n') { - text.pop_back(); - } - return text; - } - - // If all else fails return ""; #endif }