Skip to content

Commit

Permalink
add love.exposed and love.occluded event callbacks.
Browse files Browse the repository at this point in the history
Add love.window.isOccluded.

Resolves #2004.
  • Loading branch information
slime73 committed Oct 19, 2024
1 parent 6e82633 commit b116857
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/modules/event/sdl/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ Message *Event::convert(const SDL_Event &e)
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
#if defined(LOVE_ENABLE_SENSOR)
case SDL_EVENT_GAMEPAD_SENSOR_UPDATE:
#endif
msg = convertJoystickEvent(e);
break;
case SDL_EVENT_WINDOW_FOCUS_GAINED:
Expand All @@ -375,6 +373,8 @@ Message *Event::convert(const SDL_Event &e)
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
case SDL_EVENT_WINDOW_MINIMIZED:
case SDL_EVENT_WINDOW_RESTORED:
case SDL_EVENT_WINDOW_EXPOSED:
case SDL_EVENT_WINDOW_OCCLUDED:
msg = convertWindowEvent(e);
break;
case SDL_EVENT_DISPLAY_ORIENTATION:
Expand Down Expand Up @@ -680,6 +680,12 @@ Message *Event::convertWindowEvent(const SDL_Event &e)
vargs.emplace_back(event == SDL_EVENT_WINDOW_SHOWN || event == SDL_EVENT_WINDOW_RESTORED);
msg = new Message("visible", vargs);
break;
case SDL_EVENT_WINDOW_EXPOSED:
msg = new Message("exposed");
break;
case SDL_EVENT_WINDOW_OCCLUDED:
msg = new Message("occluded");
break;
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
{
double width = e.window.data1;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/love/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ function love.createhandlers()
visible = function (v)
if love.visible then return love.visible(v) end
end,
exposed = function ()
if love.exposed then return love.exposed() end
end,
occluded = function ()
if love.occluded then return love.occluded() end
end,
quit = function ()
return
end,
Expand Down
1 change: 1 addition & 0 deletions src/modules/window/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Window : public Module
virtual bool hasMouseFocus() const = 0;

virtual bool isVisible() const = 0;
virtual bool isOccluded() const = 0;

virtual void setMouseGrab(bool grab) = 0;
virtual bool isMouseGrabbed() const = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/modules/window/sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,11 @@ bool Window::isVisible() const
return window && (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) == 0;
}

bool Window::isOccluded() const
{
return window && (SDL_GetWindowFlags(window) & SDL_WINDOW_OCCLUDED) != 0;
}

void Window::setMouseGrab(bool grab)
{
mouseGrabbed = grab;
Expand Down
1 change: 1 addition & 0 deletions src/modules/window/sdl/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class Window final : public love::window::Window
bool hasMouseFocus() const override;

bool isVisible() const override;
bool isOccluded() const override;

void setMouseGrab(bool grab) override;
bool isMouseGrabbed() const override;
Expand Down
7 changes: 7 additions & 0 deletions src/modules/window/wrap_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ int w_isVisible(lua_State *L)
return 1;
}

int w_isOccluded(lua_State *L)
{
luax_pushboolean(L, instance()->isOccluded());
return 1;
}

int w_getDPIScale(lua_State *L)
{
lua_pushnumber(L, instance()->getDPIScale());
Expand Down Expand Up @@ -683,6 +689,7 @@ static const luaL_Reg functions[] =
{ "hasFocus", w_hasFocus },
{ "hasMouseFocus", w_hasMouseFocus },
{ "isVisible", w_isVisible },
{ "isOccluded", w_isOccluded },
{ "getDPIScale", w_getDPIScale },
{ "getNativeDPIScale", w_getNativeDPIScale },
{ "toPixels", w_toPixels },
Expand Down
8 changes: 7 additions & 1 deletion testing/tests/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ love.test.window.isMinimized = function(test)
end


-- love.window.isOccluded
love.test.window.isOccluded = function(test)
love.window.focus()
test:assertFalse(love.window.isOccluded(), 'check window not occluded')
end


-- love.window.isOpen
love.test.window.isOpen = function(test)
-- check open initially
Expand All @@ -210,7 +217,6 @@ end
love.test.window.isVisible = function(test)
-- check visible initially
test:assertTrue(love.window.isVisible(), 'check window visible')
-- we check closing in test.window.close
end


Expand Down

0 comments on commit b116857

Please sign in to comment.