top: TREE_FOCUS_X works properly with multiple windows

As promised, this commit will ensure that TREE_FOCUS_X
impacts only the window under which an 'F' was issued.

Previously, when 'F' was invoked it would impact every
window that was displaying forest view. Now, only that
window where 'F' was applied will show the indentation
losses whenever multiple windows were being displayed.

[ each of the 4 windows can now have different focus ]
[ pids active and not impact any other forest views! ]

Reference(s):
. 'TREE_FOCUS_X' introduction
commit c23d2708d4

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2021-07-28 00:00:00 -05:00 committed by Craig Small
parent 38eeba364a
commit 2e11351b6f
2 changed files with 18 additions and 13 deletions

View File

@ -4480,8 +4480,7 @@ static void forest_begin (WIN_t *q) {
* But, if the pid can no longer be found, he'll turn off focus! | */
static void forest_config (WIN_t *q) {
// tailored 'results stack value' extractor macro
// (TREE_FOCUS_X can't use PID_VAL w/ assignment)
#define rSv(x) q->ppt[x]->head[eu_TREE_LVL].result.s_int
#define rSv(x) PID_VAL(eu_TREE_LVL, s_int, q->ppt[(x)])
int i, level;
for (i = 0; i < PIDSmaxt; i++) {
@ -4495,14 +4494,10 @@ static void forest_config (WIN_t *q) {
q->focus_pid = q->begtask = 0;
else {
#ifdef TREE_FOCUS_X
int j = rSv(i);
rSv(i) = 0;
while (i+1 < PIDSmaxt && rSv(i+1) > level)
rSv(++i) -= j;
#else
q->focus_lvl = rSv(i);
#endif
while (i+1 < PIDSmaxt && rSv(i+1) > level)
++i;
#endif
q->focus_end = i + 1; // make 'focus_end' a proper fencpost
}
#undef rSv
@ -4524,21 +4519,28 @@ static inline const char *forest_display (const WIN_t *q, int idx) {
#endif
struct pids_stack *p = q->ppt[idx];
const char *which = (CHKw(q, Show_CMDLIN)) ? rSv(eu_CMDLINE) : rSv(EU_CMD);
int level = rSv_Lvl;
if (!CHKw(q, Show_FOREST) || rSv_Lvl == 0) return which;
#ifdef TREE_FOCUS_X
if (q->focus_pid) {
if (idx >= q->focus_beg && idx < q->focus_end)
level -= q->focus_lvl;
}
#endif
if (!CHKw(q, Show_FOREST) || level == 0) return which;
#ifndef TREE_VWINALL
if (q == Curwin) // note: the following is NOT indented
#endif
if (rSv_Hid == 'x') {
#ifdef TREE_VALTMRK
snprintf(buf, sizeof(buf), "%*s%s", (4 * rSv_Lvl), "`+ ", which);
snprintf(buf, sizeof(buf), "%*s%s", (4 * level), "`+ ", which);
#else
snprintf(buf, sizeof(buf), "+%*s%s", ((4 * rSv_Lvl) - 1), "`- ", which);
snprintf(buf, sizeof(buf), "+%*s%s", ((4 * level) - 1), "`- ", which);
#endif
return buf;
}
if (rSv_Lvl > 100) snprintf(buf, sizeof(buf), "%400s%s", " + ", which);
else snprintf(buf, sizeof(buf), "%*s%s", (4 * rSv_Lvl), " `- ", which);
if (level > 100) snprintf(buf, sizeof(buf), "%400s%s", " + ", which);
else snprintf(buf, sizeof(buf), "%*s%s", (4 * level), " `- ", which);
return buf;
#undef rSv
#undef rSv_Lvl

View File

@ -366,6 +366,9 @@ typedef struct WIN_t {
int focus_pid; // target pid when 'F' toggle is active
int focus_beg; // ppt index where 'F' toggle has begun
int focus_end; // ppt index where 'F' toggle has ended
#ifdef TREE_FOCUS_X
int focus_lvl; // the indentation level of parent task
#endif
struct pids_stack **ppt; // this window's stacks ptr array
struct WIN_t *next, // next window in window stack
*prev; // prior window in window stack