diff --git a/data/core/config.lua b/data/core/config.lua index 5ee5d57..4c56a69 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -22,6 +22,7 @@ config.transitions = true config.animation_rate = 1.0 config.blink_period = 0.8 config.draw_whitespace = false +config.borderless = true -- Disable plugin loading setting to false the config entry -- of the same name. diff --git a/data/core/init.lua b/data/core/init.lua index 7573aa3..bd92f23 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -6,6 +6,7 @@ local command local keymap local RootView local StatusView +local TitleView local CommandView local NagView local DocView @@ -358,6 +359,7 @@ function core.init() keymap = require "core.keymap" RootView = require "core.rootview" StatusView = require "core.statusview" + TitleView = require "core.titleview" CommandView = require "core.commandview" NagView = require "core.nagview" DocView = require "core.docview" @@ -398,6 +400,11 @@ function core.init() end end + if config.borderless then + system.set_window_bordered(false) + system.set_window_hit_test() + end + core.frame_start = 0 core.clip_rect_stack = {{ 0,0,0,0 }} core.log_items = {} @@ -430,9 +437,12 @@ function core.init() core.command_view = CommandView() core.status_view = StatusView() core.nag_view = NagView() + core.title_view = TitleView() local cur_node = core.root_view.root_node cur_node.is_primary_node = true + cur_node:split("up", core.title_view, {y = true}) + cur_node = cur_node.b cur_node:split("up", core.nag_view, {y = true}) cur_node = cur_node.b cur_node = cur_node:split("down", core.command_view, {y = true}) @@ -828,7 +838,7 @@ local function get_title_filename(view) end -local function compose_window_title(title) +function core.compose_window_title(title) return title == "" and "Lite XL" or title .. " - Lite XL" end @@ -877,7 +887,7 @@ function core.step() -- update window title local current_title = get_title_filename(core.active_view) if current_title ~= core.window_title then - system.set_window_title(compose_window_title(current_title)) + system.set_window_title(core.compose_window_title(current_title)) core.window_title = current_title end diff --git a/data/core/titleview.lua b/data/core/titleview.lua new file mode 100644 index 0000000..988b34b --- /dev/null +++ b/data/core/titleview.lua @@ -0,0 +1,30 @@ +local core = require "core" +local style = require "core.style" +local StatusView = require "core.statusview" + + +local TitleView = StatusView:extend() + +TitleView.separator = " " + +function TitleView:new() + TitleView.super.new(self) +end + + +function TitleView:on_mouse_pressed() + core.set_active_view(core.last_active_view) +end + + +function TitleView:get_items() + local title = core.compose_window_title(core.window_title) + return { + style.text, style.icon_font, "g ", style.font, title, + }, { + style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W", + } +end + + +return TitleView diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 2b24bae..398e73e 100644 Binary files a/data/fonts/icons.ttf and b/data/fonts/icons.ttf differ diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index ff3952f..b5027e8 100644 --- a/dev-utils/fontello-config-small.json +++ b/dev-utils/fontello-config-small.json @@ -83,6 +83,24 @@ "css": "cancel-1", "code": 67, "src": "fontawesome" + }, + { + "uid": "04f022b8bd044d4ccfffd3887ff72088", + "css": "window-minimize", + "code": 95, + "src": "fontawesome" + }, + { + "uid": "d0e62145dbf40f30e47b3819b8b43a8f", + "css": "window-restore", + "code": 119, + "src": "fontawesome" + }, + { + "uid": "7394501fc0b17cb7bda99538f92e26d6", + "css": "window-close", + "code": 87, + "src": "fontawesome" } ] -} +} \ No newline at end of file diff --git a/src/api/system.c b/src/api/system.c index 44f57fb..b5c732c 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -35,6 +35,44 @@ static char* key_name(char *dst, int sym) { return dst; } +// FIXME: shouldn't be hard-coded but should depend on TitleView's height +#define TITLE_BAR_WIDTH 100 +#define RESIZE_BORDER 40 + +static SDL_HitTestResult SDLCALL +hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { + int w, h; + + SDL_GetWindowSize(window, &w, &h); + + if (pt->y < TITLE_BAR_WIDTH && pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER) { + return SDL_HITTEST_DRAGGABLE; + } + + #define REPORT_RESIZE_HIT(name) { \ + return SDL_HITTEST_RESIZE_##name; \ + } + + if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) { + REPORT_RESIZE_HIT(TOPLEFT); + } else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) { + REPORT_RESIZE_HIT(TOP); + } else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) { + REPORT_RESIZE_HIT(TOPRIGHT); + } else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(RIGHT); + } else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(BOTTOMRIGHT); + } else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(BOTTOM); + } else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) { + REPORT_RESIZE_HIT(BOTTOMLEFT); + } else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) { + REPORT_RESIZE_HIT(LEFT); + } + + return SDL_HITTEST_NORMAL; +} static int f_poll_event(lua_State *L) { char buf[16]; @@ -201,6 +239,23 @@ static int f_set_window_mode(lua_State *L) { } +static int f_set_window_bordered(lua_State *L) { + int bordered = lua_toboolean(L, 1); + SDL_SetWindowBordered(window, bordered); + return 0; +} + + +static int f_set_window_hit_test(lua_State *L) { + if (SDL_SetWindowHitTest(window, hit_test, NULL) == -1) { + lua_pushboolean(L, 0); + } else { + lua_pushboolean(L, 1); + } + return 1; +} + + static int f_get_window_size(lua_State *L) { int x, y, w, h; SDL_GetWindowSize(window, &w, &h); @@ -441,6 +496,8 @@ static const luaL_Reg lib[] = { { "set_cursor", f_set_cursor }, { "set_window_title", f_set_window_title }, { "set_window_mode", f_set_window_mode }, + { "set_window_bordered", f_set_window_bordered }, + { "set_window_hit_test", f_set_window_hit_test }, { "get_window_size", f_get_window_size }, { "set_window_size", f_set_window_size }, { "window_has_focus", f_window_has_focus },