2020-05-12 16:51:30 -07:00
|
|
|
#include "ui_cpu.h"
|
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
#define COLOR_FG 0xff2f99ff
|
|
|
|
#define COLOR_BG 0xff323232
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Evas_Object *bg;
|
|
|
|
Evas_Object *line;
|
|
|
|
Evas_Object *obj;
|
|
|
|
Evas_Object *btn;
|
2020-06-24 05:11:10 -07:00
|
|
|
Ui *ui;
|
2020-06-23 17:06:08 -07:00
|
|
|
Eina_Bool enabled;
|
|
|
|
int pos;
|
|
|
|
int cpu_id;
|
|
|
|
double value;
|
|
|
|
double step;
|
|
|
|
} Animation;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
double *value;
|
|
|
|
Evas_Object *pb;
|
|
|
|
} Progress;
|
|
|
|
|
|
|
|
static void
|
2020-06-24 09:09:06 -07:00
|
|
|
anim_reset(Animation *anim)
|
2020-06-23 17:06:08 -07:00
|
|
|
{
|
|
|
|
uint32_t *pixels;
|
2020-06-24 09:09:06 -07:00
|
|
|
Evas_Object *o;
|
|
|
|
Evas_Coord x, y, w, h;
|
2020-06-23 17:06:08 -07:00
|
|
|
|
2020-06-24 09:09:06 -07:00
|
|
|
if (!anim) return;
|
|
|
|
|
2020-06-24 15:12:16 -07:00
|
|
|
anim->pos = anim->step = 0;
|
|
|
|
|
|
|
|
if (!anim->enabled) return;
|
|
|
|
|
2020-06-24 09:09:06 -07:00
|
|
|
evas_object_geometry_get(anim->bg, NULL, NULL, &w, &h);
|
|
|
|
if (w <= 0 || h <= 0) return;
|
|
|
|
|
|
|
|
o = anim->obj;
|
|
|
|
|
|
|
|
pixels = evas_object_image_data_get(o, EINA_TRUE);
|
|
|
|
if (!pixels) return;
|
2020-06-24 15:12:16 -07:00
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
for (y = 0; y < h; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
*(pixels++) = COLOR_BG;
|
|
|
|
}
|
2020-06-24 15:12:16 -07:00
|
|
|
}
|
2020-06-24 09:09:06 -07:00
|
|
|
evas_object_image_data_update_add(o, 0, 0, w, h);
|
2020-06-23 17:06:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2020-06-24 15:12:16 -07:00
|
|
|
animator(void *data)
|
2020-06-23 17:06:08 -07:00
|
|
|
{
|
|
|
|
uint32_t *pixels;
|
|
|
|
Evas_Object *line, *obj, *bg;
|
|
|
|
Evas_Coord x, y, w, h;
|
2020-06-24 09:09:06 -07:00
|
|
|
Evas_Coord fill_y;
|
2020-06-24 15:12:16 -07:00
|
|
|
double value;
|
2020-06-23 17:06:08 -07:00
|
|
|
Animation *anim = data;
|
|
|
|
|
2020-06-24 05:11:10 -07:00
|
|
|
if (!anim->ui->cpu_visible) return EINA_TRUE;
|
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
bg = anim->bg; line = anim->line; obj = anim->obj;
|
|
|
|
|
2020-06-24 15:12:16 -07:00
|
|
|
evas_object_geometry_get(bg, &x, &y, &w, &h);
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_move(line, x + w - anim->pos, y);
|
|
|
|
evas_object_resize(line, 1, h);
|
|
|
|
if (anim->enabled)
|
|
|
|
evas_object_show(line);
|
|
|
|
else
|
2020-06-24 06:11:56 -07:00
|
|
|
evas_object_hide(line);
|
2020-06-23 17:06:08 -07:00
|
|
|
|
|
|
|
evas_object_image_size_set(obj, w, h);
|
|
|
|
|
|
|
|
pixels = evas_object_image_data_get(obj, EINA_TRUE);
|
|
|
|
|
2020-06-24 15:12:16 -07:00
|
|
|
value = anim->value > 0 ? anim->value : 1.0;
|
|
|
|
|
|
|
|
fill_y = h - (int) ((double)(h / 100.0) * value);
|
2020-06-23 17:06:08 -07:00
|
|
|
|
2020-06-24 09:09:06 -07:00
|
|
|
for (y = 0; anim->enabled && y < h; y++)
|
2020-06-23 17:06:08 -07:00
|
|
|
{
|
2020-06-24 09:09:06 -07:00
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
if ((x == (w - anim->pos)) && (y >= fill_y))
|
|
|
|
{
|
|
|
|
if (y % 2)
|
|
|
|
*(pixels) = COLOR_FG;
|
|
|
|
else
|
|
|
|
*(pixels) = COLOR_BG;
|
|
|
|
}
|
|
|
|
else if (x <= (w - anim->pos))
|
|
|
|
*(pixels) = COLOR_BG;
|
2020-06-23 17:06:08 -07:00
|
|
|
|
2020-06-24 15:12:16 -07:00
|
|
|
pixels++;
|
|
|
|
}
|
2020-06-23 17:06:08 -07:00
|
|
|
}
|
2020-06-24 09:09:06 -07:00
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
// XXX FPS
|
|
|
|
anim->step += (double) w / (60 * 60);
|
|
|
|
anim->pos = anim->step;
|
|
|
|
|
|
|
|
if (anim->pos >= w)
|
|
|
|
{
|
2020-06-24 09:09:06 -07:00
|
|
|
anim_reset(anim);
|
2020-06-23 17:06:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-24 09:09:06 -07:00
|
|
|
static void
|
|
|
|
_anim_resize_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Animation *anim = data;
|
|
|
|
|
2020-06-24 15:12:16 -07:00
|
|
|
if (!anim->ui->cpu_visible) return;
|
|
|
|
|
|
|
|
evas_object_hide(anim->line);
|
2020-06-24 09:09:06 -07:00
|
|
|
anim_reset(anim);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_anim_move_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Animation *anim = data;
|
|
|
|
|
|
|
|
evas_object_hide(anim->line);
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
static void
|
|
|
|
_btn_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Evas_Object *rect;
|
|
|
|
Animation *anim = data;
|
|
|
|
|
|
|
|
anim->enabled = !anim->enabled;
|
|
|
|
|
|
|
|
rect = elm_object_part_content_get(anim->btn, "elm.swallow.content");
|
|
|
|
if (!anim->enabled)
|
|
|
|
evas_object_color_set(rect, 0, 0, 0, 0);
|
|
|
|
else
|
|
|
|
evas_object_color_set(rect, 47, 153, 255, 255);
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:11:10 -07:00
|
|
|
static void
|
|
|
|
_core_times_cb(void *data, Ecore_Thread *thread)
|
|
|
|
{
|
|
|
|
Progress *progress;
|
|
|
|
cpu_core_t **cores;
|
|
|
|
Eina_List *l;
|
|
|
|
Ui *ui;
|
|
|
|
int ncpu, i;
|
|
|
|
|
|
|
|
ui = data;
|
2020-06-24 15:12:16 -07:00
|
|
|
|
|
|
|
while (!ecore_thread_check(thread))
|
2020-06-24 05:11:10 -07:00
|
|
|
{
|
|
|
|
if (!ui->cpu_visible)
|
|
|
|
{
|
|
|
|
usleep(1000000);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
cores = system_cpu_usage_get(&ncpu);
|
|
|
|
EINA_LIST_FOREACH(ui->cpu_list, l, progress)
|
|
|
|
{
|
|
|
|
*progress->value = cores[i]->percent;
|
|
|
|
ecore_thread_main_loop_begin();
|
2020-06-24 15:12:16 -07:00
|
|
|
elm_progressbar_value_set(progress->pb, cores[i]->percent / 100);
|
2020-06-24 05:11:10 -07:00
|
|
|
ecore_thread_main_loop_end();
|
2020-06-24 15:12:16 -07:00
|
|
|
free(cores[i++]);
|
2020-06-24 05:11:10 -07:00
|
|
|
}
|
|
|
|
free(cores);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 16:51:30 -07:00
|
|
|
void
|
|
|
|
ui_tab_cpu_add(Ui *ui)
|
|
|
|
{
|
2020-06-23 17:06:08 -07:00
|
|
|
Evas_Object *parent, *box, *hbox, *scroller, *frame;
|
|
|
|
Evas_Object *pb, *tbl, *lbox, *btn, *rect;
|
|
|
|
Evas_Object *bg, *line, *obj;
|
2020-06-24 15:12:16 -07:00
|
|
|
int cpu_count;
|
2020-05-12 16:51:30 -07:00
|
|
|
|
|
|
|
parent = ui->content;
|
|
|
|
|
|
|
|
ui->cpu_view = box = elm_box_add(parent);
|
2020-05-24 06:41:13 -07:00
|
|
|
evas_object_size_hint_weight_set(box, EXPAND, EXPAND);
|
|
|
|
evas_object_size_hint_align_set(box, FILL, FILL);
|
2020-05-12 16:51:30 -07:00
|
|
|
elm_table_pack(ui->content, ui->cpu_view, 0, 1, 1, 1);
|
|
|
|
evas_object_hide(box);
|
|
|
|
|
|
|
|
ui->cpu_activity = hbox = elm_box_add(box);
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_size_hint_weight_set(hbox, EXPAND, EXPAND);
|
2020-05-24 06:41:13 -07:00
|
|
|
evas_object_size_hint_align_set(hbox, FILL, FILL);
|
2020-06-23 17:06:08 -07:00
|
|
|
elm_box_horizontal_set(hbox, EINA_TRUE);
|
2020-05-12 16:51:30 -07:00
|
|
|
evas_object_show(hbox);
|
|
|
|
|
|
|
|
scroller = elm_scroller_add(parent);
|
2020-05-24 06:41:13 -07:00
|
|
|
evas_object_size_hint_weight_set(scroller, EXPAND, EXPAND);
|
|
|
|
evas_object_size_hint_align_set(scroller, FILL, FILL);
|
|
|
|
elm_scroller_policy_set(scroller,
|
|
|
|
ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
|
2020-05-12 16:51:30 -07:00
|
|
|
evas_object_show(scroller);
|
2020-06-03 05:45:29 -07:00
|
|
|
elm_object_content_set(scroller, hbox);
|
2020-06-23 17:06:08 -07:00
|
|
|
elm_box_pack_end(box, scroller);
|
2020-05-12 16:51:30 -07:00
|
|
|
|
|
|
|
box = elm_box_add(ui->content);
|
2020-05-24 06:41:13 -07:00
|
|
|
evas_object_size_hint_align_set(box, FILL, FILL);
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_size_hint_weight_set(box, 0.1, EXPAND);
|
2020-05-12 16:51:30 -07:00
|
|
|
evas_object_show(box);
|
|
|
|
|
2020-06-03 05:45:29 -07:00
|
|
|
cpu_count = system_cpu_online_count_get();
|
|
|
|
for (int i = 0; i < cpu_count; i++)
|
|
|
|
{
|
2020-06-23 17:06:08 -07:00
|
|
|
lbox = elm_box_add(ui->content);
|
|
|
|
evas_object_size_hint_align_set(lbox, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(lbox, 0.1, EXPAND);
|
|
|
|
evas_object_show(lbox);
|
|
|
|
elm_box_horizontal_set(lbox, EINA_TRUE);
|
|
|
|
|
|
|
|
btn = elm_button_add(box);
|
|
|
|
evas_object_show(btn);
|
|
|
|
|
|
|
|
rect = evas_object_rectangle_add(evas_object_evas_get(box));
|
|
|
|
evas_object_size_hint_min_set(rect, 16, 16);
|
|
|
|
evas_object_color_set(rect, 47, 153, 255, 255);
|
|
|
|
evas_object_show(rect);
|
|
|
|
elm_object_part_content_set(btn, "elm.swallow.content", rect);
|
|
|
|
|
2020-05-12 16:51:30 -07:00
|
|
|
frame = elm_frame_add(box);
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_size_hint_align_set(frame, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(frame, 0, EXPAND);
|
2020-05-12 16:51:30 -07:00
|
|
|
evas_object_show(frame);
|
2020-06-24 07:26:18 -07:00
|
|
|
elm_object_style_set(frame, "pad_small");
|
2020-05-12 16:51:30 -07:00
|
|
|
|
2020-06-17 14:34:25 -07:00
|
|
|
pb = elm_progressbar_add(frame);
|
|
|
|
evas_object_size_hint_align_set(pb, FILL, FILL);
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_size_hint_weight_set(pb, 0.1, EXPAND);
|
2020-06-17 14:34:25 -07:00
|
|
|
elm_progressbar_span_size_set(pb, 1.0);
|
|
|
|
elm_progressbar_unit_format_set(pb, "%1.2f%%");
|
|
|
|
evas_object_show(pb);
|
2020-05-12 16:51:30 -07:00
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
elm_box_pack_end(lbox, btn);
|
2020-06-24 15:12:16 -07:00
|
|
|
elm_box_pack_end(lbox, pb);
|
2020-06-23 17:06:08 -07:00
|
|
|
|
|
|
|
tbl = elm_table_add(box);
|
|
|
|
evas_object_size_hint_align_set(tbl, FILL, FILL);
|
|
|
|
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_size_hint_min_set(bg, 1, 80);
|
|
|
|
|
|
|
|
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);
|
2020-06-24 09:09:06 -07:00
|
|
|
evas_object_size_hint_max_set(line, 1, -1);
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_show(line);
|
|
|
|
|
|
|
|
obj = evas_object_image_add(evas_object_evas_get(bg));
|
|
|
|
evas_object_size_hint_align_set(obj, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(obj, EXPAND, EXPAND);
|
|
|
|
evas_object_image_filled_set(obj, EINA_TRUE);
|
|
|
|
evas_object_show(obj);
|
|
|
|
|
|
|
|
Animation *anim = calloc(1, sizeof(Animation));
|
|
|
|
anim->bg = bg;
|
|
|
|
anim->obj = obj;
|
|
|
|
anim->line = line;
|
|
|
|
anim->enabled = EINA_TRUE;
|
|
|
|
anim->btn = btn;
|
|
|
|
anim->cpu_id = i;
|
2020-06-24 05:11:10 -07:00
|
|
|
anim->ui = ui;
|
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
evas_object_smart_callback_add(btn, "clicked", _btn_clicked_cb, anim);
|
2020-06-24 09:09:06 -07:00
|
|
|
evas_object_smart_callback_add(tbl, "resize", _anim_resize_cb, anim);
|
|
|
|
evas_object_smart_callback_add(tbl, "move", _anim_move_cb, anim);
|
2020-06-23 17:06:08 -07:00
|
|
|
ecore_animator_add(animator, anim);
|
|
|
|
|
|
|
|
elm_table_pack(tbl, bg, 0, 1, 1, 1);
|
|
|
|
elm_table_pack(tbl, obj, 0, 1, 1, 1);
|
|
|
|
elm_table_pack(tbl, line, 0, 1, 1, 1);
|
|
|
|
elm_box_pack_end(lbox, tbl);
|
|
|
|
elm_object_content_set(frame, lbox);
|
2020-05-12 16:51:30 -07:00
|
|
|
elm_box_pack_end(box, frame);
|
|
|
|
|
2020-06-24 15:12:16 -07:00
|
|
|
Progress *progress = calloc(1, sizeof(Progress));
|
|
|
|
progress->value = calloc(1, sizeof(float *));
|
|
|
|
progress->pb = pb;
|
|
|
|
progress->value = &anim->value;
|
|
|
|
|
2020-06-23 17:06:08 -07:00
|
|
|
ui->cpu_list = eina_list_append(ui->cpu_list, progress);
|
2020-05-12 16:51:30 -07:00
|
|
|
}
|
|
|
|
|
2020-06-24 05:11:10 -07:00
|
|
|
ui->thread_cpu = ecore_thread_run(_core_times_cb, NULL, NULL, ui);
|
2020-05-12 16:51:30 -07:00
|
|
|
|
2020-06-24 05:11:10 -07:00
|
|
|
elm_box_pack_end(hbox, box);
|
2020-05-12 16:51:30 -07:00
|
|
|
}
|
|
|
|
|