system: added raise_window() (#1131)

This commit is contained in:
Jefferson González 2022-09-29 11:31:55 -04:00 committed by GitHub
parent a0164d5902
commit ba0a454c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -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.
---

View File

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