diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-30 23:45:00 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2021-01-31 21:44:00 +0100 |
commit | 06b1674aa6202a91caf879fa4b0dae1244bf48b1 (patch) | |
tree | 87109d0d55c6c4e028d95fa0ec4e0c531bb70268 /ProcessList.c | |
parent | 51e79ddc07c0b3e070b5fe395703ce7ffe1878b9 (diff) |
Improve handling when selected last process entry
If the last process entry is selected and the process dies, stay at the
end of the list and do not jump to the start.
Also if the last entry is selected keep, after rebuilding the process
list due to a new scan, the last entry selected.
Diffstat (limited to 'ProcessList.c')
-rw-r--r-- | ProcessList.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ProcessList.c b/ProcessList.c index f434654c..5e6e917b 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -499,10 +499,12 @@ void ProcessList_rebuildPanel(ProcessList* this) { int currPos = Panel_getSelectedIndex(this->panel); int currScrollV = this->panel->scrollV; + int currSize = Panel_size(this->panel); Panel_prune(this->panel); int size = ProcessList_size(this); int idx = 0; + for (int i = 0; i < size; i++) { Process* p = ProcessList_get(this, i); @@ -513,12 +515,23 @@ void ProcessList_rebuildPanel(ProcessList* this) { continue; Panel_set(this->panel, idx, (Object*)p); - if ((this->following == -1 && idx == currPos) || (this->following != -1 && p->pid == this->following)) { + + if (this->following != -1 && p->pid == this->following) { Panel_setSelected(this->panel, idx); this->panel->scrollV = currScrollV; } idx++; } + + if (this->following == -1) { + /* If the last item was selected, keep the new last item selected */ + if (currPos == currSize - 1) + Panel_setSelected(this->panel, Panel_size(this->panel) - 1); + else + Panel_setSelected(this->panel, currPos); + + this->panel->scrollV = currScrollV; + } } Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor) { |