From 0bdade1b6cb40c5bd374a93ac0489058a7421bb5 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 2 May 2023 09:02:22 +1000 Subject: 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. --- Header.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'Header.c') 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, ¶m)) + const Settings* settings = this->host->settings; + if (!DynamicMeter_search(settings->dynamicMeters, dynamic, ¶m)) 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++; } -- cgit v1.2.3