From df568a576f7b44ac5a2b9b7222c7f39d9932f626 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Wed, 11 Apr 2018 01:26:28 +0200 Subject: Imported Upstream version 2.2.0 --- Action.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'Action.c') diff --git a/Action.c b/Action.c index a6394ac..518d103 100644 --- a/Action.c +++ b/Action.c @@ -115,7 +115,7 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis static bool changePriority(MainPanel* panel, int delta) { bool anyTagged; - bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged); + bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged); if (!ok) beep(); return anyTagged; @@ -155,6 +155,21 @@ static bool expandCollapse(Panel* panel) { return true; } +static bool collapseIntoParent(Panel* panel) { + Process* p = (Process*) Panel_getSelected(panel); + if (!p) return false; + pid_t ppid = Process_getParentPid(p); + for (int i = 0; i < Panel_size(panel); i++) { + Process* q = (Process*) Panel_get(panel, i); + if (q->pid == ppid) { + q->showChildren = false; + Panel_setSelected(panel, i); + return true; + } + } + return false; +} + Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) { settings->sortKey = sortKey; settings->direction = 1; @@ -185,6 +200,7 @@ static Htop_Reaction sortBy(State* st) { // ---------------------------------------- static Htop_Reaction actionResize(State* st) { + clear(); Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1); return HTOP_REDRAW_BAR; } @@ -260,6 +276,14 @@ static Htop_Reaction actionExpandOrCollapse(State* st) { return changed ? HTOP_RECALCULATE : HTOP_OK; } +static Htop_Reaction actionCollapseIntoParent(State* st) { + if (!st->settings->treeView) { + return HTOP_OK; + } + bool changed = collapseIntoParent(st->panel); + return changed ? HTOP_RECALCULATE : HTOP_OK; +} + static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) { return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st); } @@ -284,7 +308,7 @@ static Htop_Reaction actionSetAffinity(State* st) { void* set = Action_pickFromVector(st, affinityPanel, 15); if (set) { Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL); if (!ok) beep(); Affinity_delete(affinity); } @@ -301,7 +325,7 @@ static Htop_Reaction actionKill(State* st) { Panel_setHeader(st->panel, "Sending..."); Panel_draw(st->panel, true); refresh(); - MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL); + MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (Arg){ .i = sgn->key }, NULL); napms(500); } } @@ -556,6 +580,7 @@ void Action_setBindings(Htop_Action* keys) { keys['+'] = actionExpandOrCollapse; keys['='] = actionExpandOrCollapse; keys['-'] = actionExpandOrCollapse; + keys['\177'] = actionCollapseIntoParent; keys['u'] = actionFilterByUser; keys['F'] = Action_follow; keys['S'] = actionSetup; -- cgit v1.2.3