From f14dfc8462325e57604c4e0767b5a4d6a91776cc Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Tue, 7 Jun 2022 13:36:35 -0400 Subject: [PATCH 1/2] Work around unreliable clipboard on Linux. Most likely SDL_waylandvideo.c is to blame, but I don't know enough to rule out SDL_x11video.c. --- src/lime/system/Clipboard.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lime/system/Clipboard.hx b/src/lime/system/Clipboard.hx index cb66fc2ee..0d8013c55 100644 --- a/src/lime/system/Clipboard.hx +++ b/src/lime/system/Clipboard.hx @@ -56,6 +56,14 @@ class Clipboard #if (flash || js || html5) __update(); + #elseif linux + // Hack: SDL won't start calling __update until set_text() + // is called once. + if (_text == null) + { + __update(); + set_text(_text); + } #end return _text; From 214b5a526a8948ea95c465dfbc7f61046a8ff4b0 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Mon, 5 Sep 2022 22:25:13 -0400 Subject: [PATCH 2/2] Improve clipboard documentation. I managed to track down the relevant lines of code, and they're actually in SDL_x11clipboard.c rather than either of the files I suspected. --- src/lime/system/Clipboard.hx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lime/system/Clipboard.hx b/src/lime/system/Clipboard.hx index 0d8013c55..6e7f71557 100644 --- a/src/lime/system/Clipboard.hx +++ b/src/lime/system/Clipboard.hx @@ -52,16 +52,20 @@ class Clipboard // Get & Set Methods private static function get_text():String { - // Native clipboard calls __update when clipboard changes + // Native clipboard (except Xorg) calls __update when clipboard changes. #if (flash || js || html5) __update(); #elseif linux - // Hack: SDL won't start calling __update until set_text() - // is called once. + // Xorg won't call __update until we call set_text at least once. + // Details: SDL_x11clipboard.c calls X11_XSetSelectionOwner, + // registering this app to receive clipboard events. if (_text == null) { __update(); + + // Call set_text while changing as little as possible. (Rich text + // formatting will unavoidably be lost.) set_text(_text); } #end