diff options
-rw-r--r-- | Action.c | 3 | ||||
-rw-r--r-- | DisplayOptionsPanel.c | 1 | ||||
-rw-r--r-- | MainPanel.c | 5 | ||||
-rw-r--r-- | Process.c | 7 | ||||
-rw-r--r-- | ProcessList.c | 16 | ||||
-rw-r--r-- | Settings.c | 3 | ||||
-rw-r--r-- | Settings.h | 1 |
7 files changed, 30 insertions, 6 deletions
@@ -160,6 +160,9 @@ static bool collapseIntoParent(Panel* panel) { Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) { settings->sortKey = sortKey; settings->direction = 1; + if (settings->treeViewAlwaysByPID) { + settings->treeView = false; + } return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING; } diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index ed373190..49beb5a6 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -97,6 +97,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_setHeader(super, "Display options"); 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("Hide kernel threads", &(settings->hideKernelThreads))); Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads))); diff --git a/MainPanel.c b/MainPanel.c index 6c0c9fd1..f2b71e68 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -25,7 +25,7 @@ static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filt void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { 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) { @@ -65,6 +65,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { } else { reaction |= Action_setSortKey(settings, field); } + if (settings->treeViewAlwaysByPID) { + settings->treeView = false; + } reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS; result = HANDLED; } else if (ch != ERR && this->inc->active) { @@ -505,7 +505,12 @@ long Process_compare(const void* v1, const void* 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_NORM_CPU: return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu); diff --git a/ProcessList.c b/ProcessList.c index 78ec2b64..54b69184 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -82,7 +82,8 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) { void ProcessList_printHeader(ProcessList* this, RichString* 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++) { const char* field = Process_fields[fields[i]].title; @@ -90,10 +91,17 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) { field = "- "; } - int color = (this->settings->sortKey == fields[i]) ? - CRT_colors[PANEL_SELECTION_FOCUS] : CRT_colors[PANEL_HEADER_FOCUS]; + int color; + 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); - if (COMM == fields[i] && this->settings->showMergedCommand) { + if (COMM == fields[i] && settings->showMergedCommand) { 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]); } else if (String_eq(option[0], "tree_view")) { 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")) { this->hideKernelThreads = atoi(option[1]); } 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, "show_merged_command=%d\n", (int) this->showMergedCommand); 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, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime); fprintf(fd, "cpu_count_from_one=%d\n", (int) this->countCPUsFromOne); @@ -44,6 +44,7 @@ typedef struct Settings_ { bool degreeFahrenheit; #endif bool treeView; + bool treeViewAlwaysByPID; bool showProgramPath; bool shadowOtherUsers; bool showThreadNames; |