mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Embracing branches
This commit is contained in:
64
Action.c
64
Action.c
@ -65,13 +65,13 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
|
||||
Process* selected = (Process*)Panel_getSelected(panel);
|
||||
if (selected && selected->pid == pid)
|
||||
return Panel_getSelected(list);
|
||||
else
|
||||
beep();
|
||||
|
||||
beep();
|
||||
} else {
|
||||
return Panel_getSelected(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ static void Action_runSetup(State* st) {
|
||||
|
||||
static bool changePriority(MainPanel* panel, int delta) {
|
||||
bool anyTagged;
|
||||
bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged);
|
||||
bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg) { .i = delta }, &anyTagged);
|
||||
if (!ok)
|
||||
beep();
|
||||
return anyTagged;
|
||||
@ -128,14 +128,18 @@ static void tagAllChildren(Panel* panel, Process* parent) {
|
||||
|
||||
static bool expandCollapse(Panel* panel) {
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (!p) return false;
|
||||
if (!p)
|
||||
return false;
|
||||
|
||||
p->showChildren = !p->showChildren;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool collapseIntoParent(Panel* panel) {
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (!p) return false;
|
||||
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);
|
||||
@ -165,6 +169,7 @@ static Htop_Reaction sortBy(State* st) {
|
||||
Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
|
||||
if (fields[i] == st->settings->sortKey)
|
||||
Panel_setSelected(sortPanel, i);
|
||||
|
||||
free(name);
|
||||
}
|
||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false);
|
||||
@ -172,8 +177,10 @@ static Htop_Reaction sortBy(State* st) {
|
||||
reaction |= Action_setSortKey(st->settings, field->key);
|
||||
}
|
||||
Object_delete(sortPanel);
|
||||
|
||||
if (st->pauseProcessUpdate)
|
||||
ProcessList_sort(st->pl);
|
||||
|
||||
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
|
||||
@ -215,7 +222,10 @@ static Htop_Reaction actionToggleProgramPath(State* st) {
|
||||
|
||||
static Htop_Reaction actionToggleTreeView(State* st) {
|
||||
st->settings->treeView = !st->settings->treeView;
|
||||
if (st->settings->treeView) st->settings->direction = 1;
|
||||
if (st->settings->treeView) {
|
||||
st->settings->direction = 1;
|
||||
}
|
||||
|
||||
ProcessList_expandTree(st->pl);
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||
}
|
||||
@ -286,13 +296,18 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) {
|
||||
static Htop_Reaction actionSetAffinity(State* st) {
|
||||
if (st->pl->cpuCount == 1)
|
||||
return HTOP_OK;
|
||||
|
||||
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY))
|
||||
Panel* panel = st->panel;
|
||||
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
Affinity* affinity1 = Affinity_get(p, st->pl);
|
||||
if (!affinity1) return HTOP_OK;
|
||||
if (!affinity1)
|
||||
return HTOP_OK;
|
||||
|
||||
int width;
|
||||
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1, &width);
|
||||
width += 1; /* we add a gap between the panels */
|
||||
@ -301,8 +316,9 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
||||
void* set = Action_pickFromVector(st, affinityPanel, width, true);
|
||||
if (set) {
|
||||
Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg){ .v = affinity2 }, NULL);
|
||||
if (!ok) beep();
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg) { .v = affinity2 }, NULL);
|
||||
if (!ok)
|
||||
beep();
|
||||
Affinity_delete(affinity2);
|
||||
}
|
||||
Object_delete(affinityPanel);
|
||||
@ -318,7 +334,7 @@ static Htop_Reaction actionKill(State* st) {
|
||||
Panel_setHeader(st->panel, "Sending...");
|
||||
Panel_draw(st->panel, true);
|
||||
refresh();
|
||||
MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg){ .i = sgn->key }, NULL);
|
||||
MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
|
||||
napms(500);
|
||||
}
|
||||
}
|
||||
@ -362,7 +378,9 @@ static Htop_Reaction actionSetup(State* st) {
|
||||
|
||||
static Htop_Reaction actionLsof(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
OpenFilesScreen* ofs = OpenFilesScreen_new(p);
|
||||
InfoScreen_run((InfoScreen*)ofs);
|
||||
OpenFilesScreen_delete((Object*)ofs);
|
||||
@ -373,7 +391,9 @@ static Htop_Reaction actionLsof(State* st) {
|
||||
|
||||
static Htop_Reaction actionStrace(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
TraceScreen* ts = TraceScreen_new(p);
|
||||
bool ok = TraceScreen_forkTracer(ts);
|
||||
if (ok) {
|
||||
@ -387,7 +407,9 @@ static Htop_Reaction actionStrace(State* st) {
|
||||
|
||||
static Htop_Reaction actionTag(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
Process_toggleTag(p);
|
||||
Panel_onKey(st->panel, KEY_DOWN);
|
||||
return HTOP_OK;
|
||||
@ -555,14 +577,18 @@ static Htop_Reaction actionUntagAll(State* st) {
|
||||
|
||||
static Htop_Reaction actionTagAllChildren(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
tagAllChildren(st->panel, p);
|
||||
return HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionShowEnvScreen(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
EnvScreen* es = EnvScreen_new(p);
|
||||
InfoScreen_run((InfoScreen*)es);
|
||||
EnvScreen_delete((Object*)es);
|
||||
@ -573,7 +599,9 @@ static Htop_Reaction actionShowEnvScreen(State* st) {
|
||||
|
||||
static Htop_Reaction actionShowCommandScreen(State* st) {
|
||||
Process* p = (Process*) Panel_getSelected(st->panel);
|
||||
if (!p) return HTOP_OK;
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
CommandScreen* cmdScr = CommandScreen_new(p);
|
||||
InfoScreen_run((InfoScreen*)cmdScr);
|
||||
CommandScreen_delete((Object*)cmdScr);
|
||||
|
Reference in New Issue
Block a user