diff options
author | Desour <vorunbekannt75@web.de> | 2022-09-14 22:48:06 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-03-24 17:59:06 +0100 |
commit | 799c8b936f9a2cc4f3a8bc56237fb9a8dedf853e (patch) | |
tree | 81340f541a778e8a7fc926893389d58ddb37af7f /source | |
parent | 8da1bcf58bd8ff4d08d93c26599f8e22e68a8df4 (diff) | |
download | irrlicht-799c8b936f9a2cc4f3a8bc56237fb9a8dedf853e.tar.xz |
SDL: Support primary selection
Requires SDL >= 2.25.0 (newest master).
Diffstat (limited to 'source')
-rw-r--r-- | source/Irrlicht/COSOperator.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp index 4f44178..132232f 100644 --- a/source/Irrlicht/COSOperator.cpp +++ b/source/Irrlicht/COSOperator.cpp @@ -19,6 +19,7 @@ #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
#include <SDL_clipboard.h>
+#include <SDL_version.h>
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
#include "CIrrDeviceLinux.h"
#endif
@@ -28,6 +29,19 @@ #include "fast_atof.h"
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
+static bool sdl_supports_primary_selection = [] {
+#if SDL_VERSION_ATLEAST(2, 25, 0)
+ SDL_version linked_version;
+ SDL_GetVersion(&linked_version);
+ return (linked_version.major == 2 && linked_version.minor >= 25)
+ || linked_version.major > 2;
+#else
+ return false;
+#endif
+}();
+#endif
+
namespace irr
{
@@ -111,7 +125,13 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const if (strlen(text)==0)
return;
-#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
+#if SDL_VERSION_ATLEAST(2, 25, 0)
+ if (sdl_supports_primary_selection)
+ SDL_SetPrimarySelectionText(text);
+#endif
+
+#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
if ( IrrDeviceLinux )
IrrDeviceLinux->copyToPrimarySelection(text);
#endif
@@ -172,7 +192,19 @@ const c8* COSOperator::getTextFromClipboard() const //! gets text from the primary selection
const c8* COSOperator::getTextFromPrimarySelection() const
{
-#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
+#if SDL_VERSION_ATLEAST(2, 25, 0)
+ if (sdl_supports_primary_selection) {
+ static char *text = nullptr;
+ if (text)
+ SDL_free(text);
+ text = SDL_GetPrimarySelectionText();
+ return text;
+ }
+#endif
+ return 0;
+
+#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
if ( IrrDeviceLinux )
return IrrDeviceLinux->getTextFromPrimarySelection();
return 0;
|