diff options
Diffstat (limited to 'source/Irrlicht/COSOperator.cpp')
-rw-r--r-- | source/Irrlicht/COSOperator.cpp | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp index 25b04ad..132232f 100644 --- a/source/Irrlicht/COSOperator.cpp +++ b/source/Irrlicht/COSOperator.cpp @@ -17,7 +17,10 @@ #endif
#endif
-#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
+#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
#if defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
@@ -26,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
{
@@ -54,14 +70,15 @@ const core::stringc& COSOperator::getOperatingSystemVersion() const //! copies text to the clipboard
-//! \param text: text in utf-8
void COSOperator::copyToClipboard(const c8 *text) const
{
if (strlen(text)==0)
return;
-// Windows version
-#if defined(_IRR_WINDOWS_API_)
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
+ SDL_SetClipboardText(text);
+
+#elif defined(_IRR_WINDOWS_API_)
if (!OpenClipboard(NULL) || text == 0)
return;
@@ -102,11 +119,36 @@ void COSOperator::copyToClipboard(const c8 *text) const }
+//! copies text to the primary selection
+void COSOperator::copyToPrimarySelection(const c8 *text) const
+{
+ if (strlen(text)==0)
+ return;
+
+#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
+}
+
+
//! gets text from the clipboard
-//! \return Returns 0 if no string is in there, otherwise an utf-8 string.
const c8* COSOperator::getTextFromClipboard() const
{
-#if defined(_IRR_WINDOWS_API_)
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
+ static char *text = nullptr;
+ if (text)
+ SDL_free(text);
+ text = SDL_GetClipboardText();
+ return text;
+
+#elif defined(_IRR_WINDOWS_API_)
if (!OpenClipboard(NULL))
return 0;
@@ -147,6 +189,33 @@ const c8* COSOperator::getTextFromClipboard() const }
+//! gets text from the primary selection
+const c8* COSOperator::getTextFromPrimarySelection() const
+{
+#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;
+
+#else
+
+ return 0;
+#endif
+}
+
+
bool COSOperator::getSystemMemory(u32* Total, u32* Avail) const
{
#if defined(_IRR_WINDOWS_API_)
|