ui: add basic cpu core graphs
You can enable/disable per-cpu... Not done
This commit is contained in:
parent
136f5d5c9c
commit
dd67c71022
|
@ -1344,7 +1344,7 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
||||||
elm_object_style_set(border, "pad_small");
|
elm_object_style_set(border, "pad_small");
|
||||||
evas_object_show(border);
|
evas_object_show(border);
|
||||||
|
|
||||||
btn = evisum_ui_button_add(parent, NULL, _("Close"), _btn_quit_clicked_cb,
|
btn = evisum_ui_tab_add(parent, NULL, _("Close"), _btn_quit_clicked_cb,
|
||||||
ui);
|
ui);
|
||||||
elm_object_content_set(border, btn);
|
elm_object_content_set(border, btn);
|
||||||
elm_box_pack_end(box, border);
|
elm_box_pack_end(box, border);
|
||||||
|
|
|
@ -1,10 +1,121 @@
|
||||||
#include "ui_cpu.h"
|
#include "ui_cpu.h"
|
||||||
|
|
||||||
|
#define COLOR_FG 0xff2f99ff
|
||||||
|
#define COLOR_BG 0xff323232
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Evas_Object *bg;
|
||||||
|
Evas_Object *line;
|
||||||
|
Evas_Object *obj;
|
||||||
|
Evas_Object *btn;
|
||||||
|
Eina_Bool enabled;
|
||||||
|
int pos;
|
||||||
|
int cpu_id;
|
||||||
|
double value;
|
||||||
|
double step;
|
||||||
|
} Animation;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
double *value;
|
||||||
|
Evas_Object *pb;
|
||||||
|
} Progress;
|
||||||
|
|
||||||
|
static void
|
||||||
|
graph_clear(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
|
||||||
|
{
|
||||||
|
uint32_t *pixels;
|
||||||
|
Evas_Coord x, y;
|
||||||
|
|
||||||
|
pixels = evas_object_image_data_get(obj, EINA_TRUE);
|
||||||
|
for (y = 0; y < h; y++)
|
||||||
|
{
|
||||||
|
for (x = 0; x < w; x++)
|
||||||
|
{
|
||||||
|
*(pixels++) = COLOR_BG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
evas_object_image_pixels_dirty_set(obj, EINA_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Eina_Bool
|
||||||
|
animator(void *data EINA_UNUSED)
|
||||||
|
{
|
||||||
|
uint32_t *pixels;
|
||||||
|
Evas_Object *line, *obj, *bg;
|
||||||
|
Evas_Coord x, y, w, h;
|
||||||
|
Animation *anim = data;
|
||||||
|
|
||||||
|
bg = anim->bg; line = anim->line; obj = anim->obj;
|
||||||
|
|
||||||
|
evas_object_geometry_get(bg, &x, &y, &w, &h);
|
||||||
|
evas_object_move(line, x + w - anim->pos, y);
|
||||||
|
evas_object_resize(line, 1, h);
|
||||||
|
|
||||||
|
if (anim->enabled)
|
||||||
|
evas_object_show(line);
|
||||||
|
else
|
||||||
|
evas_object_hide(line);
|
||||||
|
|
||||||
|
evas_object_image_size_set(obj, w, h);
|
||||||
|
|
||||||
|
pixels = evas_object_image_data_get(obj, EINA_TRUE);
|
||||||
|
|
||||||
|
int fill_y = h - (int) ((double)(h / 100.0) * anim->value);
|
||||||
|
|
||||||
|
for (y = 0; y < h; y++)
|
||||||
|
{
|
||||||
|
if (!anim->enabled)
|
||||||
|
break;
|
||||||
|
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
|
||||||
|
*(pixels) = COLOR_BG;
|
||||||
|
|
||||||
|
pixels++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// XXX FPS
|
||||||
|
anim->step += (double) w / (60 * 60);
|
||||||
|
anim->pos = anim->step;
|
||||||
|
|
||||||
|
if (anim->pos >= w)
|
||||||
|
{
|
||||||
|
graph_clear(obj, w, h);
|
||||||
|
anim->pos = anim->step = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EINA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ui_tab_cpu_add(Ui *ui)
|
ui_tab_cpu_add(Ui *ui)
|
||||||
{
|
{
|
||||||
Evas_Object *parent, *box, *hbox, *frame, *scroller;
|
Evas_Object *parent, *box, *hbox, *scroller, *frame;
|
||||||
Evas_Object *pb;
|
Evas_Object *pb, *tbl, *lbox, *btn, *rect;
|
||||||
|
Evas_Object *bg, *line, *obj;
|
||||||
unsigned int cpu_count;
|
unsigned int cpu_count;
|
||||||
|
|
||||||
parent = ui->content;
|
parent = ui->content;
|
||||||
|
@ -16,78 +127,125 @@ ui_tab_cpu_add(Ui *ui)
|
||||||
evas_object_hide(box);
|
evas_object_hide(box);
|
||||||
|
|
||||||
ui->cpu_activity = hbox = elm_box_add(box);
|
ui->cpu_activity = hbox = elm_box_add(box);
|
||||||
evas_object_size_hint_weight_set(hbox, EXPAND, 0);
|
evas_object_size_hint_weight_set(hbox, EXPAND, EXPAND);
|
||||||
evas_object_size_hint_align_set(hbox, FILL, FILL);
|
evas_object_size_hint_align_set(hbox, FILL, FILL);
|
||||||
|
elm_box_horizontal_set(hbox, EINA_TRUE);
|
||||||
evas_object_show(hbox);
|
evas_object_show(hbox);
|
||||||
|
|
||||||
frame = elm_frame_add(box);
|
|
||||||
evas_object_size_hint_weight_set(frame, EXPAND, EXPAND);
|
|
||||||
evas_object_size_hint_align_set(frame, FILL, FILL);
|
|
||||||
elm_object_style_set(frame, "pad_small");
|
|
||||||
evas_object_show(frame);
|
|
||||||
|
|
||||||
scroller = elm_scroller_add(parent);
|
scroller = elm_scroller_add(parent);
|
||||||
evas_object_size_hint_weight_set(scroller, EXPAND, EXPAND);
|
evas_object_size_hint_weight_set(scroller, EXPAND, EXPAND);
|
||||||
evas_object_size_hint_align_set(scroller, FILL, FILL);
|
evas_object_size_hint_align_set(scroller, FILL, FILL);
|
||||||
elm_scroller_policy_set(scroller,
|
elm_scroller_policy_set(scroller,
|
||||||
ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
|
ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
|
||||||
evas_object_show(scroller);
|
evas_object_show(scroller);
|
||||||
|
|
||||||
elm_object_content_set(scroller, hbox);
|
elm_object_content_set(scroller, hbox);
|
||||||
elm_object_content_set(frame, scroller);
|
elm_box_pack_end(box, scroller);
|
||||||
elm_box_pack_end(box, frame);
|
|
||||||
|
|
||||||
box = elm_box_add(ui->content);
|
box = elm_box_add(ui->content);
|
||||||
evas_object_size_hint_align_set(box, FILL, FILL);
|
evas_object_size_hint_align_set(box, FILL, FILL);
|
||||||
evas_object_size_hint_weight_set(box, EXPAND, EXPAND);
|
evas_object_size_hint_weight_set(box, 0.1, EXPAND);
|
||||||
evas_object_show(box);
|
evas_object_show(box);
|
||||||
|
|
||||||
frame = elm_frame_add(box);
|
|
||||||
evas_object_size_hint_align_set(frame, FILL, 0);
|
|
||||||
evas_object_size_hint_weight_set(frame, EXPAND, EXPAND);
|
|
||||||
evas_object_show(frame);
|
|
||||||
elm_object_style_set(frame, "pad_large");
|
|
||||||
elm_box_pack_end(box, frame);
|
|
||||||
|
|
||||||
cpu_count = system_cpu_online_count_get();
|
cpu_count = system_cpu_online_count_get();
|
||||||
for (int i = 0; i < cpu_count; i++)
|
for (int i = 0; i < cpu_count; i++)
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
frame = elm_frame_add(box);
|
frame = elm_frame_add(box);
|
||||||
evas_object_size_hint_align_set(frame, FILL, 0);
|
evas_object_size_hint_align_set(frame, FILL, FILL);
|
||||||
evas_object_size_hint_weight_set(frame, EXPAND, EXPAND);
|
evas_object_size_hint_weight_set(frame, 0, EXPAND);
|
||||||
evas_object_show(frame);
|
evas_object_show(frame);
|
||||||
elm_object_style_set(frame, "pad_huge");
|
elm_object_style_set(frame, "pad_medium");
|
||||||
|
|
||||||
pb = elm_progressbar_add(frame);
|
pb = elm_progressbar_add(frame);
|
||||||
evas_object_size_hint_align_set(pb, FILL, FILL);
|
evas_object_size_hint_align_set(pb, FILL, FILL);
|
||||||
evas_object_size_hint_weight_set(pb, EXPAND, EXPAND);
|
evas_object_size_hint_weight_set(pb, 0.1, EXPAND);
|
||||||
elm_progressbar_span_size_set(pb, 1.0);
|
elm_progressbar_span_size_set(pb, 1.0);
|
||||||
elm_progressbar_unit_format_set(pb, "%1.2f%%");
|
elm_progressbar_unit_format_set(pb, "%1.2f%%");
|
||||||
evas_object_show(pb);
|
evas_object_show(pb);
|
||||||
elm_progressbar_value_set(pb, 0.0);
|
elm_progressbar_value_set(pb, 0.0);
|
||||||
|
|
||||||
elm_object_content_set(frame, pb);
|
elm_box_pack_end(lbox, pb);
|
||||||
|
elm_box_pack_end(lbox, btn);
|
||||||
|
|
||||||
|
Progress *progress = calloc(1, sizeof(Progress));
|
||||||
|
progress->value = calloc(1, sizeof(float));
|
||||||
|
progress->pb = pb;
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
progress->value = &anim->value;
|
||||||
|
evas_object_smart_callback_add(btn, "clicked", _btn_clicked_cb, anim);
|
||||||
|
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);
|
||||||
elm_box_pack_end(box, frame);
|
elm_box_pack_end(box, frame);
|
||||||
|
|
||||||
ui->cpu_list = eina_list_append(ui->cpu_list, pb);
|
ui->cpu_list = eina_list_append(ui->cpu_list, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
elm_box_pack_end(ui->cpu_activity, box);
|
elm_box_pack_end(hbox, box);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ui_tab_cpu_update(Ui *ui, Sys_Info *info)
|
ui_tab_cpu_update(Ui *ui, Sys_Info *info)
|
||||||
{
|
{
|
||||||
Eina_List *l;
|
Eina_List *l;
|
||||||
Evas_Object *pb;
|
Progress *progress;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!ui->cpu_visible)
|
if (!ui->cpu_visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EINA_LIST_FOREACH(ui->cpu_list, l, pb)
|
EINA_LIST_FOREACH(ui->cpu_list, l, progress)
|
||||||
{
|
{
|
||||||
elm_progressbar_value_set(pb, info->cores[i]->percent / 100);
|
*progress->value = info->cores[i]->percent;
|
||||||
|
elm_progressbar_value_set(progress->pb, info->cores[i]->percent / 100);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue