2020-05-12 16:51:30 -07:00
|
|
|
#include "ui_cpu.h"
|
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
typedef struct {
|
|
|
|
short id;
|
|
|
|
short percent;
|
|
|
|
unsigned int freq;
|
|
|
|
} Core;
|
2020-09-08 04:50:48 -07:00
|
|
|
|
2020-09-07 18:25:33 -07:00
|
|
|
typedef struct {
|
|
|
|
Ui *ui;
|
|
|
|
|
|
|
|
Evas_Object *bg;
|
|
|
|
Evas_Object *obj;
|
|
|
|
|
2020-09-08 07:27:37 -07:00
|
|
|
Evas_Object *colors;
|
|
|
|
|
2020-09-07 18:25:33 -07:00
|
|
|
int cpu_count;
|
|
|
|
|
2020-09-08 13:54:41 -07:00
|
|
|
Eina_Bool show_cpufreq;
|
2020-09-07 19:02:38 -07:00
|
|
|
// Have cpu scaling
|
|
|
|
Eina_Bool cpu_freq;
|
|
|
|
int freq_min;
|
|
|
|
int freq_max;
|
2020-09-07 18:25:33 -07:00
|
|
|
} Animate;
|
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
typedef struct _Color_Point {
|
|
|
|
unsigned int val;
|
|
|
|
unsigned int color;
|
|
|
|
} Color_Point;
|
|
|
|
|
|
|
|
// config for colors/sizing
|
2020-09-10 05:46:53 -07:00
|
|
|
#define COLOR_CPU_NUM 5
|
2020-09-09 18:45:47 -07:00
|
|
|
static const Color_Point cpu_colormap_in[] = {
|
|
|
|
{ 0, 0xff202020 }, // 0
|
2020-09-10 05:46:53 -07:00
|
|
|
{ 25, 0xff2030a0 }, // 1
|
|
|
|
{ 50, 0xffa040a0 }, // 2
|
|
|
|
{ 75, 0xffff9040 }, // 3
|
|
|
|
{ 100, 0xffffffff }, // 4
|
|
|
|
{ 256, 0xffffffff } // overflow to avoid if's
|
2020-09-09 18:45:47 -07:00
|
|
|
};
|
2020-09-10 05:46:53 -07:00
|
|
|
#define COLOR_FREQ_NUM 4
|
2020-09-09 18:45:47 -07:00
|
|
|
static const Color_Point freq_colormap_in[] = {
|
2020-09-10 05:46:53 -07:00
|
|
|
{ 0, 0xff202020 }, // 0
|
|
|
|
{ 33, 0xff285020 }, // 1
|
|
|
|
{ 67, 0xff30a060 }, // 2
|
|
|
|
{ 100, 0xffa0ff80 }, // 3
|
|
|
|
{ 256, 0xffa0ff80 } // overflow to avoid if's
|
2020-09-09 18:45:47 -07:00
|
|
|
};
|
|
|
|
#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))
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
static void
|
|
|
|
_color_init(const Color_Point *col_in, unsigned int n, unsigned int *col)
|
2020-09-08 03:18:45 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
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;
|
2020-09-08 05:31:12 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// wal colormap_in until colormap table is full
|
|
|
|
for (pos = 0, val = 0; pos < n; pos++)
|
2020-09-08 07:27:37 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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++;
|
|
|
|
}
|
2020-09-08 07:27:37 -07:00
|
|
|
}
|
2020-09-08 03:18:45 -07:00
|
|
|
}
|
|
|
|
|
2020-09-07 18:25:33 -07:00
|
|
|
static void
|
2020-09-09 18:45:47 -07:00
|
|
|
_core_times_main_cb(void *data, Ecore_Thread *thread)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
// this runs in a dedicated thread in the bg sleeping, collecting info
|
|
|
|
// on usage then sending as feedback to mainloop
|
|
|
|
Animate *ad = data;
|
2020-09-07 19:02:38 -07:00
|
|
|
int ncpu;
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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
|
2020-09-07 19:02:38 -07:00
|
|
|
if (!system_cpu_frequency_min_max_get(&ad->freq_min, &ad->freq_max))
|
|
|
|
ad->cpu_freq = EINA_TRUE;
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// while this thread has not been canceled
|
2020-09-07 18:25:33 -07:00
|
|
|
while (!ecore_thread_check(thread))
|
|
|
|
{
|
2020-09-08 05:31:12 -07:00
|
|
|
cpu_core_t **cores = system_cpu_usage_delayed_get(&ncpu, 100000);
|
2020-09-09 18:45:47 -07:00
|
|
|
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)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
for (int n = 0; n < ncpu; n++)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
// Copy our core state data to mainloop
|
|
|
|
Core *core = &(cores_out[n]);
|
|
|
|
core->id = n;
|
2020-09-07 19:02:38 -07:00
|
|
|
core->percent = cores[n]->percent;
|
|
|
|
if (ad->cpu_freq)
|
|
|
|
core->freq = system_cpu_n_frequency_get(n);
|
2020-09-09 18:45:47 -07:00
|
|
|
free(cores[n]);
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
2020-09-09 18:45:47 -07:00
|
|
|
ecore_thread_feedback(thread, cores_out);
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
free(cores);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-09-09 18:45:47 -07:00
|
|
|
_update(Animate *ad, Core *cores)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
Evas_Object *obj = ad->obj;
|
|
|
|
unsigned int *pixels, *pix;
|
2020-09-08 03:18:45 -07:00
|
|
|
Evas_Coord x, y, w, h;
|
2020-09-09 18:45:47 -07:00
|
|
|
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)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-10 05:46:53 -07:00
|
|
|
evas_object_image_size_set(obj, w, ad->cpu_count * 2);
|
2020-09-09 18:45:47 -07:00
|
|
|
clear = EINA_TRUE;
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// get pixel data ptr
|
2020-09-07 18:25:33 -07:00
|
|
|
pixels = evas_object_image_data_get(obj, EINA_TRUE);
|
2020-09-09 18:45:47 -07:00
|
|
|
if (!pixels) return;
|
|
|
|
// get stride (# of bytes per line)
|
|
|
|
stride = evas_object_image_stride_get(obj);
|
2020-09-07 19:02:38 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// go throuhg al the cpu cores
|
|
|
|
for (y = 0; y < ad->cpu_count; y++)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
Core *core = &(cores[y]);
|
|
|
|
unsigned int c1, c2;
|
|
|
|
|
|
|
|
// our pix ptr is the pixel row and y is both y pixel coord and core
|
|
|
|
if (clear)
|
|
|
|
{
|
|
|
|
// clear/fill with 0 value from colormap
|
2020-09-10 05:46:53 -07:00
|
|
|
pix = &(pixels[(y * 2) * (stride / 4)]);
|
2020-09-09 18:45:47 -07:00
|
|
|
for (x = 0; x < (w - 1); x++) pix[x] = cpu_colormap[0];
|
2020-09-10 05:46:53 -07:00
|
|
|
pix = &(pixels[((y * 2) + 1) * (stride / 4)]);
|
|
|
|
for (x = 0; x < (w - 1); x++) pix[x] = freq_colormap[0];
|
2020-09-09 18:45:47 -07:00
|
|
|
}
|
|
|
|
else
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
// scroll pixels 1 to the left
|
2020-09-10 05:46:53 -07:00
|
|
|
pix = &(pixels[(y * 2) * (stride / 4)]);
|
|
|
|
for (x = 0; x < (w - 1); x++) pix[x] = pix[x + 1];
|
|
|
|
pix = &(pixels[((y * 2) + 1) * (stride / 4)]);
|
2020-09-09 18:45:47 -07:00
|
|
|
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
|
2020-09-10 05:46:53 -07:00
|
|
|
// get color from cpu colormap
|
|
|
|
// last pixel == resulting pixel color
|
2020-09-09 18:45:47 -07:00
|
|
|
c1 = cpu_colormap[core->percent & 0xff];
|
2020-09-10 05:46:53 -07:00
|
|
|
pix = &(pixels[(y * 2) * (stride / 4)]);
|
|
|
|
pix[x] = c1;
|
|
|
|
// 2nd row of pixles for freq
|
2020-09-09 18:45:47 -07:00
|
|
|
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)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
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];
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
2020-09-10 05:46:53 -07:00
|
|
|
else c2 = freq_colormap[0];
|
|
|
|
pix = &(pixels[((y * 2) + 1) * (stride / 4)]);
|
|
|
|
pix[x] = c2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no freq show - then just repeat cpu usage color
|
|
|
|
pix = &(pixels[((y * 2) + 1) * (stride / 4)]);
|
|
|
|
pix[x] = c1;
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
}
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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
|
2020-09-10 05:46:53 -07:00
|
|
|
evas_object_image_data_update_add(obj, 0, 0, w, ad->cpu_count * 2);
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-09-09 18:45:47 -07:00
|
|
|
_core_times_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, void *msgdata)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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
|
2020-09-07 18:25:33 -07:00
|
|
|
Animate *ad = data;
|
2020-09-09 18:45:47 -07:00
|
|
|
Core *cores = msgdata;
|
|
|
|
_update(ad, cores);
|
|
|
|
free(cores);
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-09-09 18:45:47 -07:00
|
|
|
_win_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
|
|
|
Animate *ad = data;
|
2020-09-09 18:45:47 -07:00
|
|
|
Ui *ui = ad->ui;
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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;
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
|
2020-09-08 08:02:26 -07:00
|
|
|
static void
|
2020-09-09 18:45:47 -07:00
|
|
|
_check_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
2020-09-08 08:02:26 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
Animate *ad = data;
|
|
|
|
// sho freq overlay check changed
|
|
|
|
ad->show_cpufreq = elm_check_state_get(obj);
|
2020-09-08 08:02:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-09-09 18:45:47 -07:00
|
|
|
_colors_fill(Evas_Object *colors)
|
2020-09-08 08:02:26 -07:00
|
|
|
{
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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;
|
2020-09-08 08:02:26 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
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);
|
2020-09-08 08:02:26 -07:00
|
|
|
}
|
|
|
|
|
2020-09-07 18:25:33 -07:00
|
|
|
static void
|
2020-09-08 07:27:37 -07:00
|
|
|
_graph(Ui *ui, Evas_Object *parent)
|
2020-09-07 18:25:33 -07:00
|
|
|
{
|
2020-09-10 04:00:40 -07:00
|
|
|
Evas_Object *frame, *tbl, *box, *obj, *ic, *lb, *rec;
|
|
|
|
Evas_Object *fr, *bx, *colors, *check;
|
2020-09-10 04:12:36 -07:00
|
|
|
int i, f;
|
2020-09-10 04:00:40 -07:00
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
Animate *ad = calloc(1, sizeof(Animate));
|
|
|
|
if (!ad) return;
|
|
|
|
|
|
|
|
ad->cpu_count = system_cpu_online_count_get();
|
2020-09-11 01:58:47 -07:00
|
|
|
if (!system_cpu_frequency_min_max_get(&ad->freq_min, &ad->freq_max))
|
|
|
|
ad->cpu_freq = EINA_TRUE;
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// init colormaps from a small # of points
|
2020-09-10 05:46:53 -07:00
|
|
|
_color_init(cpu_colormap_in, COLOR_CPU_NUM, cpu_colormap);
|
|
|
|
_color_init(freq_colormap_in, COLOR_FREQ_NUM, freq_colormap);
|
2020-09-09 18:45:47 -07:00
|
|
|
|
2020-09-07 18:25:33 -07:00
|
|
|
box = parent;
|
|
|
|
|
|
|
|
frame = elm_frame_add(box);
|
|
|
|
evas_object_size_hint_align_set(frame, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(frame, EXPAND, EXPAND);
|
|
|
|
evas_object_show(frame);
|
2020-09-10 04:00:40 -07:00
|
|
|
if (ad->cpu_count > 1)
|
|
|
|
elm_object_text_set(frame, eina_slstr_printf(_("%d CPU Cores"), ad->cpu_count));
|
2020-09-08 08:02:26 -07:00
|
|
|
else
|
|
|
|
elm_object_text_set(frame, _("ONE CPU CORE...MAKE IT COUNT!!!"));
|
2020-09-07 18:25:33 -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);
|
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
obj = evas_object_image_add(evas_object_evas_get(parent));
|
2020-09-07 18:25:33 -07:00
|
|
|
evas_object_size_hint_align_set(obj, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(obj, EXPAND, EXPAND);
|
2020-09-09 18:45:47 -07:00
|
|
|
evas_object_image_smooth_scale_set(obj, EINA_FALSE);
|
2020-09-07 18:25:33 -07:00
|
|
|
evas_object_image_filled_set(obj, EINA_TRUE);
|
2020-09-09 18:45:47 -07:00
|
|
|
evas_object_image_alpha_set(obj, EINA_FALSE);
|
2020-09-07 18:25:33 -07:00
|
|
|
evas_object_show(obj);
|
|
|
|
|
2020-09-10 04:00:40 -07:00
|
|
|
elm_table_pack(tbl, obj, 0, 0, 5, ad->cpu_count);
|
|
|
|
|
|
|
|
for (i = 0; i < ad->cpu_count; i++)
|
|
|
|
{
|
|
|
|
rec = evas_object_rectangle_add(evas_object_evas_get(parent));
|
|
|
|
evas_object_color_set(rec, 0, 0, 0, 0);
|
2020-09-10 05:46:53 -07:00
|
|
|
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(8), ELM_SCALE_SIZE(8));
|
2020-09-10 04:00:40 -07:00
|
|
|
evas_object_size_hint_weight_set(rec, 0.0, EXPAND);
|
|
|
|
elm_table_pack(tbl, rec, 0, i, 1, 1);
|
|
|
|
|
|
|
|
rec = evas_object_rectangle_add(evas_object_evas_get(parent));
|
|
|
|
evas_object_color_set(rec, 0, 0, 0, 0);
|
|
|
|
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(24), ELM_SCALE_SIZE(24));
|
|
|
|
evas_object_size_hint_weight_set(rec, 0.0, EXPAND);
|
|
|
|
elm_table_pack(tbl, rec, 1, i, 1, 1);
|
|
|
|
|
|
|
|
ic = elm_icon_add(parent);
|
|
|
|
elm_icon_standard_set(ic, evisum_icon_path_get("cpu"));
|
|
|
|
evas_object_size_hint_align_set(ic, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(ic, 0.0, EXPAND);
|
|
|
|
elm_table_pack(tbl, ic, 1, i, 1, 1);
|
|
|
|
evas_object_show(ic);
|
|
|
|
|
|
|
|
rec = evas_object_rectangle_add(evas_object_evas_get(parent));
|
|
|
|
evas_object_color_set(rec, 0, 0, 0, 0);
|
2020-09-10 05:46:53 -07:00
|
|
|
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(8), ELM_SCALE_SIZE(8));
|
2020-09-10 04:00:40 -07:00
|
|
|
evas_object_size_hint_weight_set(rec, 0.0, EXPAND);
|
|
|
|
elm_table_pack(tbl, rec, 2, i, 1, 1);
|
|
|
|
|
|
|
|
lb = elm_label_add(parent);
|
2020-09-10 05:46:53 -07:00
|
|
|
snprintf(buf, sizeof(buf), "<b><color=#fff>%i</></>", i);
|
2020-09-10 04:00:40 -07:00
|
|
|
elm_object_text_set(lb, buf);
|
|
|
|
evas_object_size_hint_align_set(lb, 1.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(lb, 0.0, EXPAND);
|
|
|
|
elm_table_pack(tbl, lb, 3, i, 1, 1);
|
|
|
|
evas_object_show(lb);
|
|
|
|
}
|
2020-09-08 07:27:37 -07:00
|
|
|
|
|
|
|
bx = elm_box_add(box);
|
|
|
|
evas_object_size_hint_align_set(bx, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(bx, EXPAND, EXPAND);
|
|
|
|
evas_object_show(bx);
|
|
|
|
elm_box_pack_end(bx, tbl);
|
|
|
|
|
2020-09-08 08:02:26 -07:00
|
|
|
// Set the main content.
|
|
|
|
elm_object_content_set(frame, bx);
|
|
|
|
elm_box_pack_end(box, frame);
|
|
|
|
|
2020-09-10 04:00:40 -07:00
|
|
|
tbl = elm_table_add(box);
|
|
|
|
evas_object_size_hint_align_set(tbl, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(tbl, EXPAND, 0);
|
|
|
|
evas_object_show(tbl);
|
2020-09-08 07:27:37 -07:00
|
|
|
|
|
|
|
fr = elm_frame_add(box);
|
|
|
|
evas_object_size_hint_align_set(fr, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(fr, EXPAND, 0);
|
|
|
|
evas_object_show(fr);
|
2020-09-10 04:00:40 -07:00
|
|
|
elm_object_text_set(fr, _("Legend"));
|
|
|
|
elm_object_content_set(fr, tbl);
|
2020-09-08 07:27:37 -07:00
|
|
|
|
|
|
|
colors = evas_object_image_add(evas_object_evas_get(fr));
|
2020-09-09 18:45:47 -07:00
|
|
|
evas_object_size_hint_min_set
|
|
|
|
(colors, 100, COLORS_HEIGHT * elm_config_scale_get());
|
2020-09-08 07:27:37 -07:00
|
|
|
evas_object_size_hint_align_set(colors, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(colors, EXPAND, EXPAND);
|
2020-09-09 18:45:47 -07:00
|
|
|
evas_object_image_smooth_scale_set(colors, EINA_FALSE);
|
2020-09-08 07:27:37 -07:00
|
|
|
evas_object_image_filled_set(colors, EINA_TRUE);
|
2020-09-09 18:45:47 -07:00
|
|
|
evas_object_image_alpha_set(colors, EINA_FALSE);
|
|
|
|
_colors_fill(colors);
|
2020-09-10 04:00:40 -07:00
|
|
|
elm_table_pack(tbl, colors, 0, 0, 2, 2);
|
2020-09-08 07:27:37 -07:00
|
|
|
evas_object_show(colors);
|
2020-09-10 04:00:40 -07:00
|
|
|
|
|
|
|
lb = elm_label_add(parent);
|
2020-09-10 05:46:53 -07:00
|
|
|
elm_object_text_set(lb, "<b><color=#fff>0%</></>");
|
2020-09-10 04:00:40 -07:00
|
|
|
evas_object_size_hint_align_set(lb, 0.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
|
|
|
|
elm_table_pack(tbl, lb, 0, 0, 1, 1);
|
|
|
|
evas_object_show(lb);
|
|
|
|
|
|
|
|
lb = elm_label_add(parent);
|
2020-09-10 04:12:36 -07:00
|
|
|
f = (ad->freq_min + 500) / 1000;
|
|
|
|
if (f < 1000)
|
2020-09-10 05:46:53 -07:00
|
|
|
snprintf(buf, sizeof(buf), "<b><color=#fff>%iMHz</></>", f);
|
2020-09-10 04:12:36 -07:00
|
|
|
else
|
2020-09-10 05:46:53 -07:00
|
|
|
snprintf(buf, sizeof(buf), "<b><color=#fff>%1.1fGHz</></>", ((double)f + 0.05) / 1000.0);
|
2020-09-10 04:00:40 -07:00
|
|
|
elm_object_text_set(lb, buf);
|
|
|
|
evas_object_size_hint_align_set(lb, 0.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
|
|
|
|
elm_table_pack(tbl, lb, 0, 1, 1, 1);
|
|
|
|
evas_object_show(lb);
|
|
|
|
|
|
|
|
lb = elm_label_add(parent);
|
2020-09-10 05:46:53 -07:00
|
|
|
elm_object_text_set(lb, "<b><color=#fff>100%</></>");
|
2020-09-10 04:00:40 -07:00
|
|
|
evas_object_size_hint_align_set(lb, 1.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
|
|
|
|
elm_table_pack(tbl, lb, 1, 0, 1, 1);
|
|
|
|
evas_object_show(lb);
|
|
|
|
|
|
|
|
lb = elm_label_add(parent);
|
2020-09-10 04:12:36 -07:00
|
|
|
f = (ad->freq_max + 500) / 1000;
|
|
|
|
if (f < 1000)
|
2020-09-10 05:46:53 -07:00
|
|
|
snprintf(buf, sizeof(buf), "<b><color=#fff>%iMHz</></>", f);
|
2020-09-10 04:12:36 -07:00
|
|
|
else
|
2020-09-10 05:46:53 -07:00
|
|
|
snprintf(buf, sizeof(buf), "<b><color=#fff>%1.1fGHz</></>", ((double)f + 0.05) / 1000.0);
|
2020-09-10 04:00:40 -07:00
|
|
|
elm_object_text_set(lb, buf);
|
|
|
|
evas_object_size_hint_align_set(lb, 1.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
|
|
|
|
elm_table_pack(tbl, lb, 1, 1, 1, 1);
|
|
|
|
evas_object_show(lb);
|
2020-09-08 07:27:37 -07:00
|
|
|
|
2020-09-08 08:02:26 -07:00
|
|
|
elm_box_pack_end(box, fr);
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-08 08:02:26 -07:00
|
|
|
fr = elm_frame_add(box);
|
2020-09-09 18:45:47 -07:00
|
|
|
elm_frame_autocollapse_set(fr, EINA_TRUE);
|
2020-09-08 08:02:26 -07:00
|
|
|
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"));
|
2020-09-08 07:27:37 -07:00
|
|
|
elm_box_pack_end(box, fr);
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-09-08 08:02:26 -07:00
|
|
|
check = elm_check_add(fr);
|
|
|
|
evas_object_size_hint_align_set(check, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(check, EXPAND, 0);
|
|
|
|
elm_object_text_set(check, _("Overlay CPU frequency?"));
|
2020-09-11 01:58:47 -07:00
|
|
|
if (!ad->cpu_freq) elm_object_disabled_set(check, 1);
|
2020-09-08 08:02:26 -07:00
|
|
|
evas_object_show(check);
|
|
|
|
elm_object_content_set(fr, check);
|
|
|
|
|
2020-09-07 18:25:33 -07:00
|
|
|
ad->obj = obj;
|
|
|
|
ad->ui = ui;
|
2020-09-08 07:27:37 -07:00
|
|
|
ad->colors = colors;
|
|
|
|
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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());
|
2020-09-08 04:50:48 -07:00
|
|
|
|
2020-09-08 08:02:26 -07:00
|
|
|
evas_object_smart_callback_add(check, "changed", _check_changed_cb, ad);
|
2020-09-09 18:45:47 -07:00
|
|
|
// 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);
|
2020-09-07 18:25:33 -07:00
|
|
|
}
|
|
|
|
|
2020-09-07 08:02:34 -07:00
|
|
|
void
|
|
|
|
ui_win_cpu_add(Ui *ui)
|
|
|
|
{
|
|
|
|
Evas_Object *win, *box, *scroller;
|
|
|
|
|
|
|
|
if (ui->win_cpu) return;
|
|
|
|
|
2020-09-08 08:08:33 -07:00
|
|
|
ui->win_cpu = win = elm_win_util_standard_add("evisum",
|
2020-09-07 08:02:34 -07:00
|
|
|
_("CPU Usage"));
|
2020-09-09 18:45:47 -07:00
|
|
|
elm_win_autodel_set(win, EINA_TRUE);
|
2020-09-07 08:02:34 -07:00
|
|
|
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());
|
|
|
|
|
|
|
|
scroller = elm_scroller_add(win);
|
|
|
|
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);
|
|
|
|
evas_object_show(scroller);
|
|
|
|
|
|
|
|
box = elm_box_add(win);
|
|
|
|
evas_object_size_hint_align_set(box, FILL, FILL);
|
|
|
|
evas_object_size_hint_weight_set(box, EXPAND, EXPAND);
|
|
|
|
evas_object_show(box);
|
|
|
|
|
2020-09-08 07:27:37 -07:00
|
|
|
_graph(ui, box);
|
2020-05-12 16:51:30 -07:00
|
|
|
|
2020-09-07 08:02:34 -07:00
|
|
|
elm_object_content_set(scroller, box);
|
2020-06-28 12:02:07 -07:00
|
|
|
elm_object_content_set(win, scroller);
|
2020-09-07 18:25:33 -07:00
|
|
|
|
2020-06-28 12:02:07 -07:00
|
|
|
evisum_child_window_show(ui->win, win);
|
2020-05-12 16:51:30 -07:00
|
|
|
}
|
|
|
|
|