]> git.neil.brown.name Git - edlib.git/commitdiff
pane: add option arg to pane_has_focus()
authorNeilBrown <neil@brown.name>
Sat, 2 Sep 2023 10:32:08 +0000 (20:32 +1000)
committerNeilBrown <neil@brown.name>
Mon, 4 Sep 2023 23:07:53 +0000 (09:07 +1000)
A second arg to pane_has_focus checks is the target pane as the focus
from the given root.  This is occasionally useful.

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

index 6a643e0f91a5a407eeaa3d5a31989d77a4fcedb3..5957054fd24701716c983af0afe861ebf8b4e57c 100644 (file)
@@ -797,14 +797,21 @@ void pane_focus(struct pane *focus)
        call("pane:refocus", focus);
 }
 
-bool pane_has_focus(struct pane *focus)
+bool do_pane_has_focus(struct pane *focus, struct pane *root)
 {
        /* Would pane_focus change anything */
        struct pane *p = focus;
 
        if (!p)
                return False;
-       for (; p->parent->parent->parent != p->parent->parent; p = p->parent)
+       /* We check down to the declared root, or to on1 above
+        * the global root.  Where the focus of the global root
+        * is never matters.
+        */
+       for (;
+            p != root
+            && p->parent->parent->parent != p->parent->parent;
+            p = p->parent)
                if (p->parent->focus != p)
                        return False;
        return True;
diff --git a/core.h b/core.h
index 8987d3d496bc29f5aefafc689c812fae81bbace5..43ff81a748584dedead3fc10270e1404e2070ad3 100644 (file)
--- a/core.h
+++ b/core.h
@@ -473,7 +473,10 @@ void pane_subsume(struct pane *p safe, struct pane *parent safe);
 void pane_close(struct pane *p safe);
 bool pane_resize(struct pane *p safe, int x, int y, int w, int h);
 void pane_focus(struct pane *p);
-bool pane_has_focus(struct pane *p);
+bool do_pane_has_focus(struct pane *p, struct pane *root);
+#define pane_has_focus(...) VFUNC(pane_has_focus, __VA_ARGS__)
+#define pane_has_focus1(p) do_pane_has_focus(p, NULL)
+#define pane_has_focus2(p,r) do_pane_has_focus(p, r)
 void pane_damaged(struct pane *p, int type);
 void pane_clone_children(struct pane *from, struct pane *to);
 struct pane *pane_my_child(struct pane *p, struct pane *c);
index 23fa8ae56cadff9d4fb827ade72806725623541d..3217cd22d34af6b2b3adad89df7e43d1a4c4d58b 100644 (file)
@@ -877,10 +877,17 @@ static PyObject *Pane_focus(Pane *self safe, PyObject *args)
 
 static PyObject *Pane_has_focus(Pane *self safe, PyObject *args)
 {
+       Pane *other = NULL;
+       int ret;
+
        if (!pane_valid(self))
                return NULL;
 
-       if (pane_has_focus(self->pane)) {
+       ret = PyArg_ParseTuple(args, "|O!", &PaneType, &other);
+       if (ret <= 0)
+               return NULL;
+
+       if (pane_has_focus(self->pane, other ? other->pane : NULL)) {
                Py_INCREF(Py_True);
                return Py_True;
        } else {
@@ -1504,7 +1511,7 @@ static const PyMethodDef pane_methods[] = {
         "Clone all children onto the target"},
        {"take_focus", (PyCFunction)Pane_focus, METH_NOARGS,
         "Claim the focus for this pane"},
-       {"has_focus", (PyCFunction)Pane_has_focus, METH_NOARGS,
+       {"has_focus", (PyCFunction)Pane_has_focus, METH_VARARGS,
         "Check if pane is focus of display"},
        {"call", (void*)(PyCFunctionWithKeywords)Pane_call, METH_VARARGS|METH_KEYWORDS,
         "Call a command from a pane"},