From 8ad87d77da9f66839fc88db8424aae692c78a2f2 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 11 Apr 2021 15:08:25 +0200 Subject: [PATCH] Add correct hit-test information and menu icon --- data/core/init.lua | 4 ++- data/core/titleview.lua | 16 ++++++++- data/fonts/icons.ttf | Bin 9288 -> 9512 bytes dev-utils/fontello-config-small.json | 8 ++++- dev-utils/{run-local-plugin => run-plugin} | 0 src/api/system.c | 37 ++++++++++++--------- 6 files changed, 47 insertions(+), 18 deletions(-) rename dev-utils/{run-local-plugin => run-plugin} (100%) diff --git a/data/core/init.lua b/data/core/init.lua index bd92f23c..d4ef5494 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -400,9 +400,11 @@ function core.init() end end + core.window_borderless = false + core.hit_test_title_height = 0 if config.borderless then system.set_window_bordered(false) - system.set_window_hit_test() + core.window_borderless = true end core.frame_start = 0 diff --git a/data/core/titleview.lua b/data/core/titleview.lua index 988b34bd..e4487a55 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -16,11 +16,25 @@ function TitleView:on_mouse_pressed() core.set_active_view(core.last_active_view) end +function TitleView:on_mouse_moved(px, py, ...) +end + + +function TitleView:update() + TitleView.super.update(self) + local title_height = self.size.y + if core.window_borderless and title_height ~= core.hit_test_title_height then + local resize_border = title_height / 2 + system.set_window_hit_test(title_height, resize_border) + core.hit_test_title_height = title_height + end +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, "M ", style.font, title, }, { style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W", } diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 398e73e90734d359b00db8d867baebffa6028275..02ad3694b9c0f0ed00fa10f40cb5f02600dc2ac0 100644 GIT binary patch delta 829 zcmZ9KO-NKx6vzMf-S=iR$M@z{rGU^;iWkaREqd+zU?bI<+YF2@&7 zKZwoj0N4P4;bhi!njSY<#EXFPDtSF$=c_HX0iig>ThdM@d%1P%HgO)%eHnYoA-|uv zhipY={AM~n_pJn|=Yi_>v6MX;{%~&&Fy|@WIYtieNB*67iMW0&o1gAZ442l(K~BWS zCz5vUm+&kQI85A-wWl4nM}JF91yPr?v#H{Xn%%_HbikrBF_m9`e>VUG#Q`^+$&`~m z`SLl{zVmSN5}S30Sf+IajDo;t@bavMthn!6hOX*}YQU=*8QsPWEq)hPAM(H*G#Rm(+YL_;{ zfzoe&QCWh4S{y=a&%ymn)heKXDQD+rs?Y0h7RgSJl=5gzM$pt zMxqUk9qpZ6k+u*gZj`)Ba%?+au>6018Ws!b-0U?%Y#aVhqkZMP^2q#gosy06$n-uv z6w>>|0u<&ek9xz!?%dT8&?AC!5M$bGNKi!49tLe*w-`l~4cx delta 617 zcmZ4Cb;4tUay>5t17iRK14CGHZeoGr3!Mu<{t5;LrbWqRB?>(9|BV50V!Kyd*eKLJQ{q~}zo#W^1BVPIhKVPN1X$Vg30k=Y-27N}$o zP~I#9D8PP*`8kmP1;|&)$StX`{ulQD83Ti$1W>>wCqFq+(oALpkRJn5kegUhz$nSL z6Uc7>@)hzDb5qaGm5>DT7XTf2wjjT_q~dD79s`32$RY0wic$;GoYv1_U{GE#@kcac z`{WSDbi+#wj6g{ShBFMzV3rP$<^uZh5(5jv0-(4I&i0#H%_sHbM~ z1SVd79nHEy`E9;3@H4*v zDrUGdy>}Xnp1eWOoKbM{3qj4vqC$G&Y0RHkqF7p3HnDQCX0YC2vj7LI;O00XZf2me VEK#M&eWIR|?};XFb`X2P2LLt1dwT!? diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index b5027e87..fa7e6334 100644 --- a/dev-utils/fontello-config-small.json +++ b/dev-utils/fontello-config-small.json @@ -101,6 +101,12 @@ "css": "window-close", "code": 87, "src": "fontawesome" + }, + { + "uid": "559647a6f430b3aeadbecd67194451dd", + "css": "menu-1", + "code": 77, + "src": "fontawesome" } ] -} \ No newline at end of file +} diff --git a/dev-utils/run-local-plugin b/dev-utils/run-plugin similarity index 100% rename from dev-utils/run-local-plugin rename to dev-utils/run-plugin diff --git a/src/api/system.c b/src/api/system.c index b5c732c5..7d316d58 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -35,17 +35,22 @@ 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 +struct HitTestInfo { + int title_height; + int resize_border; +}; +typedef struct HitTestInfo HitTestInfo; -static SDL_HitTestResult SDLCALL -hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { +static HitTestInfo window_hit_info[1] = {{0, 0}}; + +static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { + const HitTestInfo *hit_info = (HitTestInfo *) data; + const int resize_border = hit_info->resize_border; int w, h; SDL_GetWindowSize(window, &w, &h); - if (pt->y < TITLE_BAR_WIDTH && pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER) { + if (pt->y < hit_info->title_height && pt->x > resize_border && pt->x < w - resize_border) { return SDL_HITTEST_DRAGGABLE; } @@ -53,21 +58,21 @@ hit_test(SDL_Window *window, const SDL_Point *pt, void *data) { return SDL_HITTEST_RESIZE_##name; \ } - if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) { + 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) { + } 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) { + } 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) { + } 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) { + } 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) { + } 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) { + } 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) { + } else if (pt->x < resize_border && pt->y < h - resize_border && pt->y > resize_border) { REPORT_RESIZE_HIT(LEFT); } @@ -247,7 +252,9 @@ static int f_set_window_bordered(lua_State *L) { static int f_set_window_hit_test(lua_State *L) { - if (SDL_SetWindowHitTest(window, hit_test, NULL) == -1) { + window_hit_info->title_height = luaL_checknumber(L, 1); + window_hit_info->resize_border = luaL_checknumber(L, 2); + if (SDL_SetWindowHitTest(window, hit_test, window_hit_info) == -1) { lua_pushboolean(L, 0); } else { lua_pushboolean(L, 1);