From 8da1bcf58bd8ff4d08d93c26599f8e22e68a8df4 Mon Sep 17 00:00:00 2001
From: Desour <vorunbekannt75@web.de>
Date: Wed, 14 Sep 2022 20:38:49 +0200
Subject: [PATCH] SDL: Support clipboard

---
 source/Irrlicht/COSOperator.cpp | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/source/Irrlicht/COSOperator.cpp b/source/Irrlicht/COSOperator.cpp
index 906035aa..4f441786 100644
--- a/source/Irrlicht/COSOperator.cpp
+++ b/source/Irrlicht/COSOperator.cpp
@@ -17,7 +17,9 @@
 #endif
 #endif
 
-#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
+#include <SDL_clipboard.h>
+#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
 #include "CIrrDeviceLinux.h"
 #endif
 #if defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
@@ -59,8 +61,10 @@ 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;
 
@@ -117,7 +121,14 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const
 //! gets text from the clipboard
 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;