From ba0a454c97fb2cb4ecbfcf821eebbf7c9da68abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jefferson=20Gonz=C3=A1lez?= Date: Thu, 29 Sep 2022 11:31:55 -0400 Subject: [PATCH] system: added raise_window() (#1131) --- docs/api/system.lua | 5 +++++ src/api/system.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/api/system.lua b/docs/api/system.lua index e5eff27f..98297a3d 100644 --- a/docs/api/system.lua +++ b/docs/api/system.lua @@ -131,6 +131,11 @@ function system.set_window_size(width, height, x, y) end ---@return boolean function system.window_has_focus() end +--- +---Raise the main window and give it input focus. +---Note: may not always be obeyed by the users window manager. +function system.raise_window() end + --- ---Opens a message box to display an error message. --- diff --git a/src/api/system.c b/src/api/system.c index cad0d12a..a4f7bbc3 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -427,6 +427,19 @@ static int f_get_window_mode(lua_State *L) { } +static int f_raise_window(lua_State *L) { + /* + SDL_RaiseWindow should be enough but on some window managers like the + one used on Gnome the window needs to first have input focus in order + to allow the window to be focused. Also on wayland the raise window event + may not always be obeyed. + */ + SDL_SetWindowInputFocus(window); + SDL_RaiseWindow(window); + return 0; +} + + static int f_show_fatal_error(lua_State *L) { const char *title = luaL_checkstring(L, 1); const char *msg = luaL_checkstring(L, 2); @@ -975,6 +988,7 @@ static const luaL_Reg lib[] = { { "get_window_size", f_get_window_size }, { "set_window_size", f_set_window_size }, { "window_has_focus", f_window_has_focus }, + { "raise_window", f_raise_window }, { "show_fatal_error", f_show_fatal_error }, { "rmdir", f_rmdir }, { "chdir", f_chdir },