]> git.neil.brown.name Git - edlib.git/commitdiff
Add global 'z' level.
authorNeilBrown <neil@brown.name>
Sun, 13 Dec 2015 04:13:19 +0000 (15:13 +1100)
committerNeilBrown <neil@brown.name>
Sun, 13 Dec 2015 04:15:20 +0000 (15:15 +1100)
'abs_z' can be compared between pane to determine global z order.

Signed-off-by: NeilBrown <neil@brown.name>
core-pane.c
core.h
lang-python.c

index a1bf339b2addca8cdd4ffba2ec0198d3b088f129..2d541c26ababae8a5fac83a322964ec87308e9a7 100644 (file)
@@ -99,6 +99,10 @@ struct pane *pane_register(struct pane *parent, int z,
        return p;
 }
 
+/* 'abs_z' is a global z-depth number.
+ * 'abs_z' of root is 0, and abs_z of every other pane is 1 more than abs_zhi
+ * of siblings with lower 'z', or same as parent if no such siblings.
+ */
 static void __pane_refresh(struct cmd_info ci)
 {
        struct pane *c;
@@ -106,9 +110,12 @@ static void __pane_refresh(struct cmd_info ci)
        struct pane *p = ci.home;
        int ret = 0;
        int nextz;
+       int abs_z = p->abs_z;
 
-       if (p->damaged & DAMAGED_CLOSED)
+       if (p->damaged & DAMAGED_CLOSED) {
+               p->abs_zhi = abs_z;
                return;
+       }
 
        if (p->focus == NULL)
                p->focus = list_first_entry_or_null(
@@ -119,9 +126,7 @@ static void __pane_refresh(struct cmd_info ci)
        damage |= p->damaged;
        if (!damage)
                return;
-       if (damage == DAMAGED_CHILD)
-               damage = 0;
-       else {
+       if (damage & (DAMAGED_NEED_CALL)) {
                struct cmd_info ci2 = ci;
                ci2.extra = damage;
                if (ci2.extra & DAMAGED_SIZE)
@@ -133,21 +138,31 @@ static void __pane_refresh(struct cmd_info ci)
                ret = p->handle->func(&ci2);
                if (ret == 0)
                        pane_check_size(p);
-       }
+       } else
+               damage = 0;
        p->damaged = 0;
        ci.extra = damage;
        nextz = 0;
        while (nextz >= 0) {
                int z = nextz;
+               int abs_zhi = abs_z;
                nextz = -1;
                list_for_each_entry(c, &p->children, siblings) {
                        if (c->z > z && (nextz == -1 || c->z < nextz))
                                nextz = c->z;
                        if (c->z == z) {
+                               if (c->abs_z != abs_z) {
+                                       c->abs_z = abs_z;
+                                       c->damaged |= DAMAGED_Z;
+                               }
                                ci.home = c;
                                __pane_refresh(ci);
+                               if (c->abs_zhi > abs_zhi)
+                                       abs_zhi = c->abs_zhi;
                        }
                }
+               p->abs_zhi = abs_zhi;
+               abs_z = abs_zhi + 1;
        }
        if (ret == 2) {
                /* "Refresh" requested a post-order call */
@@ -162,9 +177,10 @@ void pane_refresh(struct pane *p)
 {
        struct cmd_info ci = {0};
        pane_damaged(p, DAMAGED_CURSOR);
-       /* Always refresh a while display */
+       /* Always refresh a whole display */
        while (p->parent)
                p = p->parent;
+       p->abs_z = 0;
        ci.focus = ci.home = p;
        ci.key = "Refresh";
        __pane_refresh(ci);
diff --git a/core.h b/core.h
index c7cf6210fd813dfdfff0e6785aa4f0bf7072fefd..08aeb8ca2a1759c9f9768e81e35fa00ccd5e692d 100644 (file)
--- a/core.h
+++ b/core.h
@@ -48,6 +48,7 @@ struct pane {
        int                     h,w;
        struct pane             *focus;
        int                     cx, cy; /* cursor position */
+       int                     abs_z, abs_zhi; /* 'hi' is the max of all children */
 
        int                     damaged;
 
@@ -320,7 +321,10 @@ enum {
 
        DAMAGED_CLOSED  = 1024,
        DAMAGED_EVENTS  = 2048, /* event loop changed, resubmit requests */
+       DAMAGED_Z       = 4096, /* global-z has changed */
 };
+#define DAMAGED_NEED_CALL (DAMAGED_SIZE | DAMAGED_CONTENT | DAMAGED_CURSOR \
+                          | DAMAGED_EVENTS)
 
 struct pane *pane_register(struct pane *parent, int z,
                           struct command *handle, void *data,
index 39e7f228fcb27841e45194407bfff0f86b60faaf..7935cfcbd87114e89ed4fbbfbcad379dc889ef3d 100644 (file)
@@ -444,6 +444,7 @@ static PyObject *pane_getnum(Pane *p, char *which)
        case 'X': n = p->pane->cx; break;
        case 'Y': n = p->pane->cy; break;
        case 'z': n = p->pane->z; break;
+       case 'Z': n = p->pane->abs_z; break;
        }
        return PyInt_FromLong(n);
 }
@@ -461,6 +462,10 @@ static int pane_setnum(Pane *p, PyObject *v, char *which)
                PyErr_SetString(PyExc_TypeError, "z cannot be set");
                return -1;
        }
+       if (*which == 'Z') {
+               PyErr_SetString(PyExc_TypeError, "abs_z cannot be set");
+               return -1;
+       }
        val = PyInt_AsLong(v);
        if (val == -1 && PyErr_Occurred())
                return -1;
@@ -540,6 +545,9 @@ static PyGetSetDef pane_getseters[] = {
     {"cy",
      (getter)pane_getnum, (setter)pane_setnum,
      "Cursor Y offset in pane", "Y" },
+    {"abs_z",
+     (getter)pane_getnum, (setter)pane_setnum,
+     "global Z offset", "Z" },
     {"parent",
      (getter)pane_getpane, (setter)pane_nosetpane,
      "Parent pane", "p"},