mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
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:
@@ -89,11 +89,6 @@ bool System::getConstant(System::PowerState in, const char *&out)
|
|||||||
return powerStates.find(in, out);
|
return powerStates.find(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool System::getConstant(System::SystemTheme in, const char *&out)
|
|
||||||
{
|
|
||||||
return systemThemes.find(in, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringMap<System::PowerState, System::POWER_MAX_ENUM>::Entry System::powerEntries[] =
|
StringMap<System::PowerState, System::POWER_MAX_ENUM>::Entry System::powerEntries[] =
|
||||||
{
|
{
|
||||||
{"unknown", System::POWER_UNKNOWN},
|
{"unknown", System::POWER_UNKNOWN},
|
||||||
@@ -105,14 +100,5 @@ StringMap<System::PowerState, System::POWER_MAX_ENUM>::Entry System::powerEntrie
|
|||||||
|
|
||||||
StringMap<System::PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
|
StringMap<System::PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
|
||||||
|
|
||||||
StringMap<System::SystemTheme, System::THEME_MAX_ENUM>::Entry System::systemThemeEntries[] =
|
|
||||||
{
|
|
||||||
{"unknown", System::THEME_UNKNOWN},
|
|
||||||
{"light", System::THEME_LIGHT},
|
|
||||||
{"dark", System::THEME_DARK}
|
|
||||||
};
|
|
||||||
|
|
||||||
StringMap<System::SystemTheme, System::THEME_MAX_ENUM> System::systemThemes(System::systemThemeEntries, sizeof(System::systemThemeEntries));
|
|
||||||
|
|
||||||
} // system
|
} // system
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -48,14 +48,6 @@ public:
|
|||||||
POWER_MAX_ENUM
|
POWER_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SystemTheme
|
|
||||||
{
|
|
||||||
THEME_UNKNOWN,
|
|
||||||
THEME_LIGHT,
|
|
||||||
THEME_DARK,
|
|
||||||
THEME_MAX_ENUM
|
|
||||||
};
|
|
||||||
|
|
||||||
System(const char *name);
|
System(const char *name);
|
||||||
virtual ~System() {}
|
virtual ~System() {}
|
||||||
|
|
||||||
@@ -99,13 +91,6 @@ public:
|
|||||||
**/
|
**/
|
||||||
virtual PowerState getPowerInfo(int &seconds, int &percent) const = 0;
|
virtual PowerState getPowerInfo(int &seconds, int &percent) const = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get information about the system theme.
|
|
||||||
*
|
|
||||||
* @return System theme, which can be either light, dark, or unknown.
|
|
||||||
**/
|
|
||||||
virtual SystemTheme getTheme() const = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the specified URL with the user's default program to handle that
|
* Opens the specified URL with the user's default program to handle that
|
||||||
* particular URL type.
|
* particular URL type.
|
||||||
@@ -146,14 +131,11 @@ public:
|
|||||||
|
|
||||||
static bool getConstant(const char *in, PowerState &out);
|
static bool getConstant(const char *in, PowerState &out);
|
||||||
static bool getConstant(PowerState in, const char *&out);
|
static bool getConstant(PowerState in, const char *&out);
|
||||||
static bool getConstant(SystemTheme in, const char *&out);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static StringMap<PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
|
static StringMap<PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
|
||||||
static StringMap<PowerState, POWER_MAX_ENUM> powerStates;
|
static StringMap<PowerState, POWER_MAX_ENUM> powerStates;
|
||||||
static StringMap<SystemTheme, THEME_MAX_ENUM>::Entry systemThemeEntries[];
|
|
||||||
static StringMap<SystemTheme, THEME_MAX_ENUM> systemThemes;
|
|
||||||
|
|
||||||
}; // System
|
}; // System
|
||||||
|
|
||||||
|
|||||||
@@ -93,15 +93,6 @@ love::system::System::PowerState System::getPowerInfo(int &seconds, int &percent
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::SystemTheme System::getTheme() const
|
|
||||||
{
|
|
||||||
SDL_SystemTheme sdlstate = SDL_GetSystemTheme();
|
|
||||||
SystemTheme state = THEME_UNKNOWN;
|
|
||||||
systemThemes.find(sdlstate, state);
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool System::openURL(const std::string &url) const
|
bool System::openURL(const std::string &url) const
|
||||||
{
|
{
|
||||||
return SDL_OpenURL(url.c_str());
|
return SDL_OpenURL(url.c_str());
|
||||||
@@ -137,15 +128,6 @@ EnumMap<System::PowerState, SDL_PowerState, System::POWER_MAX_ENUM>::Entry Syste
|
|||||||
|
|
||||||
EnumMap<System::PowerState, SDL_PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
|
EnumMap<System::PowerState, SDL_PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
|
||||||
|
|
||||||
EnumMap<System::SystemTheme, SDL_SystemTheme, System::THEME_MAX_ENUM>::Entry System::systemThemeEntries[] =
|
|
||||||
{
|
|
||||||
{System::THEME_UNKNOWN, SDL_SYSTEM_THEME_UNKNOWN},
|
|
||||||
{System::THEME_LIGHT, SDL_SYSTEM_THEME_LIGHT},
|
|
||||||
{System::THEME_DARK, SDL_SYSTEM_THEME_DARK},
|
|
||||||
};
|
|
||||||
|
|
||||||
EnumMap<System::SystemTheme, SDL_SystemTheme, System::THEME_MAX_ENUM> System::systemThemes(System::systemThemeEntries, sizeof(System::systemThemeEntries));
|
|
||||||
|
|
||||||
} // sdl
|
} // sdl
|
||||||
} // system
|
} // system
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
// SDL
|
// SDL
|
||||||
#include <SDL3/SDL_power.h>
|
#include <SDL3/SDL_power.h>
|
||||||
#include <SDL3/SDL_system.h>
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -50,7 +49,6 @@ public:
|
|||||||
std::string getClipboardText() const override;
|
std::string getClipboardText() const override;
|
||||||
|
|
||||||
PowerState getPowerInfo(int &seconds, int &percent) const override;
|
PowerState getPowerInfo(int &seconds, int &percent) const override;
|
||||||
SystemTheme getTheme() const override;
|
|
||||||
bool openURL(const std::string &url) const override;
|
bool openURL(const std::string &url) const override;
|
||||||
std::vector<std::string> getPreferredLocales() const override;
|
std::vector<std::string> getPreferredLocales() const override;
|
||||||
|
|
||||||
@@ -60,8 +58,6 @@ private:
|
|||||||
|
|
||||||
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
|
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
|
||||||
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM> powerStates;
|
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM> powerStates;
|
||||||
static EnumMap<SystemTheme, SDL_SystemTheme, THEME_MAX_ENUM>::Entry systemThemeEntries[];
|
|
||||||
static EnumMap<SystemTheme, SDL_SystemTheme, THEME_MAX_ENUM> systemThemes;
|
|
||||||
|
|
||||||
}; // System
|
}; // System
|
||||||
|
|
||||||
|
|||||||
@@ -87,15 +87,6 @@ int w_getPowerInfo(lua_State *L)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_getTheme(lua_State *L)
|
|
||||||
{
|
|
||||||
System::SystemTheme theme = instance()->getTheme();
|
|
||||||
const char *str = "unknown";
|
|
||||||
System::getConstant(theme, str);
|
|
||||||
lua_pushstring(L, str);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_openURL(lua_State *L)
|
int w_openURL(lua_State *L)
|
||||||
{
|
{
|
||||||
std::string url = luax_checkstring(L, 1);
|
std::string url = luax_checkstring(L, 1);
|
||||||
@@ -140,7 +131,6 @@ static const luaL_Reg functions[] =
|
|||||||
{ "setClipboardText", w_setClipboardText },
|
{ "setClipboardText", w_setClipboardText },
|
||||||
{ "getClipboardText", w_getClipboardText },
|
{ "getClipboardText", w_getClipboardText },
|
||||||
{ "getPowerInfo", w_getPowerInfo },
|
{ "getPowerInfo", w_getPowerInfo },
|
||||||
{ "getTheme", w_getTheme },
|
|
||||||
{ "openURL", w_openURL },
|
{ "openURL", w_openURL },
|
||||||
{ "vibrate", w_vibrate },
|
{ "vibrate", w_vibrate },
|
||||||
{ "hasBackgroundMusic", w_hasBackgroundMusic },
|
{ "hasBackgroundMusic", w_hasBackgroundMusic },
|
||||||
|
|||||||
@@ -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_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
|
} // window
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -114,6 +114,14 @@ public:
|
|||||||
ORIENTATION_MAX_ENUM
|
ORIENTATION_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum SystemTheme
|
||||||
|
{
|
||||||
|
THEME_UNKNOWN,
|
||||||
|
THEME_LIGHT,
|
||||||
|
THEME_DARK,
|
||||||
|
THEME_MAX_ENUM
|
||||||
|
};
|
||||||
|
|
||||||
struct WindowSize
|
struct WindowSize
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
@@ -252,11 +260,19 @@ public:
|
|||||||
|
|
||||||
virtual void requestAttention(bool continuous) = 0;
|
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(Setting);
|
||||||
STRINGMAP_CLASS_DECLARE(FullscreenType);
|
STRINGMAP_CLASS_DECLARE(FullscreenType);
|
||||||
STRINGMAP_CLASS_DECLARE(MessageBoxType);
|
STRINGMAP_CLASS_DECLARE(MessageBoxType);
|
||||||
STRINGMAP_CLASS_DECLARE(FileDialogType);
|
STRINGMAP_CLASS_DECLARE(FileDialogType);
|
||||||
STRINGMAP_CLASS_DECLARE(DisplayOrientation);
|
STRINGMAP_CLASS_DECLARE(DisplayOrientation);
|
||||||
|
STRINGMAP_CLASS_DECLARE(SystemTheme);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
@@ -1655,6 +1655,25 @@ void Window::requestAttention(bool continuous)
|
|||||||
// TODO: Linux?
|
// 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
|
} // sdl
|
||||||
} // window
|
} // window
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
// LOVE
|
// LOVE
|
||||||
#include "window/Window.h"
|
#include "window/Window.h"
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
|
#include "common/EnumMap.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
|
|
||||||
// SDL
|
// SDL
|
||||||
@@ -133,6 +134,8 @@ public:
|
|||||||
|
|
||||||
void requestAttention(bool continuous) override;
|
void requestAttention(bool continuous) override;
|
||||||
|
|
||||||
|
SystemTheme getSystemTheme() const override;
|
||||||
|
|
||||||
void handleSDLEvent(const SDL_Event &event);
|
void handleSDLEvent(const SDL_Event &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -191,6 +194,9 @@ private:
|
|||||||
|
|
||||||
Uint32 dialogEventId;
|
Uint32 dialogEventId;
|
||||||
|
|
||||||
|
static EnumMap<SystemTheme, SDL_SystemTheme, THEME_MAX_ENUM>::Entry systemThemeEntries[];
|
||||||
|
static EnumMap<SystemTheme, SDL_SystemTheme, THEME_MAX_ENUM> systemThemes;
|
||||||
|
|
||||||
}; // Window
|
}; // Window
|
||||||
|
|
||||||
} // sdl
|
} // sdl
|
||||||
|
|||||||
@@ -765,6 +765,15 @@ int w_getPointer(lua_State *L)
|
|||||||
return 1;
|
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[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "getDisplayCount", w_getDisplayCount },
|
{ "getDisplayCount", w_getDisplayCount },
|
||||||
@@ -809,6 +818,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "showFileDialog", w_showFileDialog },
|
{ "showFileDialog", w_showFileDialog },
|
||||||
{ "requestAttention", w_requestAttention },
|
{ "requestAttention", w_requestAttention },
|
||||||
{ "getPointer", w_getPointer },
|
{ "getPointer", w_getPointer },
|
||||||
|
{ "getSystemTheme", w_getSystemTheme },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user