aboutsummaryrefslogtreecommitdiffstats
path: root/MainPanel.c
diff options
context:
space:
mode:
Diffstat (limited to 'MainPanel.c')
-rw-r--r--MainPanel.c99
1 files changed, 55 insertions, 44 deletions
diff --git a/MainPanel.c b/MainPanel.c
index 89b4e7d..8349023 100644
--- a/MainPanel.c
+++ b/MainPanel.c
@@ -6,18 +6,23 @@ Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
+#include "config.h" // IWYU pragma: keep
+
#include "MainPanel.h"
#include <ctype.h>
#include <stdlib.h>
+#include <sys/types.h>
#include "CRT.h"
#include "FunctionBar.h"
+#include "Machine.h"
#include "Platform.h"
-#include "Process.h"
-#include "ProcessList.h"
#include "ProvideCurses.h"
+#include "Row.h"
+#include "RowField.h"
#include "Settings.h"
+#include "Table.h"
#include "XUtils.h"
@@ -30,33 +35,32 @@ void MainPanel_updateLabels(MainPanel* this, bool list, bool filter) {
FunctionBar_setLabel(bar, KEY_F(4), filter ? "FILTER" : "Filter");
}
-static void MainPanel_pidSearch(MainPanel* this, int ch) {
+static void MainPanel_idSearch(MainPanel* this, int ch) {
Panel* super = (Panel*) this;
- pid_t pid = ch - 48 + this->pidSearch;
+ pid_t id = ch - 48 + this->idSearch;
for (int i = 0; i < Panel_size(super); i++) {
- const Process* p = (const Process*) Panel_get(super, i);
- if (p && p->pid == pid) {
+ const Row* row = (const Row*) Panel_get(super, i);
+ if (row && row->id == id) {
Panel_setSelected(super, i);
break;
}
}
- this->pidSearch = pid * 10;
- if (this->pidSearch > 10000000) {
- this->pidSearch = 0;
+ this->idSearch = id * 10;
+ if (this->idSearch > 10000000) {
+ this->idSearch = 0;
}
}
static const char* MainPanel_getValue(Panel* this, int i) {
- const Process* p = (const Process*) Panel_get(this, i);
- return Process_getCommand(p);
+ Row* row = (Row*) Panel_get(this, i);
+ return Row_sortKeyString(row);
}
static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
MainPanel* this = (MainPanel*) super;
-
- HandlerResult result = IGNORED;
-
+ Machine* host = this->state->host;
Htop_Reaction reaction = HTOP_OK;
+ HandlerResult result = IGNORED;
/* Let supervising ScreenManager handle resize */
if (ch == KEY_RESIZE)
@@ -66,20 +70,19 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
bool needReset = ch != ERR;
#ifdef HAVE_GETMOUSE
/* except mouse events while mouse support is disabled */
- if (!(ch != KEY_MOUSE || this->state->settings->enableMouse))
+ if (!(ch != KEY_MOUSE || host->settings->enableMouse))
needReset = false;
#endif
if (needReset)
- this->state->hideProcessSelection = false;
+ this->state->hideSelection = false;
- Settings* settings = this->state->settings;
+ Settings* settings = host->settings;
ScreenSettings* ss = settings->ss;
if (EVENT_IS_HEADER_CLICK(ch)) {
int x = EVENT_HEADER_CLICK_GET_X(ch);
- const ProcessList* pl = this->state->pl;
int hx = super->scrollH + x + 1;
- ProcessField field = ProcessList_keyAt(pl, hx);
+ RowField field = RowField_keyAt(settings, hx);
if (ss->treeView && ss->treeViewAlwaysByPID) {
ss->treeView = false;
ss->direction = 1;
@@ -93,12 +96,12 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
result = HANDLED;
} else if (EVENT_IS_SCREEN_TAB_CLICK(ch)) {
int x = EVENT_SCREEN_TAB_GET_X(ch);
- reaction |= Action_setScreenTab(settings, x);
+ reaction |= Action_setScreenTab(this->state, x);
result = HANDLED;
} else if (ch != ERR && this->inc->active) {
bool filterChanged = IncSet_handleKey(this->inc, ch, super, MainPanel_getValue, NULL);
if (filterChanged) {
- this->state->pl->incFilter = IncSet_filter(this->inc);
+ host->activeTable->incFilter = IncSet_filter(this->inc);
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
}
if (this->inc->found) {
@@ -107,23 +110,23 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
}
result = HANDLED;
} else if (ch == 27) {
- this->state->hideProcessSelection = true;
+ this->state->hideSelection = true;
return HANDLED;
} else if (ch != ERR && ch > 0 && ch < KEY_MAX && this->keys[ch]) {
reaction |= (this->keys[ch])(this->state);
result = HANDLED;
} else if (0 < ch && ch < 255 && isdigit((unsigned char)ch)) {
- MainPanel_pidSearch(this, ch);
+ MainPanel_idSearch(this, ch);
} else {
if (ch != ERR) {
- this->pidSearch = 0;
+ this->idSearch = 0;
} else {
reaction |= HTOP_KEEP_FOLLOWING;
}
}
if ((reaction & HTOP_REDRAW_BAR) == HTOP_REDRAW_BAR) {
- MainPanel_updateLabels(this, settings->ss->treeView, this->state->pl->incFilter);
+ MainPanel_updateLabels(this, settings->ss->treeView, host->activeTable->incFilter);
}
if ((reaction & HTOP_RESIZE) == HTOP_RESIZE) {
result |= RESIZE;
@@ -138,41 +141,38 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
result |= RESCAN;
}
if ((reaction & HTOP_SAVE_SETTINGS) == HTOP_SAVE_SETTINGS) {
- this->state->settings->changed = true;
+ host->settings->changed = true;
}
if ((reaction & HTOP_QUIT) == HTOP_QUIT) {
return BREAK_LOOP;
}
if ((reaction & HTOP_KEEP_FOLLOWING) != HTOP_KEEP_FOLLOWING) {
- this->state->pl->following = -1;
+ host->activeTable->following = -1;
Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
}
return result;
}
-int MainPanel_selectedPid(MainPanel* this) {
- const Process* p = (const Process*) Panel_getSelected((Panel*)this);
- if (p) {
- return p->pid;
- }
- return -1;
+int MainPanel_selectedRow(MainPanel* this) {
+ const Row* row = (const Row*) Panel_getSelected((Panel*)this);
+ return row ? row->id : -1;
}
-bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged) {
+bool MainPanel_foreachRow(MainPanel* this, MainPanel_foreachRowFn fn, Arg arg, bool* wasAnyTagged) {
Panel* super = (Panel*) this;
bool ok = true;
bool anyTagged = false;
for (int i = 0; i < Panel_size(super); i++) {
- Process* p = (Process*) Panel_get(super, i);
- if (p->tag) {
- ok = fn(p, arg) && ok;
+ Row* row = (Row*) Panel_get(super, i);
+ if (row->tag) {
+ ok &= fn(row, arg);
anyTagged = true;
}
}
if (!anyTagged) {
- Process* p = (Process*) Panel_getSelected(super);
- if (p) {
- ok &= fn(p, arg);
+ Row* row = (Row*) Panel_getSelected(super);
+ if (row) {
+ ok &= fn(row, arg);
}
}
@@ -190,14 +190,15 @@ static void MainPanel_drawFunctionBar(Panel* super, bool hideFunctionBar) {
return;
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
- if (this->state->pauseProcessUpdate) {
+ if (this->state->pauseUpdate) {
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
}
}
static void MainPanel_printHeader(Panel* super) {
MainPanel* this = (MainPanel*) super;
- ProcessList_printHeader(this->state->pl, &super->header);
+ Machine* host = this->state->host;
+ Table_printHeader(host->settings, &super->header);
}
const PanelClass MainPanel_class = {
@@ -212,9 +213,12 @@ const PanelClass MainPanel_class = {
MainPanel* MainPanel_new(void) {
MainPanel* this = AllocThis(MainPanel);
- Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(Settings_isReadonly() ? MainFunctions_ro : MainFunctions, NULL, NULL));
+ this->processBar = FunctionBar_new(MainFunctions, NULL, NULL);
+ this->readonlyBar = FunctionBar_new(MainFunctions_ro, NULL, NULL);
+ FunctionBar* activeBar = Settings_isReadonly() ? this->readonlyBar : this->processBar;
+ Panel_init((Panel*) this, 1, 1, 1, 1, Class(Row), false, activeBar);
this->keys = xCalloc(KEY_MAX, sizeof(Htop_Action));
- this->inc = IncSet_new(MainPanel_getFunctionBar(this));
+ this->inc = IncSet_new(activeBar);
Action_setBindings(this->keys);
Platform_setBindings(this->keys);
@@ -226,9 +230,16 @@ void MainPanel_setState(MainPanel* this, State* state) {
this->state = state;
}
+void MainPanel_setFunctionBar(MainPanel* this, bool readonly) {
+ this->super.defaultBar = readonly ? this->readonlyBar : this->processBar;
+ this->inc->defaultBar = this->super.defaultBar;
+}
+
void MainPanel_delete(Object* object) {
Panel* super = (Panel*) object;
MainPanel* this = (MainPanel*) object;
+ MainPanel_setFunctionBar(this, false);
+ FunctionBar_delete(this->readonlyBar);
Panel_done(super);
IncSet_delete(this->inc);
free(this->keys);

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