Skip to content

Commit

Permalink
Fix love.resize when SDL3 is used
Browse files Browse the repository at this point in the history
Also fixes #2100.
  • Loading branch information
slime73 committed Oct 15, 2024
1 parent b69a22d commit 31ce65b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/modules/event/sdl/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,37 @@ Message *Event::convertWindowEvent(const SDL_Event &e)
vargs.emplace_back(event == SDL_EVENT_WINDOW_SHOWN);
msg = new Message("visible", vargs);
break;
#if SDL_VERSION_ATLEAST(3, 0, 0)
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
{
double width = e.window.data1;
double height = e.window.data2;

gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
win = Module::getInstance<window::Window>(Module::M_WINDOW);
if (win)
win->onSizeChanged(e.window.data1, e.window.data2);

// The size values in the Window aren't necessarily the same as the
// graphics size, which is what we want to output.
if (gfx)
{
width = gfx->getWidth();
height = gfx->getHeight();
}
else if (win)
{
width = win->getWidth();
height = win->getHeight();
windowToDPICoords(&width, &height);
}

vargs.emplace_back(width);
vargs.emplace_back(height);
msg = new Message("resize", vargs);
}
break;
#else
case SDL_EVENT_WINDOW_RESIZED:
{
double width = e.window.data1;
Expand Down Expand Up @@ -855,6 +886,7 @@ Message *Event::convertWindowEvent(const SDL_Event &e)
if (win)
win->onSizeChanged(e.window.data1, e.window.data2);
break;
#endif
case SDL_EVENT_WINDOW_MINIMIZED:
case SDL_EVENT_WINDOW_RESTORED:
#ifdef LOVE_ANDROID
Expand Down
2 changes: 1 addition & 1 deletion src/modules/window/sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ bool Window::onSizeChanged(int width, int height)
#endif

#if SDL_VERSION_ATLEAST(3, 0, 0)
if (SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight))
if (!SDL_GetWindowSizeInPixels(window, &pixelWidth, &pixelHeight))
#else
// TODO: Use SDL_GetWindowSizeInPixels here when supported.
if (glcontext != nullptr)
Expand Down

0 comments on commit 31ce65b

Please sign in to comment.