From: Jim Warner Date: Sat, 19 Mar 2022 05:00:00 +0000 (-0500) Subject: top: fix initial cursor position for fields management X-Git-Tag: v4.0.0~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a5f3f7b265548580df1804b9d64c97b28a1edad;p=procps-ng top: fix initial cursor position for fields management 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 --- diff --git a/top/top.c b/top/top.c index 2fcd1e13..d8889bbc 100644 --- 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; diff --git a/top/top.h b/top/top.h index 1c05a7a7..5e499d92 100644 --- 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)