From 091c19be58645e8e3c8c3451f7d7a67d92deb91c Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 25 Aug 2023 15:32:27 +1000 Subject: [PATCH] Change window-scaling to display-scaling The emacs scaling commands now affect the whole display (window), not just a single pane. This is more consistent. It is done just by changing an attribute on the display pane. Signed-off-by: NeilBrown --- DOC/Developer/06-rendering.md | 5 +++- DOC/TODO.md | 2 +- lib-popup.c | 37 --------------------------- lib-tile.c | 47 ---------------------------------- mode-emacs.c | 48 +++++++++++++++++++++++++---------- 5 files changed, 40 insertions(+), 99 deletions(-) diff --git a/DOC/Developer/06-rendering.md b/DOC/Developer/06-rendering.md index 14b6a743..92d21175 100644 --- a/DOC/Developer/06-rendering.md +++ b/DOC/Developer/06-rendering.md @@ -260,11 +260,14 @@ appearing in the pane stack: - "scale" - should be a pair of values in format WIDTHxHEIGHT. If given, content will be scaled so that this many "points" will fit within the window. A "point" is one tenth of the size of an "M" - which is stored (in the same WxH format) in the "scale:M" attrbiute + which is stored (in the same WxH format) in the "scale:M" attribute which is set by the display pane. So if "scale" is "800x250" then text is scales so that least 80 M's fit across and 25 M's fit down. + Alternately "scale" can be a single integer in which can the standard + scaling is multiplied by 1/1000th of that number. + ### lib-renderline diff --git a/DOC/TODO.md b/DOC/TODO.md index ecd90022..132dce2f 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -39,7 +39,7 @@ the file. following punctuation (=) and try there. - [X] resolve shift-left vs shift_left distinction - add a "fixed" suffix? Also consider render-wrap -- [ ] should zoom affect whole window, not just pane? +- [X] should zoom affect whole window, not just pane? - [X] ditch cached-size for images - store in pane data instead. - [X] use foreach_attr for parsing image details - [ ] mergeview command to show diff between "found" and "replacement". diff --git a/lib-popup.c b/lib-popup.c index 06e858d7..6cbb6673 100644 --- a/lib-popup.c +++ b/lib-popup.c @@ -442,42 +442,6 @@ restart: return 1; } -static int get_scale(struct pane *p) -{ - char *sc = pane_attr_get(p, "scale"); - int scale; - - if (!sc) - return 1000; - - scale = atoi(sc); - if (scale > 3) - return scale; - return 1000; -} - -DEF_CMD(popup_scale_relative) -{ - struct pane *p = ci->home; - int scale = get_scale(p); - int rpt = RPT_NUM(ci); - - if (rpt > 10) rpt = 10; - if (rpt < -10) rpt = -10; - while (rpt > 0) { - scale = scale * 11/10; - rpt -= 1; - } - while (rpt < 0) { - scale = scale * 9 / 10; - rpt += 1; - } - - attr_set_int(&p->attrs, "scale", scale); - call("view:changed", ci->focus); - return 1; -} - DEF_CMD(popup_do_close) { const char *str; @@ -610,6 +574,5 @@ void edlib_init(struct pane *ed safe) key_add(popup_map, "Window:y+", &popup_ignore); key_add(popup_map, "Window:y-", &popup_ignore); key_add(popup_map, "Window:close-others", &popup_close_others); - key_add(popup_map, "Window:scale-relative", &popup_scale_relative); key_add(popup_map, "pane:defocus", &popup_defocus); } diff --git a/lib-tile.c b/lib-tile.c index 8367fe4a..ed5a6aa9 100644 --- a/lib-tile.c +++ b/lib-tile.c @@ -124,20 +124,6 @@ DEF_CMD(tile_clone) return 1; } -static int get_scale(struct pane *p) -{ - char *sc = pane_attr_get(p, "scale"); - int scale; - - if (!sc) - return 1000; - - scale = atoi(sc); - if (scale > 3) - return scale; - return 1000; -} - DEF_CMD(tile_attach) { struct pane *display = ci->focus; @@ -212,9 +198,6 @@ static struct pane *tile_split(struct pane **pp safe, int horiz, int after, list_for_each_entry_safe(child, t, &p->children, siblings) if (child != p2) pane_reparent(child, p2); - /* Move attrs "scale" attr to the new pane */ - attr_set_str(&p2->attrs, "scale", attr_find(p->attrs, "scale")); - attr_set_str(&p->attrs, "scale", NULL); p = p2; } alloc(ti2, pane); @@ -232,7 +215,6 @@ static struct pane *tile_split(struct pane **pp safe, int horiz, int after, if (!ret) return NULL; - attr_set_str(&ret->attrs, "scale", attr_find(p->attrs, "scale")); ti2->p = ret; if (after) pane_move_after(ret, p); @@ -374,9 +356,6 @@ static int tile_destroy(struct pane *p safe) ti->direction = tmp; ti2->p = remain; - attr_set_str(&p->attrs, "scale", - attr_find(remain->attrs, "scale")); - attr_set_str(&remain->attrs, "scale", NULL); pane_subsume(remain, p); } return 1; @@ -861,31 +840,6 @@ DEF_CMD(tile_window_close_others) return ti->direction != Neither ? 1 : Efalse; } -DEF_CMD(tile_window_scale_relative) -{ - struct pane *p = ci->home; - int scale = get_scale(p); - int rpt = RPT_NUM(ci); - - if (wrong_pane(ci)) - return Efallthrough; - - if (rpt > 10) rpt = 10; - if (rpt < -10) rpt = -10; - while (rpt > 0) { - scale = scale * 12/10; - rpt -= 1; - } - while (rpt < 0) { - scale = scale * 10/ 12; - rpt += 1; - } - - attr_set_int(&p->attrs, "scale", scale); - call("view:changed", ci->focus); - return 1; -} - DEF_CMD(tile_other) { /* Choose some other tile. If there aren't any, make one. @@ -1095,7 +1049,6 @@ void edlib_init(struct pane *ed safe) key_add(tile_map, "Window:split-y", &tile_window_splity); key_add(tile_map, "Window:close", &tile_window_close); key_add(tile_map, "Window:close-others", &tile_window_close_others); - key_add(tile_map, "Window:scale-relative", &tile_window_scale_relative); key_add(tile_map, "Window:bury", &tile_window_bury); key_add(tile_map, "OtherPane", &tile_other); diff --git a/mode-emacs.c b/mode-emacs.c index eae28935..a8c22924 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -521,7 +521,6 @@ DEF_CMD(emacs_recenter) } REDEF_CMD(emacs_simple); -REDEF_CMD(emacs_simple_neg); REDEF_CMD(emacs_simple_num); REDEF_CMD(emacs_simple_str); static struct simple_command { @@ -535,8 +534,6 @@ static struct simple_command { {CMD(emacs_simple), "Window:split-y", "K:CX-2"}, {CMD(emacs_simple), "Window:split-x", "K:CX-3"}, {CMD(emacs_simple), "Window:close", "K:CX-0"}, - {CMD(emacs_simple), "Window:scale-relative", "K:CX:C-="}, - {CMD(emacs_simple_neg), "Window:scale-relative", "K:CX:C--"}, {CMD(emacs_simple), "Window:bury", "K:A-B"}, {CMD(emacs_simple), "Display:new", "K:CX5-2"}, {CMD(emacs_simple), "Display:close", "K:CX5-0"}, @@ -566,16 +563,6 @@ REDEF_CMD(emacs_simple) return call(sc->type, ci->focus, ci->num, ci->mark); } -REDEF_CMD(emacs_simple_neg) -{ - struct simple_command *sc = container_of(ci->comm, struct simple_command, cmd); - - if (!ci->mark) - return Enoarg; - - return call(sc->type, ci->focus, -RPT_NUM(ci), ci->mark); -} - REDEF_CMD(emacs_simple_num) { struct simple_command *sc = container_of(ci->comm, struct simple_command, cmd); @@ -2771,6 +2758,38 @@ DEF_CMD(emacs_growx_again) return emacs_growx_func(ci); } +DEF_CMD(emacs_scale_relative) +{ + struct pane *p = ci->focus; + char *sc = pane_attr_get(p, "scale:M"); + int scale = 0; + char num[20]; + + if (!sc) { + call("Message:modal", p, 0, NULL, + "Cannot zoom display with fixed-sized font"); + return 1; + } + sc = pane_attr_get(p, "scale"); + if (sc && strchr(sc, 'x')) { + call("Message:modal", p, 0, NULL, + "Cannot zoom display with fixed layout"); + return 1; + } + + if (sc) + scale = atoi(sc); + if (scale <= 0) + scale = 1000; + if (ci->key[strlen(ci->key)-1] == '-') + scale = 10 * scale / 12; + else + scale = 12 * scale / 10; + snprintf(num, sizeof(num)-1, "%d", scale); + call("Display:set:scale", p, 0, NULL, num); + return 1; +} + DEF_CMD(emacs_curs_pos) { struct mark *c; @@ -3362,6 +3381,9 @@ static void emacs_init(void) key_add(m, "K-{", &emacs_growx_again); key_add(m, "K-}", &emacs_growx_again); + key_add(m, "K:CX:C-=", &emacs_scale_relative); + key_add(m, "K:CX:C--", &emacs_scale_relative); + key_add(m, "K:C-S", &emacs_start_search); key_add(m, "K:C-R", &emacs_start_search); key_add(m, "K:A-%", &emacs_start_search); -- 2.39.5