aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-04-07 18:48:57 +0100
committerrxi <rxi@users.noreply.github.com>2020-04-07 18:49:11 +0100
commitd4284edd5cbe35b81500bc9d217390fbde32f018 (patch)
tree8ab01fb301c3c40a9db2c42d7232e07277632668
parent2a5a36f64e9003e19bb513d2855adef1380251c8 (diff)
downloadpragtical-d4284edd5cbe35b81500bc9d217390fbde32f018.tar.gz
pragtical-d4284edd5cbe35b81500bc9d217390fbde32f018.zip
Replaced system.set_fullscreen with system.set_window_mode
Solves #24
-rw-r--r--data/core/commands/core.lua2
-rw-r--r--src/api/system.c15
2 files changed, 11 insertions, 6 deletions
diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua
index 8843a75c..52e9954a 100644
--- a/data/core/commands/core.lua
+++ b/data/core/commands/core.lua
@@ -20,7 +20,7 @@ command.add(nil, {
["core:toggle-fullscreen"] = function()
fullscreen = not fullscreen
- system.set_fullscreen(fullscreen)
+ system.set_window_mode(fullscreen and "fullscreen" or "normal")
end,
["core:reload-module"] = function()
diff --git a/src/api/system.c b/src/api/system.c
index cd183765..eaa32c4b 100644
--- a/src/api/system.c
+++ b/src/api/system.c
@@ -161,10 +161,15 @@ static int f_set_window_title(lua_State *L) {
}
-static int f_set_fullscreen(lua_State *L) {
- luaL_checkany(L, 1);
- bool b = lua_toboolean(L, 1);
- SDL_SetWindowFullscreen(window, b ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+static const char *window_opts[] = { "normal", "maximized", "fullscreen", 0 };
+enum { WIN_NORMAL, WIN_MAXIMIZED, WIN_FULLSCREEN };
+
+static int f_set_window_mode(lua_State *L) {
+ int n = luaL_checkoption(L, 1, "normal", window_opts);
+ SDL_SetWindowFullscreen(window,
+ n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+ if (n == WIN_NORMAL) { SDL_RestoreWindow(window); }
+ if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); }
return 0;
}
@@ -327,7 +332,7 @@ static const luaL_Reg lib[] = {
{ "poll_event", f_poll_event },
{ "set_cursor", f_set_cursor },
{ "set_window_title", f_set_window_title },
- { "set_fullscreen", f_set_fullscreen },
+ { "set_window_mode", f_set_window_mode },
{ "window_has_focus", f_window_has_focus },
{ "show_confirm_dialog", f_show_confirm_dialog },
{ "list_dir", f_list_dir },