mirror of
https://github.com/minetest/irrlicht.git
synced 2024-12-26 18:50:31 +01:00
SDL: Support primary selection
Requires SDL >= 2.25.0 (newest master).
This commit is contained in:
parent
8da1bcf58b
commit
799c8b936f
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||||
#include <SDL_clipboard.h>
|
#include <SDL_clipboard.h>
|
||||||
|
#include <SDL_version.h>
|
||||||
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
|
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
|
||||||
#include "CIrrDeviceLinux.h"
|
#include "CIrrDeviceLinux.h"
|
||||||
#endif
|
#endif
|
||||||
@ -28,6 +29,19 @@
|
|||||||
|
|
||||||
#include "fast_atof.h"
|
#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
|
namespace irr
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -111,7 +125,13 @@ void COSOperator::copyToPrimarySelection(const c8 *text) const
|
|||||||
if (strlen(text)==0)
|
if (strlen(text)==0)
|
||||||
return;
|
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 )
|
if ( IrrDeviceLinux )
|
||||||
IrrDeviceLinux->copyToPrimarySelection(text);
|
IrrDeviceLinux->copyToPrimarySelection(text);
|
||||||
#endif
|
#endif
|
||||||
@ -172,7 +192,19 @@ const c8* COSOperator::getTextFromClipboard() const
|
|||||||
//! gets text from the primary selection
|
//! gets text from the primary selection
|
||||||
const c8* COSOperator::getTextFromPrimarySelection() const
|
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 )
|
if ( IrrDeviceLinux )
|
||||||
return IrrDeviceLinux->getTextFromPrimarySelection();
|
return IrrDeviceLinux->getTextFromPrimarySelection();
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user