From 7531a0ddc80f557426aff98ddad8fa2e12609065 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 10 Apr 2021 19:35:57 +0200 Subject: [PATCH] Preliminary implementation of border-less mode Not yet functional but most ingredients are there --- data/core/config.lua | 1 + data/core/init.lua | 14 ++++++- data/core/titleview.lua | 30 ++++++++++++++ data/fonts/icons.ttf | Bin 8680 -> 9288 bytes dev-utils/fontello-config-small.json | 20 +++++++++- src/api/system.c | 57 +++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 data/core/titleview.lua diff --git a/data/core/config.lua b/data/core/config.lua index 5ee5d576..4c56a697 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 7573aa32..bd92f23c 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 00000000..988b34bd --- /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 2b24bae7683d02cb6c3fe281cec032baf12c67b3..398e73e90734d359b00db8d867baebffa6028275 100644 GIT binary patch delta 1240 zcmZ8gU1%It6h7z9?93*+nb}D!IOxOyy7CmC$d+@(Hv^Z0Dc0&-A#~fr%4Y$ zgdOrnXbu5_pu;#EgISn^Q!o#Ukc2ekpa50Jp{!Q)YAuhZ^(i2`K z?FoM;>j~X4P0gtL_(nm$#VXID0}v2tW)H@W{;QP>iF5P|ui zARuF65=2oGpPw|tk#N5xN5+jQ%X|!7H4;^Elq)Gbh%#5*@oDVoj-wWqWIZ}ErJ2^0 z9`9xsPfOB;3zBqNQn*#5t%n@AWE%heIBcP52$o^K@qgk&c~pTHV9z$s8YWu9>~n5t zIKb9G@H27Sw zxD?@nX|Ud5OU41*-8KyzXf_PFdg2bKLWA>k^V5$$xo4d_ zd^G!eW$;MN&F6u8OSA7PWBm=s5xDFC2rto3U*XniiWSGPA6I*hoE6^{zw)*F^1hqW zlWq;Ient%lF%20CD54J~l+llE*p2}VVh1XyVhA-Z(Tk5=Qi`>fUf0@Wt;T~a|ZbH zrJH7PakCFlIX|#g$QjweQ)5leea8M&fd$_O@s;@|^U;D;siqd+I6qiuv2dbP&KS{$ zk>5c02=o1xQMIXGf6LsxVEnpa}Af4l?}VRTzQgsw*>S}v;W?{k+aR2SKKTy z{kXM61vy8jsVLXz;CutbDZn~J`)iyrz>_wh;x6m`Jcoc62^_`*&SDm6TtF6i6di~C zjz05WH(gyOl-MM3ZD;Sp?jGa{g2E@N@bIZV_|e1tg3u6R%PUD7kWZDV_RDc{XK@1i z?A?+PF%;I?>dUSfk`F|ABFoGTzB|lr1R3+)aBGU)2-RoRZ@&6`=(Un`r{^erO5M90 zKG{TAY_o#T3%?HSqSJJ)sjKpPWH`FoeJ$7OEL{%tCMRovxXAx^#YN|D+bW@kEn26R zl2&TM6gz5Mt*Tp|^X$4^_4@tZpcv9gAwep6$V)!*Qx63wNE(Gmr?717nUiC&qyp40 I#eVAl0Fu^y3IG5A diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index ff3952ff..b5027e87 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 44f57fb7..b5c732c5 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 },