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 9edadf47a90f9743f8ff2933387300e146542d5b
Author: Alastair Poole <[email protected]>
AuthorDate: Fri May 29 22:36:05 2026 +0100

    network: network in/out swatches.
---
 NEWS                           |   1 +
 src/bin/ui/evisum_ui_cache.c   |   1 -
 src/bin/ui/evisum_ui_network.c | 172 +++++++++++++++++++++++++++--------------
 3 files changed, 115 insertions(+), 59 deletions(-)

diff --git a/NEWS b/NEWS
index 3a89634..e185538 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Evisum 2.0.11
   * Fix the history bounds to include up to the current time.
   * Add a basic uptime API libenigmatic can provide.
   * Add UI for disk i/o as well as disk usage.
+  * Add read/write network i/o swatches to the network UI.
 
 =============
 Evisum 2.0.10
diff --git a/src/bin/ui/evisum_ui_cache.c b/src/bin/ui/evisum_ui_cache.c
index 91d5e6d..453f0d9 100644
--- a/src/bin/ui/evisum_ui_cache.c
+++ b/src/bin/ui/evisum_ui_cache.c
@@ -40,7 +40,6 @@ evisum_ui_item_cache_steal(Evisum_Ui_Cache *cache, Eina_List *objs) {
         }
         if (!found) {
             cache->active = eina_list_remove_list(cache->active, l);
-            if (it->obj) evas_object_del(it->obj);
             free(it);
         }
     }
diff --git a/src/bin/ui/evisum_ui_network.c b/src/bin/ui/evisum_ui_network.c
index 7c02ba7..ff8f61a 100644
--- a/src/bin/ui/evisum_ui_network.c
+++ b/src/bin/ui/evisum_ui_network.c
@@ -31,6 +31,11 @@ typedef struct {
 #define WIN_WIDTH                   320
 #define WIN_HEIGHT                  480
 
+typedef enum {
+    NETWORK_LINE_IN,
+    NETWORK_LINE_OUT,
+    NETWORK_LINE_MAX
+} Network_Line;
 
 typedef struct {
     char name[255];
@@ -40,24 +45,30 @@ typedef struct {
     uint64_t peak_in;
     uint64_t peak_out;
 
-    double history[NETWORK_GRAPH_SAMPLES];
-    int history_count;
+    double history[NETWORK_LINE_MAX][NETWORK_GRAPH_SAMPLES];
+    int history_count[NETWORK_LINE_MAX];
 
-    uint8_t color_r;
-    uint8_t color_g;
-    uint8_t color_b;
+    uint8_t color_r[NETWORK_LINE_MAX];
+    uint8_t color_g[NETWORK_LINE_MAX];
+    uint8_t color_b[NETWORK_LINE_MAX];
 
     Evas_Object *legend_row;
-    Evas_Object *legend_btn;
-    Evas_Object *legend_swatch;
+    Evas_Object *legend_btn[NETWORK_LINE_MAX];
+    Evas_Object *legend_swatch[NETWORK_LINE_MAX];
     Evas_Object *legend_label;
-    Eina_Bool enabled;
+    void *legend_data[NETWORK_LINE_MAX];
+    Eina_Bool enabled[NETWORK_LINE_MAX];
     Evisum_Ui_Network_View *view;
 
     Eina_Bool is_new;
     Eina_Bool delete_me;
 } Network_View_Interface;
 
+typedef struct {
+    Network_View_Interface *iface;
+    Network_Line line;
+} Network_Legend_Data;
+
 typedef struct {
     char name[255];
     uint64_t in;
@@ -80,21 +91,29 @@ _evisum_ui_network_graph_objects_valid(Evisum_Ui_Network_View *view) {
 }
 
 static void
-_evisum_ui_network_legend_toggle_state_apply(Network_View_Interface *iface) {
+_evisum_ui_network_legend_toggle_state_apply(Network_View_Interface *iface, Network_Line line) {
     if (!iface) return;
 
-    if (!iface->enabled && iface->legend_swatch) evas_object_hide(iface->legend_swatch);
-    else if (iface->enabled && iface->legend_swatch) evas_object_show(iface->legend_swatch);
+    if (!iface->enabled[line] && iface->legend_swatch[line]) evas_object_hide(iface->legend_swatch[line]);
+    else if (iface->enabled[line] && iface->legend_swatch[line]) evas_object_show(iface->legend_swatch[line]);
+
+    if (iface->legend_label && evas_object_evas_get(iface->legend_label))
+        elm_object_disabled_set(iface->legend_label,
+                                !iface->enabled[NETWORK_LINE_IN] && !iface->enabled[NETWORK_LINE_OUT]);
+    else iface->legend_label = NULL;
 }
 
 static void
 _evisum_ui_network_legend_toggle_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) {
-    Network_View_Interface *iface = data;
+    Network_Legend_Data *legend = data;
+    Network_View_Interface *iface;
 
-    if (!iface || !iface->view || !iface->legend_btn || !iface->legend_row) return;
+    if (!legend) return;
+    iface = legend->iface;
+    if (!iface || !iface->view || !iface->legend_btn[legend->line] || !iface->legend_row) return;
     if (!_evisum_ui_network_graph_objects_valid(iface->view)) return;
-    iface->enabled = !iface->enabled;
-    _evisum_ui_network_legend_toggle_state_apply(iface);
+    iface->enabled[legend->line] = !iface->enabled[legend->line];
+    _evisum_ui_network_legend_toggle_state_apply(iface, legend->line);
     _evisum_ui_network_graph_redraw(iface->view, iface->view->interfaces);
 }
 
@@ -132,7 +151,10 @@ _evisum_ui_network_btn_menu_clicked_cb(void *data, Evas_Object *obj, void *event
 
 static void
 _evisum_ui_network_iface_color_apply(Network_View_Interface *iface) {
-    evisum_graph_color_get(iface->name, &iface->color_r, &iface->color_g, &iface->color_b);
+    evisum_graph_color_get(eina_slstr_printf("%s|in", iface->name), &iface->color_r[NETWORK_LINE_IN],
+                           &iface->color_g[NETWORK_LINE_IN], &iface->color_b[NETWORK_LINE_IN]);
+    evisum_graph_color_get(eina_slstr_printf("%s|out", iface->name), &iface->color_r[NETWORK_LINE_OUT],
+                           &iface->color_g[NETWORK_LINE_OUT], &iface->color_b[NETWORK_LINE_OUT]);
 }
 
 static char *
@@ -156,10 +178,45 @@ _evisum_ui_network_transfer_format(double rate) {
 }
 
 static void
-_evisum_ui_network_iface_legend_add(Evisum_Ui_Network_View *view, Network_View_Interface *iface) {
-    Evas_Object *row, *swatch, *lb, *btn;
+_evisum_ui_network_legend_swatch_add(Network_View_Interface *iface, Network_Line line, Evas_Object *row) {
+    Evas_Object *btn, *swatch;
+    Network_Legend_Data *legend;
     Evas *evas;
 
+    if (!iface || !row || iface->legend_btn[line]) return;
+
+    evas = evas_object_evas_get(row);
+    btn = elm_button_add(row);
+    evas_object_size_hint_min_set(btn, 16 * elm_config_scale_get(), 16 * elm_config_scale_get());
+    evas_object_size_hint_max_set(btn, 16 * elm_config_scale_get(), 16 * elm_config_scale_get());
+    evas_object_size_hint_align_set(btn, 0.0, 0.5);
+    evas_object_show(btn);
+    legend = calloc(1, sizeof(*legend));
+    if (legend) {
+        legend->iface = iface;
+        legend->line = line;
+        iface->legend_data[line] = legend;
+        evas_object_smart_callback_add(btn, "clicked", _evisum_ui_network_legend_toggle_cb, legend);
+    }
+    elm_box_pack_end(row, btn);
+
+    swatch = evas_object_rectangle_add(evas);
+    evas_object_color_set(swatch, iface->color_r[line], iface->color_g[line], iface->color_b[line], 255);
+    evas_object_size_hint_min_set(swatch, 12 * elm_config_scale_get(), 12 * elm_config_scale_get());
+    evas_object_size_hint_max_set(swatch, 12 * elm_config_scale_get(), 12 * elm_config_scale_get());
+    evas_object_size_hint_align_set(swatch, 0.0, 0.5);
+    elm_object_content_set(btn, swatch);
+    evas_object_show(swatch);
+
+    iface->legend_btn[line] = btn;
+    iface->legend_swatch[line] = swatch;
+    _evisum_ui_network_legend_toggle_state_apply(iface, line);
+}
+
+static void
+_evisum_ui_network_iface_legend_add(Evisum_Ui_Network_View *view, Network_View_Interface *iface) {
+    Evas_Object *row, *lb;
+
     if (!view->legend_bx || iface->legend_row) return;
 
     row = elm_box_add(view->legend_bx);
@@ -170,22 +227,8 @@ _evisum_ui_network_iface_legend_add(Evisum_Ui_Network_View *view, Network_View_I
     elm_box_pack_end(view->legend_bx, row);
     evas_object_show(row);
 
-    evas = evas_object_evas_get(row);
-    btn = elm_button_add(row);
-    evas_object_size_hint_min_set(btn, 16 * elm_config_scale_get(), 16 * elm_config_scale_get());
-    evas_object_size_hint_max_set(btn, 16 * elm_config_scale_get(), 16 * elm_config_scale_get());
-    evas_object_size_hint_align_set(btn, 0.0, 0.5);
-    evas_object_show(btn);
-    evas_object_smart_callback_add(btn, "clicked", _evisum_ui_network_legend_toggle_cb, iface);
-    elm_box_pack_end(row, btn);
-
-    swatch = evas_object_rectangle_add(evas);
-    evas_object_color_set(swatch, iface->color_r, iface->color_g, iface->color_b, 255);
-    evas_object_size_hint_min_set(swatch, 12 * elm_config_scale_get(), 12 * elm_config_scale_get());
-    evas_object_size_hint_max_set(swatch, 12 * elm_config_scale_get(), 12 * elm_config_scale_get());
-    evas_object_size_hint_align_set(swatch, 0.0, 0.5);
-    elm_object_content_set(btn, swatch);
-    evas_object_show(swatch);
+    _evisum_ui_network_legend_swatch_add(iface, NETWORK_LINE_IN, row);
+    _evisum_ui_network_legend_swatch_add(iface, NETWORK_LINE_OUT, row);
 
     lb = elm_label_add(row);
     evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
@@ -195,19 +238,22 @@ _evisum_ui_network_iface_legend_add(Evisum_Ui_Network_View *view, Network_View_I
     evas_object_show(lb);
 
     iface->legend_row = row;
-    iface->legend_btn = btn;
-    iface->legend_swatch = swatch;
     iface->legend_label = lb;
     iface->view = view;
-    _evisum_ui_network_legend_toggle_state_apply(iface);
+    _evisum_ui_network_legend_toggle_state_apply(iface, NETWORK_LINE_IN);
+    _evisum_ui_network_legend_toggle_state_apply(iface, NETWORK_LINE_OUT);
 }
 
 static void
 _evisum_ui_network_iface_legend_del(Network_View_Interface *iface) {
     if (iface->legend_row) evas_object_del(iface->legend_row);
+    for (Network_Line line = NETWORK_LINE_IN; line < NETWORK_LINE_MAX; line++) {
+        free(iface->legend_data[line]);
+        iface->legend_btn[line] = NULL;
+        iface->legend_swatch[line] = NULL;
+        iface->legend_data[line] = NULL;
+    }
     iface->legend_row = NULL;
-    iface->legend_btn = NULL;
-    iface->legend_swatch = NULL;
     iface->legend_label = NULL;
     iface->view = NULL;
 }
@@ -226,11 +272,11 @@ _evisum_ui_network_iface_legend_update(Network_View_Interface *iface) {
 }
 
 static void
-_evisum_ui_network_iface_history_add(Network_View_Interface *iface, double value) {
-    if (iface->history_count < NETWORK_GRAPH_SAMPLES) iface->history[iface->history_count++] = value;
+_evisum_ui_network_iface_history_add(Network_View_Interface *iface, Network_Line line, double value) {
+    if (iface->history_count[line] < NETWORK_GRAPH_SAMPLES) iface->history[line][iface->history_count[line]++] = value;
     else {
-        memmove(&iface->history[0], &iface->history[1], sizeof(double) * (NETWORK_GRAPH_SAMPLES - 1));
-        iface->history[NETWORK_GRAPH_SAMPLES - 1] = value;
+        memmove(&iface->history[line][0], &iface->history[line][1], sizeof(double) * (NETWORK_GRAPH_SAMPLES - 1));
+        iface->history[line][NETWORK_GRAPH_SAMPLES - 1] = value;
     }
 }
 
@@ -240,9 +286,11 @@ _evisum_ui_network_histories_reset(Eina_List *interfaces) {
     Network_View_Interface *iface;
 
     EINA_LIST_FOREACH(interfaces, l, iface) {
-        iface->history_count = 0;
-        memset(iface->history, 0, sizeof(iface->history));
-        _evisum_ui_network_iface_history_add(iface, 0.0);
+        for (Network_Line line = NETWORK_LINE_IN; line < NETWORK_LINE_MAX; line++) {
+            iface->history_count[line] = 0;
+            memset(iface->history[line], 0, sizeof(iface->history[line]));
+            _evisum_ui_network_iface_history_add(iface, line, 0.0);
+        }
     }
 }
 
@@ -276,19 +324,22 @@ _evisum_ui_network_graph_redraw(Evisum_Ui_Network_View *view, Eina_List *interfa
     peak = view->graph_peak;
     if (peak < 1.0) peak = 1.0;
 
-    total = eina_list_count(interfaces);
+    total = eina_list_count(interfaces) * NETWORK_LINE_MAX;
     nseries = 0;
     series = calloc(total, sizeof(Evisum_Ui_Graph_Series));
     if ((total > 0) && (!series)) return;
 
     EINA_LIST_FOREACH(interfaces, l, iface) {
-        if (iface->delete_me || !iface->enabled || (iface->history_count < 2)) continue;
-        series[nseries].history = iface->history;
-        series[nseries].history_count = iface->history_count;
-        series[nseries].color_r = iface->color_r;
-        series[nseries].color_g = iface->color_g;
-        series[nseries].color_b = iface->color_b;
-        nseries++;
+        if (iface->delete_me) continue;
+        for (Network_Line line = NETWORK_LINE_IN; line < NETWORK_LINE_MAX; line++) {
+            if (!iface->enabled[line] || (iface->history_count[line] < 2)) continue;
+            series[nseries].history = iface->history[line];
+            series[nseries].history_count = iface->history_count[line];
+            series[nseries].color_r = iface->color_r[line];
+            series[nseries].color_g = iface->color_g[line];
+            series[nseries].color_b = iface->color_b[line];
+            nseries++;
+        }
     }
 
     evisum_ui_graph_draw(view->graph_bg, view->graph_img, NETWORK_GRAPH_SAMPLES, NETWORK_GRID_X_STEP_SAMPLES,
@@ -375,7 +426,8 @@ _evisum_ui_network_update_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUS
             iface = calloc(1, sizeof(*iface));
             if (!iface) continue;
             iface->is_new = EINA_TRUE;
-            iface->enabled = EINA_TRUE;
+            for (Network_Line line = NETWORK_LINE_IN; line < NETWORK_LINE_MAX; line++)
+                iface->enabled[line] = EINA_TRUE;
             snprintf(iface->name, sizeof(iface->name), "%s", s->name);
             iface->in = s->in;
             iface->out = s->out;
@@ -406,13 +458,17 @@ _evisum_ui_network_update_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUS
     }
 
     EINA_LIST_FOREACH(view->interfaces, l, iface) {
-        double rate = (double) iface->in + (double) iface->out;
+        double in = (double) iface->in;
+        double out = (double) iface->out;
         if (iface->is_new) {
             _evisum_ui_network_iface_color_apply(iface);
             _evisum_ui_network_iface_legend_add(view, iface);
         }
-        _evisum_ui_network_iface_history_add(iface, rate);
-        if (rate > view->graph_peak) view->graph_peak = rate;
+        _evisum_ui_network_iface_history_add(iface, NETWORK_LINE_IN, in);
+        _evisum_ui_network_iface_history_add(iface, NETWORK_LINE_OUT, out);
+        if (in > view->graph_peak) view->graph_peak = in;
+        if (out > view->graph_peak) view->graph_peak = out;
+        if (view->graph_peak < 1.0) view->graph_peak = 1.0;
         _evisum_ui_network_iface_legend_update(iface);
     }
 

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

Reply via email to