raster pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=1c737a8a7215f27c3ae11e1144a3f7d465bd3005

commit 1c737a8a7215f27c3ae11e1144a3f7d465bd3005
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Thu Sep 10 02:45:47 2020 +0100

    cpu usage/freq display - fix rendering. clearing, efficiency and more
    
    read commnts as to what the code is doing... otherwise its
    siginificantly more efficient now, more correct, cleaner, and simpler
    even with more features (like properly interpolated colormaps).
---
 src/bin/ui/ui_cpu.c | 521 ++++++++++++++++++++++++----------------------------
 1 file changed, 235 insertions(+), 286 deletions(-)

diff --git a/src/bin/ui/ui_cpu.c b/src/bin/ui/ui_cpu.c
index 5f9de9a..8c629b7 100644
--- a/src/bin/ui/ui_cpu.c
+++ b/src/bin/ui/ui_cpu.c
@@ -1,338 +1,305 @@
 #include "ui_cpu.h"
 
-#define RGB_VALID(x) ((x) < 0) ? 0 : (((x) > 255) ? 255 : (x))
-
-#define BAR_HEIGHT 15
-
-typedef enum {
-    COLOR_FG  =  0xff2f99ff,
-    COLOR_BG  =  0xff202020,
-
-    COLOR_0   =  0xff57bb8a,
-    COLOR_5   =  0xff63b682,
-    COLOR_10  =  0xff73b87e,
-    COLOR_15  =  0xff84bb7b,
-    COLOR_20  =  0xff94bd77,
-    COLOR_25  =  0xffa4c073,
-    COLOR_30  =  0xffb0be6e,
-    COLOR_35  =  0xffc4c56d,
-    COLOR_40  =  0xffd4c86a,
-    COLOR_45  =  0xffe2c965,
-    COLOR_50  =  0xfff5ce62,
-    COLOR_55  =  0xfff3c563,
-    COLOR_60  =  0xffe9b861,
-    COLOR_65  =  0xffe6ad61,
-    COLOR_70  =  0xffecac67,
-    COLOR_75  =  0xffe9a268,
-    COLOR_80  =  0xffe79a69,
-    COLOR_85  =  0xffe5926b,
-    COLOR_90  =  0xffe2886c,
-    COLOR_95  =  0xffe0816d,
-    COLOR_100 =  0xffdd776e,
-} Colors;
-
-static int
-_core_color(int percent)
-{
-   if (percent >= 100) return COLOR_100;
-   if (percent >= 95) return COLOR_95;
-   if (percent >= 90) return COLOR_90;
-   if (percent >= 85) return COLOR_85;
-   if (percent >= 80) return COLOR_80;
-   if (percent >= 75) return COLOR_75;
-   if (percent >= 70) return COLOR_70;
-   if (percent >= 65) return COLOR_65;
-   if (percent >= 60) return COLOR_60;
-   if (percent >= 55) return COLOR_55;
-   if (percent >= 50) return COLOR_50;
-   if (percent >= 45) return COLOR_45;
-   if (percent >= 40) return COLOR_40;
-   if (percent >= 35) return COLOR_35;
-   if (percent >= 30) return COLOR_30;
-   if (percent >= 25) return COLOR_25;
-   if (percent >= 20) return COLOR_20;
-   if (percent >= 15) return COLOR_15;
-   if (percent >= 10) return COLOR_10;
-   if (percent >= 5) return COLOR_5;
-
-   return COLOR_0;
-}
+typedef struct {
+   short id;
+   short percent;
+   unsigned int freq;
+} Core;
 
 typedef struct {
    Ui             *ui;
-   Ecore_Animator *animator;
 
    Evas_Object    *bg;
-   Evas_Object    *line;
    Evas_Object    *obj;
 
    Evas_Object    *colors;
 
-   Eina_Bool       redraw;
-
    int             cpu_count;
-   Eina_List      *cores;
 
    Eina_Bool       show_cpufreq;
    // Have cpu scaling
    Eina_Bool       cpu_freq;
    int             freq_min;
    int             freq_max;
-
-   int             pos;
-   double          step;
 } Animate;
 
-typedef struct
-{
-   int id;
-   int freq;
-   int percent;
-} Core;
+typedef struct _Color_Point {
+   unsigned int val;
+   unsigned int color;
+} Color_Point;
+
+// config for colors/sizing
+static const Color_Point cpu_colormap_in[] = {
+   {   0, 0xff202020 }, // 0
+   {  33, 0xff2030a0 }, // 1
+   {  66, 0xffa040a0 }, // 2
+   { 100, 0xffff9040 }, // 3
+   { 256, 0xffff9040 }  // overflow to avoid if's
+};
+static const Color_Point freq_colormap_in[] = {
+   {   0, 0x00000000 }, // 0
+   {  50, 0x00105020 }, // 1
+   { 100, 0x002060c0 }, // 2
+   { 256, 0x002060c0 }  // overflow to avoid if's
+};
+#define BAR_HEIGHT 2
+#define COLORS_HEIGHT 20
+
+// stored colormap tables
+static unsigned int cpu_colormap[256];
+static unsigned int freq_colormap[256];
+
+// handy macros to access argb values from pixels
+#define AVAL(x) (((x) >> 24) & 0xff)
+#define RVAL(x) (((x) >> 16) & 0xff)
+#define GVAL(x) (((x) >>  8) & 0xff)
+#define BVAL(x) (((x)      ) & 0xff)
+#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
 
-static int
-_core_alpha(int percent, int fr, int fr_max, int fr_min)
+static void
+_color_init(const Color_Point *col_in, unsigned int n, unsigned int *col)
 {
-   int r, g, b, a;
-   int color;
+   unsigned int pos, interp, val, dist, d;
+   unsigned int a, r, g, b;
+   unsigned int a1, r1, g1, b1, v1;
+   unsigned int a2, r2, g2, b2, v2;
 
-   color = _core_color(percent);
-
-   r = (color >> 16) & 0xff;
-   g = (color >> 8) & 0xff;
-   b = (color & 0xff);
-   a = 0xff;
-
-   if (fr)
+   // wal colormap_in until colormap table is full
+   for (pos = 0, val = 0; pos < n; pos++)
      {
-        int rng, n;
-        rng = fr_max - fr_min;
-        n = fr - fr_min;
-        double fade = (100.0 - ((n * 100) / rng)) / 100.0;
-
-        r = (percent / 100.0) * 0xff;
-        b = fade * 0xff;
-        r = RGB_VALID(r);
-        b = RGB_VALID(b);
+        // get first color and value position
+        v1 = col_in[pos].val;
+        a1 = AVAL(col_in[pos].color);
+        r1 = RVAL(col_in[pos].color);
+        g1 = GVAL(col_in[pos].color);
+        b1 = BVAL(col_in[pos].color);
+        // get second color and valuje position
+        v2 = col_in[pos + 1].val;
+        a2 = AVAL(col_in[pos + 1].color);
+        r2 = RVAL(col_in[pos + 1].color);
+        g2 = GVAL(col_in[pos + 1].color);
+        b2 = BVAL(col_in[pos + 1].color);
+        // get distance between values (how many entires to fill)
+        dist = v2 - v1;
+        // walk over the span of colors from point a to point b
+        for (interp = v1; interp < v2; interp++)
+          {
+             // distance from starting point
+             d = interp - v1;
+             // calculate linear interpolation between start and given d
+             a = ((d * a2) + ((dist - d) * a1)) / dist;
+             r = ((d * r2) + ((dist - d) * r1)) / dist;
+             g = ((d * g2) + ((dist - d) * g1)) / dist;
+             b = ((d * b2) + ((dist - d) * b1)) / dist;
+             // write out resulting color value
+             col[val] = ARGB(a, r, g, b);
+             val++;
+          }
      }
-
-   color = (a << 24) + (r << 16) + (g << 8) + b;
-
-   return color;
 }
 
 static void
-_core_times_cb(void *data, Ecore_Thread *thread)
+_core_times_main_cb(void *data, Ecore_Thread *thread)
 {
-   Animate *ad;
+   // this runs in a dedicated thread in the bg sleeping, collecting info
+   // on usage then sending as feedback to mainloop
+   Animate *ad = data;
    int ncpu;
 
-   ad = data;
-
+   // when we begin to run - get min and max freq. note - no locks so
+   // not that great... writing to data in thread that mainloop thread
+   // will read
    if (!system_cpu_frequency_min_max_get(&ad->freq_min, &ad->freq_max))
      ad->cpu_freq = EINA_TRUE;
 
+   // while this thread has not been canceled
    while (!ecore_thread_check(thread))
      {
         cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, 100000);
-        for (int n = 0; n < ncpu; n++)
+        Core *cores_out = calloc(ncpu, sizeof(Core));
+
+        // producer-consumer moduel. this thread produces data and sends as
+        // feedback to mainloop to consume
+        if (cores_out)
           {
-             // Copy our core state data to the animator.
-             Core *core = eina_list_nth(ad->cores, n);
-             if (core)
+             for (int n = 0; n < ncpu; n++)
                {
+                  // Copy our core state data to mainloop
+                  Core *core = &(cores_out[n]);
+                  core->id = n;
                   core->percent = cores[n]->percent;
                   if (ad->cpu_freq)
                     core->freq = system_cpu_n_frequency_get(n);
+                  free(cores[n]);
                }
-             free(cores[n]);
+             ecore_thread_feedback(thread, cores_out);
           }
         free(cores);
      }
 }
 
 static void
-_win_del_cb(void *data, Evas_Object *obj,
-                    void *event_info EINA_UNUSED)
-{
-   Animate *ad = data;
-   Ui *ui = ad->ui;
-   Core *core;
-
-   ecore_animator_del(ad->animator);
-
-   ecore_thread_cancel(ui->thread_cpu);
-
-   ecore_thread_wait(ui->thread_cpu, 0.2);
-
-   EINA_LIST_FREE(ad->cores, core)
-     {
-        free(core);
-     }
-
-   free(ad);
-
-   evas_object_del(obj);
-   ui->win_cpu = NULL;
-}
-
-static void
-_reset(Animate *ad)
-{
-   ad->pos = ad->step = 0;
-}
-
-static Eina_Bool
-_bg_fill(Animate *ad)
-{
-   uint32_t *pixels;
-   Evas_Coord x, y, w, h;
-
-   if (ecore_thread_check(ad->ui->thread_cpu)) return EINA_FALSE;
-
-   evas_object_geometry_get(ad->bg, NULL, NULL, &w, &h);
-   pixels = evas_object_image_data_get(ad->obj, EINA_TRUE);
-   if (!pixels) return EINA_FALSE;
-   for (y = 0; y < h; y++)
-     {
-        for (x = 0; x < w; x++)
-          {
-             *(pixels++) = COLOR_BG;
-          }
-     }
-   ad->redraw = EINA_FALSE;
-   return EINA_TRUE;
-}
-
-static Eina_Bool
-_animate(void *data)
+_update(Animate *ad, Core *cores)
 {
-   uint32_t *pixels;
-   Evas_Object *line, *obj, *bg;
+   Evas_Object *obj = ad->obj;
+   unsigned int *pixels, *pix;
    Evas_Coord x, y, w, h;
-   Animate *ad = data;
-
-   if (ecore_thread_check(ad->ui->thread_cpu)) return EINA_FALSE;
-
-   bg = ad->bg; line = ad->line; obj = ad->obj;
-
-   evas_object_geometry_get(bg, &x, &y, &w, &h);
-
-   int rem = h % ad->cpu_count;
-   h -= rem;
-
-   evas_object_image_size_set(obj, w, h);
-   evas_object_resize(bg, w, h);
-   evas_object_image_data_update_add(obj, 0, 0, w, h);
-
-   evas_object_geometry_get(obj, NULL, NULL, NULL, &h);
-   evas_object_move(line, x + w - ad->pos, y);
-   evas_object_resize(line, 1, h);
-   evas_object_show(line);
-
-   if (ad->redraw)
+   int iw, stride;
+   Eina_Bool clear = EINA_FALSE;
+
+   evas_object_geometry_get(obj, &x, &y, &w, &h);
+   evas_object_image_size_get(obj, &iw, NULL);
+   // if image pixel size doesn't match geom - we need to resize, so set
+   // new size and mark it for clearing when we fill
+   if (iw != w)
      {
-        _bg_fill(ad);
-        return EINA_TRUE;
+        evas_object_image_size_set(obj, w, ad->cpu_count);
+        clear = EINA_TRUE;
      }
 
+   // get pixel data ptr
    pixels = evas_object_image_data_get(obj, EINA_TRUE);
-   if (!pixels) return EINA_TRUE;
-
-   int block = h / ad->cpu_count;
+   if (!pixels) return;
+   // get stride (# of bytes per line)
+   stride = evas_object_image_stride_get(obj);
 
-   for (y = 0; y < h; y++)
+   // go throuhg al the cpu cores
+   for (y = 0; y < ad->cpu_count; y++)
      {
-        for (x = 0; x < w; x++)
+        Core *core = &(cores[y]);
+        unsigned int c1, c2;
+        unsigned int a, r, g, b;
+        unsigned int a2, r2, g2, b2;
+
+        // our pix ptr is the pixel row and y is both y pixel coord and core
+        pix = &(pixels[y * (stride / 4)]);
+        if (clear)
+          {
+             // clear/fill with 0 value from colormap
+             for (x = 0; x < (w - 1); x++) pix[x] = cpu_colormap[0];
+          }
+        else
           {
-             int n = y / block;
-             Core *core = eina_list_nth(ad->cores, n);
-             if (core && x == (w - ad->pos))
+             // scroll pixels 1 to the left
+             for (x = 0; x < (w - 1); x++) pix[x] = pix[x + 1];
+          }
+        // final pixel on end of each row... set it to a new value
+        // get color from cpu colormap and decompose to rgb
+        c1 = cpu_colormap[core->percent & 0xff];
+        a = AVAL(c1);
+        r = RVAL(c1);
+        g = GVAL(c1);
+        b = BVAL(c1);
+        // if we overlay freq, then we will do argb addition of freq color
+        // and cpu percent usage color. designed to affect mostly different
+        // rgb channels so you can see when freq goes up but not cpu % or
+        // vice-versa
+        if ((ad->show_cpufreq) && (ad->cpu_freq))
+          {
+             int v = core->freq - ad->freq_min;
+             int d = ad->freq_max - ad->freq_min;
+
+             // if there is a difference between min and max ... a range
+             if (d > 0)
                {
-                 if (ad->show_cpufreq && ad->cpu_freq)
-                   *(pixels) = _core_alpha(core->percent, core->freq, 
ad->freq_min, ad->freq_max);
-                 else
-                   *(pixels) = _core_color(core->percent);
+                  v = (100 * v) / d;
+                  if (v < 0) v = 0;
+                  else if (v > 100) v = 100;
+                  // v now is 0->100 as a percentage of possible frequency
+                  // the cpu can do
+                  c2 = freq_colormap[v & 0xff];
+                  a2 = AVAL(c2);
+                  r2 = RVAL(c2);
+                  g2 = GVAL(c2);
+                  b2 = BVAL(c2);
+                  // do argb add and then limit arb to max of 0xff since
+                  // the add can overflow 0xff
+                  a += a2;
+                  r += r2;
+                  g += g2;
+                  b += b2;
+                  if (a > 0xff) a = 0xff;
+                  if (r > 0xff) r = 0xff;
+                  if (g > 0xff) g = 0xff;
+                  if (b > 0xff) b = 0xff;
                }
-             pixels++;
           }
+        // last pixel == resulting pixel color
+        pix[x] = ARGB(a, r, g, b);
      }
-
-   ad->step += (double) (w * ecore_animator_frametime_get()) / 60.0;
-   ad->pos = ad->step;
-
-   if (ad->pos >= w)
-     _reset(ad);
-
-   return EINA_TRUE;
+   // hand back pixel data ptr so evas knows we are done with it
+   evas_object_image_data_set(obj, pixels);
+   // now add update region for all pixels in the image at the end as we
+   // changed everything
+   evas_object_image_data_update_add(obj, 0, 0, w, ad->cpu_count);
 }
 
 static void
-_anim_resize_cb(void *data, Evas_Object *obj EINA_UNUSED,
-                void *event_info EINA_UNUSED)
+_core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void 
*msgdata)
 {
-   Evas_Coord w, h, x, y;
-   uint32_t *pixels;
+   // when the thread sends feedback to mainloop, the feedback is cpu and freq
+   // stat info from the feedback thread, so update based on that info then
+   // free it as we don't need it anyway - producer+consumer model
    Animate *ad = data;
-
-   ad->redraw = EINA_TRUE;
-   _reset(ad);
-   evas_object_hide(ad->line);
-
-   // Update our color guide.
-   h = BAR_HEIGHT * elm_config_scale_get();
-   evas_object_size_hint_min_set(ad->colors, -1, h);
-   evas_object_geometry_get(ad->bg, NULL, NULL, &w, NULL);
-   evas_object_image_size_set(ad->colors, w, h);
-   evas_object_image_data_update_add(ad->colors, 0, 0, w, h);
-
-   pixels = evas_object_image_data_get(ad->colors, EINA_TRUE);
-   if (!pixels) return;
-
-   for (y = 0; y < h; y++)
-     {
-        for (x = 0; x < w; x++)
-          {
-             int n = (100.0 / w) * x;
-             *(pixels++) = _core_alpha(n, 0, 0, 0);
-          }
-     }
+   Core *cores = msgdata;
+   _update(ad, cores);
+   free(cores);
 }
 
 static void
-_anim_move_cb(void *data, Evas_Object *obj EINA_UNUSED,
-              void *event_info EINA_UNUSED)
+_win_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 
void *event_info EINA_UNUSED)
 {
    Animate *ad = data;
+   Ui *ui = ad->ui;
 
-   evas_object_hide(ad->line);
+   // on deletion of window, cancel thread, free animate data and set cpu
+   // dialog handle to null
+   ecore_thread_cancel(ui->thread_cpu);
+   ecore_thread_wait(ui->thread_cpu, 0.5);
+   free(ad);
+   ui->win_cpu = NULL;
 }
 
 static void
-_options_clicked_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
-                   void *event_info EINA_UNUSED)
+_check_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
+                  void *event_info EINA_UNUSED)
 {
-   Evas_Object *fr = obj;
-
-   elm_frame_collapse_go(fr, !elm_frame_collapse_get(fr));
+   Animate *ad = data;
+   // sho freq overlay check changed
+   ad->show_cpufreq = elm_check_state_get(obj);
 }
 
 static void
-_check_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
-                  void *event_info EINA_UNUSED)
+_colors_fill(Evas_Object *colors)
 {
-    Animate *ad = data;
+   // fill a 2 pixel high (and 100 wide) image with 2 gradients matching
+   // the colormaps we calculated as a legend
+   int x, stride;
+   unsigned int *pixels;
 
-    ad->show_cpufreq = elm_check_state_get(obj);
+   evas_object_image_size_set(colors, 101, 2);
+   pixels = evas_object_image_data_get(colors, EINA_TRUE);
+   if (!pixels) return;
+   stride = evas_object_image_stride_get(colors);
+   // cpu percent (first row)
+   for (x = 0; x <= 100; x++) pixels[x] = cpu_colormap[x];
+   // cpu freq (next row)
+   for (x = 0; x <= 100; x++) pixels[x + (stride / 4)] = freq_colormap[x];
+   evas_object_image_data_set(colors, pixels);
+   evas_object_image_data_update_add(colors, 0, 0, 101, 1);
 }
 
 static void
 _graph(Ui *ui, Evas_Object *parent)
 {
-   Evas_Object *frame, *tbl, *box, *bg, *obj, *line;
+   Evas_Object *frame, *tbl, *box, *obj;
    Evas_Object *fr, *hbx, *bx, *colors, *check;
    int n;
 
+   // init colormaps from a small # of points
+   _color_init(cpu_colormap_in, 4, cpu_colormap);
+   _color_init(freq_colormap_in, 3, freq_colormap);
+
    box = parent;
 
    n = system_cpu_online_count_get();
@@ -351,28 +318,15 @@ _graph(Ui *ui, Evas_Object *parent)
    evas_object_size_hint_weight_set(tbl, EXPAND, EXPAND);
    evas_object_show(tbl);
 
-   bg = evas_object_rectangle_add(evas_object_evas_get(box));
-   evas_object_size_hint_align_set(bg, FILL, FILL);
-   evas_object_size_hint_weight_set(bg, EXPAND, EXPAND);
-   evas_object_show(bg);
-
-   line = evas_object_rectangle_add(evas_object_evas_get(bg));
-   evas_object_size_hint_align_set(line, FILL, FILL);
-   evas_object_size_hint_weight_set(line, EXPAND, EXPAND);
-   evas_object_color_set(line, 255, 47, 153, 255);
-   evas_object_size_hint_max_set(line, 1, -1);
-   evas_object_show(line);
-
-   obj = evas_object_image_add(evas_object_evas_get(bg));
+   obj = evas_object_image_add(evas_object_evas_get(parent));
    evas_object_size_hint_align_set(obj, FILL, FILL);
    evas_object_size_hint_weight_set(obj, EXPAND, EXPAND);
+   evas_object_image_smooth_scale_set(obj, EINA_FALSE);
    evas_object_image_filled_set(obj, EINA_TRUE);
-   evas_object_image_colorspace_set(obj, EVAS_COLORSPACE_ARGB8888);
+   evas_object_image_alpha_set(obj, EINA_FALSE);
    evas_object_show(obj);
 
-   elm_table_pack(tbl, bg, 0, 0, 1, 1);
    elm_table_pack(tbl, obj, 0, 0, 1, 1);
-   elm_table_pack(tbl, line, 0, 0, 1, 1);
 
    bx = elm_box_add(box);
    evas_object_size_hint_align_set(bx, FILL, FILL);
@@ -398,22 +352,25 @@ _graph(Ui *ui, Evas_Object *parent)
    elm_object_content_set(fr, hbx);
 
    colors = evas_object_image_add(evas_object_evas_get(fr));
+   evas_object_size_hint_min_set
+     (colors, 100, COLORS_HEIGHT * elm_config_scale_get());
    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, EINA_FALSE);
    evas_object_image_filled_set(colors, EINA_TRUE);
-   evas_object_image_colorspace_set(colors, EVAS_COLORSPACE_ARGB8888);
+   evas_object_image_alpha_set(colors, EINA_FALSE);
+   _colors_fill(colors);
    evas_object_show(colors);
    elm_box_pack_end(hbx, colors);
 
    elm_box_pack_end(box, fr);
 
    fr = elm_frame_add(box);
+   elm_frame_autocollapse_set(fr, EINA_TRUE);
    evas_object_size_hint_align_set(fr, FILL, FILL);
    evas_object_size_hint_weight_set(fr, EXPAND, 0);
    evas_object_show(fr);
    elm_object_text_set(fr, _("Options"));
-   elm_frame_collapse_set(fr, 0);
-   evas_object_smart_callback_add(fr, "clicked", _options_clicked_cb, NULL);
    elm_box_pack_end(box, fr);
 
    check = elm_check_add(fr);
@@ -426,36 +383,27 @@ _graph(Ui *ui, Evas_Object *parent)
    Animate *ad = calloc(1, sizeof(Animate));
    if (!ad) return;
 
-   ad->bg = bg;
    ad->obj = obj;
-   ad->line = line;
    ad->ui = ui;
-   ad->redraw = EINA_TRUE;
    ad->cpu_count = system_cpu_online_count_get();
 
    ad->colors = colors;
 
-   for (int i = 0; i < ad->cpu_count; i++)
-     {
-        Core *core = calloc(1, sizeof(Core));
-        if (core)
-          {
-             core->id = i;
-             ad->cores = eina_list_append(ad->cores, core);
-          }
-     }
-
-   // Enough space for our CPUs cores.
-   evas_object_size_hint_min_set(bg, 1, (BAR_HEIGHT * ad->cpu_count) * 
elm_config_scale_get());
+   // min size ofr cpu color graph to show all cores.
+   evas_object_size_hint_min_set
+     (obj, 100, (BAR_HEIGHT * ad->cpu_count) * elm_config_scale_get());
 
    evas_object_smart_callback_add(check, "changed", _check_changed_cb, ad);
-   evas_object_smart_callback_add(tbl, "resize", _anim_resize_cb, ad);
-   evas_object_smart_callback_add(tbl, "move", _anim_move_cb, ad);
-   evas_object_smart_callback_add(ui->win_cpu, "delete,request", _win_del_cb, 
ad);
-
-   ad->animator = ecore_animator_add(_animate, ad);
-
-   ui->thread_cpu = ecore_thread_run(_core_times_cb, NULL, NULL, ad);
+   // since win is on auto-delete, just listen for when it is deleted,
+   // whatever the cause/reason
+   evas_object_event_callback_add(ui->win_cpu, EVAS_CALLBACK_DEL, _win_del_cb, 
ad);
+
+   // run a feedback thread that sends feedback to the mainloop
+   ui->thread_cpu = ecore_thread_feedback_run(_core_times_main_cb,
+                                              _core_times_feedback_cb,
+                                              NULL,
+                                              NULL,
+                                              ad, EINA_TRUE);
 }
 
 void
@@ -467,6 +415,7 @@ ui_win_cpu_add(Ui *ui)
 
    ui->win_cpu = win = elm_win_util_standard_add("evisum",
                    _("CPU Usage"));
+   elm_win_autodel_set(win, EINA_TRUE);
    evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
    evas_object_size_hint_align_set(win, FILL, FILL);
    evisum_ui_background_random_add(win, evisum_ui_effects_enabled_get());

-- 


Reply via email to