From da60309fc9ed6f75dfa84d6cbfe58c703e2944f3 Mon Sep 17 00:00:00 2001 From: wangqr Date: Sun, 11 Nov 2018 00:48:08 -0500 Subject: [PATCH] Don't follow process when selecting non-process-specific options Disable the follow process logic in Action_pickFromVector(), when selecting sort order or user filter, since they don't apply on specific process. Fix #856 --- Action.c | 27 ++++++++++++++++----------- Action.h | 2 +- linux/Platform.c | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Action.c b/Action.c index 9a7c3c56..6c9a6b9a 100644 --- a/Action.c +++ b/Action.c @@ -62,7 +62,7 @@ typedef struct State_ { }*/ -Object* Action_pickFromVector(State* st, Panel* list, int x) { +Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; Header* header = st->header; Settings* settings = st->settings; @@ -75,8 +75,8 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel* panelFocus; int ch; bool unfollow = false; - int pid = MainPanel_selectedPid((MainPanel*)panel); - if (header->pl->following == -1) { + int pid = followProcess ? MainPanel_selectedPid((MainPanel*)panel) : -1; + if (followProcess && header->pl->following == -1) { header->pl->following = pid; unfollow = true; } @@ -88,11 +88,16 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel_move(panel, 0, y); Panel_resize(panel, COLS, LINES-y-1); if (panelFocus == list && ch == 13) { - Process* selected = (Process*)Panel_getSelected(panel); - if (selected && selected->pid == pid) + if (followProcess) { + Process* selected = (Process*)Panel_getSelected(panel); + if (selected && selected->pid == pid) + return Panel_getSelected(list); + else + beep(); + } else { return Panel_getSelected(list); - else - beep(); + } + } return NULL; } @@ -189,7 +194,7 @@ static Htop_Reaction sortBy(State* st) { Panel_setSelected(sortPanel, i); free(name); } - ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15); + ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false); if (field) { reaction |= Action_setSortKey(st->settings, field->key); } @@ -305,7 +310,7 @@ static Htop_Reaction actionSetAffinity(State* st) { Panel* affinityPanel = AffinityPanel_new(st->pl, affinity); Affinity_delete(affinity); - void* set = Action_pickFromVector(st, affinityPanel, 15); + void* set = Action_pickFromVector(st, affinityPanel, 15, true); if (set) { Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl); bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL); @@ -319,7 +324,7 @@ static Htop_Reaction actionSetAffinity(State* st) { static Htop_Reaction actionKill(State* st) { Panel* signalsPanel = (Panel*) SignalsPanel_new(); - ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15); + ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true); if (sgn) { if (sgn->key != 0) { Panel_setHeader(st->panel, "Sending..."); @@ -340,7 +345,7 @@ static Htop_Reaction actionFilterByUser(State* st) { Vector_insertionSort(usersPanel->items); ListItem* allUsers = ListItem_new("All users", -1); Panel_insert(usersPanel, 0, (Object*) allUsers); - ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20); + ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false); if (picked) { if (picked == allUsers) { st->pl->userId = -1; diff --git a/Action.h b/Action.h index 1dfdcb47..144a44fd 100644 --- a/Action.h +++ b/Action.h @@ -39,7 +39,7 @@ typedef struct State_ { } State; -Object* Action_pickFromVector(State* st, Panel* list, int x); +Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); // ---------------------------------------- diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74..13dec277 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -93,7 +93,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { if (!p) return HTOP_OK; IOPriority ioprio = p->ioPriority; Panel* ioprioPanel = IOPriorityPanel_new(ioprio); - void* set = Action_pickFromVector(st, ioprioPanel, 21); + void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel); bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL);