From 46791aefe59e610b9d2055fbb05785e43ee633f6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 12 Apr 2021 11:54:52 +0200 Subject: [PATCH] Implement maximize/restore controls Remove also resize from top and right of the window --- data/core/titleview.lua | 14 ++++++++++++-- data/fonts/icons.ttf | Bin 9512 -> 9620 bytes dev-utils/fontello-config-small.json | 12 +++++++++--- src/api/system.c | 28 ++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/data/core/titleview.lua b/data/core/titleview.lua index c53c5371..702d8b63 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -3,10 +3,18 @@ local common = require "core.common" local style = require "core.style" local View = require "core.view" +local restore_command = { + symbol = "w", action = function() system.set_window_mode("normal") end +} + +local maximize_command = { + symbol = "W", action = function() system.set_window_mode("maximized") end +} + local title_commands = { {symbol = "_", action = function() system.set_window_mode("minimized") end}, - {symbol = "w", action = function() system.set_window_mode("maximized") end}, - {symbol = "W", action = function() core.quit() end}, + maximize_command, + {symbol = "X", action = function() core.quit() end}, } local TitleView = View:extend() @@ -28,6 +36,8 @@ 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 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("_") diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 02ad3694b9c0f0ed00fa10f40cb5f02600dc2ac0..00b4cc3bd262b1cb9f3339d2e5379c4b45f983c2 100644 GIT binary patch delta 998 zcmYL|OGs2v7{~wTK1Lm#w=J%Iv%2DH*=|{r>;+opaAQ-<_$wW38i= z!$yF$0SJT=!L;joV*%+YKzJHD)o(89gNS|DX*{r&HPfEgRcE1J+5}v^Jdy zr+atIOwih2t}S=5OUfY@@h^bUWZ*5t992`+QuzWT+#P9UNP4pgBAE!dAXbf8oD z#ts)aq5j-(EA4_yHq$JP!o*7Drr@_1{Vp{Lx-!$3L0gDx8}9_srBdC=BoJEhtDVp24&r#v_n>;?hqrrAnm|yXUM?9|I^G+Z0xI~}J)6DKY zUpeaXFrQPnqoxPCF{$iE)6J=FL*q{v#N3%ajL*HMmq5+ReUqPAltq(Q*_XF8QzsEED-R>}t?Vi#u_Hny3whWuTewFt0-oD1P*x0Qg! z>yCv|$!vQ#G7t}Da-4ev!kKI=m9*E_*5$PF#4_C)LkKA(kwrVg)X@RN5k!Xi`Ojac z099nDGM1ZRM?Gp$w_d5dES{u$?z1`tR;*mHb{P$Wv1Ctbu!jCKu|(`lSXr`m&NkVW G^nU>%Zn)|I delta 885 zcmZ9JPe>GD7{;G(XLeoPf9~jRe^_wMO_DTJ+Pq{&7)T|E%C6wSrge5!ncW$7*D``E z5-W(XJ`WW|Ap~}af;|NhBwY&Z5Yi#M1?o8ngbwz8^$Fz+@4Ua~dB6E)=9z`FOK0Yr zW@-R703emg>rTr;OFii&!1X$Fu^jg|YevH0Afgg=Hj5hS59|IUdn*U(w>H`pG z0tr6oI!L#BI8&PVQ&(49>_~@STmlG&L=68NVOn^V&%1nlM)6dy$w`>sRc@XhBPB}Q zJ1#3gJu53n-INugJ|Rmy;gYOyC8t)rl^cQEYHX#aFgX@F{u3dQEwJ`ru_$|qAJV#* z#?Na>{!nX;yj9oT^=`}k$#cTBSwn(^E#VG+`Iw9Y@-CEZ$cCqB{#41(adH uqSMA8k%=i{9Yy*z|4(;m&LVq4yS>K9GfI9rlHi+>Q9cwMsl1GC1b+kneWslN diff --git a/dev-utils/fontello-config-small.json b/dev-utils/fontello-config-small.json index fa7e6334..895de303 100644 --- a/dev-utils/fontello-config-small.json +++ b/dev-utils/fontello-config-small.json @@ -1,5 +1,5 @@ { - "name": "", + "name": "icons", "css_prefix_text": "icon-", "css_use_suffix": false, "hinting": true, @@ -99,7 +99,7 @@ { "uid": "7394501fc0b17cb7bda99538f92e26d6", "css": "window-close", - "code": 87, + "code": 88, "src": "fontawesome" }, { @@ -107,6 +107,12 @@ "css": "menu-1", "code": 77, "src": "fontawesome" + }, + { + "uid": "07f0832c07f3d9713fffb06c8bffa027", + "css": "window-maximize", + "code": 87, + "src": "fontawesome" } ] -} +} \ No newline at end of file diff --git a/src/api/system.c b/src/api/system.c index 024b04f0..cd6ba90f 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -44,6 +44,9 @@ typedef struct HitTestInfo HitTestInfo; static HitTestInfo window_hit_info[1] = {{0, 0}}; +#define RESIZE_FROM_TOP 0 +#define RESIZE_FROM_RIGHT 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; @@ -52,7 +55,10 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p SDL_GetWindowSize(window, &w, &h); - if (pt->y < hit_info->title_height && pt->y > hit_info->resize_border && + if (pt->y < hit_info->title_height && + #if RESIZE_FROM_TOP + pt->y > hit_info->resize_border && + #endif pt->x > resize_border && pt->x < w - controls_width) { return SDL_HITTEST_DRAGGABLE; } @@ -63,12 +69,16 @@ static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *p if (pt->x < resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPLEFT); + #if RESIZE_FROM_TOP } else if (pt->x > resize_border && pt->x < w - controls_width && pt->y < resize_border) { REPORT_RESIZE_HIT(TOP); + #endif } else if (pt->x > w - resize_border && pt->y < resize_border) { REPORT_RESIZE_HIT(TOPRIGHT); + #if RESIZE_FROM_RIGHT } else if (pt->x > w - resize_border && pt->y > resize_border && pt->y < h - resize_border) { REPORT_RESIZE_HIT(RIGHT); + #endif } 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) { @@ -298,6 +308,21 @@ static int f_window_has_focus(lua_State *L) { } +static int f_get_window_mode(lua_State *L) { + unsigned flags = SDL_GetWindowFlags(window); + if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) { + lua_pushstring(L, "fullscreen"); + } else if (flags & SDL_WINDOW_MINIMIZED) { + lua_pushstring(L, "minimized"); + } else if (flags & SDL_WINDOW_MAXIMIZED) { + lua_pushstring(L, "maximized"); + } else { + lua_pushstring(L, "normal"); + } + return 1; +} + + static int f_show_fatal_error(lua_State *L) { const char *title = luaL_checkstring(L, 1); const char *msg = luaL_checkstring(L, 2); @@ -508,6 +533,7 @@ static const luaL_Reg lib[] = { { "set_cursor", f_set_cursor }, { "set_window_title", f_set_window_title }, { "set_window_mode", f_set_window_mode }, + { "get_window_mode", f_get_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 },