From 2e11351b6fc2f445fbfbfcedc196d6d9dac2c4f3 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Wed, 28 Jul 2021 00:00:00 -0500 Subject: [PATCH] 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 c23d2708d4a6a80e029289d630c84824d27b1ada Signed-off-by: Jim Warner --- top/top.c | 28 +++++++++++++++------------- top/top.h | 3 +++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/top/top.c b/top/top.c index ad0b509b..81fa5a9e 100644 --- a/top/top.c +++ b/top/top.c @@ -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 diff --git a/top/top.h b/top/top.h index 2bff534a..4d5f308c 100644 --- a/top/top.h +++ b/top/top.h @@ -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 -- 2.40.0