From 06b1674aa6202a91caf879fa4b0dae1244bf48b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 30 Jan 2021 23:45:00 +0100 Subject: 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. --- ProcessList.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ProcessList.c') 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) { -- cgit v1.2.3