diff --git a/src/modules/window/Window.cpp b/src/modules/window/Window.cpp index 3e74db675..5ad2480ed 100644 --- a/src/modules/window/Window.cpp +++ b/src/modules/window/Window.cpp @@ -51,6 +51,7 @@ WindowSettings::WindowSettings() , display(0) , highdpi(false) , sRGB(false) + , refreshrate(0.0) { } @@ -99,6 +100,7 @@ StringMap::Entry Window::settingEntri {"display", SETTING_DISPLAY}, {"highdpi", SETTING_HIGHDPI}, {"srgb", SETTING_SRGB}, + {"refreshrate", SETTING_REFRESHRATE}, }; StringMap Window::settings(Window::settingEntries, sizeof(Window::settingEntries)); diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index dd0e1a18d..b7988f313 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -59,6 +59,7 @@ public: SETTING_DISPLAY, SETTING_HIGHDPI, SETTING_SRGB, + SETTING_REFRESHRATE, SETTING_MAX_ENUM }; @@ -198,6 +199,7 @@ struct WindowSettings int display; // = 0 bool highdpi; // false bool sRGB; // false + double refreshrate; // 0.0 }; // WindowSettings diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index c149c9d35..8bc0d1935 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -390,6 +390,12 @@ void Window::updateSettings(const WindowSettings &newsettings) SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); curMode.settings.sRGB = newsettings.sRGB; + + SDL_DisplayMode dmode = {}; + SDL_GetCurrentDisplayMode(curMode.settings.display, &dmode); + + // May be 0 if the refresh rate can't be determined. + curMode.settings.refreshrate = (double) dmode.refresh_rate; } void Window::getWindow(int &width, int &height, WindowSettings &settings) diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index c90f29e4d..c828c1379 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -105,17 +105,16 @@ int w_setMode(lua_State *L) settings.minheight = luax_intflag(L, 3, settingName(Window::SETTING_MIN_HEIGHT), 1); settings.borderless = luax_boolflag(L, 3, settingName(Window::SETTING_BORDERLESS), false); settings.centered = luax_boolflag(L, 3, settingName(Window::SETTING_CENTERED), true); - settings.display = luax_intflag(L, 3, settingName(Window::SETTING_DISPLAY), 1); + settings.display = luax_intflag(L, 3, settingName(Window::SETTING_DISPLAY), 1) - 1; settings.highdpi = luax_boolflag(L, 3, settingName(Window::SETTING_HIGHDPI), false); settings.sRGB = luax_boolflag(L, 3, settingName(Window::SETTING_SRGB), false); + // We don't explicitly set the refresh rate, it's "read-only". + // For backward-compatibility. TODO: remove! int fsaa = luax_intflag(L, 3, settingName(Window::SETTING_FSAA), 0); if (fsaa > settings.msaa) settings.msaa = fsaa; - // Display index is 1-based in Lua and 0-based internally. - settings.display--; - luax_catchexcept(L, [&](){ luax_pushboolean(L, instance()->setWindow(w, h, &settings)); } ); @@ -176,6 +175,9 @@ int w_getMode(lua_State *L) luax_pushboolean(L, settings.sRGB); lua_setfield(L, -2, settingName(Window::SETTING_SRGB)); + lua_pushnumber(L, settings.refreshrate); + lua_setfield(L, -2, settingName(Window::SETTING_REFRESHRATE)); + return 3; }