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