summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <mail@alastairpoole.com>2021-11-03 08:41:00 +0000
committerAlastair Poole <mail@alastairpoole.com>2021-11-03 08:41:00 +0000
commitd1aa17f4e3c6432ad8dd1adf941895d2c38ee00a (patch)
treeb33a4293531ccfc0b70b14ecde45899ca08f6881
parent8393a979e660f2c49f9bfde678474584b13cf54b (diff)
bars: something to work on...
-rw-r--r--src/bin/ui/ui_cpu.c1
-rw-r--r--src/bin/ui/ui_cpu.h1
-rw-r--r--src/bin/ui/visuals/cpu_bars.c135
-rw-r--r--src/bin/ui/visuals/cpu_bars.h9
-rw-r--r--src/bin/ui/visuals/meson.build2
-rw-r--r--src/bin/ui/visuals/visuals.x2
6 files changed, 150 insertions, 0 deletions
diff --git a/src/bin/ui/ui_cpu.c b/src/bin/ui/ui_cpu.c
index d78337c..0b214dd 100644
--- a/src/bin/ui/ui_cpu.c
+++ b/src/bin/ui/ui_cpu.c
@@ -260,6 +260,7 @@ ui_cpu_win_add(Evisum_Ui *ui)
260 exit(1); 260 exit(1);
261 } 261 }
262 pd = vis->func(box); 262 pd = vis->func(box);
263 pd->win = win;
263 pd->ui = ui; 264 pd->ui = ui;
264 265
265 elm_object_content_set(scr, tb); 266 elm_object_content_set(scr, tb);
diff --git a/src/bin/ui/ui_cpu.h b/src/bin/ui/ui_cpu.h
index 34ae496..346c537 100644
--- a/src/bin/ui/ui_cpu.h
+++ b/src/bin/ui/ui_cpu.h
@@ -31,6 +31,7 @@ typedef struct {
31 Ecore_Thread *thread; 31 Ecore_Thread *thread;
32 32
33 Evas_Object *menu; 33 Evas_Object *menu;
34 Evas_Object *win;
34 Elm_Layout *btn_menu; 35 Elm_Layout *btn_menu;
35 Eina_Bool btn_visible; 36 Eina_Bool btn_visible;
36 37
diff --git a/src/bin/ui/visuals/cpu_bars.c b/src/bin/ui/visuals/cpu_bars.c
new file mode 100644
index 0000000..bb7b7e0
--- /dev/null
+++ b/src/bin/ui/visuals/cpu_bars.c
@@ -0,0 +1,135 @@
1#include "cpu_bars.h"
2
3#define BAR_WIDTH 16
4
5typedef struct {
6 int cpu_count;
7 int *cpu_order;
8 Eina_List *objects;
9 Evas_Object *tb;
10 Evas_Object *bg;
11} Ext;
12
13static void
14_core_times_main_cb(void *data, Ecore_Thread *thread)
15{
16 int ncpu;
17 Ui_Cpu_Data *pd = data;
18 Ext *ext = pd->ext;
19
20 while (!ecore_thread_check(thread))
21 {
22 cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, 400000);
23 Core *cores_out = calloc(ncpu, sizeof(Core));
24
25 if (cores_out)
26 {
27 for (int n = 0; n < ncpu; n++)
28 {
29 int id = ext->cpu_order[n];
30 Core *core = &(cores_out[n]);
31 core->id = id;
32 core->percent = cores[id]->percent;
33 free(cores[id]);
34 }
35 ecore_thread_feedback(thread, cores_out);
36 }
37 free(cores);
38 }
39}
40
41static void
42_core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgdata)
43{
44 Ui_Cpu_Data *pd;
45 Core *cores;
46 Ext *ext;
47 Evas_Coord oh, ow, ox, oy;
48 int step = 0;
49
50 pd = data;
51 ext = pd->ext;
52 cores = msgdata;
53
54 evas_object_geometry_get(ext->tb, NULL, &oy, &ow, &oh);
55 evas_object_geometry_get(pd->win, NULL, NULL, NULL, &oh);
56
57 step = (oh / 100);
58
59 for (int i = 0; i < ext->cpu_count; i++)
60 {
61 Core *core = &cores[i];
62 Evas_Object *rec = eina_list_nth(ext->objects, i);
63 evas_object_geometry_get(rec, &ox, NULL, NULL, NULL);
64 int c = temp_colormap[core->percent & 0xff];
65 evas_object_color_set(rec, RVAL(c), GVAL(c), BVAL(c), AVAL(c));
66 evas_object_resize(rec, ELM_SCALE_SIZE(BAR_WIDTH), ELM_SCALE_SIZE(core->percent * step));
67 evas_object_move(rec, ox, oy - ELM_SCALE_SIZE(core->percent * step));
68 elm_table_align_set(ext->tb, 0.0, 1.0);
69 }
70
71 free(cores);
72}
73
74static void
75_cb_free(void *data)
76{
77 Ext *ext = data;
78
79 eina_list_free(ext->objects);
80
81 free(ext->cpu_order);
82 free(ext);
83}
84
85Ui_Cpu_Data *
86cpu_visual_bars(Evas_Object *parent_bx)
87{
88 Evas_Object *tb, *rec;
89 Ext *ext;
90 int i;
91
92 Ui_Cpu_Data *pd = calloc(1, sizeof(Ui_Cpu_Data));
93 if (!pd) return NULL;
94
95 pd->ext = ext = calloc(1, sizeof(Ext));
96 EINA_SAFETY_ON_NULL_RETURN_VAL(ext, NULL);
97 pd->ext_free_cb = _cb_free;
98
99 /* Populate lookup table to match id with topology core id */
100 ext->cpu_count = system_cpu_count_get();
101 ext->cpu_order = malloc((ext->cpu_count) * sizeof(int));
102 for (i = 0; i < ext->cpu_count; i++)
103 ext->cpu_order[i] = i;
104 system_cpu_topology_get(ext->cpu_order, ext->cpu_count);
105
106 ext->tb = tb = elm_table_add(parent_bx);
107 elm_table_padding_set(tb, ELM_SCALE_SIZE(2), ELM_SCALE_SIZE(2));
108 evas_object_size_hint_weight_set(tb, EXPAND, EXPAND);
109 evas_object_size_hint_align_set(tb, 0.5, 1.0);
110 evas_object_show(tb);
111
112 for (i = 0; i < ext->cpu_count; i++)
113 {
114 rec = evas_object_rectangle_add(evas_object_evas_get(tb));
115 evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(BAR_WIDTH), 1);
116 elm_table_pack(tb, rec, i, 0, 1, 1);
117 evas_object_show(rec);
118 ext->objects = eina_list_append(ext->objects, rec);
119 }
120
121 rec = evas_object_rectangle_add(evas_object_evas_get(tb));
122 evas_object_size_hint_weight_set(rec, EXPAND, EXPAND);
123 evas_object_size_hint_align_set(rec, FILL, FILL);
124 elm_table_pack(tb, rec, 0, 0, i, 2);
125
126 elm_box_pack_end(parent_bx, tb);
127
128 pd->thread = ecore_thread_feedback_run(_core_times_main_cb,
129 _core_times_feedback_cb,
130 NULL,
131 NULL,
132 pd, 1);
133 return pd;
134}
135
diff --git a/src/bin/ui/visuals/cpu_bars.h b/src/bin/ui/visuals/cpu_bars.h
new file mode 100644
index 0000000..978296c
--- /dev/null
+++ b/src/bin/ui/visuals/cpu_bars.h
@@ -0,0 +1,9 @@
1#ifndef CPU_BARS_H
2#define CPU_BARS_H
3
4#include "ui/ui_cpu.h"
5
6Ui_Cpu_Data *
7cpu_visual_bars(Evas_Object *parent);
8
9#endif
diff --git a/src/bin/ui/visuals/meson.build b/src/bin/ui/visuals/meson.build
index f00a2a7..3a504f5 100644
--- a/src/bin/ui/visuals/meson.build
+++ b/src/bin/ui/visuals/meson.build
@@ -3,4 +3,6 @@ src += files([
3 'cpu_default.h', 3 'cpu_default.h',
4 'cpu_basic.c', 4 'cpu_basic.c',
5 'cpu_basic.h', 5 'cpu_basic.h',
6 'cpu_bars.c',
7 'cpu_bars.h',
6]) 8])
diff --git a/src/bin/ui/visuals/visuals.x b/src/bin/ui/visuals/visuals.x
index 408fc98..5a575ab 100644
--- a/src/bin/ui/visuals/visuals.x
+++ b/src/bin/ui/visuals/visuals.x
@@ -1,7 +1,9 @@
1#include "cpu_default.h" 1#include "cpu_default.h"
2#include "cpu_basic.h" 2#include "cpu_basic.h"
3#include "cpu_bars.h"
3 4
4Cpu_Visual visualizations[] = { 5Cpu_Visual visualizations[] = {
5 { .name = "default", .func = cpu_visual_default }, 6 { .name = "default", .func = cpu_visual_default },
6 { .name = "basic", .func = cpu_visual_basic }, 7 { .name = "basic", .func = cpu_visual_basic },
8 { .name = "bars", .func = cpu_visual_bars },
7}; 9};