This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository evisum.

View the commit online.

commit 4ba79699bf05f266bf18e9d6457ce9a91062cbd2
Author: Alastair Poole <[email protected]>
AuthorDate: Sun Mar 29 05:39:26 2026 +0100

    visuals: tidy them up
---
 src/bin/ui/evisum_ui_cpu.c     |  11 ++-
 src/bin/ui/visuals/README.md   |   7 ++
 src/bin/ui/visuals/cpu_bars.c  |  87 ++++++++++++++++++--
 src/bin/ui/visuals/cpu_basic.c | 182 +++++++++++++++++++++++++++++++++++------
 4 files changed, 255 insertions(+), 32 deletions(-)

diff --git a/src/bin/ui/evisum_ui_cpu.c b/src/bin/ui/evisum_ui_cpu.c
index 890c70a..3eaddca 100644
--- a/src/bin/ui/evisum_ui_cpu.c
+++ b/src/bin/ui/evisum_ui_cpu.c
@@ -112,10 +112,11 @@ evisum_ui_cpu_win_restart(Evisum_Ui *ui) {
 void
 evisum_ui_cpu_win_add(Evisum_Ui *ui) {
     Ui_Cpu_Data *pd;
-    Evas_Object *win, *box, *scr, *btn, *ic;
+    Evas_Object *win, *box, *scr, *btn, *ic, *bg;
     Evas_Object *tb;
     Elm_Layout *lay;
     Cpu_Visual *vis;
+    uint8_t bg_r, bg_g, bg_b;
 
     if (ui->cpu.win) {
         elm_win_raise(ui->cpu.win);
@@ -127,6 +128,14 @@ evisum_ui_cpu_win_add(Evisum_Ui *ui) {
     evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
     evas_object_size_hint_align_set(win, FILL, FILL);
 
+    evisum_graph_widget_colors_get(&bg_r, &bg_g, &bg_b, NULL, NULL, NULL, NULL, NULL, NULL);
+    bg = elm_bg_add(win);
+    elm_bg_color_set(bg, bg_r, bg_g, bg_b);
+    evas_object_size_hint_weight_set(bg, EXPAND, EXPAND);
+    evas_object_size_hint_align_set(bg, FILL, FILL);
+    elm_win_resize_object_add(win, bg);
+    evas_object_show(bg);
+
     scr = elm_scroller_add(win);
     evas_object_size_hint_weight_set(scr, EXPAND, EXPAND);
     evas_object_size_hint_align_set(scr, FILL, FILL);
diff --git a/src/bin/ui/visuals/README.md b/src/bin/ui/visuals/README.md
new file mode 100644
index 0000000..e01c54e
--- /dev/null
+++ b/src/bin/ui/visuals/README.md
@@ -0,0 +1,7 @@
+# Visuals
+
+It's not too difficult to add visualizations.
+
+If I can do it anyone can.
+
+Have some fun. Think of unique ways to represent data.
diff --git a/src/bin/ui/visuals/cpu_bars.c b/src/bin/ui/visuals/cpu_bars.c
index 9c15b37..671c39a 100644
--- a/src/bin/ui/visuals/cpu_bars.c
+++ b/src/bin/ui/visuals/cpu_bars.c
@@ -1,6 +1,8 @@
 #include "cpu_bars.h"
+#include "ui/evisum_ui_graph.h"
 
 #define BAR_WIDTH 16
+#define POLL_USEC 33333
 
 typedef struct {
     int cpu_count;
@@ -31,6 +33,22 @@ _bar_gradient_apply(Evas_Object *rec, unsigned int top, unsigned int bottom) {
     evas_map_free(map);
 }
 
+static void
+_cpu_percent_colors_fill(Evas_Object *colors) {
+    unsigned int *pixels;
+    int stride;
+
+    evas_object_image_size_set(colors, 101, 1);
+    pixels = evas_object_image_data_get(colors, 1);
+    if (!pixels) return;
+    stride = evas_object_image_stride_get(colors) / 4;
+
+    for (int x = 0; x <= 100; x++) pixels[x] = cpu_colormap[x];
+
+    evas_object_image_data_set(colors, pixels);
+    evas_object_image_data_update_add(colors, 0, 0, stride, 1);
+}
+
 static void
 _core_times_main_cb(void *data, Ecore_Thread *thread) {
     int ncpu;
@@ -40,7 +58,7 @@ _core_times_main_cb(void *data, Ecore_Thread *thread) {
     ecore_thread_name_set(thread, "cpu");
 
     while (!ecore_thread_check(thread)) {
-        cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, 100000);
+        cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, POLL_USEC);
         Core *cores_out = calloc(ncpu, sizeof(Core));
 
         if (cores_out) {
@@ -78,8 +96,8 @@ _core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgd
         Core *core = &cores[i];
         Evas_Object *rec = eina_list_nth(ext->objects, i);
         evas_object_geometry_get(rec, &ox, NULL, NULL, NULL);
-        unsigned int c_top = temp_colormap[core->percent & 0xff];
-        unsigned int c_bottom = temp_colormap[0];
+        unsigned int c_top = cpu_colormap[core->percent & 0xff];
+        unsigned int c_bottom = cpu_colormap[0];
         int h = core->percent * step;
         if (!h) h = 1;
         evas_object_resize(rec, ELM_SCALE_SIZE(BAR_WIDTH), ELM_SCALE_SIZE(h));
@@ -103,8 +121,10 @@ _cb_free(void *data) {
 
 Ui_Cpu_Data *
 cpu_visual_bars(Evas_Object *parent_bx) {
-    Evas_Object *tb, *rec;
+    Evas_Object *tb, *rec, *container, *fr, *legend_tbl, *colors, *lb, *bg;
     Ext *ext;
+    uint8_t text_r, text_g, text_b;
+    char text_hex[7];
     int i;
 
     Ui_Cpu_Data *pd = calloc(1, sizeof(Ui_Cpu_Data));
@@ -120,10 +140,23 @@ cpu_visual_bars(Evas_Object *parent_bx) {
     for (i = 0; i < ext->cpu_count; i++) ext->cpu_order[i] = i;
     system_cpu_topology_get(ext->cpu_order, ext->cpu_count);
 
-    ext->tb = tb = elm_table_add(parent_bx);
+    container = elm_table_add(parent_bx);
+    evas_object_size_hint_weight_set(container, EXPAND, EXPAND);
+    evas_object_size_hint_align_set(container, FILL, FILL);
+    evas_object_show(container);
+
+    bg = evas_object_rectangle_add(evas_object_evas_get(container));
+    evisum_ui_graph_bg_set(bg);
+    evas_object_size_hint_weight_set(bg, EXPAND, EXPAND);
+    evas_object_size_hint_align_set(bg, FILL, FILL);
+    elm_table_pack(container, bg, 0, 0, 1, 1);
+    evas_object_show(bg);
+
+    ext->tb = tb = elm_table_add(container);
     elm_table_padding_set(tb, ELM_SCALE_SIZE(2), ELM_SCALE_SIZE(2));
     evas_object_size_hint_weight_set(tb, EXPAND, EXPAND);
     evas_object_size_hint_align_set(tb, 0.5, 1.0);
+    elm_table_pack(container, tb, 0, 0, 1, 1);
     evas_object_show(tb);
 
     for (i = 0; i < ext->cpu_count; i++) {
@@ -139,7 +172,49 @@ cpu_visual_bars(Evas_Object *parent_bx) {
     evas_object_size_hint_align_set(rec, FILL, FILL);
     elm_table_pack(tb, rec, 0, 0, i, 2);
 
-    elm_box_pack_end(parent_bx, tb);
+    elm_box_pack_end(parent_bx, container);
+
+    evisum_cpu_default_colors_get(&text_r, &text_g, &text_b, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                                  NULL, NULL);
+    snprintf(text_hex, sizeof(text_hex), "%02x%02x%02x", text_r, text_g, text_b);
+
+    fr = elm_frame_add(parent_bx);
+    evas_object_size_hint_align_set(fr, FILL, FILL);
+    evas_object_size_hint_weight_set(fr, EXPAND, 0.0);
+    elm_object_text_set(fr, _("Legend"));
+    evas_object_show(fr);
+    elm_box_pack_end(parent_bx, fr);
+
+    legend_tbl = elm_table_add(fr);
+    evas_object_size_hint_align_set(legend_tbl, FILL, FILL);
+    evas_object_size_hint_weight_set(legend_tbl, EXPAND, EXPAND);
+    evas_object_show(legend_tbl);
+    elm_object_content_set(fr, legend_tbl);
+
+    colors = evas_object_image_add(evas_object_evas_get(fr));
+    evas_object_size_hint_min_set(colors, ELM_SCALE_SIZE(100), ELM_SCALE_SIZE(20));
+    evas_object_size_hint_align_set(colors, FILL, FILL);
+    evas_object_size_hint_weight_set(colors, EXPAND, EXPAND);
+    evas_object_image_smooth_scale_set(colors, 0);
+    evas_object_image_filled_set(colors, 1);
+    evas_object_image_alpha_set(colors, 0);
+    _cpu_percent_colors_fill(colors);
+    elm_table_pack(legend_tbl, colors, 0, 0, 2, 1);
+    evas_object_show(colors);
+
+    lb = elm_label_add(fr);
+    elm_object_text_set(lb, eina_slstr_printf("<b><color=#%s>0%%</></>", text_hex));
+    evas_object_size_hint_align_set(lb, 0.0, 0.5);
+    evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
+    elm_table_pack(legend_tbl, lb, 0, 0, 1, 1);
+    evas_object_show(lb);
+
+    lb = elm_label_add(fr);
+    elm_object_text_set(lb, eina_slstr_printf("<b><color=#%s>100%%</></>", text_hex));
+    evas_object_size_hint_align_set(lb, 1.0, 0.5);
+    evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
+    elm_table_pack(legend_tbl, lb, 1, 0, 1, 1);
+    evas_object_show(lb);
 
     pd->thread = ecore_thread_feedback_run(_core_times_main_cb, _core_times_feedback_cb, NULL, NULL, pd, 1);
     return pd;
diff --git a/src/bin/ui/visuals/cpu_basic.c b/src/bin/ui/visuals/cpu_basic.c
index d7f9dfb..bab2cf1 100644
--- a/src/bin/ui/visuals/cpu_basic.c
+++ b/src/bin/ui/visuals/cpu_basic.c
@@ -1,9 +1,21 @@
 #include "cpu_basic.h"
+#include "ui/evisum_ui_graph.h"
+
+#define CORE_TILE_SIZE  128
+#define CORE_MIN_SIZE   16
+#define POLL_USEC       33333
 
 typedef struct {
     int cpu_count;
     int *cpu_order;
+    Evas_Object *container;
     Eina_List *objects;
+    Eina_List *pads;
+    int cols;
+    int rows;
+    Eina_Bool cpu_freq;
+    int freq_min;
+    int freq_max;
 } Ext;
 
 static void
@@ -12,10 +24,12 @@ _core_times_main_cb(void *data, Ecore_Thread *thread) {
     Ui_Cpu_Data *pd = data;
     Ext *ext = pd->ext;
 
+    if (!system_cpu_frequency_min_max_get(&ext->freq_min, &ext->freq_max)) ext->cpu_freq = 1;
+
     ecore_thread_name_set(thread, "cpu");
 
     while (!ecore_thread_check(thread)) {
-        cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, 100000);
+        cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, POLL_USEC);
         Core *cores_out = calloc(ncpu, sizeof(Core));
 
         if (cores_out) {
@@ -24,6 +38,7 @@ _core_times_main_cb(void *data, Ecore_Thread *thread) {
                 Core *core = &(cores_out[n]);
                 core->id = id;
                 core->percent = cores[id]->percent;
+                if (ext->cpu_freq) core->freq = system_cpu_n_frequency_get(id);
                 free(cores[id]);
             }
             ecore_thread_feedback(thread, cores_out);
@@ -42,14 +57,47 @@ _core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgd
     ext = pd->ext;
     cores = msgdata;
 
+    int tile = CORE_TILE_SIZE;
+    if (ext->cols > 0 && ext->rows > 0) {
+        Evas_Coord tw = 0, th = 0;
+        int side, fit_w, fit_h;
+
+        evas_object_geometry_get(ext->container, NULL, NULL, &tw, &th);
+        side = (tw < th) ? tw : th;
+        if (side > 0) {
+            fit_w = side / ext->cols;
+            fit_h = side / ext->rows;
+            tile = (fit_w < fit_h) ? fit_w : fit_h;
+            if (tile > CORE_TILE_SIZE) tile = CORE_TILE_SIZE;
+            if (tile < CORE_MIN_SIZE) tile = CORE_MIN_SIZE;
+        }
+    }
     for (int i = 0; i < ext->cpu_count; i++) {
         Core *core = &cores[i];
-        Evas_Object *lb = eina_list_nth(ext->objects, i);
-        Evas_Object *rec = evas_object_data_get(lb, "r");
+        Evas_Object *pad = eina_list_nth(ext->pads, i);
+        Evas_Object *rec = eina_list_nth(ext->objects, i);
         int c = cpu_colormap[core->percent & 0xff];
-        evas_object_color_set(rec, RVAL(c), GVAL(c), BVAL(c), AVAL(c));
+        int size = CORE_MIN_SIZE;
 
-        elm_object_text_set(lb, eina_slstr_printf("%d%%", core->percent));
+        if (ext->cpu_freq) {
+            int v = core->freq - ext->freq_min;
+            int d = ext->freq_max - ext->freq_min;
+            if (d > 0) {
+                v = (100 * v) / d;
+                if (v < 0) v = 0;
+                else if (v > 100) v = 100;
+                size = CORE_MIN_SIZE + ((v * (tile - CORE_MIN_SIZE)) / 100);
+            }
+        } else {
+            size = CORE_MIN_SIZE + ((core->percent * (tile - CORE_MIN_SIZE)) / 100);
+        }
+
+        if (size > tile) size = tile;
+        evas_object_size_hint_min_set(pad, tile, tile);
+        evas_object_size_hint_max_set(pad, tile, tile);
+        evas_object_size_hint_max_set(rec, size, size);
+        evas_object_size_hint_min_set(rec, size, size);
+        evas_object_color_set(rec, RVAL(c), GVAL(c), BVAL(c), AVAL(c));
     }
 
     free(cores);
@@ -60,6 +108,7 @@ _cb_free(void *data) {
     Ext *ext = data;
 
     eina_list_free(ext->objects);
+    eina_list_free(ext->pads);
 
     free(ext->cpu_order);
     free(ext);
@@ -73,10 +122,28 @@ _row_fit(int n) {
     return value + 1;
 }
 
+static void
+_cpu_percent_colors_fill(Evas_Object *colors) {
+    unsigned int *pixels;
+    int stride;
+
+    evas_object_image_size_set(colors, 101, 1);
+    pixels = evas_object_image_data_get(colors, 1);
+    if (!pixels) return;
+    stride = evas_object_image_stride_get(colors) / 4;
+
+    for (int x = 0; x <= 100; x++) pixels[x] = cpu_colormap[x];
+
+    evas_object_image_data_set(colors, pixels);
+    evas_object_image_data_update_add(colors, 0, 0, stride, 1);
+}
+
 Ui_Cpu_Data *
 cpu_visual_basic(Evas_Object *parent_bx) {
-    Evas_Object *tb;
+    Evas_Object *container, *grid, *fr, *legend_tbl, *colors, *lb, *bg;
     Ext *ext;
+    uint8_t text_r, text_g, text_b;
+    char text_hex[7];
 
     Ui_Cpu_Data *pd = calloc(1, sizeof(Ui_Cpu_Data));
     if (!pd) return NULL;
@@ -91,32 +158,97 @@ cpu_visual_basic(Evas_Object *parent_bx) {
     for (int i = 0; i < ext->cpu_count; i++) ext->cpu_order[i] = i;
     system_cpu_topology_get(ext->cpu_order, ext->cpu_count);
 
-    tb = elm_table_add(parent_bx);
-    evas_object_size_hint_weight_set(tb, EXPAND, EXPAND);
-    evas_object_size_hint_align_set(tb, 0.5, 0.5);
-    evas_object_show(tb);
+    container = elm_table_add(parent_bx);
+    evas_object_size_hint_weight_set(container, EXPAND, EXPAND);
+    evas_object_size_hint_align_set(container, FILL, FILL);
+    evas_object_show(container);
+    ext->container = container;
+
+    bg = evas_object_rectangle_add(evas_object_evas_get(container));
+    evisum_ui_graph_bg_set(bg);
+    evas_object_size_hint_weight_set(bg, EXPAND, EXPAND);
+    evas_object_size_hint_align_set(bg, FILL, FILL);
+    elm_table_pack(container, bg, 0, 0, 1, 1);
+    evas_object_show(bg);
+
+    grid = elm_table_add(container);
+    elm_table_padding_set(grid, 0, 0);
+    elm_table_align_set(grid, 0.5, 0.5);
+    evas_object_size_hint_weight_set(grid, 0.0, 0.0);
+    evas_object_size_hint_align_set(grid, 0.5, 0.5);
+    elm_table_pack(container, grid, 0, 0, 1, 1);
+    evas_object_show(grid);
 
     int row = 0, col = 0, w = _row_fit(ext->cpu_count);
+    int rows = (ext->cpu_count + w - 1) / w;
+    ext->cols = w;
+    ext->rows = rows;
+
+    evisum_cpu_default_colors_get(&text_r, &text_g, &text_b, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                                  NULL, NULL);
+    snprintf(text_hex, sizeof(text_hex), "%02x%02x%02x", text_r, text_g, text_b);
 
     for (int i = 0; i < ext->cpu_count; i++) {
-        if (!(i % w)) {
-            row++;
-            col = 0;
-        } else col++;
-        Evas_Object *rec = evas_object_rectangle_add(evas_object_evas_get(tb));
-        evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(64), ELM_SCALE_SIZE(64));
-        elm_table_pack(tb, rec, col, row, 1, 1);
+        row = i / w;
+        col = i % w;
+        Evas_Object *pad = evas_object_rectangle_add(evas_object_evas_get(grid));
+        evas_object_color_set(pad, 0, 0, 0, 0);
+        evas_object_size_hint_min_set(pad, CORE_TILE_SIZE, CORE_TILE_SIZE);
+        evas_object_size_hint_max_set(pad, CORE_TILE_SIZE, CORE_TILE_SIZE);
+        elm_table_pack(grid, pad, col, row, 1, 1);
+        evas_object_show(pad);
+        ext->pads = eina_list_append(ext->pads, pad);
+
+        Evas_Object *rec = evas_object_rectangle_add(evas_object_evas_get(grid));
+        evas_object_size_hint_weight_set(rec, 0.0, 0.0);
+        evas_object_size_hint_align_set(rec, 0.5, 0.5);
+        evas_object_size_hint_min_set(rec, CORE_MIN_SIZE, CORE_MIN_SIZE);
+        evas_object_size_hint_max_set(rec, CORE_MIN_SIZE, CORE_MIN_SIZE);
+        elm_table_pack(grid, rec, col, row, 1, 1);
         evas_object_show(rec);
-        Evas_Object *lb = elm_label_add(tb);
-        evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
-        evas_object_size_hint_align_set(lb, FILL, FILL);
-        elm_table_pack(tb, lb, col, row, 1, 1);
-        evas_object_show(lb);
-        evas_object_data_set(lb, "r", rec);
-        ext->objects = eina_list_append(ext->objects, lb);
+        ext->objects = eina_list_append(ext->objects, rec);
     }
 
-    elm_box_pack_end(parent_bx, tb);
+    evas_object_size_hint_min_set(grid, w * CORE_TILE_SIZE, rows * CORE_TILE_SIZE);
+    elm_box_pack_end(parent_bx, container);
+
+    fr = elm_frame_add(parent_bx);
+    evas_object_size_hint_align_set(fr, FILL, FILL);
+    evas_object_size_hint_weight_set(fr, EXPAND, 0.0);
+    elm_object_text_set(fr, _("Legend"));
+    evas_object_show(fr);
+    elm_box_pack_end(parent_bx, fr);
+
+    legend_tbl = elm_table_add(fr);
+    evas_object_size_hint_align_set(legend_tbl, FILL, FILL);
+    evas_object_size_hint_weight_set(legend_tbl, EXPAND, EXPAND);
+    evas_object_show(legend_tbl);
+    elm_object_content_set(fr, legend_tbl);
+
+    colors = evas_object_image_add(evas_object_evas_get(fr));
+    evas_object_size_hint_min_set(colors, ELM_SCALE_SIZE(100), ELM_SCALE_SIZE(20));
+    evas_object_size_hint_align_set(colors, FILL, FILL);
+    evas_object_size_hint_weight_set(colors, EXPAND, EXPAND);
+    evas_object_image_smooth_scale_set(colors, 0);
+    evas_object_image_filled_set(colors, 1);
+    evas_object_image_alpha_set(colors, 0);
+    _cpu_percent_colors_fill(colors);
+    elm_table_pack(legend_tbl, colors, 0, 0, 2, 1);
+    evas_object_show(colors);
+
+    lb = elm_label_add(fr);
+    elm_object_text_set(lb, eina_slstr_printf("<b><color=#%s>0%%</></>", text_hex));
+    evas_object_size_hint_align_set(lb, 0.0, 0.5);
+    evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
+    elm_table_pack(legend_tbl, lb, 0, 0, 1, 1);
+    evas_object_show(lb);
+
+    lb = elm_label_add(fr);
+    elm_object_text_set(lb, eina_slstr_printf("<b><color=#%s>100%%</></>", text_hex));
+    evas_object_size_hint_align_set(lb, 1.0, 0.5);
+    evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
+    elm_table_pack(legend_tbl, lb, 1, 0, 1, 1);
+    evas_object_show(lb);
 
     pd->thread = ecore_thread_feedback_run(_core_times_main_cb, _core_times_feedback_cb, NULL, NULL, pd, 1);
     return pd;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to