diff --git a/CPUMeter.c b/CPUMeter.c index 09bc909a..07c6a003 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -46,6 +46,7 @@ MeterType AllCPUsMeter = { .caption = "CPU", .draw = AllCPUsMeter_draw, .init = AllCPUsMeter_init, + .setMode = AllCPUsMeter_setMode, .done = AllCPUsMeter_done }; @@ -110,12 +111,19 @@ void AllCPUsMeter_done(Meter* this) { Meter_delete((Object*)meters[i]); } +void AllCPUsMeter_setMode(Meter* this, int mode) { + this->mode = mode; + int processors = this->pl->processorCount; + int h = Meter_modes[this->mode]->h; + this->h = h * processors; +} + void AllCPUsMeter_draw(Meter* this, int x, int y, int w) { int processors = this->pl->processorCount; Meter** meters = (Meter**) this->drawBuffer; - this->h = Meter_modes[this->mode]->h * processors; for (int i = 0; i < processors; i++) { Meter_setMode(meters[i], this->mode); - meters[i]->draw(meters[i], x, y+i, w); + meters[i]->draw(meters[i], x, y, w); + y += meters[i]->h; } } diff --git a/CPUMeter.h b/CPUMeter.h index 65ee37cb..f9f389a3 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -41,6 +41,8 @@ void AllCPUsMeter_init(Meter* this); void AllCPUsMeter_done(Meter* this); +void AllCPUsMeter_setMode(Meter* this, int mode); + void AllCPUsMeter_draw(Meter* this, int x, int y, int w); #endif diff --git a/Header.c b/Header.c index 74518d74..766dc75e 100644 --- a/Header.c +++ b/Header.c @@ -122,8 +122,7 @@ MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) { } void Header_defaultMeters(Header* this) { - for (int i = 1; i <= this->pl->processorCount; i++) - TypedVector_add(this->leftMeters, Meter_new(this->pl, i, &CPUMeter)); + TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &AllCPUsMeter)); TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &MemoryMeter)); TypedVector_add(this->leftMeters, Meter_new(this->pl, 0, &SwapMeter)); TypedVector_add(this->rightMeters, Meter_new(this->pl, 0, &TasksMeter)); diff --git a/Meter.c b/Meter.c index e95cf308..152fe670 100644 --- a/Meter.c +++ b/Meter.c @@ -36,6 +36,7 @@ typedef struct MeterMode_ MeterMode; typedef void(*MeterType_Init)(Meter*); typedef void(*MeterType_Done)(Meter*); +typedef void(*MeterType_SetMode)(Meter*, int); typedef void(*Meter_SetValues)(Meter*, char*, int); typedef void(*Meter_Draw)(Meter*, int, int, int); @@ -57,6 +58,7 @@ struct MeterType_ { char* caption; MeterType_Init init; MeterType_Done done; + MeterType_SetMode setMode; Meter_Draw draw; }; @@ -226,6 +228,8 @@ void Meter_setMode(Meter* this, int modeIndex) { assert(modeIndex < LAST_METERMODE); if (this->type->mode == 0) { this->draw = this->type->draw; + if (this->type->setMode) + this->type->setMode(this, modeIndex); } else { assert(modeIndex >= 1); if (this->drawBuffer) @@ -382,7 +386,6 @@ void GraphMeterMode_draw(Meter* this, int x, int y, int w) { value += this->values[i]; value /= this->total; drawBuffer[METER_BUFFER_LEN - 1] = value; - mvprintw(0,0,"%f ",value); for (int i = METER_BUFFER_LEN - w, k = 0; i < METER_BUFFER_LEN; i++, k++) { double value = drawBuffer[i]; DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' ); diff --git a/Meter.h b/Meter.h index f97a593c..73fa6578 100644 --- a/Meter.h +++ b/Meter.h @@ -38,6 +38,7 @@ typedef struct MeterMode_ MeterMode; typedef void(*MeterType_Init)(Meter*); typedef void(*MeterType_Done)(Meter*); +typedef void(*MeterType_SetMode)(Meter*, int); typedef void(*Meter_SetValues)(Meter*, char*, int); typedef void(*Meter_Draw)(Meter*, int, int, int); @@ -59,6 +60,7 @@ struct MeterType_ { char* caption; MeterType_Init init; MeterType_Done done; + MeterType_SetMode setMode; Meter_Draw draw; }; @@ -99,7 +101,7 @@ typedef enum { LAST_METERMODE } MeterModeId; -extern MeterType* Meter_types[9]; +extern MeterType* Meter_types[]; extern MeterMode* Meter_modes[];