track tog view focus via panel stack instead of a custom flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/tog/tog.c b/tog/tog.c
index 049b067..a2e7ba4 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -202,7 +202,6 @@ struct tog_view {
PANEL *panel;
int nlines, ncols, begin_y, begin_x;
int lines, cols; /* copies of LINES and COLS */
- int focussed;
struct tog_view *parent;
struct tog_view *child;
@@ -321,10 +320,10 @@ view_show(struct tog_view *view)
show_panel(view->parent->panel);
}
+ show_panel(view->panel);
err = view->show(view);
if (err)
return err;
- show_panel(view->panel);
if (view->child && view->child->begin_x > view->begin_x) {
err = view->child->show(view->child);
@@ -394,8 +393,6 @@ view_input(struct tog_view **new, struct tog_view **dead,
*focus = next;
else
*focus = TAILQ_FIRST(views);
- view->focussed = 0;
- (*focus)->focussed = 1;
break;
case '~':
prev = TAILQ_PREV(view, tog_view_list_head, entry);
@@ -403,8 +400,6 @@ view_input(struct tog_view **new, struct tog_view **dead,
*focus = prev;
else
*focus = TAILQ_LAST(views, tog_view_list_head);
- view->focussed = 0;
- (*focus)->focussed = 1;
break;
case 'q':
err = view->input(new, dead, view, ch);
@@ -455,7 +450,8 @@ view_vborder(struct tog_view *view)
int
view_needs_focus_indication(struct tog_view *view)
{
- if (!view->focussed)
+ PANEL *top_panel = panel_below(NULL);
+ if (view->panel != top_panel)
return 0;
if (view->child && view->child->begin_x > view->begin_x)
@@ -478,7 +474,6 @@ view_loop(struct tog_view *view)
TAILQ_INIT(&views);
TAILQ_INSERT_HEAD(&views, view, entry);
- view->focussed = 1;
while (!TAILQ_EMPTY(&views) && !done) {
err = view_show(view);
if (err)
@@ -502,15 +497,12 @@ view_loop(struct tog_view *view)
view = dead_view->parent;
else
view = TAILQ_LAST(&views, tog_view_list_head);
- if (view)
- view->focussed = 1;
err = view_close(dead_view);
if (err)
goto done;
}
if (new_view) {
struct tog_view *v, *t;
- view->focussed = 0;
/* Only allow one view per type. */
TAILQ_FOREACH_SAFE(v, &views, entry, t) {
if (v->type != new_view->type)
@@ -525,10 +517,8 @@ view_loop(struct tog_view *view)
err = view_set_child(new_view->parent, new_view);
if (err)
goto done;
- new_view->parent->focussed = 0;
}
view = new_view;
- view->focussed = 1;
}
}
done: