mirror of https://github.com/xzeldon/htop.git
Add "Tree view is always sorted by PID" option to mimic htop 2 behavior
This commit is contained in:
parent
3d1703f16f
commit
e8c6994f40
3
Action.c
3
Action.c
|
@ -160,6 +160,9 @@ static bool collapseIntoParent(Panel* panel) {
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||||
settings->sortKey = sortKey;
|
settings->sortKey = sortKey;
|
||||||
settings->direction = 1;
|
settings->direction = 1;
|
||||||
|
if (settings->treeViewAlwaysByPID) {
|
||||||
|
settings->treeView = false;
|
||||||
|
}
|
||||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||||
|
|
||||||
Panel_setHeader(super, "Display options");
|
Panel_setHeader(super, "Display options");
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
|
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
|
||||||
|
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->treeViewAlwaysByPID)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
|
Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));
|
Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));
|
||||||
Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads)));
|
Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads)));
|
||||||
|
|
|
@ -25,7 +25,7 @@ static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filt
|
||||||
|
|
||||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||||
FunctionBar_setLabel(bar, KEY_F(5), mode ? "Sorted" : "Tree ");
|
FunctionBar_setLabel(bar, KEY_F(5), mode ? "List " : "Tree ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanel_pidSearch(MainPanel* this, int ch) {
|
void MainPanel_pidSearch(MainPanel* this, int ch) {
|
||||||
|
@ -65,6 +65,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||||
} else {
|
} else {
|
||||||
reaction |= Action_setSortKey(settings, field);
|
reaction |= Action_setSortKey(settings, field);
|
||||||
}
|
}
|
||||||
|
if (settings->treeViewAlwaysByPID) {
|
||||||
|
settings->treeView = false;
|
||||||
|
}
|
||||||
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
} else if (ch != ERR && this->inc->active) {
|
} else if (ch != ERR && this->inc->active) {
|
||||||
|
|
|
@ -505,7 +505,12 @@ long Process_compare(const void* v1, const void* v2) {
|
||||||
p1 = (const Process*)v2;
|
p1 = (const Process*)v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (settings->sortKey) {
|
ProcessField key = settings->sortKey;
|
||||||
|
if (settings->treeView && settings->treeViewAlwaysByPID) {
|
||||||
|
key = PID;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
case PERCENT_CPU:
|
case PERCENT_CPU:
|
||||||
case PERCENT_NORM_CPU:
|
case PERCENT_NORM_CPU:
|
||||||
return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu);
|
return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu);
|
||||||
|
|
|
@ -82,7 +82,8 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
||||||
RichString_prune(header);
|
RichString_prune(header);
|
||||||
|
|
||||||
const ProcessField* fields = this->settings->fields;
|
const Settings* settings = this->settings;
|
||||||
|
const ProcessField* fields = settings->fields;
|
||||||
|
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
const char* field = Process_fields[fields[i]].title;
|
const char* field = Process_fields[fields[i]].title;
|
||||||
|
@ -90,10 +91,17 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
||||||
field = "- ";
|
field = "- ";
|
||||||
}
|
}
|
||||||
|
|
||||||
int color = (this->settings->sortKey == fields[i]) ?
|
int color;
|
||||||
CRT_colors[PANEL_SELECTION_FOCUS] : CRT_colors[PANEL_HEADER_FOCUS];
|
if (settings->treeView && settings->treeViewAlwaysByPID) {
|
||||||
|
color = CRT_colors[PANEL_HEADER_FOCUS];
|
||||||
|
} else if (settings->sortKey == fields[i]) {
|
||||||
|
color = CRT_colors[PANEL_SELECTION_FOCUS];
|
||||||
|
} else {
|
||||||
|
color = CRT_colors[PANEL_HEADER_FOCUS];
|
||||||
|
}
|
||||||
|
|
||||||
RichString_appendWide(header, color, field);
|
RichString_appendWide(header, color, field);
|
||||||
if (COMM == fields[i] && this->settings->showMergedCommand) {
|
if (COMM == fields[i] && settings->showMergedCommand) {
|
||||||
RichString_appendAscii(header, color, "(merged)");
|
RichString_appendAscii(header, color, "(merged)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,8 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
|
||||||
this->direction = atoi(option[1]);
|
this->direction = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "tree_view")) {
|
} else if (String_eq(option[0], "tree_view")) {
|
||||||
this->treeView = atoi(option[1]);
|
this->treeView = atoi(option[1]);
|
||||||
|
} else if (String_eq(option[0], "tree_view_always_by_pid")) {
|
||||||
|
this->treeViewAlwaysByPID = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
||||||
this->hideKernelThreads = atoi(option[1]);
|
this->hideKernelThreads = atoi(option[1]);
|
||||||
} else if (String_eq(option[0], "hide_userland_threads")) {
|
} else if (String_eq(option[0], "hide_userland_threads")) {
|
||||||
|
@ -287,6 +289,7 @@ bool Settings_write(Settings* this) {
|
||||||
fprintf(fd, "strip_exe_from_cmdline=%d\n", (int) this->stripExeFromCmdline);
|
fprintf(fd, "strip_exe_from_cmdline=%d\n", (int) this->stripExeFromCmdline);
|
||||||
fprintf(fd, "show_merged_command=%d\n", (int) this->showMergedCommand);
|
fprintf(fd, "show_merged_command=%d\n", (int) this->showMergedCommand);
|
||||||
fprintf(fd, "tree_view=%d\n", (int) this->treeView);
|
fprintf(fd, "tree_view=%d\n", (int) this->treeView);
|
||||||
|
fprintf(fd, "tree_view_always_by_pid=%d\n", (int) this->treeViewAlwaysByPID);
|
||||||
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
||||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
||||||
fprintf(fd, "cpu_count_from_one=%d\n", (int) this->countCPUsFromOne);
|
fprintf(fd, "cpu_count_from_one=%d\n", (int) this->countCPUsFromOne);
|
||||||
|
|
|
@ -44,6 +44,7 @@ typedef struct Settings_ {
|
||||||
bool degreeFahrenheit;
|
bool degreeFahrenheit;
|
||||||
#endif
|
#endif
|
||||||
bool treeView;
|
bool treeView;
|
||||||
|
bool treeViewAlwaysByPID;
|
||||||
bool showProgramPath;
|
bool showProgramPath;
|
||||||
bool shadowOtherUsers;
|
bool shadowOtherUsers;
|
||||||
bool showThreadNames;
|
bool showThreadNames;
|
||||||
|
|
Loading…
Reference in New Issue