]> git.neil.brown.name Git - edlib.git/commitdiff
Revise pane_resize and DAMAGED_SIZE handling.
authorNeilBrown <neil@brown.name>
Fri, 22 May 2020 22:31:29 +0000 (08:31 +1000)
committerNeilBrown <neil@brown.name>
Mon, 1 Jun 2020 11:10:35 +0000 (21:10 +1000)
DAMAGED_SIZE means that the pane needs to reconsider its own size and/or
that of its children, depending on who is reponsible.

When changing size, pane_resize() should always be used.  It sets
DAMAGED_SIZE if needed so propagating to children will follow a common
path.

DAMAGED_SIZE is now set automatically where children are added, so many
places that currently set it, don't need to any more.

The Notify:resize signal is now sent by pane_resize() (not when
DAMAGED_SIZE it set) and the handler should generally just set
DAMAGED_SIZE on the target.

DAMAGE_CONTENT should not be set when the size changes - that has a
separate use.

Signed-off-by: NeilBrown <neil@brown.name>
core-pane.c
display-ncurses.c
lib-messageline.c
lib-popup.c
lib-tile.c
lib-view.c

index e700c8805a6e2094dafb41899b6a59d9c30775cb..7292261e2d0e75b3f3e4bb95c058c1fb28c38fd7 100644 (file)
@@ -62,8 +62,6 @@ static void pane_init(struct pane *p safe, struct pane *par)
        p->data = safe_cast NULL;
        p->damaged = 0;
        p->attrs = NULL;
-       if (par)
-               pane_damaged(p, DAMAGED_SIZE);
 }
 
 static void __pane_check(struct pane *p safe)
@@ -101,8 +99,6 @@ void pane_damaged(struct pane *p, int type)
                return;
        }
        p->damaged |= type;
-       if (type == DAMAGED_SIZE)
-               pane_notify("Notify:resize", p);
 
        z = p->z;
        if (z < 0)
@@ -123,6 +119,7 @@ void pane_damaged(struct pane *p, int type)
        while ((p->damaged | type) != p->damaged) {
                if (z > 0 && (type & DAMAGED_SIZE_CHILD))
                        /* overlay changed size, so we must refresh */
+                       /* FIXME should this be a notification? */
                        p->damaged |= DAMAGED_CONTENT;
                p->damaged |= type;
                z = p->z;
@@ -155,6 +152,9 @@ struct pane *__pane_register(struct pane *parent, short z,
                if (p->damaged & DAMAGED_CLOSED)
                        /* ChildRegistered objected */
                        p = NULL;
+               else
+                       /* Need to set size of child */
+                       pane_damaged(parent, DAMAGED_SIZE);
        }
        return p;
 }
@@ -177,7 +177,8 @@ static void pane_do_resize(struct pane *p safe, int damage)
                p->abs_zhi = abs_z;
                return;
        }
-       if ((damage & DAMAGED_SIZE) && p->z == 0)
+       if ((damage & DAMAGED_SIZE) && p->z == 0 &&
+           (p->parent->w || p->parent->h))
                /* Parent was resized and didn't propagate, so we need to */
                pane_resize(p, 0, 0, p->parent->w, p->parent->h);
 
@@ -533,7 +534,7 @@ void pane_resize(struct pane *p safe, int x, int y, int w, int h)
 
        if (x >= 0 &&
            (p->x != x || p->y != y)) {
-               damage |= DAMAGED_CONTENT | DAMAGED_SIZE;
+               damage |= DAMAGED_SIZE;
                p->x = x;
                p->y = y;
        }
@@ -550,7 +551,10 @@ void pane_resize(struct pane *p safe, int x, int y, int w, int h)
                p->w = 1;
        if (p->h <= 0)
                p->h = 1;
+       /* tell the pane to resize its children later */
        pane_damaged(p, damage);
+       if (damage)
+               pane_notify("Notify:resize", p);
 }
 
 void pane_reparent(struct pane *p safe, struct pane *newparent safe)
@@ -626,6 +630,7 @@ void pane_subsume(struct pane *p safe, struct pane *parent safe)
        p->data = data;
 
        parent->damaged |= p->damaged;
+       pane_damaged(p, DAMAGED_SIZE);
 
        pane_close(p);
 }
index d27bcff2f2b682c0bdf39d9625fb89940d16de58..0d23dc08ae171f76ae1284d7bc1ac5f3175175c5 100644 (file)
@@ -739,6 +739,7 @@ static struct pane *ncurses_init(struct pane *ed,
        SCREEN *scr;
        struct pane *p;
        struct display_data *dd;
+       int rows, cols;
        FILE *f;
 
        set_screen(NULL);
@@ -756,9 +757,13 @@ static struct pane *ncurses_init(struct pane *ed,
        dd->scr = scr;
        dd->scr_file = f;
        dd->cursor.x = dd->cursor.y = -1;
-       dd->is_xterm =  (term && strncmp(term, "xterm", 5) == 0);
+       dd->is_xterm = (term && strncmp(term, "xterm", 5) == 0);
 
        p = pane_register(ed, 0, &ncurses_handle.c, dd);
+       if (!p) {
+               unalloc(dd, pane);
+               return NULL;
+       }
        set_screen(p);
 
        start_color();
@@ -779,7 +784,8 @@ static struct pane *ncurses_init(struct pane *ed,
                  REPORT_MOUSE_POSITION, NULL);
        mouseinterval(10);
 
-       getmaxyx(stdscr, p->h, p->w);
+       getmaxyx(stdscr, rows, cols);
+       pane_resize(p, 0, 0, cols, rows);
 
        call("editor:request:all-displays", p);
        if (!prepare_recrep(p)) {
@@ -787,7 +793,6 @@ static struct pane *ncurses_init(struct pane *ed,
                if (!tty)
                        call_comm("event:signal", p, &handle_winch, SIGWINCH);
        }
-       pane_damaged(p, DAMAGED_SIZE);
        return p;
 }
 
@@ -801,7 +806,7 @@ REDEF_CMD(handle_winch)
        resize_term(size.ws_row, size.ws_col);
 
        clear();
-       pane_damaged(p, DAMAGED_SIZE);
+       pane_resize(p, 0, 0, size.ws_row, size.ws_col);
        return 1;
 }
 
index 785664d292c8e386d0f933c57644251367ee6095..6b1574c2d54e684edb9799e5eecbe43af9908131 100644 (file)
@@ -53,6 +53,7 @@ DEF_CMD(messageline_border)
                mli->hidden = 0;
        else
                mli->hidden = 1;
+       /* trigger a resize of children */
        pane_damaged(ci->home, DAMAGED_SIZE);
        return 0; /* Allow other panes to remove other borders */
 }
@@ -132,7 +133,6 @@ DEF_CMD(messageline_child_registered)
 {
        struct mlinfo *mli = ci->home->data;
        mli->child = ci->focus;
-       pane_damaged(ci->home, DAMAGED_SIZE);
        pane_focus(ci->focus);
        return 1;
 }
index 29d99c34049b4febead2e8ffb685eb5a4dae53a3..391325fd0985834b020797f0d0e5b056d751f8fc 100644 (file)
@@ -207,6 +207,12 @@ DEF_CMD(popup_style)
        return 1;
 }
 
+DEF_CMD(popup_notify_refresh_size)
+{
+       pane_damaged(ci->home, DAMAGED_SIZE);
+       return 1;
+}
+
 DEF_CMD(popup_refresh_size)
 {
        struct popup_info *ppi = ci->home->data;
@@ -437,7 +443,7 @@ void edlib_init(struct pane *ed safe)
        key_add(popup_map, "Abort", &popup_abort);
        key_add(popup_map, "popup:style", &popup_style);
        key_add(popup_map, "Refresh:size", &popup_refresh_size);
-       key_add(popup_map, "Notify:resize", &popup_refresh_size);
+       key_add(popup_map, "Notify:resize", &popup_notify_refresh_size);
        key_add(popup_map, "popup:get-target", &popup_get_target);
        key_add(popup_map, "popup:close", &popup_do_close);
        key_add(popup_map, "popup:set-callback", &popup_set_callback);
index b667ba81e47dc5a7a7fa02de0460b442c3800969..3d46e6b578575cb492e02d5aa6f348523336e4c0 100644 (file)
@@ -367,7 +367,6 @@ static int tile_destroy(struct pane *p safe)
                ti->direction = tmp;
                ti2->p = remain;
                pane_subsume(remain, p);
-               pane_damaged(p, DAMAGED_SIZE);
        }
        return 1;
 }
@@ -439,17 +438,14 @@ static void tile_adjust(struct pane *p safe)
                        continue;
                ti = t->data;
                if (ti->direction == Horiz) {
-                       t->y = 0;
-                       t->h = p->h;
+                       pane_resize(t, t->x, 0, t->w, p->h);
                        used += t->w;
                        size = p->w;
                } else {
-                       t->x = 0;
-                       t->w = p->w;
+                       pane_resize(t, 0, t->y, p->w, t->h);
                        used += t->h;
                        size = p->h;
                }
-               pane_damaged(t, DAMAGED_SIZE);
                if (ti->avail_inline)
                        avail_cnt++;
                cnt++;
@@ -495,16 +491,13 @@ static void tile_adjust(struct pane *p safe)
                        remain -= mysize;
                        if (diff)
                                change = 1;
-                       if (ti2->direction == Horiz) {
-                               t->w += diff;
-                               used += diff;
-                               cnt--;
-                       } else {
-                               t->h += diff;
-                               used += diff;
-                               cnt--;
-                       }
-                       pane_damaged(t, DAMAGED_SIZE);
+                       if (ti2->direction == Horiz)
+                               pane_resize(t, t->x, t->y, t->w + diff, t->h);
+                        else
+                               pane_resize(t, t->x, t->y, t->w, t->h + diff);
+
+                       used += diff;
+                       cnt--;
                }
                if (!change)
                        break;
@@ -515,13 +508,12 @@ static void tile_adjust(struct pane *p safe)
                if (t->z)
                        continue;
                if (ti2->direction == Horiz) {
-                       t->x = pos;
+                       pane_resize(t, pos, t->y, t->w, t->h);
                        pos += t->w;
                } else {
-                       t->y = pos;
+                       pane_resize(t, t->x, pos, t->w, t->h);
                        pos += t->h;
                }
-               pane_damaged(t, DAMAGED_SIZE);
                tile_adjust(t);
        }
 }
@@ -579,14 +571,14 @@ static int tile_grow(struct pane *p safe, int horiz, int size)
                        /* Strange - there should have been two elements in list */
                        return 1;
                if (ti->direction == Horiz) {
-                       p->w += size;
-                       other->w -= size;
-               } else{
-                       p->h += size;
-                       other->h -= size;
+                       pane_resize(p, p->x, p->y, p->w + size, p->h);
+                       pane_resize(other, other->x, other->y,
+                                   other->w - size, other->h);
+               } else {
+                       pane_resize(p, p->x, p->y, p->w, p->h + size);
+                       pane_resize(other, other->x, other->y,
+                                   other->w, other->h - size);
                }
-               pane_damaged(p, DAMAGED_SIZE);
-               pane_damaged(other, DAMAGED_SIZE);
                tile_adjust(p->parent);
                return 1;
        }
@@ -601,10 +593,10 @@ static int tile_grow(struct pane *p safe, int horiz, int size)
        if (avail < size)
                return 0;
        if (ti->direction == Horiz)
-               p->w += size;
+               pane_resize(p, p->x, p->y, p->w + size, p->h);
        else
-               p->h += size;
-       pane_damaged(p, DAMAGED_SIZE);
+               pane_resize(p, p->x, p->y, p->w, p->h + size);
+
        ti->avail_inline = 0; /* make sure this one doesn't suffer */
        tile_adjust(p->parent);
        return 1;
@@ -747,7 +739,6 @@ DEF_CMD(tile_window_xplus)
        if (wrong_pane(ci))
                return 0;
        tile_grow(p, 1, RPT_NUM(ci));
-       pane_damaged(p, DAMAGED_SIZE);
        return 1;
 }
 
@@ -758,7 +749,6 @@ DEF_CMD(tile_window_xminus)
        if (wrong_pane(ci))
                return 0;
        tile_grow(p, 1, -RPT_NUM(ci));
-       pane_damaged(p, DAMAGED_SIZE);
        return 1;
 }
 DEF_CMD(tile_window_yplus)
@@ -768,7 +758,6 @@ DEF_CMD(tile_window_yplus)
        if (wrong_pane(ci))
                return 0;
        tile_grow(p, 0, RPT_NUM(ci));
-       pane_damaged(p, DAMAGED_SIZE);
        return 1;
 }
 DEF_CMD(tile_window_yminus)
@@ -778,7 +767,6 @@ DEF_CMD(tile_window_yminus)
        if (wrong_pane(ci))
                return 0;
        tile_grow(p, 0, -RPT_NUM(ci));
-       pane_damaged(p, DAMAGED_SIZE);
        return 1;
 }
 
@@ -880,7 +868,7 @@ DEF_CMD(tile_window_scale_relative)
        }
 
        attr_set_int(&p->attrs, "scale", scale);
-       pane_damaged(p, DAMAGED_SIZE);
+       call("view:changed", ci->focus);
        return 1;
 }
 
index 43030840f8effc58cbffbb37376c3f689026c508..4e7a50cef0c89a8b4919fc4d65b201d749758f80 100644 (file)
@@ -278,7 +278,6 @@ DEF_CMD(view_child_registered)
        struct pane *p = ci->home;
        struct view_data *vd = p->data;
        vd->child = ci->focus;
-       pane_damaged(p, DAMAGED_SIZE|DAMAGED_CONTENT);
        return 1;
 }
 
@@ -296,6 +295,7 @@ DEF_CMD(view_refresh_size)
                vd->border = calc_border(ci->focus);
        b = vd->border < 0 ? 0 : vd->border;
        if (vd->line_height < 0) {
+               /* FIXME should use scale */
                struct call_return cr = call_ret(all, "text-size", ci->home,
                                                 -1, NULL, "M",
                                                 0, NULL, "bold");
@@ -385,7 +385,6 @@ static struct pane *do_view_attach(struct pane *par, int border)
        /* Capture status-changed notification so we can update 'changed' flag in
         * status line */
        call("doc:request:doc:status-changed", p);
-       pane_damaged(p, DAMAGED_SIZE);
        return p;
 }