summaryrefslogtreecommitdiffstats
path: root/Header.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-05-02 09:02:22 +1000
committerNathan Scott <nathans@redhat.com>2023-05-08 13:06:07 +1000
commit0bdade1b6cb40c5bd374a93ac0489058a7421bb5 (patch)
tree0e0225f7dbf6867402c5ed3481a705d01941f42e /Header.c
parente4ebe18b67c366d367231a1123b057c82018cf5b (diff)
Introduce Machine class for host-specific info (split from ProcessList)
First stage in sanitizing the process list structure so that htop can support other types of lists too (cgroups, filesystems, ...), in the not-too-distant future. This introduces struct Machine for system-wide information while keeping process-list information in ProcessList (now much less). Next step is to propogate this separation into each platform, to match these core changes.
Diffstat (limited to 'Header.c')
-rw-r--r--Header.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/Header.c b/Header.c
index b2fc56cc..3fafc70a 100644
--- a/Header.c
+++ b/Header.c
@@ -25,12 +25,11 @@ in the source distribution for its full text.
#include "XUtils.h"
-Header* Header_new(ProcessList* pl, Settings* settings, HeaderLayout hLayout) {
+Header* Header_new(Machine* host, HeaderLayout hLayout) {
Header* this = xCalloc(1, sizeof(Header));
this->columns = xMallocArray(HeaderLayout_getColumns(hLayout), sizeof(Vector*));
- this->settings = settings;
- this->pl = pl;
this->headerLayout = hLayout;
+ this->host = host;
Header_forEachColumn(this, i) {
this->columns[i] = Vector_new(Class(Meter), true, DEFAULT_SIZE);
@@ -92,7 +91,8 @@ static void Header_addMeterByName(Header* this, const char* name, MeterModeId mo
if ((end = strrchr(dynamic, ')')) == NULL)
return; // htoprc parse failure
*end = '\0';
- if (!DynamicMeter_search(this->settings->dynamicMeters, dynamic, &param))
+ const Settings* settings = this->host->settings;
+ if (!DynamicMeter_search(settings->dynamicMeters, dynamic, &param))
return; // name lookup failure
} else {
param = 0;
@@ -105,7 +105,7 @@ static void Header_addMeterByName(Header* this, const char* name, MeterModeId mo
for (const MeterClass* const* type = Platform_meterTypes; *type; type++) {
if (0 == strncmp(name, (*type)->name, nameLen) && (*type)->name[nameLen] == '\0') {
- Meter* meter = Meter_new(this->pl, param, *type);
+ Meter* meter = Meter_new(this->host, param, *type);
if (mode != 0) {
Meter_setMode(meter, mode);
}
@@ -116,10 +116,11 @@ static void Header_addMeterByName(Header* this, const char* name, MeterModeId mo
}
void Header_populateFromSettings(Header* this) {
- Header_setLayout(this, this->settings->hLayout);
+ const Settings* settings = this->host->settings;
+ Header_setLayout(this, settings->hLayout);
Header_forEachColumn(this, col) {
- const MeterColumnSetting* colSettings = &this->settings->hColumns[col];
+ const MeterColumnSetting* colSettings = &settings->hColumns[col];
Vector_prune(this->columns[col]);
for (size_t i = 0; i < colSettings->len; i++) {
Header_addMeterByName(this, colSettings->names[i], colSettings->modes[i], col);
@@ -130,7 +131,7 @@ void Header_populateFromSettings(Header* this) {
}
void Header_writeBackToSettings(const Header* this) {
- Settings* settings = this->settings;
+ Settings* settings = this->host->settings;
Settings_setHeaderLayout(settings, this->headerLayout);
Header_forEachColumn(this, col) {
@@ -172,7 +173,7 @@ Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int
Vector* meters = this->columns[column];
- Meter* meter = Meter_new(this->pl, param, type);
+ Meter* meter = Meter_new(this->host, param, type);
Vector_add(meters, meter);
return meter;
}
@@ -274,7 +275,8 @@ static int calcColumnWidthCount(const Header* this, const Meter* curMeter, const
}
int Header_calculateHeight(Header* this) {
- const int pad = this->settings->headerMargin ? 2 : 0;
+ const Settings* settings = this->host->settings;
+ const int pad = settings->headerMargin ? 2 : 0;
int maxHeight = pad;
Header_forEachColumn(this, col) {
@@ -295,7 +297,7 @@ int Header_calculateHeight(Header* this) {
this->pad = pad;
}
- if (this->settings->screenTabs) {
+ if (settings->screenTabs) {
maxHeight++;
}

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