Merge pull request #2256 from MikuAuahDark/system-theme

Add love.window.getSystemTheme()
This commit is contained in:
Sasha Szpakowski
2025-11-25 12:48:10 -04:00
committed by GitHub
7 changed files with 66 additions and 0 deletions
+3
View File
@@ -573,6 +573,9 @@ Message *Event::convert(const SDL_Event &e)
case SDL_EVENT_LOCALE_CHANGED:
msg = new Message("localechanged");
break;
case SDL_EVENT_SYSTEM_THEME_CHANGED:
msg = new Message("themechanged");
break;
case SDL_EVENT_SENSOR_UPDATE:
sensorInstance = Module::getInstance<sensor::Sensor>(M_SENSOR);
if (sensorInstance)
+3
View File
@@ -150,6 +150,9 @@ function love.createhandlers()
sensorupdated = function (sensorType, x, y, z)
if love.sensorupdated then return love.sensorupdated(sensorType, x, y, z) end
end,
themechanged = function ()
if love.themechanged then return love.themechanged() end
end,
}, {
__index = function(self, name)
error("Unknown event: " .. name)
+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 }
};