mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Added love.window.setScreenSaverEnabled and love.window.isScreenSaverEnabled (resolves issue #1088.)
This commit is contained in:
@@ -556,12 +556,6 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
|
|||||||
{
|
{
|
||||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
// Users won't expect the screensaver to activate if a game is in
|
|
||||||
// focus. Also, joystick input may not delay the screensaver timer.
|
|
||||||
if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
|
||||||
SDL_DisableScreenSaver();
|
|
||||||
else
|
|
||||||
SDL_EnableScreenSaver();
|
|
||||||
vargs.push_back(new Variant(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED));
|
vargs.push_back(new Variant(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED));
|
||||||
msg = new Message("focus", vargs);
|
msg = new Message("focus", vargs);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -53,23 +53,9 @@ SpriteBatch::SpriteBatch(Texture *texture, int size, Mesh::Usage usage)
|
|||||||
throw love::Exception("Invalid SpriteBatch size.");
|
throw love::Exception("Invalid SpriteBatch size.");
|
||||||
|
|
||||||
GLenum gl_usage = Mesh::getGLBufferUsage(usage);
|
GLenum gl_usage = Mesh::getGLBufferUsage(usage);
|
||||||
|
size_t vertex_size = sizeof(Vertex) * 4 * size;
|
||||||
|
|
||||||
const size_t vertex_size = sizeof(Vertex) * 4 * size;
|
array_buf = new GLBuffer(vertex_size, nullptr, GL_ARRAY_BUFFER, gl_usage, GLBuffer::MAP_EXPLICIT_RANGE_MODIFY);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
array_buf = new GLBuffer(vertex_size, nullptr, GL_ARRAY_BUFFER, gl_usage, GLBuffer::MAP_EXPLICIT_RANGE_MODIFY);
|
|
||||||
}
|
|
||||||
catch (love::Exception &)
|
|
||||||
{
|
|
||||||
delete array_buf;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (std::bad_alloc &)
|
|
||||||
{
|
|
||||||
delete array_buf;
|
|
||||||
throw love::Exception("Out of memory.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteBatch::~SpriteBatch()
|
SpriteBatch::~SpriteBatch()
|
||||||
|
|||||||
@@ -137,6 +137,9 @@ public:
|
|||||||
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
||||||
virtual love::image::ImageData *getIcon() = 0;
|
virtual love::image::ImageData *getIcon() = 0;
|
||||||
|
|
||||||
|
virtual void setScreenSaverEnabled(bool enable) = 0;
|
||||||
|
virtual bool isScreenSaverEnabled() const = 0;
|
||||||
|
|
||||||
virtual void minimize() = 0;
|
virtual void minimize() = 0;
|
||||||
virtual void maximize() = 0;
|
virtual void maximize() = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ Window::Window()
|
|||||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||||
throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError());
|
throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError());
|
||||||
|
|
||||||
|
// Make sure the screensaver doesn't activate by default.
|
||||||
|
setScreenSaverEnabled(false);
|
||||||
|
|
||||||
SDL_version version = {};
|
SDL_version version = {};
|
||||||
SDL_GetVersion(&version);
|
SDL_GetVersion(&version);
|
||||||
hasSDL203orEarlier = (version.major == 2 && version.minor == 0 && version.patch <= 3);
|
hasSDL203orEarlier = (version.major == 2 && version.minor == 0 && version.patch <= 3);
|
||||||
@@ -842,6 +845,19 @@ love::image::ImageData *Window::getIcon()
|
|||||||
return curMode.icon.get();
|
return curMode.icon.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::setScreenSaverEnabled(bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
SDL_EnableScreenSaver();
|
||||||
|
else
|
||||||
|
SDL_DisableScreenSaver();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Window::isScreenSaverEnabled() const
|
||||||
|
{
|
||||||
|
return SDL_IsScreenSaverEnabled() != SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::minimize()
|
void Window::minimize()
|
||||||
{
|
{
|
||||||
if (window != nullptr)
|
if (window != nullptr)
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ public:
|
|||||||
bool setIcon(love::image::ImageData *imgd);
|
bool setIcon(love::image::ImageData *imgd);
|
||||||
love::image::ImageData *getIcon();
|
love::image::ImageData *getIcon();
|
||||||
|
|
||||||
|
void setScreenSaverEnabled(bool enable);
|
||||||
|
bool isScreenSaverEnabled() const;
|
||||||
|
|
||||||
void minimize();
|
void minimize();
|
||||||
void maximize();
|
void maximize();
|
||||||
|
|
||||||
|
|||||||
@@ -329,6 +329,18 @@ int w_getIcon(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_setScreenSaverEnabled(lua_State *L)
|
||||||
|
{
|
||||||
|
instance()->setScreenSaverEnabled(luax_toboolean(L, 1));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_isScreenSaverEnabled(lua_State *L)
|
||||||
|
{
|
||||||
|
luax_pushboolean(L, instance()->isScreenSaverEnabled());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_setTitle(lua_State *L)
|
int w_setTitle(lua_State *L)
|
||||||
{
|
{
|
||||||
std::string title = luax_checkstring(L, 1);
|
std::string title = luax_checkstring(L, 1);
|
||||||
@@ -509,6 +521,8 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getPosition", w_getPosition },
|
{ "getPosition", w_getPosition },
|
||||||
{ "setIcon", w_setIcon },
|
{ "setIcon", w_setIcon },
|
||||||
{ "getIcon", w_getIcon },
|
{ "getIcon", w_getIcon },
|
||||||
|
{ "setScreenSaverEnabled", w_setScreenSaverEnabled },
|
||||||
|
{ "isScreenSaverEnabled", w_isScreenSaverEnabled },
|
||||||
{ "setTitle", w_setTitle },
|
{ "setTitle", w_setTitle },
|
||||||
{ "getTitle", w_getTitle },
|
{ "getTitle", w_getTitle },
|
||||||
{ "hasFocus", w_hasFocus },
|
{ "hasFocus", w_hasFocus },
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ int w_setPosition(lua_State *L);
|
|||||||
int w_getPosition(lua_State *L);
|
int w_getPosition(lua_State *L);
|
||||||
int w_setIcon(lua_State *L);
|
int w_setIcon(lua_State *L);
|
||||||
int w_getIcon(lua_State *L);
|
int w_getIcon(lua_State *L);
|
||||||
|
int w_setScreenSaverEnabled(lua_State *L);
|
||||||
|
int w_isScreenSaverEnabled(lua_State *L);
|
||||||
int w_setTitle(lua_State *L);
|
int w_setTitle(lua_State *L);
|
||||||
int w_getTitle(lua_State *L);
|
int w_getTitle(lua_State *L);
|
||||||
int w_hasFocus(lua_State *L);
|
int w_hasFocus(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user