ProcessList: sort before panel rebuild if needed

This commit is contained in:
Denis Lisov 2021-12-16 01:33:32 +03:00 committed by BenBE
parent 4aeb146ce8
commit a3a7958721
4 changed files with 9 additions and 5 deletions

View File

@ -189,8 +189,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
} }
Object_delete(sortPanel); Object_delete(sortPanel);
if (st->pauseProcessUpdate) st->pl->needsSort = true;
ProcessList_sort(st->pl);
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
} }
@ -281,8 +280,7 @@ static Htop_Reaction actionLowerPriority(State* st) {
static Htop_Reaction actionInvertSortOrder(State* st) { static Htop_Reaction actionInvertSortOrder(State* st) {
ScreenSettings_invertSortOrder(st->settings->ss); ScreenSettings_invertSortOrder(st->settings->ss);
if (st->pauseProcessUpdate) st->pl->needsSort = true;
ProcessList_sort(st->pl);
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING; return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
} }

View File

@ -27,6 +27,7 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users
this->processTable = Hashtable_new(200, false); this->processTable = Hashtable_new(200, false);
this->displayTreeSet = Hashtable_new(200, false); this->displayTreeSet = Hashtable_new(200, false);
this->draftingTreeSet = Hashtable_new(200, false); this->draftingTreeSet = Hashtable_new(200, false);
this->needsSort = true;
this->usersTable = usersTable; this->usersTable = usersTable;
this->pidMatchList = pidMatchList; this->pidMatchList = pidMatchList;
@ -496,6 +497,7 @@ void ProcessList_sort(ProcessList* this) {
} else { } else {
Vector_insertionSort(this->processes); Vector_insertionSort(this->processes);
} }
this->needsSort = false;
} }
ProcessField ProcessList_keyAt(const ProcessList* this, int at) { ProcessField ProcessList_keyAt(const ProcessList* this, int at) {
@ -531,6 +533,9 @@ void ProcessList_collapseAllBranches(ProcessList* this) {
} }
void ProcessList_rebuildPanel(ProcessList* this) { void ProcessList_rebuildPanel(ProcessList* this) {
if (this->needsSort)
ProcessList_sort(this);
const char* incFilter = this->incFilter; const char* incFilter = this->incFilter;
const int currPos = Panel_getSelectedIndex(this->panel); const int currPos = Panel_getSelectedIndex(this->panel);

View File

@ -50,6 +50,7 @@ typedef struct ProcessList_ {
Hashtable* displayTreeSet; Hashtable* displayTreeSet;
Hashtable* draftingTreeSet; Hashtable* draftingTreeSet;
bool needsSort;
Hashtable* dynamicMeters; /* runtime-discovered meters */ Hashtable* dynamicMeters; /* runtime-discovered meters */
Hashtable* dynamicColumns; /* runtime-discovered Columns */ Hashtable* dynamicColumns; /* runtime-discovered Columns */

View File

@ -126,7 +126,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
// always update header, especially to avoid gaps in graph meters // always update header, especially to avoid gaps in graph meters
Header_updateData(this->header); Header_updateData(this->header);
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) { if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) {
ProcessList_sort(pl); pl->needsSort = true;
*sortTimeout = 1; *sortTimeout = 1;
} }
// force redraw if the number of UID digits was changed // force redraw if the number of UID digits was changed