summaryrefslogtreecommitdiffstats
path: root/Settings.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-12-18 11:03:31 -0300
committerBenBE <BenBE@geshi.org>2020-12-19 16:02:34 +0100
commit2327260ee888146beab3da66507c7744334a6973 (patch)
tree06b3919321515cc4fdea7de0b5ead4744f3600ec /Settings.c
parente8c6994f40c9c69089e9f80abb2f895d2e077c7e (diff)
Separate tree and list sort orders
Implements the suggestion from https://github.com/htop-dev/htop/issues/399#issuecomment-747861013 Thanks to the refactors from 0bd5c8fb5da and 6393baa74e5, this was really easy and clean to do. It maintains the "Tree view always by PID" option in the Settings, which results in some specific behaviors such as "clicking on the column header to exit tree view" and "picking a new sort order to exit tree view", for the sake of the muscle memory of long time htop users. :)
Diffstat (limited to 'Settings.c')
-rw-r--r--Settings.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/Settings.c b/Settings.c
index 3b629a87..9122955d 100644
--- a/Settings.c
+++ b/Settings.c
@@ -137,8 +137,13 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
} else if (String_eq(option[0], "sort_key")) {
// This "+1" is for compatibility with the older enum format.
this->sortKey = atoi(option[1]) + 1;
+ } else if (String_eq(option[0], "tree_sort_key")) {
+ // This "+1" is for compatibility with the older enum format.
+ this->treeSortKey = atoi(option[1]) + 1;
} else if (String_eq(option[0], "sort_direction")) {
this->direction = atoi(option[1]);
+ } else if (String_eq(option[0], "tree_sort_direction")) {
+ this->treeDirection = 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")) {
@@ -275,6 +280,8 @@ bool Settings_write(Settings* this) {
// This "-1" is for compatibility with the older enum format.
fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1);
fprintf(fd, "sort_direction=%d\n", (int) this->direction);
+ fprintf(fd, "tree_sort_key=%d\n", (int) this->treeSortKey - 1);
+ fprintf(fd, "tree_sort_direction=%d\n", (int) this->treeDirection);
fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads);
fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads);
fprintf(fd, "shadow_other_users=%d\n", (int) this->shadowOtherUsers);
@@ -319,7 +326,9 @@ Settings* Settings_new(int initialCpuCount) {
Settings* this = xCalloc(1, sizeof(Settings));
this->sortKey = PERCENT_CPU;
+ this->treeSortKey = PID;
this->direction = 1;
+ this->treeDirection = 1;
this->shadowOtherUsers = false;
this->showThreadNames = false;
this->hideKernelThreads = false;
@@ -430,9 +439,17 @@ Settings* Settings_new(int initialCpuCount) {
}
void Settings_invertSortOrder(Settings* this) {
- if (this->direction == 1) {
- this->direction = -1;
- } else {
+ int* attr = (this->treeView) ? &(this->treeDirection) : &(this->direction);
+ *attr = (*attr == 1) ? -1 : 1;
+}
+
+void Settings_setSortKey(Settings* this, ProcessField sortKey) {
+ if (this->treeViewAlwaysByPID || !this->treeView) {
+ this->sortKey = sortKey;
this->direction = 1;
+ this->treeView = false;
+ } else {
+ this->treeSortKey = sortKey;
+ this->treeDirection = 1;
}
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy