Browse Source

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

Calling the function brings the window into the foreground and makes it the focused window for keyboard input.
Sasha Szpakowski 2 years ago
parent
commit
2c3ea60c79

+ 1 - 0
src/modules/window/Window.h

@@ -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 - 0
src/modules/window/sdl/Window.cpp

@@ -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 - 0
src/modules/window/sdl/Window.h

@@ -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 - 0
src/modules/window/wrap_Window.cpp

@@ -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 },