Make non-borderless mode work
This commit is contained in:
parent
4de97d51fb
commit
f7375924ab
|
@ -28,6 +28,8 @@ command.add(nil, {
|
||||||
["core:toggle-fullscreen"] = function()
|
["core:toggle-fullscreen"] = function()
|
||||||
fullscreen = not fullscreen
|
fullscreen = not fullscreen
|
||||||
system.set_window_mode(fullscreen and "fullscreen" or "normal")
|
system.set_window_mode(fullscreen and "fullscreen" or "normal")
|
||||||
|
core.show_title_bar(not fullscreen)
|
||||||
|
core.title_view:configure_hit_test(not fullscreen)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:reload-module"] = function()
|
["core:reload-module"] = function()
|
||||||
|
|
|
@ -400,13 +400,6 @@ function core.init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
core.window_borderless = false
|
|
||||||
core.hit_test_title_height = 0
|
|
||||||
if config.borderless then
|
|
||||||
system.set_window_bordered(false)
|
|
||||||
core.window_borderless = true
|
|
||||||
end
|
|
||||||
|
|
||||||
core.frame_start = 0
|
core.frame_start = 0
|
||||||
core.clip_rect_stack = {{ 0,0,0,0 }}
|
core.clip_rect_stack = {{ 0,0,0,0 }}
|
||||||
core.log_items = {}
|
core.log_items = {}
|
||||||
|
@ -474,6 +467,10 @@ function core.init()
|
||||||
command.perform("core:open-log")
|
command.perform("core:open-log")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
system.set_window_bordered(not config.borderless)
|
||||||
|
core.title_view:configure_hit_test(config.borderless)
|
||||||
|
core.title_view.visible = config.borderless
|
||||||
|
|
||||||
if #plugins_refuse_list.userdir.plugins > 0 or #plugins_refuse_list.datadir.plugins > 0 then
|
if #plugins_refuse_list.userdir.plugins > 0 or #plugins_refuse_list.datadir.plugins > 0 then
|
||||||
local opt = {
|
local opt = {
|
||||||
{ font = style.font, text = "Exit", default_no = true },
|
{ font = style.font, text = "Exit", default_no = true },
|
||||||
|
@ -696,6 +693,11 @@ function core.set_active_view(view)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function core.show_title_bar(show)
|
||||||
|
core.title_view.visible = show
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.add_thread(f, weak_ref)
|
function core.add_thread(f, weak_ref)
|
||||||
local key = weak_ref or #core.threads + 1
|
local key = weak_ref or #core.threads + 1
|
||||||
local fn = function() return core.try(f) end
|
local fn = function() return core.try(f) end
|
||||||
|
|
|
@ -25,28 +25,28 @@ end
|
||||||
|
|
||||||
function TitleView:new()
|
function TitleView:new()
|
||||||
TitleView.super.new(self)
|
TitleView.super.new(self)
|
||||||
-- FIXME: decide if visible is actually needed
|
|
||||||
self.visible = true
|
self.visible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function TitleView:update()
|
function TitleView:configure_hit_test(borderless)
|
||||||
if self.visible then
|
if borderless then
|
||||||
self.size.y = title_view_height()
|
local title_height = title_view_height()
|
||||||
else
|
|
||||||
self.size.y = 0
|
|
||||||
end
|
|
||||||
TitleView.super.update(self)
|
|
||||||
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("_")
|
local icon_w = style.icon_font:get_width("_")
|
||||||
local icon_spacing = icon_w
|
local icon_spacing = icon_w
|
||||||
local controls_width = (icon_w + icon_spacing) * #title_commands + icon_spacing
|
local controls_width = (icon_w + icon_spacing) * #title_commands + icon_spacing
|
||||||
system.set_window_hit_test(title_height, controls_width, icon_spacing)
|
system.set_window_hit_test(title_height, controls_width, icon_spacing)
|
||||||
core.hit_test_title_height = title_height
|
-- core.hit_test_title_height = title_height
|
||||||
|
else
|
||||||
|
system.set_window_hit_test()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TitleView:update()
|
||||||
|
self.size.y = self.visible and title_view_height() or 0
|
||||||
|
title_commands[2] = core.window_mode == "maximized" and restore_command or maximize_command
|
||||||
|
TitleView.super.update(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function TitleView:draw_window_title()
|
function TitleView:draw_window_title()
|
||||||
local h = style.font:get_height()
|
local h = style.font:get_height()
|
||||||
|
@ -95,6 +95,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function TitleView:on_mouse_moved(px, py, ...)
|
function TitleView:on_mouse_moved(px, py, ...)
|
||||||
|
if self.size.y == 0 then return end
|
||||||
TitleView.super.on_mouse_moved(self, px, py, ...)
|
TitleView.super.on_mouse_moved(self, px, py, ...)
|
||||||
self.hovered_item = nil
|
self.hovered_item = nil
|
||||||
local x_min, x_max, y_min, y_max = self.size.x, 0, self.size.y, 0
|
local x_min, x_max, y_min, y_max = self.size.x, 0, self.size.y, 0
|
||||||
|
|
|
@ -276,15 +276,15 @@ static int f_set_window_bordered(lua_State *L) {
|
||||||
|
|
||||||
|
|
||||||
static int f_set_window_hit_test(lua_State *L) {
|
static int f_set_window_hit_test(lua_State *L) {
|
||||||
|
if (lua_gettop(L) == 0) {
|
||||||
|
SDL_SetWindowHitTest(window, NULL, NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
window_hit_info->title_height = luaL_checknumber(L, 1);
|
window_hit_info->title_height = luaL_checknumber(L, 1);
|
||||||
window_hit_info->controls_width = luaL_checknumber(L, 2);
|
window_hit_info->controls_width = luaL_checknumber(L, 2);
|
||||||
window_hit_info->resize_border = luaL_checknumber(L, 3);
|
window_hit_info->resize_border = luaL_checknumber(L, 3);
|
||||||
if (SDL_SetWindowHitTest(window, hit_test, window_hit_info) == -1) {
|
SDL_SetWindowHitTest(window, hit_test, window_hit_info);
|
||||||
lua_pushboolean(L, 0);
|
return 0;
|
||||||
} else {
|
|
||||||
lua_pushboolean(L, 1);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue