]> git.neil.brown.name Git - edlib.git/commitdiff
Change window-scaling to display-scaling
authorNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 05:32:27 +0000 (15:32 +1000)
committerNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 05:35:37 +0000 (15:35 +1000)
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 <neil@brown.name>
DOC/Developer/06-rendering.md
DOC/TODO.md
lib-popup.c
lib-tile.c
mode-emacs.c

index 14b6a74382ae2acee4ddc9f2e013a4b033168c45..92d21175030a3b55228e32b6bb041dbda47a1c47 100644 (file)
@@ -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
 
index ecd90022ea59b73896132ad58633079c75b746f3..132dce2f22394f35195f0d55d35c223ca46a6b8b 100644 (file)
@@ -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".
index 06e858d715451a447a78a2aa0b7305cdf1029b97..6cbb667309fec09b56a116f3e791567704ce3408 100644 (file)
@@ -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);
 }
index 8367fe4acdc554a34f8349b3169caca30727ab37..ed5a6aa9cc0bffc02f02769904d00f59979f6811 100644 (file)
@@ -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);
index eae289356f68bfb762535f664728c2ea51be0c24..a8c22924b5aab944742ca448bc94a8a687b397df 100644 (file)
@@ -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);