mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-25 15:25:45 +00:00
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.
This commit is contained in:
parent
fd1ad863dc
commit
fd4e6b432b
72
Action.c
72
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;
|
||||
|
||||
|
5
Action.h
5
Action.h
@ -20,6 +20,7 @@ in the source distribution for its full text.
|
||||
#include "Settings.h"
|
||||
#include "UsersTable.h"
|
||||
|
||||
|
||||
typedef enum {
|
||||
HTOP_OK = 0x00,
|
||||
HTOP_REFRESH = 0x01,
|
||||
@ -31,11 +32,13 @@ typedef enum {
|
||||
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
|
||||
} Htop_Reaction;
|
||||
|
||||
struct MainPanel_;
|
||||
|
||||
typedef struct State_ {
|
||||
Settings* settings;
|
||||
UsersTable* ut;
|
||||
ProcessList* pl;
|
||||
Panel* panel;
|
||||
struct MainPanel_* mainPanel;
|
||||
Header* header;
|
||||
bool pauseProcessUpdate;
|
||||
bool hideProcessSelection;
|
||||
|
@ -123,7 +123,11 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_
|
||||
const int nPanels = this->panelCount;
|
||||
for (int i = 0; i < nPanels; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection), State_hideFunctionBar(this->state));
|
||||
Panel_draw(panel,
|
||||
force_redraw,
|
||||
i == focus,
|
||||
panel != (Panel*)this->state->mainPanel || !this->state->hideProcessSelection,
|
||||
State_hideFunctionBar(this->state));
|
||||
mvvline(panel->y, panel->x + panel->w, ' ', panel->h + (State_hideFunctionBar(this->state) ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
5
htop.c
5
htop.c
@ -294,9 +294,8 @@ static void millisleep(unsigned long millisec) {
|
||||
}
|
||||
|
||||
static void setCommFilter(State* state, char** commFilter) {
|
||||
MainPanel* panel = (MainPanel*)state->panel;
|
||||
ProcessList* pl = state->pl;
|
||||
IncSet* inc = panel->inc;
|
||||
IncSet* inc = state->mainPanel->inc;
|
||||
|
||||
IncSet_setFilter(inc, *commFilter);
|
||||
pl->incFilter = IncSet_filter(inc);
|
||||
@ -453,7 +452,7 @@ int main(int argc, char** argv) {
|
||||
.settings = settings,
|
||||
.ut = ut,
|
||||
.pl = pl,
|
||||
.panel = (Panel*) panel,
|
||||
.mainPanel = panel,
|
||||
.header = header,
|
||||
.pauseProcessUpdate = false,
|
||||
.hideProcessSelection = false,
|
||||
|
@ -130,9 +130,7 @@ void Platform_done(void) {
|
||||
}
|
||||
|
||||
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||
Panel* panel = st->panel;
|
||||
|
||||
const LinuxProcess* p = (const LinuxProcess*) Panel_getSelected(panel);
|
||||
const LinuxProcess* p = (const LinuxProcess*) Panel_getSelected((Panel*)st->mainPanel);
|
||||
if (!p)
|
||||
return HTOP_OK;
|
||||
|
||||
@ -141,7 +139,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||
const void* set = Action_pickFromVector(st, ioprioPanel, 21, true);
|
||||
if (set) {
|
||||
IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel);
|
||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL);
|
||||
bool ok = MainPanel_foreachProcess(st->mainPanel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL);
|
||||
if (!ok) {
|
||||
beep();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user