Avoid always calling system.get_window_mode

This commit is contained in:
Francesco Abbate 2021-04-12 13:31:32 +02:00
parent 46791aefe5
commit 4de97d51fb
3 changed files with 16 additions and 2 deletions

View File

@ -411,6 +411,7 @@ function core.init()
core.clip_rect_stack = {{ 0,0,0,0 }}
core.log_items = {}
core.docs = {}
core.window_mode = "normal"
core.threads = setmetatable({}, { __mode = "k" })
local project_dir_abs = system.absolute_path(project_dir)
@ -812,6 +813,10 @@ function core.on_event(type, ...)
core.root_view:on_mouse_released(...)
elseif type == "mousewheel" then
core.root_view:on_mouse_wheel(...)
elseif type == "resized" then
core.window_mode = system.get_window_mode()
elseif type == "minimized" or type == "maximized" or type == "restored" then
core.window_mode = type == "restored" and "normal" or type
elseif type == "filedropped" then
local filename, mx, my = ...
local info = system.get_file_info(filename)

View File

@ -36,8 +36,7 @@ function TitleView:update()
self.size.y = 0
end
TitleView.super.update(self)
local window_mode = system.get_window_mode()
title_commands[2] = window_mode == "maximized" and restore_command or maximize_command
title_commands[2] = core.window_mode == "maximized" and restore_command or maximize_command
local title_height = self.size.y
if core.window_borderless and title_height ~= core.hit_test_title_height then
local icon_w = style.icon_font:get_width("_")

View File

@ -117,6 +117,16 @@ top:
rencache_invalidate();
lua_pushstring(L, "exposed");
return 1;
} else if (e.window.event == SDL_WINDOWEVENT_MINIMIZED) {
lua_pushstring(L, "minimized");
return 1;
} else if (e.window.event == SDL_WINDOWEVENT_MAXIMIZED) {
fprintf(stderr, "maximized event!\n");
lua_pushstring(L, "maximized");
return 1;
} else if (e.window.event == SDL_WINDOWEVENT_RESTORED) {
lua_pushstring(L, "restored");
return 1;
}
if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
lua_pushstring(L, "focuslost");