]> granicus.if.org Git - procps-ng/commitdiff
top: fix initial cursor position for fields management
authorJim Warner <james.warner@comcast.net>
Sat, 19 Mar 2022 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Mon, 21 Mar 2022 10:13:46 +0000 (21:13 +1100)
When we transitioned from 'char' based fields to 'int'
proper initial cursor positioning (highlight) was lost
in the 'fields_utility' function. The highlight should
appear on the current sort field. Instead, however, it
was often positioned on the first field listed or some
completely different field other than that sort field.

So this patch will restore the master branch behavior.

[ and on the assumption that a sort field is visible ]
[ we will search first for a field with the 'on' bit ]

Reference(s):
. Mar, 2022 - trade 'char' for 'int'
commit 46aa96e438435628810b33d20cb1c14dc33dd84f

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c
top/top.h

index 2fcd1e1305f1e7ffd7859c5a1070d6b64891ece3..d8889bbc4954831f21285334f211bd3b323bfc06 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -2307,8 +2307,8 @@ static void fields_utility (void) {
 #endif
  #define swapEM  { int c; unSCRL; c = w->rc.fieldscur[i]; \
        w->rc.fieldscur[i] = *p; *p = c; p = &w->rc.fieldscur[i]; }
- #define spewFI  { int *t; f = w->rc.sortindx; t = msch(w->rc.fieldscur, f + FLD_OFFSET, EU_MAXPFLGS); \
-       if (!t) t = msch(w->rc.fieldscur, (f + FLD_OFFSET) | 0x01, EU_MAXPFLGS); \
+ #define spewFI  { int *t; f = w->rc.sortindx; t = msch(w->rc.fieldscur, ENUcvt(f, ENUon), EU_MAXPFLGS); \
+       if (!t) t = msch(w->rc.fieldscur, ENUcvt(f, ENUoff), EU_MAXPFLGS); \
        i = (t) ? (int)(t - w->rc.fieldscur) : 0; }
    WIN_t *w = Curwin;             // avoid gcc bloat with a local copy
    const char *h = NULL;
index 1c05a7a74791d6ca21048dbffd3b1dedb3eb7b96..5e499d92e4efd3a5e9f9079fab11f7fad69bd233 100644 (file)
--- a/top/top.h
+++ b/top/top.h
@@ -404,6 +404,9 @@ typedef struct WIN_t {
 #define FLDviz(q,i)  ( (q)->rc.fieldscur[i] &  0x01 )
 #define ENUviz(w,E)  ( NULL != msch((w)->procflgs, E, w->maxpflgs) )
 #define ENUpos(w,E)  ( (int)(msch((w)->pflgsall, E, (w)->totpflgs) - (w)->pflgsall) )
+#define ENUcvt(E,x)  ( (int)(((E + FLD_OFFSET) << 1) | x) )
+#define ENUon        0x01
+#define ENUoff       0x00
 
         // Support for variable width columns (and potentially scrolling too)
 #define VARcol(E)    (-1 == Fieldstab[E].width)