mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Error if a window isn't open when love.system.set/getClipboardText are called (resolves issue #1290).
--HG-- branch : minor
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include "window/Window.h"
|
||||||
|
|
||||||
// SDL
|
// SDL
|
||||||
#include <SDL_clipboard.h>
|
#include <SDL_clipboard.h>
|
||||||
@@ -46,13 +47,27 @@ int System::getProcessorCount() const
|
|||||||
return SDL_GetCPUCount();
|
return SDL_GetCPUCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool System::isWindowOpen() const
|
||||||
|
{
|
||||||
|
auto window = Module::getInstance<window::Window>(M_WINDOW);
|
||||||
|
return window != nullptr && window->isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
void System::setClipboardText(const std::string &text) const
|
void System::setClipboardText(const std::string &text) const
|
||||||
{
|
{
|
||||||
|
// SDL requires the video subsystem to be initialized and a window to be
|
||||||
|
// opened in order for clipboard text to work, on at least some platforms.
|
||||||
|
if (!isWindowOpen())
|
||||||
|
throw love::Exception("A window must be created in order for setClipboardText to function properly.");
|
||||||
|
|
||||||
SDL_SetClipboardText(text.c_str());
|
SDL_SetClipboardText(text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string System::getClipboardText() const
|
std::string System::getClipboardText() const
|
||||||
{
|
{
|
||||||
|
if (!isWindowOpen())
|
||||||
|
throw love::Exception("A window must be created in order for getClipboardText to function properly.");
|
||||||
|
|
||||||
std::string text("");
|
std::string text("");
|
||||||
|
|
||||||
char *ctext = SDL_GetClipboardText();
|
char *ctext = SDL_GetClipboardText();
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool isWindowOpen() const;
|
||||||
|
|
||||||
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
|
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
|
||||||
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM> powerStates;
|
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM> powerStates;
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,15 @@ int w_getProcessorCount(lua_State *L)
|
|||||||
int w_setClipboardText(lua_State *L)
|
int w_setClipboardText(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *text = luaL_checkstring(L, 1);
|
const char *text = luaL_checkstring(L, 1);
|
||||||
instance()->setClipboardText(text);
|
luax_catchexcept(L, [&]() { instance()->setClipboardText(text); });
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_getClipboardText(lua_State *L)
|
int w_getClipboardText(lua_State *L)
|
||||||
{
|
{
|
||||||
luax_pushstring(L, instance()->getClipboardText());
|
std::string text;
|
||||||
|
luax_catchexcept(L, [&]() { text = instance()->getClipboardText(); });
|
||||||
|
luax_pushstring(L, text);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user