Move love.system.getTheme() to love.window.getSystemTheme().

Despite its name, `SDL_GetSystemTheme()` needs the video subsystem to properly function. So, put it in love.window instead.
This commit is contained in:
Miku AuahDark
2025-11-25 15:29:24 +08:00
parent 139a45bfae
commit c4d30081f4
10 changed files with 60 additions and 64 deletions
+9
View File
@@ -112,5 +112,14 @@ STRINGMAP_CLASS_BEGIN(Window, Window::DisplayOrientation, Window::ORIENTATION_MA
}
STRINGMAP_CLASS_END(Window, Window::DisplayOrientation, Window::ORIENTATION_MAX_ENUM, orientation)
STRINGMAP_CLASS_BEGIN(Window, Window::SystemTheme, Window::THEME_MAX_ENUM, systemThemes)
{
{"unknown", Window::THEME_UNKNOWN},
{"light", Window::THEME_LIGHT},
{"dark", Window::THEME_DARK}
};
STRINGMAP_CLASS_END(Window, Window::SystemTheme, Window::THEME_MAX_ENUM, systemThemes)
} // window
} // love
+16
View File
@@ -114,6 +114,14 @@ public:
ORIENTATION_MAX_ENUM
};
enum SystemTheme
{
THEME_UNKNOWN,
THEME_LIGHT,
THEME_DARK,
THEME_MAX_ENUM
};
struct WindowSize
{
int width;
@@ -252,11 +260,19 @@ public:
virtual void requestAttention(bool continuous) = 0;
/**
* Get information about the system theme.
*
* @return System theme, which can be either light, dark, or unknown.
**/
virtual SystemTheme getSystemTheme() const = 0;
STRINGMAP_CLASS_DECLARE(Setting);
STRINGMAP_CLASS_DECLARE(FullscreenType);
STRINGMAP_CLASS_DECLARE(MessageBoxType);
STRINGMAP_CLASS_DECLARE(FileDialogType);
STRINGMAP_CLASS_DECLARE(DisplayOrientation);
STRINGMAP_CLASS_DECLARE(SystemTheme);
protected:
+19
View File
@@ -1655,6 +1655,25 @@ void Window::requestAttention(bool continuous)
// TODO: Linux?
}
Window::SystemTheme Window::getSystemTheme() const
{
SDL_SystemTheme sdlstate = SDL_GetSystemTheme();
SystemTheme state = THEME_UNKNOWN;
systemThemes.find(sdlstate, state);
return state;
}
EnumMap<Window::SystemTheme, SDL_SystemTheme, Window::THEME_MAX_ENUM>::Entry Window::systemThemeEntries[] =
{
{Window::THEME_UNKNOWN, SDL_SYSTEM_THEME_UNKNOWN},
{Window::THEME_LIGHT, SDL_SYSTEM_THEME_LIGHT},
{Window::THEME_DARK, SDL_SYSTEM_THEME_DARK},
};
EnumMap<Window::SystemTheme, SDL_SystemTheme, Window::THEME_MAX_ENUM> Window::systemThemes(Window::systemThemeEntries, sizeof(Window::systemThemeEntries));
} // sdl
} // window
} // love
+6
View File
@@ -24,6 +24,7 @@
// LOVE
#include "window/Window.h"
#include "common/config.h"
#include "common/EnumMap.h"
#include "graphics/Graphics.h"
// SDL
@@ -133,6 +134,8 @@ public:
void requestAttention(bool continuous) override;
SystemTheme getSystemTheme() const override;
void handleSDLEvent(const SDL_Event &event);
private:
@@ -191,6 +194,9 @@ private:
Uint32 dialogEventId;
static EnumMap<SystemTheme, SDL_SystemTheme, THEME_MAX_ENUM>::Entry systemThemeEntries[];
static EnumMap<SystemTheme, SDL_SystemTheme, THEME_MAX_ENUM> systemThemes;
}; // Window
} // sdl
+10
View File
@@ -765,6 +765,15 @@ int w_getPointer(lua_State *L)
return 1;
}
int w_getSystemTheme(lua_State *L)
{
Window::SystemTheme theme = instance()->getSystemTheme();
const char *str = "unknown";
Window::getConstant(theme, str);
lua_pushstring(L, str);
return 1;
}
static const luaL_Reg functions[] =
{
{ "getDisplayCount", w_getDisplayCount },
@@ -809,6 +818,7 @@ static const luaL_Reg functions[] =
{ "showFileDialog", w_showFileDialog },
{ "requestAttention", w_requestAttention },
{ "getPointer", w_getPointer },
{ "getSystemTheme", w_getSystemTheme },
{ 0, 0 }
};