Added system.set_fullscreen() and core:toggle-fullscreen command

This commit is contained in:
rxi 2020-03-25 22:44:59 +00:00
parent 1e9c3bef1f
commit efed38d59c
3 changed files with 18 additions and 0 deletions

View file

@ -7,6 +7,8 @@ local DocView = require "core.docview"
local LogView = require "core.logview" local LogView = require "core.logview"
local fullscreen = false
command.add(nil, { command.add(nil, {
["core:quit"] = function() ["core:quit"] = function()
core.quit() core.quit()
@ -16,6 +18,11 @@ command.add(nil, {
core.quit(true) core.quit(true)
end, end,
["core:toggle-fullscreen"] = function()
fullscreen = not fullscreen
system.set_fullscreen(fullscreen)
end,
["core:reload-module"] = function() ["core:reload-module"] = function()
core.command_view:enter("Reload Module", function(text, item) core.command_view:enter("Reload Module", function(text, item)
local text = item and item.text or text local text = item and item.text or text

View file

@ -88,6 +88,7 @@ keymap.add {
["ctrl+p"] = "core:open-project-file", ["ctrl+p"] = "core:open-project-file",
["ctrl+o"] = "core:open-file", ["ctrl+o"] = "core:open-file",
["ctrl+n"] = "core:new-doc", ["ctrl+n"] = "core:new-doc",
["alt+return"] = "core:toggle-fullscreen",
["alt+shift+j"] = "root:split-left", ["alt+shift+j"] = "root:split-left",
["alt+shift+l"] = "root:split-right", ["alt+shift+l"] = "root:split-right",

View file

@ -1,6 +1,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <stdbool.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "api.h" #include "api.h"
#ifdef _WIN32 #ifdef _WIN32
@ -160,6 +161,14 @@ 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);
return 0;
}
static int f_window_has_focus(lua_State *L) { static int f_window_has_focus(lua_State *L) {
unsigned flags = SDL_GetWindowFlags(window); unsigned flags = SDL_GetWindowFlags(window);
lua_pushboolean(L, flags & SDL_WINDOW_INPUT_FOCUS); lua_pushboolean(L, flags & SDL_WINDOW_INPUT_FOCUS);
@ -318,6 +327,7 @@ static const luaL_Reg lib[] = {
{ "poll_event", f_poll_event }, { "poll_event", f_poll_event },
{ "set_cursor", f_set_cursor }, { "set_cursor", f_set_cursor },
{ "set_window_title", f_set_window_title }, { "set_window_title", f_set_window_title },
{ "set_fullscreen", f_set_fullscreen },
{ "window_has_focus", f_window_has_focus }, { "window_has_focus", f_window_has_focus },
{ "show_confirm_dialog", f_show_confirm_dialog }, { "show_confirm_dialog", f_show_confirm_dialog },
{ "list_dir", f_list_dir }, { "list_dir", f_list_dir },