Add love.window.focus (resolves #1911).

Calling the function brings the window into the foreground and makes it the focused window for keyboard input.
This commit is contained in:
Sasha Szpakowski
2023-04-01 18:02:16 -03:00
parent 0b48dacb4e
commit 2c3ea60c79
4 changed files with 18 additions and 0 deletions
+1
View File
@@ -178,6 +178,7 @@ public:
virtual void minimize() = 0;
virtual void maximize() = 0;
virtual void restore() = 0;
virtual void focus() = 0;
virtual bool isMaximized() const = 0;
virtual bool isMinimized() const = 0;
+9
View File
@@ -1182,6 +1182,15 @@ void Window::restore()
}
}
void Window::focus()
{
if (window != nullptr)
{
SDL_RaiseWindow(window);
updateSettings(settings, true);
}
}
bool Window::isMaximized() const
{
return window != nullptr && (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED);
+1
View File
@@ -87,6 +87,7 @@ public:
void minimize() override;
void maximize() override;
void restore() override;
void focus() override;
bool isMaximized() const override;
bool isMinimized() const override;
+7
View File
@@ -548,6 +548,12 @@ int w_restore(lua_State *)
return 0;
}
int w_focus(lua_State *)
{
instance()->focus();
return 0;
}
int w_isMaximized(lua_State *L)
{
luax_pushboolean(L, instance()->isMaximized());
@@ -668,6 +674,7 @@ static const luaL_Reg functions[] =
{ "minimize", w_minimize },
{ "maximize", w_maximize },
{ "restore", w_restore },
{ "focus", w_focus },
{ "isMaximized", w_isMaximized },
{ "isMinimized", w_isMinimized },
{ "showMessageBox", w_showMessageBox },