summaryrefslogtreecommitdiffstats
path: root/Action.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-02-05 14:12:49 +0100
committerChristian Göttsche <cgzones@googlemail.com>2021-02-05 14:12:49 +0100
commitfd4e6b432bcc0d6bac1a15a2ea492b4a540b75a1 (patch)
tree559e4dde1887a4f75b10309e2eddbf6843497ef0 /Action.c
parentfd1ad863dca36da7166d9767218f5382074de4d2 (diff)
Use MainPanel type in State struct
The State struct holds a pointer to the main process panel. Use the distinct MainPanel type, to improve maintainability regrading its usage. This avoids usages of down-casts from Panel to MainPanel, only up-casts from MainPanel to Panel are now required.
Diffstat (limited to 'Action.c')
-rw-r--r--Action.c72
1 files changed, 35 insertions, 37 deletions
diff --git a/Action.c b/Action.c
index 4efb7e3d..0ca9a8ba 100644
--- a/Action.c
+++ b/Action.c
@@ -41,18 +41,18 @@ in the source distribution for its full text.
Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) {
- Panel* panel = st->panel;
+ MainPanel* mainPanel = st->mainPanel;
Header* header = st->header;
- int y = panel->y;
+ int y = ((Panel*)mainPanel)->y;
ScreenManager* scr = ScreenManager_new(header, st->settings, st, false);
scr->allowFocusChange = false;
ScreenManager_add(scr, list, x - 1);
- ScreenManager_add(scr, panel, -1);
+ ScreenManager_add(scr, (Panel*)mainPanel, -1);
Panel* panelFocus;
int ch;
bool unfollow = false;
- int pid = followProcess ? MainPanel_selectedPid((MainPanel*)panel) : -1;
+ int pid = followProcess ? MainPanel_selectedPid(mainPanel) : -1;
if (followProcess && header->pl->following == -1) {
header->pl->following = pid;
unfollow = true;
@@ -62,11 +62,11 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
header->pl->following = -1;
}
ScreenManager_delete(scr);
- Panel_move(panel, 0, y);
- Panel_resize(panel, COLS, LINES - y - 1);
+ Panel_move((Panel*)mainPanel, 0, y);
+ Panel_resize((Panel*)mainPanel, COLS, LINES - y - 1);
if (panelFocus == list && ch == 13) {
if (followProcess) {
- const Process* selected = (const Process*)Panel_getSelected(panel);
+ const Process* selected = (const Process*)Panel_getSelected((Panel*)mainPanel);
if (selected && selected->pid == pid)
return Panel_getSelected(list);
@@ -235,25 +235,25 @@ static Htop_Reaction actionToggleTreeView(State* st) {
}
static Htop_Reaction actionIncFilter(State* st) {
- IncSet* inc = ((MainPanel*)st->panel)->inc;
- IncSet_activate(inc, INC_FILTER, st->panel);
+ IncSet* inc = (st->mainPanel)->inc;
+ IncSet_activate(inc, INC_FILTER, (Panel*)st->mainPanel);
st->pl->incFilter = IncSet_filter(inc);
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionIncSearch(State* st) {
- IncSet_reset(((MainPanel*)st->panel)->inc, INC_SEARCH);
- IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
+ IncSet_reset(st->mainPanel->inc, INC_SEARCH);
+ IncSet_activate(st->mainPanel->inc, INC_SEARCH, (Panel*)st->mainPanel);
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionHigherPriority(State* st) {
- bool changed = changePriority((MainPanel*)st->panel, -1);
+ bool changed = changePriority(st->mainPanel, -1);
return changed ? HTOP_REFRESH : HTOP_OK;
}
static Htop_Reaction actionLowerPriority(State* st) {
- bool changed = changePriority((MainPanel*)st->panel, 1);
+ bool changed = changePriority(st->mainPanel, 1);
return changed ? HTOP_REFRESH : HTOP_OK;
}
@@ -265,7 +265,7 @@ static Htop_Reaction actionInvertSortOrder(State* st) {
}
static Htop_Reaction actionExpandOrCollapse(State* st) {
- bool changed = expandCollapse(st->panel);
+ bool changed = expandCollapse((Panel*)st->mainPanel);
return changed ? HTOP_RECALCULATE : HTOP_OK;
}
@@ -273,7 +273,7 @@ static Htop_Reaction actionCollapseIntoParent(State* st) {
if (!st->settings->treeView) {
return HTOP_OK;
}
- bool changed = collapseIntoParent(st->panel);
+ bool changed = collapseIntoParent((Panel*)st->mainPanel);
return changed ? HTOP_RECALCULATE : HTOP_OK;
}
@@ -290,9 +290,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
return HTOP_OK;
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY))
- Panel* panel = st->panel;
-
- const Process* p = (const Process*) Panel_getSelected(panel);
+ const Process* p = (const Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -308,7 +306,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
const 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);
+ bool ok = MainPanel_foreachProcess(st->mainPanel, Affinity_set, (Arg) { .v = affinity2 }, NULL);
if (!ok)
beep();
Affinity_delete(affinity2);
@@ -323,10 +321,10 @@ static Htop_Reaction actionKill(State* st) {
const ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true);
if (sgn) {
if (sgn->key != 0) {
- Panel_setHeader(st->panel, "Sending...");
- Panel_draw(st->panel, false, true, true, State_hideFunctionBar(st));
+ Panel_setHeader((Panel*)st->mainPanel, "Sending...");
+ Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
refresh();
- MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
+ MainPanel_foreachProcess(st->mainPanel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
napms(500);
}
}
@@ -354,21 +352,21 @@ static Htop_Reaction actionFilterByUser(State* st) {
}
Htop_Reaction Action_follow(State* st) {
- st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
- Panel_setSelectionColor(st->panel, PANEL_SELECTION_FOLLOW);
+ st->pl->following = MainPanel_selectedPid(st->mainPanel);
+ Panel_setSelectionColor((Panel*)st->mainPanel, PANEL_SELECTION_FOLLOW);
return HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionSetup(State* st) {
Action_runSetup(st);
int headerHeight = Header_calculateHeight(st->header);
- Panel_move(st->panel, 0, headerHeight);
- Panel_resize(st->panel, COLS, LINES-headerHeight-1);
+ Panel_move((Panel*)st->mainPanel, 0, headerHeight);
+ Panel_resize((Panel*)st->mainPanel, COLS, LINES-headerHeight-1);
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}
static Htop_Reaction actionLsof(State* st) {
- const Process* p = (Process*) Panel_getSelected(st->panel);
+ const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -381,7 +379,7 @@ static Htop_Reaction actionLsof(State* st) {
}
static Htop_Reaction actionShowLocks(State* st) {
- const Process* p = (Process*) Panel_getSelected(st->panel);
+ const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p) return HTOP_OK;
ProcessLocksScreen* pls = ProcessLocksScreen_new(p);
InfoScreen_run((InfoScreen*)pls);
@@ -392,7 +390,7 @@ static Htop_Reaction actionShowLocks(State* st) {
}
static Htop_Reaction actionStrace(State* st) {
- const Process* p = (Process*) Panel_getSelected(st->panel);
+ const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -408,12 +406,12 @@ static Htop_Reaction actionStrace(State* st) {
}
static Htop_Reaction actionTag(State* st) {
- Process* p = (Process*) Panel_getSelected(st->panel);
+ Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
Process_toggleTag(p);
- Panel_onKey(st->panel, KEY_DOWN);
+ Panel_onKey((Panel*)st->mainPanel, KEY_DOWN);
return HTOP_OK;
}
@@ -582,24 +580,24 @@ static Htop_Reaction actionHelp(State* st) {
}
static Htop_Reaction actionUntagAll(State* st) {
- for (int i = 0; i < Panel_size(st->panel); i++) {
- Process* p = (Process*) Panel_get(st->panel, i);
+ for (int i = 0; i < Panel_size((Panel*)st->mainPanel); i++) {
+ Process* p = (Process*) Panel_get((Panel*)st->mainPanel, i);
p->tag = false;
}
return HTOP_REFRESH;
}
static Htop_Reaction actionTagAllChildren(State* st) {
- Process* p = (Process*) Panel_getSelected(st->panel);
+ Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
- tagAllChildren(st->panel, p);
+ tagAllChildren((Panel*)st->mainPanel, p);
return HTOP_OK;
}
static Htop_Reaction actionShowEnvScreen(State* st) {
- Process* p = (Process*) Panel_getSelected(st->panel);
+ Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -612,7 +610,7 @@ static Htop_Reaction actionShowEnvScreen(State* st) {
}
static Htop_Reaction actionShowCommandScreen(State* st) {
- Process* p = (Process*) Panel_getSelected(st->panel);
+ Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;

© 2014-2024 Faster IT GmbH | imprint | privacy policy