From f74cde982fba7df515a02ff07a00df966da3eff4 Mon Sep 17 00:00:00 2001 From: Christoph Budziszewski Date: Thu, 11 Jun 2020 23:00:16 +0200 Subject: [PATCH 1/3] removed whitespace from end of lines --- CPUMeter.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index de5490df1..8fbd1d459 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -219,7 +219,7 @@ MeterClass CPUMeter_class = { .defaultMode = BAR_METERMODE, .maxItems = CPU_METER_ITEMCOUNT, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "CPU", .uiName = "CPU", .caption = "CPU", @@ -234,7 +234,7 @@ MeterClass AllCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "AllCPUs", .uiName = "CPUs (1/1)", .description = "CPUs (1/1): all CPUs", @@ -253,7 +253,7 @@ MeterClass AllCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "AllCPUs2", .uiName = "CPUs (1&2/2)", .description = "CPUs (1&2/2): all CPUs in 2 shorter columns", @@ -272,7 +272,7 @@ MeterClass LeftCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "LeftCPUs", .uiName = "CPUs (1/2)", .description = "CPUs (1/2): first half of list", @@ -291,7 +291,7 @@ MeterClass RightCPUsMeter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "RightCPUs", .uiName = "CPUs (2/2)", .description = "CPUs (2/2): second half of list", @@ -310,7 +310,7 @@ MeterClass LeftCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "LeftCPUs2", .uiName = "CPUs (1&2/4)", .description = "CPUs (1&2/4): first half in 2 shorter columns", @@ -329,7 +329,7 @@ MeterClass RightCPUs2Meter_class = { }, .defaultMode = CUSTOM_METERMODE, .total = 100.0, - .attributes = CPUMeter_attributes, + .attributes = CPUMeter_attributes, .name = "RightCPUs2", .uiName = "CPUs (3&4/4)", .description = "CPUs (3&4/4): second half in 2 shorter columns", From 7fdd8d3732354b3fcca2d0430731e8e33345ddda Mon Sep 17 00:00:00 2001 From: Christoph Budziszewski Date: Thu, 11 Jun 2020 23:21:52 +0200 Subject: [PATCH 2/3] adding support for more than 2 smaller cpumeter columns --- CPUMeter.c | 92 +++++++++++++++++++++++++++++++++++++++++++----- CPUMeter.h | 5 +++ linux/Platform.c | 3 ++ 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 8fbd1d459..9c63f41ee 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -137,6 +137,15 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { } } +static int MapClassnameToColumncount(Meter* this){ + if (strchr(Meter_name(this), '4')) + return 4; + else if (strchr(Meter_name(this), '2')) + return 2; + else + return 1; +} + static void AllCPUsMeter_init(Meter* this) { int cpus = this->pl->cpuCount; if (!this->drawData) @@ -152,10 +161,8 @@ static void AllCPUsMeter_init(Meter* this) { if (this->mode == 0) this->mode = BAR_METERMODE; int h = Meter_modes[this->mode]->h; - if (strchr(Meter_name(this), '2')) - this->h = h * ((count+1) / 2); - else - this->h = h * count; + int ncol = MapClassnameToColumncount(this); + this->h = h * ((count + ncol - 1)/ ncol); } static void AllCPUsMeter_done(Meter* this) { @@ -175,10 +182,8 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) { for (int i = 0; i < count; i++) { Meter_setMode(meters[i], mode); } - if (strchr(Meter_name(this), '2')) - this->h = h * ((count+1) / 2); - else - this->h = h * count; + int ncol = MapClassnameToColumncount(this); + this->h = h * ((count + ncol - 1)/ ncol); } static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) { @@ -209,6 +214,21 @@ static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) { } } +static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){ + Meter** meters = (Meter**) this->drawData; + int start, count; + AllCPUsMeter_getRange(this, &start, &count); + int ncol = MapClassnameToColumncount(this); + int colwidth = (w-ncol)/ncol + 1; + int diff = (w - (colwidth * ncol)); + for (int i = 0; i < count; i++){ + int d = (i%ncol) > diff ? diff : (i % ncol) ; // dynamic spacer + int xpos = x + ((i % ncol) * colwidth) + d; + int ypos = y + ((i / ncol) * meters[0]->h); + meters[i]->draw(meters[i], xpos, ypos, colwidth); + } +} + MeterClass CPUMeter_class = { .super = { .extends = Class(Meter), @@ -340,3 +360,59 @@ MeterClass RightCPUs2Meter_class = { .done = AllCPUsMeter_done }; +MeterClass AllCPUs4Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "AllCPUs4", + .uiName = "CPUs (1&2&3&4/4)", + .description = "CPUs (1&2&3&4/4): all CPUs in 4 shorter columns", + .caption = "CPU", + .draw = MultiColCPUsMeter_draw, + .init = AllCPUsMeter_init, + .updateMode = AllCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; + +MeterClass LeftCPUs4Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "LeftCPUs4", + .uiName = "CPUs (1-4/8)", + .description = "CPUs (1-4/8): first half in 4 shorter columns", + .caption = "CPU", + .draw = MultiColCPUsMeter_draw, + .init = AllCPUsMeter_init, + .updateMode = AllCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; + +MeterClass RightCPUs4Meter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = CPUMeter_display + }, + .defaultMode = CUSTOM_METERMODE, + .total = 100.0, + .attributes = CPUMeter_attributes, + .name = "RightCPUs4", + .uiName = "CPUs (5-8/8)", + .description = "CPUs (5-8/8): second half in 4 shorter columns", + .caption = "CPU", + .draw = MultiColCPUsMeter_draw, + .init = AllCPUsMeter_init, + .updateMode = AllCPUsMeter_updateMode, + .done = AllCPUsMeter_done +}; diff --git a/CPUMeter.h b/CPUMeter.h index 2f1639680..5018028c9 100644 --- a/CPUMeter.h +++ b/CPUMeter.h @@ -47,5 +47,10 @@ extern MeterClass LeftCPUs2Meter_class; extern MeterClass RightCPUs2Meter_class; +extern MeterClass AllCPUs4Meter_class; + +extern MeterClass LeftCPUs4Meter_class; + +extern MeterClass RightCPUs4Meter_class; #endif diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74b..62222bc66 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -121,10 +121,13 @@ MeterClass* Platform_meterTypes[] = { &HostnameMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, + &AllCPUs4Meter_class, &LeftCPUsMeter_class, &RightCPUsMeter_class, &LeftCPUs2Meter_class, &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, &BlankMeter_class, NULL }; From b55f9320bc40a465cd33ddbf6e8c9b7223ae538d Mon Sep 17 00:00:00 2001 From: Christoph Budziszewski Date: Fri, 12 Jun 2020 23:53:05 +0200 Subject: [PATCH 3/3] fixed x/y coordinate mixup --- CPUMeter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 9c63f41ee..99be44f82 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -221,10 +221,11 @@ static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){ int ncol = MapClassnameToColumncount(this); int colwidth = (w-ncol)/ncol + 1; int diff = (w - (colwidth * ncol)); + int nrows = (count + ncol - 1) / ncol; for (int i = 0; i < count; i++){ - int d = (i%ncol) > diff ? diff : (i % ncol) ; // dynamic spacer - int xpos = x + ((i % ncol) * colwidth) + d; - int ypos = y + ((i / ncol) * meters[0]->h); + int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer + int xpos = x + ((i / nrows) * colwidth) + d; + int ypos = y + ((i % nrows) * meters[0]->h); meters[i]->draw(meters[i], xpos, ypos, colwidth); } }