mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Added love.window.getDisplayName, to get the name of a connected display.
This commit is contained in:
@@ -87,6 +87,8 @@ public:
|
||||
|
||||
virtual int getDisplayCount() const = 0;
|
||||
|
||||
virtual const char *getDisplayName(int displayindex) const = 0;
|
||||
|
||||
virtual std::vector<WindowSize> getFullscreenSizes(int displayindex) const = 0;
|
||||
|
||||
virtual int getWidth() const = 0;
|
||||
|
||||
@@ -44,6 +44,8 @@ Window::Window()
|
||||
{
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||
throw love::Exception("%s", SDL_GetError());
|
||||
|
||||
printf("DISPLAY: %s\n", SDL_GetDisplayName(0));
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
@@ -461,6 +463,16 @@ int Window::getDisplayCount() const
|
||||
return SDL_GetNumVideoDisplays();
|
||||
}
|
||||
|
||||
const char *Window::getDisplayName(int displayindex) const
|
||||
{
|
||||
const char *name = SDL_GetDisplayName(displayindex);
|
||||
|
||||
if (name == nullptr)
|
||||
throw love::Exception("Invalid display index: %d", displayindex + 1);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
typedef Window::WindowSize WindowSize;
|
||||
|
||||
std::vector<WindowSize> Window::getFullscreenSizes(int displayindex) const
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
int getDisplayCount() const;
|
||||
|
||||
const char *getDisplayName(int displayindex) const;
|
||||
|
||||
std::vector<WindowSize> getFullscreenSizes(int displayindex) const;
|
||||
|
||||
int getWidth() const;
|
||||
|
||||
@@ -34,6 +34,17 @@ int w_getDisplayCount(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDisplayName(lua_State *L)
|
||||
{
|
||||
int index = luaL_checkint(L, 1) - 1;
|
||||
|
||||
const char *name = nullptr;
|
||||
luax_catchexcept(L, [&](){ name = instance->getDisplayName(index); });
|
||||
|
||||
lua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *settingName(Window::Setting setting)
|
||||
{
|
||||
const char *name = nullptr;
|
||||
@@ -326,6 +337,7 @@ int w_getPixelScale(lua_State *L)
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getDisplayCount", w_getDisplayCount },
|
||||
{ "getDisplayName", w_getDisplayName },
|
||||
{ "setMode", w_setMode },
|
||||
{ "getMode", w_getMode },
|
||||
{ "getFullscreenModes", w_getFullscreenModes },
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace window
|
||||
{
|
||||
|
||||
int w_getDisplayCount(lua_State *L);
|
||||
int w_getDisplayName(lua_State *L);
|
||||
int w_setMode(lua_State *L);
|
||||
int w_getMode(lua_State *L);
|
||||
int w_getFullscreenModes(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user