]> granicus.if.org Git - procps-ng/commitdiff
top: TREE_FOCUS_X works properly with multiple windows
authorJim Warner <james.warner@comcast.net>
Wed, 28 Jul 2021 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Sun, 1 Aug 2021 10:36:55 +0000 (20:36 +1000)
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 <james.warner@comcast.net>
top/top.c
top/top.h

index ad0b509bd6ba0f27adb4129fcf7764d6462f8e38..81fa5a9e049ac3ce3a18d4321fffec83f03ad9b0 100644 (file)
--- 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
index 2bff534a7773da92134d209a74e076feee0f9c6d..4d5f308c186102d846d176ae60e1b01ee8acb2e9 100644 (file)
--- 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