From 99ec6247ecca5179694d63be78dcc47bd90236aa Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 13 Jan 2022 13:13:13 -0600 Subject: [PATCH] top: provide for avoiding task focus ('F') distortions In the patch referenced below the focus task logic was improved to ensure that newly cloned tasks 'above' the focused task did not force an effect like the up arrow key. That commit also acknowledged that when some task 'above' ended, it *would* act like the down arrow key. Well, with this commit a task ending 'above' a focused task no longer distorts the focus. That's assuming the new '#define FOCUS_HARD_Y' is specified plus the total focused tasks does not exceed the current screen rows. Thus, the manual scrolling with up and down arrow keys is allowed when the total focused exceeds screen rows. [ but keep in mind that when a focused task has been ] [ hardened some otherwise useful toggles will not be ] [ available. keystrokes like 'v' and even 'F' itself ] [ can not be applied to another task with no scroll. ] Reference(s): . 01/03/22, newlib branch equivalent commit commit 0e744d3656b1e0299f1083b7f7eabf60fb080f10 . 09/24/21, master branch 'focus' logic improved commit d7e6c27a7944fbaa1493f207fd521bd59984c955 Signed-off-by: Jim Warner --- top/top.c | 13 +++++++++++-- top/top.h | 5 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/top/top.c b/top/top.c index 496a9bc4..fa2905c1 100644 --- a/top/top.c +++ b/top/top.c @@ -4887,7 +4887,7 @@ static inline const char *forest_display (const WIN_t *q, int idx) { const char *which = (CHKw(q, Show_CMDLIN)) ? *p->cmdline : p->cmd; int level = p->pad_3; -#ifdef TREE_FOCUS_X +#ifdef FOCUS_TREE_X if (q->focus_pid) { if (idx >= q->focus_beg && idx < q->focus_end) level -= q->focus_lvl; @@ -4928,7 +4928,7 @@ static void forest_excluded (WIN_t *q) { if (i == Frame_maxtask) q->focus_pid = q->begtask = 0; else { -#ifdef TREE_FOCUS_X +#ifdef FOCUS_TREE_X q->focus_lvl = level; #endif while (i+1 < Frame_maxtask && q->ppt[i+1]->pad_3 > level) @@ -4939,6 +4939,15 @@ static void forest_excluded (WIN_t *q) { q->begtask = q->focus_beg; q->begnext = 0; // as 'mkVIZoff' but in any window } +#ifdef FOCUS_HARD_Y + // if some task 'above' us ended, try to maintain focus + // ( but allow scrolling when there are many children ) + if (q->begtask > q->focus_beg + && (Screen_rows > (q->focus_end - q->focus_beg))) { + q->begtask = q->focus_beg; + q->begnext = 0; // as 'mkVIZoff' but in any window + } +#endif } } // end: forest_excluded diff --git a/top/top.h b/top/top.h index 3143d8e6..44c68224 100644 --- a/top/top.h +++ b/top/top.h @@ -33,6 +33,8 @@ //#define CASEUP_SUFIX /* show time/mem/cnts suffix in upper case */ //#define CPU_ZEROTICS /* tolerate few tics when cpu off vs. idle */ //#define EQUCOLHDRYES /* yes, equalize the column header lengths */ +//#define FOCUS_HARD_Y /* 'F' will avoid topmost task distortions */ +//#define FOCUS_TREE_X /* 'F' resets forest view indentation to 0 */ //#define GETOPTFIX_NO /* do not address getopt_long deficiencies */ //#define INSP_JUSTNOT /* do not smooth unprintable right margins */ //#define INSP_OFFDEMO /* disable demo screens, issue msg instead */ @@ -61,7 +63,6 @@ //#define TOG4_NOTRUNC /* ensure no truncation for 2 abreast mode */ //#define TOG4_OFF_MEM /* don't show two abreast memory statistic */ //#define TOG4_OFF_SEP /* don't show two abreast visual separator */ -//#define TREE_FOCUS_X /* 'F' resets forest view indentation to 0 */ //#define TREE_NORESET /* sort keys should not force 'V' view off */ //#define TREE_SCANALL /* rescan array w/ forest view, avoid sort */ //#define TREE_VALTMRK /* use an indented '+' with collapsed pids */ @@ -447,7 +448,7 @@ 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 +#ifdef FOCUS_TREE_X int focus_lvl; // the indentation level of parent task #endif proc_t **ppt; // this window's proc_t ptr array