forked from Mirrorlandia_minetest/irrlicht
Use non-static member vars for SDL clipboard / primary selection buffers
This commit is contained in:
parent
a67f3003de
commit
ba1cd19983
@ -30,7 +30,7 @@
|
||||
#include "fast_atof.h"
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
static bool sdl_supports_primary_selection = [] {
|
||||
static const bool sdl_supports_primary_selection = [] {
|
||||
#if SDL_VERSION_ATLEAST(2, 25, 0)
|
||||
SDL_version linked_version;
|
||||
SDL_GetVersion(&linked_version);
|
||||
@ -62,6 +62,15 @@ COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVer
|
||||
}
|
||||
|
||||
|
||||
COSOperator::~COSOperator()
|
||||
{
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
SDL_free(ClipboardSelectionText);
|
||||
SDL_free(PrimarySelectionText);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//! returns the current operating system version as string.
|
||||
const core::stringc& COSOperator::getOperatingSystemVersion() const
|
||||
{
|
||||
@ -142,11 +151,9 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const
|
||||
const c8* COSOperator::getTextFromClipboard() const
|
||||
{
|
||||
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
static char *text = nullptr;
|
||||
if (text)
|
||||
SDL_free(text);
|
||||
text = SDL_GetClipboardText();
|
||||
return text;
|
||||
SDL_free(ClipboardSelectionText);
|
||||
ClipboardSelectionText = SDL_GetClipboardText();
|
||||
return ClipboardSelectionText;
|
||||
|
||||
#elif defined(_IRR_WINDOWS_API_)
|
||||
if (!OpenClipboard(NULL))
|
||||
@ -195,11 +202,9 @@ 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;
|
||||
SDL_free(PrimarySelectionText);
|
||||
PrimarySelectionText = SDL_GetPrimarySelectionText();
|
||||
return PrimarySelectionText;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -23,6 +23,11 @@ public:
|
||||
#endif
|
||||
COSOperator(const core::stringc& osversion);
|
||||
|
||||
~COSOperator();
|
||||
|
||||
COSOperator(const COSOperator &) = delete;
|
||||
COSOperator &operator=(const COSOperator &) = delete;
|
||||
|
||||
//! returns the current operation system version as string.
|
||||
const core::stringc& getOperatingSystemVersion() const override;
|
||||
|
||||
@ -56,6 +61,12 @@ private:
|
||||
mutable core::stringc ClipboardBuf;
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
// These need to be freed with SDL_free
|
||||
mutable char *ClipboardSelectionText = nullptr;
|
||||
mutable char *PrimarySelectionText = nullptr;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
Loading…
Reference in New Issue
Block a user