evisum/src/bin/ui/ui_process_list.c

1703 lines
48 KiB
C
Raw Normal View History

2020-11-09 05:40:00 -08:00
#include "config.h"
2020-11-09 06:28:55 -08:00
#include "evisum_config.h"
2020-11-09 05:40:00 -08:00
#include "ui.h"
2020-11-09 06:28:55 -08:00
#include "ui/ui_process_list.h"
2020-11-09 05:40:00 -08:00
#include "ui/ui_process_view.h"
#include <stdio.h>
2021-02-05 03:46:02 -08:00
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
2020-11-09 05:40:00 -08:00
#include <sys/types.h>
#include <sys/resource.h>
#include <pwd.h>
2020-12-29 02:41:15 -08:00
#define PROGRESS_CUSTOM_FORMAT 0
#define DIRTY_GENLIST_HACK 1
2020-12-29 02:41:15 -08:00
extern int EVISUM_EVENT_CONFIG_CHANGED;
typedef struct
{
Sort_Type type;
int (*sort_cb)(const void *p1, const void *p2);
} Sorter;
typedef struct
{
2020-12-29 05:53:08 -08:00
Ecore_Thread *thread;
Evisum_Ui_Cache *cache;
Ecore_Event_Handler *handler[2];
2021-02-05 01:21:52 -08:00
Eina_Hash *cpu_times;
2020-12-29 05:53:08 -08:00
Eina_Bool skip_wait;
2021-01-05 09:44:48 -08:00
Sorter sorters[SORT_BY_MAX];
2021-02-05 01:21:52 -08:00
pid_t selected_pid;
int poll_count;
2021-01-18 00:49:44 -08:00
2020-12-29 05:53:08 -08:00
Ui *ui;
Ecore_Timer *resize_timer;
2020-12-29 05:53:08 -08:00
Evas_Object *win;
2020-12-31 14:58:25 -08:00
Evas_Object *main_menu;
2020-12-29 05:53:08 -08:00
Evas_Object *menu;
2021-02-05 01:21:52 -08:00
struct
{
char *text;
size_t len;
Ecore_Timer *timer;
Evas_Object *pop;
Evas_Object *entry;
Eina_Bool visible;
double keytime;
} search;
2020-12-29 05:53:08 -08:00
Evas_Object *genlist;
Elm_Genlist_Item_Class itc;
Evas_Object *btn_menu;
2021-02-05 01:21:52 -08:00
Eina_List *headers;
2020-12-29 05:53:08 -08:00
Evas_Object *btn_cmd;
2021-02-05 01:21:52 -08:00
Evas_Object *btn_uid;
Evas_Object *btn_pid;
2021-02-06 00:50:53 -08:00
Evas_Object *btn_threads;
2021-01-03 17:59:23 -08:00
Evas_Object *btn_pri;
Evas_Object *btn_nice;
2020-12-29 05:53:08 -08:00
Evas_Object *btn_size;
Evas_Object *btn_rss;
2021-02-03 00:03:55 -08:00
Evas_Object *btn_state;
2021-02-06 00:50:53 -08:00
Evas_Object *btn_time;
2020-12-29 05:53:08 -08:00
Evas_Object *btn_cpu_usage;
} Ui_Data;
2020-12-16 11:20:32 -08:00
static Ui_Data *_pd = NULL;
2020-12-29 05:05:11 -08:00
#if PROGRESS_CUSTOM_FORMAT
2020-12-29 02:41:15 -08:00
2020-11-16 14:37:16 -08:00
static double _cpu_usage = 0.0;
2020-12-29 02:41:15 -08:00
#endif
2020-11-09 05:40:00 -08:00
static void
_item_unrealized_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *o;
Ui_Data *pd;
2020-11-09 05:40:00 -08:00
Eina_List *contents = NULL;
pd = data;
2020-11-09 05:40:00 -08:00
elm_genlist_item_all_contents_unset(event_info, &contents);
EINA_LIST_FREE(contents, o)
{
2021-01-05 08:32:45 -08:00
if (!evisum_ui_item_cache_item_release(pd->cache, o))
{
evas_object_del(o);
}
2020-11-09 05:40:00 -08:00
}
}
static void
_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
Proc_Info *proc = data;
proc_info_free(proc);
}
static Evas_Object *
2021-02-06 00:50:53 -08:00
_item_column_add(Evas_Object *tb, const char *text, int col)
2020-11-09 05:40:00 -08:00
{
Evas_Object *rec, *lb;
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
lb = elm_label_add(tb);
evas_object_data_set(tb, text, lb);
evas_object_size_hint_align_set(lb, FILL, FILL);
evas_object_size_hint_weight_set(lb, EXPAND, EXPAND);
evas_object_show(lb);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
rec = evas_object_rectangle_add(evas_object_evas_get(tb));
evas_object_data_set(lb, "rec", rec);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, col, 0, 1, 1);
elm_table_pack(tb, lb, col, 0, 1, 1);
2020-11-09 05:40:00 -08:00
return lb;
2020-11-09 05:40:00 -08:00
}
2020-12-29 05:05:11 -08:00
#if PROGRESS_CUSTOM_FORMAT
2020-11-16 14:37:16 -08:00
static char *
_pb_format_cb(double val)
{
2020-11-16 15:43:02 -08:00
static char buf[32];
2020-11-16 14:37:16 -08:00
snprintf(buf, sizeof(buf), "%1.1f %%", _cpu_usage);
return strdup(buf);
}
static void
_pb_format_free_cb(char *str)
{
free(str);
}
2020-12-29 02:41:15 -08:00
#endif
2020-11-16 14:37:16 -08:00
2020-11-09 05:40:00 -08:00
static Evas_Object *
2021-01-26 13:28:05 -08:00
_item_create(Evas_Object *obj)
2020-11-09 05:40:00 -08:00
{
2021-02-06 00:50:53 -08:00
Evas_Object *tb, *lb, *ic, *rec;
2020-11-09 05:40:00 -08:00
Evas_Object *hbx, *pb;
int i = 0;
2021-02-06 00:50:53 -08:00
tb = elm_table_add(obj);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_align_set(tb, FILL, 0);
evas_object_size_hint_weight_set(tb, EXPAND, EXPAND);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
hbx = elm_box_add(tb);
2020-11-09 05:40:00 -08:00
elm_box_horizontal_set(hbx, 1);
evas_object_size_hint_align_set(hbx, 0.0, FILL);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(hbx, EXPAND, EXPAND);
2020-11-09 05:40:00 -08:00
evas_object_show(hbx);
2021-02-06 00:50:53 -08:00
ic = elm_icon_add(tb);
2020-11-09 05:40:00 -08:00
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
evas_object_size_hint_align_set(ic, FILL, FILL);
2020-12-16 08:42:21 -08:00
evas_object_size_hint_min_set(ic, ELM_SCALE_SIZE(16), ELM_SCALE_SIZE(16));
evas_object_size_hint_max_set(ic, ELM_SCALE_SIZE(16), ELM_SCALE_SIZE(16));
2020-11-09 05:40:00 -08:00
evas_object_show(ic);
2021-02-06 00:50:53 -08:00
evas_object_data_set(tb, "icon", ic);
2020-11-09 05:40:00 -08:00
elm_box_pack_end(hbx, ic);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, hbx, i, 0, 1, 1);
2020-12-15 16:16:29 -08:00
2021-02-06 00:50:53 -08:00
rec = evas_object_rectangle_add(evas_object_evas_get(tb));
2021-02-03 03:22:04 -08:00
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(4), 1);
2020-12-15 16:16:29 -08:00
elm_box_pack_end(hbx, rec);
2021-02-06 00:50:53 -08:00
rec = evas_object_rectangle_add(evas_object_evas_get(tb));
2020-12-15 16:16:29 -08:00
evas_object_data_set(ic, "rec", rec);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i++, 0, 1, 1);
2020-12-15 16:16:29 -08:00
2021-02-06 00:50:53 -08:00
lb = elm_label_add(tb);
evas_object_size_hint_weight_set(lb, 0, EXPAND);
2021-02-06 00:50:53 -08:00
evas_object_data_set(tb, "proc_cmd", lb);
evas_object_data_set(lb, "hbx", hbx);
evas_object_show(lb);
elm_box_pack_end(hbx, lb);
2020-12-15 16:16:29 -08:00
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_uid", i++);
evas_object_size_hint_align_set(lb, 1.0, FILL);
lb = _item_column_add(tb, "proc_pid", i++);
2021-02-04 11:48:20 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_threads", i++);
2021-02-03 08:29:13 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_prio", i++);
2021-01-03 17:59:23 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_nice", i++);
2021-01-03 17:59:23 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_size", i++);
2020-12-31 04:06:55 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_rss", i++);
2020-12-31 04:06:55 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_state", i++);
2020-12-31 04:06:55 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2021-02-06 00:50:53 -08:00
lb = _item_column_add(tb, "proc_time", i++);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_align_set(lb, 1.0, FILL);
2020-12-15 16:16:29 -08:00
2020-11-09 05:40:00 -08:00
pb = elm_progressbar_add(hbx);
evas_object_size_hint_weight_set(pb, EXPAND, EXPAND);
evas_object_size_hint_align_set(pb, FILL, FILL);
2020-12-29 05:05:11 -08:00
elm_progressbar_unit_format_set(pb, "%1.1f %%");
#if PROGRESS_CUSTOM_FORMAT
2021-01-22 06:02:59 -08:00
elm_progressbar_unit_format_function_set(pb,
_pb_format_cb,
_pb_format_free_cb);
2020-12-29 02:41:15 -08:00
#endif
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, pb, i++, 0, 1, 1);
evas_object_data_set(tb, "proc_cpu_usage", pb);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
return tb;
2020-11-09 05:40:00 -08:00
}
2021-02-03 00:03:55 -08:00
static void
_run_time_set(char *buf, size_t n, int64_t secs)
{
int rem;
if (secs < 86400)
2021-02-05 03:46:02 -08:00
snprintf(buf, n, "%02" PRIi64 ":%02"PRIi64, secs / 60, secs % 60);
2021-02-03 00:03:55 -08:00
else
{
rem = secs % 3600;
2021-02-05 03:46:02 -08:00
snprintf(buf, n, "%02" PRIi64 ":%02d:%02d", secs / 3600, rem / 60, rem % 60);
2021-02-03 00:03:55 -08:00
}
}
2020-11-09 05:40:00 -08:00
static Evas_Object *
_content_get(void *data, Evas_Object *obj, const char *source)
{
Proc_Info *proc;
struct passwd *pwd_entry;
2020-12-29 04:31:54 -08:00
Evas_Object *rec, *lb, *o, *hbx, *pb;
2020-12-29 02:41:15 -08:00
char buf[128];
2020-11-09 05:40:00 -08:00
Evas_Coord w, ow;
2020-12-16 11:20:32 -08:00
Ui_Data *pd = _pd;
2020-11-09 05:40:00 -08:00
proc = (void *) data;
if (strcmp(source, "elm.swallow.content")) return NULL;
if (!proc) return NULL;
Item_Cache *it = evisum_ui_item_cache_item_get(pd->cache);
2020-11-09 05:40:00 -08:00
if (!it)
{
fprintf(stderr, "Error: Object cache creation failed.\n");
exit(-1);
}
2021-02-04 11:48:20 -08:00
evas_object_geometry_get(pd->btn_menu, NULL, NULL, &ow, NULL);
evas_object_geometry_get(pd->btn_cmd, NULL, NULL, &w, NULL);
w += (ow - 8);
lb = evas_object_data_get(it->obj, "proc_cmd");
snprintf(buf, sizeof(buf), "%s", proc->command);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
hbx = evas_object_data_get(lb, "hbx");
evas_object_geometry_get(hbx, NULL, NULL, &ow, NULL);
if (ow > w)
{
evas_object_size_hint_min_set(pd->btn_cmd, w, 1);
pd->skip_wait = 1;
}
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
elm_box_recalculate(hbx);
o = evas_object_data_get(it->obj, "icon");
const char *new = evisum_icon_path_get(evisum_icon_cache_find(proc));
const char *old = NULL;
elm_image_file_get(o, &old, NULL);
if (!old || strcmp(old, new))
elm_icon_standard_set(o, new);
rec = evas_object_data_get(o, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(o);
2021-02-04 13:28:08 -08:00
evas_object_geometry_get(pd->btn_uid, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_uid");
pwd_entry = getpwuid(proc->uid);
if (pwd_entry)
snprintf(buf, sizeof(buf), "%s", pwd_entry->pw_name);
else
snprintf(buf, sizeof(buf), "%i", proc->uid);
if (strcmp(buf, elm_object_text_get(lb)))
{
elm_object_text_set(lb, buf);
evas_object_geometry_get(lb, NULL, NULL, &ow, NULL);
if (ow > w)
{
evas_object_size_hint_min_set(pd->btn_uid, w, 1);
pd->skip_wait = 1;
}
}
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
evas_object_geometry_get(pd->btn_pid, NULL, NULL, &w, NULL);
2020-12-29 04:31:54 -08:00
lb = evas_object_data_get(it->obj, "proc_pid");
2020-12-29 02:41:15 -08:00
snprintf(buf, sizeof(buf), "%d", proc->pid);
2020-12-29 04:31:54 -08:00
if (strcmp(buf, elm_object_text_get(lb)))
2021-02-04 11:48:20 -08:00
elm_object_text_set(lb, buf);
2020-12-29 04:31:54 -08:00
rec = evas_object_data_get(lb, "rec");
2021-02-04 11:48:20 -08:00
evas_object_size_hint_min_set(rec, w, 1);
2020-12-29 04:31:54 -08:00
evas_object_show(lb);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
evas_object_geometry_get(pd->btn_threads, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_threads");
snprintf(buf, sizeof(buf), "%d", proc->numthreads);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
2021-01-03 17:59:23 -08:00
evas_object_geometry_get(pd->btn_pri, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_prio");
snprintf(buf, sizeof(buf), "%d", proc->priority);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
2021-02-04 11:48:20 -08:00
evas_object_size_hint_min_set(rec, w, 1);
2021-01-03 17:59:23 -08:00
evas_object_show(lb);
evas_object_geometry_get(pd->btn_nice, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_nice");
snprintf(buf, sizeof(buf), "%d", proc->nice);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
evas_object_geometry_get(pd->btn_size, NULL, NULL, &w, NULL);
2020-12-29 04:31:54 -08:00
lb = evas_object_data_get(it->obj, "proc_size");
2020-12-29 02:41:15 -08:00
snprintf(buf, sizeof(buf), "%s", evisum_size_format(proc->mem_size));
2020-12-29 04:31:54 -08:00
if (strcmp(buf, elm_object_text_get(lb)))
2021-02-04 11:48:20 -08:00
elm_object_text_set(lb, buf);
2020-12-29 04:31:54 -08:00
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
evas_object_show(lb);
2020-11-09 05:40:00 -08:00
evas_object_geometry_get(pd->btn_rss, NULL, NULL, &w, NULL);
2020-12-29 04:31:54 -08:00
lb = evas_object_data_get(it->obj, "proc_rss");
2020-12-29 02:41:15 -08:00
snprintf(buf, sizeof(buf), "%s", evisum_size_format(proc->mem_rss));
2020-12-29 04:31:54 -08:00
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
evas_object_size_hint_min_set(rec, w, 1);
2021-02-04 11:48:20 -08:00
evas_object_show(lb);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
evas_object_geometry_get(pd->btn_state, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_state");
snprintf(buf, sizeof(buf), "%s", proc->state);
2020-12-31 04:06:55 -08:00
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
2021-02-04 11:48:20 -08:00
evas_object_size_hint_min_set(rec, w, 1);
2020-12-31 04:06:55 -08:00
evas_object_show(lb);
2021-02-03 00:03:55 -08:00
evas_object_geometry_get(pd->btn_time, NULL, NULL, &w, NULL);
lb = evas_object_data_get(it->obj, "proc_time");
_run_time_set(buf, sizeof(buf), proc->run_time);
if (strcmp(buf, elm_object_text_get(lb)))
elm_object_text_set(lb, buf);
rec = evas_object_data_get(lb, "rec");
2021-02-04 11:48:20 -08:00
evas_object_size_hint_min_set(rec, w, 1);
2021-02-03 00:03:55 -08:00
evas_object_show(lb);
2020-11-09 05:40:00 -08:00
pb = evas_object_data_get(it->obj, "proc_cpu_usage");
2020-12-29 05:05:11 -08:00
#if PROGRESS_CUSTOM_FORMAT
2020-11-16 14:37:16 -08:00
_cpu_usage = proc->cpu_usage;
2020-12-29 05:05:11 -08:00
#endif
2020-12-29 02:41:15 -08:00
double value = proc->cpu_usage / 100.0;
double last = elm_progressbar_value_get(pb);
if (!EINA_DBL_EQ(value, last))
elm_progressbar_value_set(pb, proc->cpu_usage / 100.0);
2020-11-09 05:40:00 -08:00
evas_object_show(pb);
return it->obj;
}
static void
_genlist_ensure_n_items(Evas_Object *genlist, unsigned int items,
Elm_Genlist_Item_Class *itc)
2020-11-09 05:40:00 -08:00
{
Elm_Object_Item *it;
unsigned int i, existing = elm_genlist_items_count(genlist);
if (items < existing)
{
for (i = existing - items; i > 0; i--)
{
it = elm_genlist_last_item_get(genlist);
if (it)
2021-01-05 08:32:45 -08:00
{
elm_object_item_del(it);
}
2020-11-09 05:40:00 -08:00
}
}
if (items == existing) return;
for (i = existing; i < items; i++)
{
elm_genlist_item_append(genlist, itc, NULL, NULL,
ELM_GENLIST_ITEM_NONE, NULL, NULL);
}
}
static Eina_Bool
_bring_in(void *data)
{
Ui_Data *pd;
2020-11-09 05:40:00 -08:00
int h_page, v_page;
pd = data;
2021-02-05 01:21:52 -08:00
elm_scroller_gravity_set(pd->genlist, 0.0, 0.0);
elm_scroller_last_page_get(pd->genlist, &h_page, &v_page);
elm_scroller_page_bring_in(pd->genlist, h_page, v_page);
2021-01-18 00:49:44 -08:00
elm_genlist_realized_items_update(pd->genlist);
evas_object_show(pd->genlist);
2020-11-09 05:40:00 -08:00
2021-01-24 05:48:40 -08:00
return 0;
2020-11-09 05:40:00 -08:00
}
static Eina_List *
_process_list_sort(Eina_List *list, Ui_Data *pd)
2020-11-09 05:40:00 -08:00
{
Ui *ui;
Sorter s;
ui = pd->ui;
s = pd->sorters[ui->proc.sort_type];
list = eina_list_sort(list, eina_list_count(list), s.sort_cb);
if (ui->proc.sort_reverse)
list = eina_list_reverse(list);
return list;
}
static Eina_List *
_process_list_uid_trim(Eina_List *list, uid_t uid)
{
Proc_Info *proc;
Eina_List *l, *l_next;
2020-11-09 05:40:00 -08:00
EINA_LIST_FOREACH_SAFE(list, l, l_next, proc)
{
if (proc->uid != uid)
2020-11-09 05:40:00 -08:00
{
proc_info_free(proc);
list = eina_list_remove_list(list, l);
2020-11-09 05:40:00 -08:00
}
}
return list;
}
static void
_cpu_times_free_cb(void *data)
{
int64_t *cpu_time = data;
free(cpu_time);
}
static Eina_List *
_process_list_search_trim(Eina_List *list, Ui_Data *pd)
{
Eina_List *l, *l_next;
Proc_Info *proc;
2021-02-06 00:50:53 -08:00
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
EINA_LIST_FOREACH_SAFE(list, l, l_next, proc)
{
2021-01-22 06:02:59 -08:00
if ((proc->pid == ui->program_pid) ||
2021-02-05 01:21:52 -08:00
((pd->search.len) &&
(strncasecmp(proc->command, pd->search.text, pd->search.len) &&
(!strstr(proc->command, pd->search.text))))
2021-01-22 06:02:59 -08:00
)
2020-11-09 05:40:00 -08:00
{
proc_info_free(proc);
list = eina_list_remove_list(list, l);
}
else
{
2021-02-06 00:50:53 -08:00
int64_t *cpu_time, id = proc->pid;
2021-02-06 00:50:53 -08:00
if ((cpu_time = eina_hash_find(pd->cpu_times, &id)))
{
2021-02-06 00:50:53 -08:00
if (*cpu_time)
proc->cpu_usage = (double) (proc->cpu_time - *cpu_time) /
pd->ui->proc.poll_delay;
*cpu_time = proc->cpu_time;
}
else
{
2021-02-06 00:50:53 -08:00
cpu_time = malloc(sizeof(int64_t));
if (cpu_time)
{
*cpu_time = proc->cpu_time;
eina_hash_add(pd->cpu_times, &id, cpu_time);
}
}
2020-11-09 05:40:00 -08:00
}
}
return list;
}
2020-11-09 05:40:00 -08:00
static Eina_List *
_process_list_get(Ui_Data *pd)
{
Eina_List *list;
Ui *ui;
2020-11-09 05:40:00 -08:00
ui = pd->ui;
2020-11-09 05:40:00 -08:00
list = proc_info_all_get();
2020-11-09 05:40:00 -08:00
if (ui->proc.show_user)
list = _process_list_uid_trim(list, getuid());
2020-11-09 05:40:00 -08:00
list = _process_list_search_trim(list, pd);
list = _process_list_sort(list, pd);
2020-11-09 05:40:00 -08:00
return list;
2020-11-09 05:40:00 -08:00
}
static void
_process_list(void *data, Ecore_Thread *thread)
{
Ui_Data *pd;
Eina_List *list;
2020-11-09 05:40:00 -08:00
Ui *ui;
Proc_Info *proc;
int i, delay = 1;
2020-11-09 05:40:00 -08:00
pd = data;
ui = pd->ui;
2020-11-09 05:40:00 -08:00
2020-12-16 11:20:32 -08:00
while (!ecore_thread_check(thread))
2020-11-09 05:40:00 -08:00
{
2020-12-28 13:00:11 -08:00
for (i = 0; i < delay * 8; i++)
2020-11-09 05:40:00 -08:00
{
if (ecore_thread_check(thread)) return;
if (pd->skip_wait)
2020-11-09 05:40:00 -08:00
{
pd->skip_wait = 0;
2020-11-09 05:40:00 -08:00
break;
}
2020-12-28 13:00:11 -08:00
usleep(125000);
2020-11-09 05:40:00 -08:00
}
2020-12-31 12:17:02 -08:00
list = _process_list_get(pd);
if (!pd->skip_wait)
ecore_thread_feedback(thread, list);
else
{
EINA_LIST_FREE(list, proc)
proc_info_free(proc);
}
delay = ui->proc.poll_delay;
2020-11-09 05:40:00 -08:00
}
}
static void
_process_list_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED,
void *msg EINA_UNUSED)
{
Ui_Data *pd;
Eina_List *list;
Proc_Info *proc;
Elm_Object_Item *it;
pd = data;
list = msg;
2021-02-07 06:59:20 -08:00
_genlist_ensure_n_items(pd->genlist, eina_list_count(list), &pd->itc);
it = elm_genlist_first_item_get(pd->genlist);
EINA_LIST_FREE(list, proc)
{
if (!it)
proc_info_free(proc);
else
{
Proc_Info *prev = elm_object_item_data_get(it);
if (prev)
proc_info_free(prev);
elm_object_item_data_set(it, proc);
it = elm_genlist_item_next_get(it);
}
}
elm_genlist_realized_items_update(pd->genlist);
#if DIRTY_GENLIST_HACK
Eina_List *real = elm_genlist_realized_items_get(pd->genlist);
2021-02-07 06:59:20 -08:00
int n = eina_list_count(pd->cache->active);
if (n > eina_list_count(real) * 2)
{
2021-01-05 08:32:45 -08:00
evisum_ui_item_cache_steal(pd->cache, real);
pd->skip_wait = 1;
}
eina_list_free(real);
#endif
#if 0
printf("active %d and inactive %d\n",
eina_list_count(pd->cache->active),
eina_list_count(pd->cache->inactive));
#endif
2021-01-18 00:49:44 -08:00
if (!pd->poll_count)
ecore_timer_add(1.0, _bring_in, pd);
pd->poll_count++;
}
static void
_process_list_update(Ui_Data *pd)
{
pd->skip_wait = 1;
}
2020-11-09 05:40:00 -08:00
static void
_btn_icon_state_update(Evas_Object *btn, Eina_Bool reverse)
2020-11-09 05:40:00 -08:00
{
2021-02-06 01:57:58 -08:00
Evas_Object *ic = elm_icon_add(btn);
2020-11-09 05:40:00 -08:00
if (reverse)
2021-02-06 01:57:58 -08:00
elm_icon_standard_set(ic, evisum_icon_path_get("go-down"));
2020-11-09 05:40:00 -08:00
else
2021-02-06 01:57:58 -08:00
elm_icon_standard_set(ic, evisum_icon_path_get("go-up"));
2020-11-09 05:40:00 -08:00
2021-02-06 01:57:58 -08:00
evisum_ui_icon_size_set(ic, ELM_SCALE_SIZE(ICON_SIZE));
elm_object_part_content_set(btn, "icon", ic);
evas_object_show(ic);
2020-11-09 05:40:00 -08:00
}
static void
_btn_icon_state_init(Evas_Object *btn, Eina_Bool reverse,
2020-11-09 05:40:00 -08:00
Eina_Bool selected EINA_UNUSED)
{
2021-02-06 01:57:58 -08:00
Evas_Object *ic = elm_icon_add(btn);
2020-11-09 05:40:00 -08:00
if (reverse)
2021-02-06 01:57:58 -08:00
elm_icon_standard_set(ic, evisum_icon_path_get("go-down"));
2020-11-09 05:40:00 -08:00
else
2021-02-06 01:57:58 -08:00
elm_icon_standard_set(ic, evisum_icon_path_get("go-up"));
2020-11-09 05:40:00 -08:00
2021-02-06 01:57:58 -08:00
evisum_ui_icon_size_set(ic, ELM_SCALE_SIZE(ICON_SIZE));
elm_object_part_content_set(btn, "icon", ic);
evas_object_show(ic);
2020-11-09 05:40:00 -08:00
}
static void
_btn_clicked_state_save(Ui_Data *pd, Evas_Object *btn)
2020-11-09 05:40:00 -08:00
{
Ui *ui = pd->ui;
_btn_icon_state_update(btn, ui->proc.sort_reverse);
2020-11-09 05:40:00 -08:00
_process_list_update(pd);
2020-11-09 05:40:00 -08:00
2021-02-05 01:21:52 -08:00
elm_scroller_page_bring_in(pd->genlist, 0, 0);
2020-11-09 05:40:00 -08:00
}
static void
_btn_pid_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_PID)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_PID;
_btn_clicked_state_save(pd, pd->btn_pid);
2020-11-09 05:40:00 -08:00
}
static void
_btn_uid_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_UID)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_UID;
_btn_clicked_state_save(pd, pd->btn_uid);
2020-11-09 05:40:00 -08:00
}
static void
_btn_cpu_usage_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_CPU_USAGE)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_CPU_USAGE;
_btn_clicked_state_save(pd, pd->btn_cpu_usage);
2020-11-09 05:40:00 -08:00
}
static void
_btn_size_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_SIZE)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_SIZE;
_btn_clicked_state_save(pd, pd->btn_size);
2020-11-09 05:40:00 -08:00
}
2021-01-03 17:59:23 -08:00
static void
_btn_pri_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
if (ui->proc.sort_type == SORT_BY_PRI)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_PRI;
_btn_clicked_state_save(pd, pd->btn_pri);
}
static void
_btn_nice_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
if (ui->proc.sort_type == SORT_BY_NICE)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_NICE;
_btn_clicked_state_save(pd, pd->btn_nice);
}
2020-11-09 05:40:00 -08:00
static void
_btn_rss_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_RSS)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_RSS;
_btn_clicked_state_save(pd, pd->btn_rss);
2020-11-09 05:40:00 -08:00
}
static void
_btn_cmd_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_CMD)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_CMD;
_btn_clicked_state_save(pd, pd->btn_cmd);
2020-11-09 05:40:00 -08:00
}
2020-12-31 04:06:55 -08:00
static void
_btn_threads_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
2020-12-31 04:06:55 -08:00
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
if (ui->proc.sort_type == SORT_BY_THREADS)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_THREADS;
_btn_clicked_state_save(pd, pd->btn_threads);
}
2021-02-03 00:03:55 -08:00
static void
_btn_time_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
if (ui->proc.sort_type == SORT_BY_TIME)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_TIME;
2021-02-03 02:17:40 -08:00
_btn_clicked_state_save(pd, pd->btn_time);
2021-02-03 00:03:55 -08:00
}
2020-11-09 05:40:00 -08:00
static void
_btn_state_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
if (ui->proc.sort_type == SORT_BY_STATE)
ui->proc.sort_reverse = !ui->proc.sort_reverse;
ui->proc.sort_type = SORT_BY_STATE;
_btn_clicked_state_save(pd, pd->btn_state);
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_dismissed_cb(void *data EINA_UNUSED, Evas_Object *obj,
void *ev EINA_UNUSED)
{
Ui_Data *pd = data;
2020-11-09 05:40:00 -08:00
evas_object_del(obj);
pd->menu = NULL;
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_start_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
kill(pd->selected_pid, SIGCONT);
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_stop_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
kill(pd->selected_pid, SIGSTOP);
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_kill_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
kill(pd->selected_pid, SIGKILL);
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
elm_menu_close(pd->menu);
pd->menu = NULL;
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_debug_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
2020-11-09 05:40:00 -08:00
{
Proc_Info *proc;
const char *terminal = "xterm";
Ui_Data *pd = data;
2020-11-09 05:40:00 -08:00
_item_menu_cancel_cb(pd, NULL, NULL);
2020-11-09 05:40:00 -08:00
proc = proc_info_by_pid(pd->selected_pid);
2020-11-09 05:40:00 -08:00
if (!proc) return;
if (ecore_file_app_installed("terminology"))
terminal = "terminology";
ecore_exe_run(eina_slstr_printf("%s -e gdb attach %d", terminal, proc->pid),
NULL);
proc_info_free(proc);
}
static void
_item_menu_actions_add(Evas_Object *menu, Elm_Object_Item *menu_it, Ui_Data *pd)
2020-11-09 05:40:00 -08:00
{
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("bug"),
_("Debug"), _item_menu_debug_cb, pd);
2020-11-09 05:40:00 -08:00
}
static void
_item_menu_manual_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
_item_menu_cancel_cb(pd, NULL, NULL);
ui_process_view_win_add(pd->selected_pid, PROC_VIEW_MANUAL);
}
static void
_item_menu_threads_cb(void *data, Evas_Object *obj EINA_UNUSED,
2021-01-24 07:20:25 -08:00
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
_item_menu_cancel_cb(pd, NULL, NULL);
ui_process_view_win_add(pd->selected_pid, PROC_VIEW_THREADS);
}
static void
_item_menu_children_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
2020-11-09 05:40:00 -08:00
{
Ui_Data *pd = data;
2020-11-09 05:40:00 -08:00
_item_menu_cancel_cb(pd, NULL, NULL);
2020-11-09 05:40:00 -08:00
ui_process_view_win_add(pd->selected_pid, PROC_VIEW_CHILDREN);
}
static void
_item_menu_general_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui_Data *pd = data;
_item_menu_cancel_cb(pd, NULL, NULL);
ui_process_view_win_add(pd->selected_pid, PROC_VIEW_DEFAULT);
}
static void
_item_menu_info_add(Evas_Object *menu, Elm_Object_Item *menu_it, Ui_Data *pd)
{
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("info"),
_("General"), _item_menu_general_cb, pd);
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("proc"),
_("Children"), _item_menu_children_cb, pd);
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("threads"),
_("Threads"), _item_menu_threads_cb, pd);
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("manual"),
_("Manual"), _item_menu_manual_cb, pd);
2020-11-09 05:40:00 -08:00
}
static Evas_Object *
_item_menu_create(Ui_Data *pd, Proc_Info *proc)
2020-11-09 05:40:00 -08:00
{
Elm_Object_Item *menu_it, *menu_it2;
Evas_Object *menu;
Eina_Bool stopped;
if (!proc) return NULL;
pd->selected_pid = proc->pid;
2020-11-09 05:40:00 -08:00
2020-12-17 05:15:43 -08:00
pd->menu = menu = elm_menu_add(pd->win);
2020-11-09 05:40:00 -08:00
if (!menu) return NULL;
evas_object_smart_callback_add(menu, "dismissed",
_item_menu_dismissed_cb, pd);
2020-11-09 05:40:00 -08:00
stopped = !(!strcmp(proc->state, "stop"));
menu_it = elm_menu_item_add(menu, NULL,
2020-11-16 17:14:12 -08:00
evisum_icon_path_get(evisum_icon_cache_find(proc)),
2020-11-09 05:40:00 -08:00
proc->command, NULL, NULL);
menu_it2 = elm_menu_item_add(menu, menu_it, evisum_icon_path_get("actions"),
2020-11-09 05:40:00 -08:00
_("Actions"), NULL, NULL);
_item_menu_actions_add(menu, menu_it2, pd);
2020-11-09 05:40:00 -08:00
elm_menu_item_separator_add(menu, menu_it);
menu_it2 = elm_menu_item_add(menu, menu_it, evisum_icon_path_get("start"),
_("Start"), _item_menu_start_cb, pd);
2020-11-09 05:40:00 -08:00
elm_object_item_disabled_set(menu_it2, stopped);
menu_it2 = elm_menu_item_add(menu, menu_it, evisum_icon_path_get("stop"),
_("Stop"), _item_menu_stop_cb, pd);
2020-11-09 05:40:00 -08:00
elm_object_item_disabled_set(menu_it2, !stopped);
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("kill"), "Kill",
_item_menu_kill_cb, pd);
2020-11-09 05:40:00 -08:00
elm_menu_item_separator_add(menu, menu_it);
2020-11-10 18:21:39 -08:00
menu_it2 = elm_menu_item_add(menu, menu_it, evisum_icon_path_get("info"),
_("Info"), NULL, pd);
_item_menu_info_add(menu, menu_it2, pd);
2020-11-09 05:40:00 -08:00
elm_menu_item_separator_add(menu, menu_it);
elm_menu_item_add(menu, menu_it, evisum_icon_path_get("cancel"),
_("Cancel"), _item_menu_cancel_cb, pd);
2020-11-09 05:40:00 -08:00
return menu;
}
static void
_item_pid_secondary_clicked_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj, void *event_info)
{
Evas_Object *menu;
Evas_Event_Mouse_Up *ev;
Ui_Data *pd;
2020-11-09 05:40:00 -08:00
Elm_Object_Item *it;
Proc_Info *proc;
ev = event_info;
if (ev->button != 3) return;
it = elm_genlist_at_xy_item_get(obj, ev->output.x, ev->output.y, NULL);
proc = elm_object_item_data_get(it);
if (!proc) return;
pd = data;
2020-11-09 05:40:00 -08:00
menu = _item_menu_create(pd, proc);
2020-11-09 05:40:00 -08:00
if (!menu) return;
elm_menu_move(menu, ev->canvas.x, ev->canvas.y);
evas_object_show(menu);
}
static void
_item_pid_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Elm_Object_Item *it;
Proc_Info *proc;
Ui_Data *pd = data;
2020-11-09 05:40:00 -08:00
it = event_info;
2021-01-24 05:48:40 -08:00
elm_genlist_item_selected_set(it, 0);
if (pd->menu) return;
2020-11-09 05:40:00 -08:00
proc = elm_object_item_data_get(it);
if (!proc) return;
pd->selected_pid = proc->pid;
ui_process_view_win_add(proc->pid, PROC_VIEW_DEFAULT);
2020-11-09 05:40:00 -08:00
}
static void
_main_menu_dismissed_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *ev EINA_UNUSED)
{
2020-12-31 14:58:25 -08:00
Ui_Data *pd = data;
2020-11-09 05:40:00 -08:00
2020-12-31 14:58:25 -08:00
elm_ctxpopup_dismiss(pd->main_menu);
evas_object_del(pd->main_menu);
2020-11-09 05:40:00 -08:00
2020-12-31 14:58:25 -08:00
pd->main_menu = NULL;
2020-11-09 05:40:00 -08:00
}
static Evas_Object *
_btn_create(Evas_Object *parent, const char *icon, const char *text, void *cb,
void *data)
{
2020-12-15 16:16:29 -08:00
Evas_Object *btn, *ic;
2020-11-09 05:40:00 -08:00
btn = elm_button_add(parent);
2020-12-15 16:16:29 -08:00
evas_object_size_hint_weight_set(btn, 0, EXPAND);
2020-11-09 05:40:00 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
ic = elm_icon_add(btn);
elm_icon_standard_set(ic, evisum_icon_path_get(icon));
2020-12-15 16:16:29 -08:00
evas_object_size_hint_min_set(ic, ELM_SCALE_SIZE(16), 1);
2020-11-09 05:40:00 -08:00
elm_object_part_content_set(btn, "icon", ic);
evas_object_show(ic);
elm_object_tooltip_text_set(btn, text);
evas_object_smart_callback_add(btn, "clicked", cb, data);
2020-12-15 16:16:29 -08:00
return btn;
2020-11-09 05:40:00 -08:00
}
static void
_btn_menu_clicked_cb(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
2020-12-31 14:58:25 -08:00
Ui_Data *pd;
Ui *ui;
pd = data;
ui = pd->ui;
2020-11-09 05:40:00 -08:00
2020-12-31 14:58:25 -08:00
if (!pd->main_menu)
pd->main_menu = evisum_ui_main_menu_create(ui, ui->proc.win, obj);
2020-11-09 05:40:00 -08:00
else
2020-12-31 14:58:25 -08:00
_main_menu_dismissed_cb(pd, NULL, NULL);
2020-11-09 05:40:00 -08:00
}
2021-02-05 01:21:52 -08:00
typedef struct
{
Evas_Object *btn;
Evas_Object *rec;
} List_Header;
static Evas_Object
2021-02-05 02:06:10 -08:00
*_btn_min_size(Ui_Data *pd, Evas_Object *btn)
2021-02-05 01:21:52 -08:00
{
2021-02-05 02:06:10 -08:00
Evas_Object *rec = evas_object_rectangle_add(evas_object_evas_get(btn));
2021-02-05 04:12:32 -08:00
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(BTN_WIDTH), 1);
2021-02-05 02:19:53 -08:00
evas_object_size_hint_weight_set(rec, EXPAND, 0);
2021-02-05 01:21:52 -08:00
List_Header *hdr = malloc(sizeof(List_Header));
2021-02-05 02:06:10 -08:00
hdr->rec = rec;
hdr->btn = btn;
2021-02-05 01:21:52 -08:00
pd->headers = eina_list_append(pd->headers, hdr);
return rec;
}
2020-11-09 05:40:00 -08:00
static Evas_Object *
_ui_content_system_add(Ui_Data *pd, Evas_Object *parent)
2020-11-09 05:40:00 -08:00
{
2021-02-06 00:50:53 -08:00
Evas_Object *tb, *btn, *list, *rec;
Ui *ui = pd->ui;
2020-11-09 05:40:00 -08:00
int i = 0;
2021-02-06 00:50:53 -08:00
tb = elm_table_add(parent);
evas_object_size_hint_weight_set(tb, EXPAND, EXPAND);
evas_object_size_hint_align_set(tb, FILL, FILL);
evas_object_show(tb);
2020-12-15 16:16:29 -08:00
2021-02-04 11:48:20 -08:00
rec = evas_object_rectangle_add(evas_object_evas_get(parent));
2021-02-07 06:59:20 -08:00
evas_object_size_hint_min_set(rec, 1, ELM_SCALE_SIZE(24));
evas_object_size_hint_max_set(rec, 1, ELM_SCALE_SIZE(24));
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
2021-02-04 11:48:20 -08:00
2021-02-06 00:50:53 -08:00
pd->btn_menu = btn = _btn_create(tb, "menu", _("Menu"),
2020-12-31 14:58:25 -08:00
_btn_menu_clicked_cb, pd);
2021-02-07 06:59:20 -08:00
rec = evas_object_rectangle_add(evas_object_evas_get(parent));
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(24), ELM_SCALE_SIZE(24));
evas_object_size_hint_max_set(rec, ELM_SCALE_SIZE(24), ELM_SCALE_SIZE(24));
elm_table_pack(tb, rec, i, 1, 1, 1);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, btn, i++, 1, 1, 1);
2020-11-09 05:40:00 -08:00
pd->btn_cmd = btn = elm_button_add(parent);
2020-11-09 20:38:32 -08:00
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_CMD ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_CMD);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2020-11-09 20:38:32 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
2020-12-31 04:06:55 -08:00
elm_object_text_set(btn, _("command"));
2020-11-09 20:38:32 -08:00
evas_object_show(btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, btn, i++, 1, 1, 1);
evas_object_smart_callback_add(btn, "clicked",
_btn_cmd_clicked_cb, pd);
2020-11-09 20:38:32 -08:00
2021-02-04 11:48:20 -08:00
pd->btn_uid = btn = elm_button_add(parent);
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_UID ?
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_UID);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2021-02-04 11:48:20 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
elm_object_text_set(btn, _("user"));
evas_object_show(btn);
2021-02-05 02:19:53 -08:00
rec = _btn_min_size(pd, btn);
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(90), 1);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
2021-02-04 11:48:20 -08:00
evas_object_smart_callback_add(btn, "clicked",
_btn_uid_clicked_cb, pd);
2020-12-31 04:06:55 -08:00
pd->btn_pid = btn = elm_button_add(parent);
2020-11-09 20:38:32 -08:00
_btn_icon_state_init(btn,
2020-12-31 04:06:55 -08:00
(ui->proc.sort_type == SORT_BY_PID ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
2020-12-31 04:06:55 -08:00
ui->proc.sort_type == SORT_BY_PID);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2020-11-09 20:38:32 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
2020-12-31 04:06:55 -08:00
elm_object_text_set(btn, _("pid"));
2020-11-09 20:38:32 -08:00
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
evas_object_smart_callback_add(btn, "clicked",
2020-12-31 04:06:55 -08:00
_btn_pid_clicked_cb, pd);
2020-11-09 20:38:32 -08:00
2021-02-06 00:50:53 -08:00
pd->btn_threads = btn = elm_button_add(parent);
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_THREADS ?
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_THREADS);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2021-02-06 00:50:53 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
elm_object_text_set(btn, _("thr"));
evas_object_show(btn);
rec = _btn_min_size(pd, btn);
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
evas_object_smart_callback_add(btn, "clicked",
_btn_threads_clicked_cb, pd);
2021-01-03 17:59:23 -08:00
pd->btn_pri = btn = elm_button_add(parent);
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_PRI ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
2021-01-03 17:59:23 -08:00
ui->proc.sort_type == SORT_BY_PRI);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2021-01-03 17:59:23 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
elm_object_text_set(btn, _("prio"));
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
2021-01-03 17:59:23 -08:00
evas_object_smart_callback_add(btn, "clicked",
_btn_pri_clicked_cb, pd);
pd->btn_nice = btn = elm_button_add(parent);
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_NICE ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
2021-01-03 17:59:23 -08:00
ui->proc.sort_type == SORT_BY_NICE);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2021-01-03 17:59:23 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
elm_object_text_set(btn, _("nice"));
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
2021-01-03 17:59:23 -08:00
evas_object_smart_callback_add(btn, "clicked",
_btn_nice_clicked_cb, pd);
pd->btn_size = btn = elm_button_add(parent);
2020-11-09 20:38:32 -08:00
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_SIZE ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_SIZE);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2020-11-09 20:38:32 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
2020-12-31 04:06:55 -08:00
elm_object_text_set(btn, _("size"));
2020-11-09 20:38:32 -08:00
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
evas_object_smart_callback_add(btn, "clicked",
_btn_size_clicked_cb, pd);
2020-11-09 20:38:32 -08:00
pd->btn_rss = btn = elm_button_add(parent);
2020-11-09 20:38:32 -08:00
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_RSS ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_RSS);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2020-11-09 20:38:32 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
2020-12-31 04:06:55 -08:00
elm_object_text_set(btn, _("res"));
2020-11-09 20:38:32 -08:00
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
evas_object_smart_callback_add(btn, "clicked",
_btn_rss_clicked_cb, pd);
2020-11-09 20:38:32 -08:00
2021-02-06 00:50:53 -08:00
pd->btn_state = btn = elm_button_add(parent);
2020-12-31 04:06:55 -08:00
_btn_icon_state_init(btn,
2021-02-06 00:50:53 -08:00
(ui->proc.sort_type == SORT_BY_STATE ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
2021-02-06 00:50:53 -08:00
ui->proc.sort_type == SORT_BY_STATE);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2020-12-31 04:06:55 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
2021-02-06 00:50:53 -08:00
elm_object_text_set(btn, _("state"));
2020-12-31 04:06:55 -08:00
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
2020-12-31 04:06:55 -08:00
evas_object_smart_callback_add(btn, "clicked",
2021-02-06 00:50:53 -08:00
_btn_state_clicked_cb, pd);
2020-12-31 04:06:55 -08:00
2021-02-03 00:03:55 -08:00
pd->btn_time = btn = elm_button_add(parent);
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_TIME ?
2021-02-03 00:03:55 -08:00
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_TIME);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2021-02-03 00:03:55 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
elm_object_text_set(btn, _("time"));
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
2021-02-03 00:03:55 -08:00
evas_object_smart_callback_add(btn, "clicked",
_btn_time_clicked_cb, pd);
pd->btn_cpu_usage = btn = elm_button_add(parent);
2020-11-09 20:38:32 -08:00
_btn_icon_state_init(btn,
(ui->proc.sort_type == SORT_BY_CPU_USAGE ?
2021-01-24 05:48:40 -08:00
ui->proc.sort_reverse : 0),
ui->proc.sort_type == SORT_BY_CPU_USAGE);
2021-02-07 06:59:20 -08:00
evas_object_size_hint_weight_set(btn, 1.0, 0);
2020-11-09 20:38:32 -08:00
evas_object_size_hint_align_set(btn, FILL, FILL);
2020-12-31 04:06:55 -08:00
elm_object_text_set(btn, _("cpu %"));
2020-11-09 20:38:32 -08:00
evas_object_show(btn);
2021-02-05 02:06:10 -08:00
rec = _btn_min_size(pd, btn);
2021-02-05 02:42:09 -08:00
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(80), 1);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, i, 1, 1, 1);
elm_table_pack(tb, btn, i++, 1, 1, 1);
evas_object_smart_callback_add(btn, "clicked",
_btn_cpu_usage_clicked_cb, pd);
2020-11-09 05:40:00 -08:00
2021-02-05 02:06:10 -08:00
pd->genlist = list = elm_genlist_add(parent);
elm_genlist_homogeneous_set(list, 1);
2021-02-05 01:21:52 -08:00
elm_scroller_gravity_set(pd->genlist, 0.0, 1.0);
2021-02-05 02:06:10 -08:00
elm_object_focus_allow_set(list, 1);
2021-02-05 01:21:52 -08:00
elm_scroller_policy_set(pd->genlist, ELM_SCROLLER_POLICY_OFF,
(ui->proc.show_scroller ?
2021-01-21 09:03:29 -08:00
ELM_SCROLLER_POLICY_AUTO :
ELM_SCROLLER_POLICY_OFF));
2021-02-05 02:06:10 -08:00
elm_genlist_multi_select_set(list, 0);
evas_object_size_hint_weight_set(list, EXPAND, EXPAND);
evas_object_size_hint_align_set(list, FILL, FILL);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, list, 0, 2, i, 1);
2020-11-09 05:40:00 -08:00
pd->itc.item_style = "full";
pd->itc.func.text_get = NULL;
pd->itc.func.content_get = _content_get;
pd->itc.func.filter_get = NULL;
pd->itc.func.del = _item_del;
evas_object_smart_callback_add(pd->genlist, "selected",
2020-12-30 05:40:38 -08:00
_item_pid_clicked_cb, pd);
evas_object_event_callback_add(pd->genlist, EVAS_CALLBACK_MOUSE_UP,
_item_pid_secondary_clicked_cb, pd);
evas_object_smart_callback_add(pd->genlist, "unrealized",
_item_unrealized_cb, pd);
2020-12-15 16:16:29 -08:00
2021-02-06 00:50:53 -08:00
return tb;
2020-11-09 05:40:00 -08:00
}
2020-12-17 05:15:43 -08:00
static Eina_Bool
2021-01-21 05:03:53 -08:00
_search_empty_cb(void *data)
2020-12-17 05:15:43 -08:00
{
Ui_Data *pd = data;
2021-02-05 01:21:52 -08:00
if (!pd->search.len)
2020-12-17 05:15:43 -08:00
{
2021-02-05 01:21:52 -08:00
evas_object_lower(pd->search.pop);
elm_object_focus_allow_set(pd->search.entry, 0);
pd->search.visible = 0;
pd->search.timer = NULL;
pd->skip_wait = 1;
2021-01-24 05:48:40 -08:00
return 0;
2020-12-17 05:15:43 -08:00
}
2021-02-05 01:21:52 -08:00
if (pd->search.keytime &&
((ecore_loop_time_get() - pd->search.keytime) > 0.1))
{
pd->skip_wait = 1;
2021-02-05 01:21:52 -08:00
pd->search.keytime = 0;
}
2021-01-24 05:48:40 -08:00
return 1;
2020-12-17 05:15:43 -08:00
}
2021-01-22 08:37:51 -08:00
static void
_search_clear(Ui_Data *pd)
{
2021-02-05 01:21:52 -08:00
if (pd->search.text)
free(pd->search.text);
pd->search.text = NULL;
pd->search.len = 0;
2021-01-22 08:37:51 -08:00
}
2021-01-21 05:03:53 -08:00
static void
_search_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
2021-01-22 08:37:51 -08:00
Evas_Event_Key_Down *ev;
2021-01-21 05:03:53 -08:00
const char *text;
Ui_Data *pd;
pd = data;
2021-01-22 08:37:51 -08:00
ev = event_info;
if (ev && !strcmp(ev->keyname, "Escape"))
2021-02-05 01:21:52 -08:00
elm_object_text_set(pd->search.entry, "");
2021-01-22 08:37:51 -08:00
2021-01-21 05:03:53 -08:00
text = elm_object_text_get(obj);
if (text)
{
2021-02-05 01:21:52 -08:00
pd->search.keytime = ecore_loop_time_get();
2021-01-22 08:37:51 -08:00
_search_clear(pd);
2021-02-05 01:21:52 -08:00
pd->search.text = strdup(text);
pd->search.len = strlen(text);
if (!pd->search.timer)
pd->search.timer = ecore_timer_add(0.05, _search_empty_cb, pd);
2021-01-21 05:03:53 -08:00
}
}
2020-12-24 02:46:35 -08:00
static void
_search_add(Ui_Data *pd)
{
2021-02-06 00:50:53 -08:00
Evas_Object *tb, *fr, *rec, *entry;
2020-12-24 02:46:35 -08:00
2021-02-06 00:50:53 -08:00
pd->search.pop = tb = elm_table_add(pd->win);
evas_object_lower(tb);
2020-12-24 02:46:35 -08:00
rec = evas_object_rectangle_add(evas_object_evas_get(pd->win));
evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(220), ELM_SCALE_SIZE(128));
evas_object_size_hint_max_set(rec, ELM_SCALE_SIZE(220), ELM_SCALE_SIZE(128));
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, rec, 0, 0, 1, 1);
2020-12-24 02:46:35 -08:00
2021-01-21 05:03:53 -08:00
fr = elm_frame_add(pd->win);
elm_object_text_set(fr, _("Search"));
evas_object_size_hint_weight_set(fr, 0, 0);
evas_object_size_hint_align_set(fr, FILL, 0.5);
evas_object_show(fr);
2020-12-24 02:46:35 -08:00
2021-02-05 01:21:52 -08:00
pd->search.entry = entry = elm_entry_add(fr);
2021-01-21 05:03:53 -08:00
evas_object_size_hint_weight_set(entry, 0, 0);
evas_object_size_hint_align_set(entry, 0.5, 0.5);
2020-12-24 02:46:35 -08:00
elm_entry_single_line_set(entry, 1);
2021-01-21 05:03:53 -08:00
elm_entry_scrollable_set(entry, 1);
2020-12-24 02:46:35 -08:00
elm_entry_editable_set(entry, 1);
elm_object_focus_allow_set(entry, 0);
evas_object_show(entry);
2021-01-21 05:03:53 -08:00
elm_object_content_set(fr, entry);
2021-02-06 00:50:53 -08:00
elm_table_pack(tb, fr, 0, 0, 1, 1);
2020-12-24 02:46:35 -08:00
2021-01-21 05:03:53 -08:00
evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
_search_key_down_cb, pd);
2020-12-24 02:46:35 -08:00
}
2020-12-17 05:15:43 -08:00
2020-11-09 05:40:00 -08:00
static void
2020-12-24 02:46:35 -08:00
_win_key_down_search(Ui_Data *pd, Evas_Event_Key_Down *ev)
2020-11-09 05:40:00 -08:00
{
2020-12-24 02:46:35 -08:00
Evas_Coord w, h;
2020-12-17 05:15:43 -08:00
2020-11-09 05:40:00 -08:00
if (!strcmp(ev->keyname, "Escape"))
{
2021-02-05 01:21:52 -08:00
elm_object_text_set(pd->search.entry, "");
2021-02-03 00:03:55 -08:00
_search_clear(pd);
pd->skip_wait = 0;
2021-02-05 01:21:52 -08:00
elm_object_focus_allow_set(pd->search.entry, 0);
evas_object_lower(pd->search.pop);
pd->search.visible = 0;
2020-12-17 05:15:43 -08:00
}
2021-01-23 09:12:11 -08:00
else if (ev->string && strcmp(ev->keyname, "BackSpace"))
2020-12-17 05:15:43 -08:00
{
2021-01-21 05:27:26 -08:00
if (isspace(ev->string[0])) return;
2020-12-24 02:46:35 -08:00
size_t len = strlen(ev->string);
2021-01-21 05:14:13 -08:00
if (len)
2021-01-21 05:03:53 -08:00
{
2021-02-05 01:21:52 -08:00
elm_entry_entry_append(pd->search.entry, ev->string);
elm_entry_cursor_pos_set(pd->search.entry, len);
_search_key_down_cb(pd, NULL, pd->search.entry, NULL);
2021-01-22 06:02:59 -08:00
}
2020-12-17 05:15:43 -08:00
evas_object_geometry_get(pd->win, NULL, NULL, &w, &h);
2021-02-05 01:21:52 -08:00
evas_object_move(pd->search.pop, w / 2, h / 2);
evas_object_raise(pd->search.pop);
elm_object_focus_allow_set(pd->search.entry, 1);
elm_object_focus_set(pd->search.entry, 1);
evas_object_show(pd->search.pop);
pd->search.visible = 1;
2020-12-17 05:15:43 -08:00
}
2020-12-24 02:46:35 -08:00
}
static void
_win_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Key_Down *ev;
Ui_Data *pd;
2020-12-30 05:40:38 -08:00
Evas_Coord x, y, w, h;
2020-12-24 02:46:35 -08:00
pd = data;
ev = event_info;
if (!ev || !ev->keyname)
return;
if (!pd) return;
2021-02-05 01:21:52 -08:00
elm_scroller_region_get(pd->genlist, &x, &y, &w, &h);
2020-12-30 05:40:38 -08:00
2021-02-05 01:21:52 -08:00
if (!strcmp(ev->keyname, "Escape") && !pd->search.visible)
{
evas_object_del(pd->win);
return;
}
2020-12-30 05:40:38 -08:00
else if (!strcmp(ev->keyname, "Prior"))
2021-02-05 01:21:52 -08:00
elm_scroller_region_bring_in(pd->genlist, x, y - h, w, h);
2020-12-30 05:40:38 -08:00
else if (!strcmp(ev->keyname, "Next"))
2021-02-05 01:21:52 -08:00
elm_scroller_region_bring_in(pd->genlist, x, y + h, w, h);
else
_win_key_down_search(pd, ev);
2020-12-24 02:46:35 -08:00
pd->skip_wait = 1;
2020-11-09 05:40:00 -08:00
}
static Eina_Bool
_resize_cb(void *data)
{
Ui_Data *pd = data;
pd->skip_wait = 0;
pd->resize_timer = NULL;
2021-01-24 05:48:40 -08:00
return 0;
}
2020-11-09 05:40:00 -08:00
static void
_win_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
2020-11-09 05:40:00 -08:00
{
Ui_Data *pd;
Ui *ui;
pd = data;
ui = pd->ui;
2020-11-09 05:40:00 -08:00
elm_genlist_realized_items_update(pd->genlist);
2020-11-09 05:40:00 -08:00
pd->skip_wait = 1;
if (pd->resize_timer)
ecore_timer_reset(pd->resize_timer);
else pd->resize_timer = ecore_timer_add(0.2, _resize_cb, pd);
2021-02-05 01:21:52 -08:00
evas_object_lower(pd->search.pop);
2020-12-31 14:58:25 -08:00
if (pd->main_menu)
_main_menu_dismissed_cb(pd, NULL, NULL);
2020-11-09 05:40:00 -08:00
2021-02-06 00:50:53 -08:00
evas_object_geometry_get(obj, NULL, NULL,
&ui->proc.width, &ui->proc.height);
}
2021-02-04 13:28:08 -08:00
static Eina_Bool
2021-01-22 06:02:59 -08:00
_evisum_config_changed_cb(void *data, int type EINA_UNUSED,
void *event EINA_UNUSED)
{
Eina_Iterator *it;
Ui *ui;
Ui_Data *pd = data;
void *d = NULL;
ui = pd->ui;
it = eina_hash_iterator_data_new(pd->cpu_times);
while (eina_iterator_next(it, &d))
{
int64_t *t = d;
*t = 0;
}
eina_iterator_free(it);
2021-02-05 01:21:52 -08:00
elm_scroller_policy_set(pd->genlist, ELM_SCROLLER_POLICY_OFF,
(ui->proc.show_scroller ?
2021-01-21 09:03:29 -08:00
ELM_SCROLLER_POLICY_AUTO :
ELM_SCROLLER_POLICY_OFF));
pd->skip_wait = 1;
2021-01-24 05:48:40 -08:00
return 1;
}
2020-12-30 11:31:50 -08:00
static void
2021-01-22 06:02:59 -08:00
_win_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj,
void *event_info EINA_UNUSED)
2020-12-30 11:31:50 -08:00
{
Ui_Data *pd;
Ui *ui;
pd = data;
ui = pd->ui;
evas_object_geometry_get(obj, &ui->proc.x, &ui->proc.y, NULL, NULL);
2020-12-30 11:31:50 -08:00
}
2020-11-09 05:40:00 -08:00
static void
2021-01-22 06:02:59 -08:00
_win_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
2020-11-09 05:40:00 -08:00
{
Ui *ui;
2021-02-05 01:21:52 -08:00
List_Header *h;
Ui_Data *pd = data;
ui = pd->ui;
2020-11-09 05:40:00 -08:00
evisum_ui_config_save(ui);
2020-11-09 06:54:03 -08:00
2021-02-05 01:21:52 -08:00
if (pd->search.timer)
ecore_timer_del(pd->search.timer);
2020-12-16 08:01:03 -08:00
if (pd->thread)
ecore_thread_cancel(pd->thread);
2020-11-09 05:40:00 -08:00
if (pd->thread)
ecore_thread_wait(pd->thread, 0.5);
2020-11-09 05:40:00 -08:00
ecore_event_handler_del(pd->handler[0]);
2021-02-05 01:21:52 -08:00
EINA_LIST_FREE(pd->headers, h)
free(h);
2020-12-15 16:16:29 -08:00
pd->thread = NULL;
ui->proc.win = NULL;
2020-11-09 05:40:00 -08:00
2021-02-05 01:21:52 -08:00
if (pd->search.text)
free(pd->search.text);
2021-01-21 05:03:53 -08:00
if (pd->cache)
evisum_ui_item_cache_free(pd->cache);
eina_hash_free(pd->cpu_times);
2020-11-09 07:32:02 -08:00
free(pd);
pd = NULL;
2020-11-09 05:40:00 -08:00
}
static void
_init(Ui_Data *pd)
{
2021-02-06 00:50:53 -08:00
pd->sorters[SORT_BY_NONE].sort_cb = proc_sort_by_pid;
pd->sorters[SORT_BY_PID].sort_cb = proc_sort_by_pid;
pd->sorters[SORT_BY_UID].sort_cb = proc_sort_by_uid;
pd->sorters[SORT_BY_NICE].sort_cb = proc_sort_by_nice;
pd->sorters[SORT_BY_PRI].sort_cb = proc_sort_by_pri;
pd->sorters[SORT_BY_CPU].sort_cb = proc_sort_by_cpu;
pd->sorters[SORT_BY_THREADS].sort_cb = proc_sort_by_threads;
pd->sorters[SORT_BY_SIZE].sort_cb = proc_sort_by_size;
pd->sorters[SORT_BY_RSS].sort_cb = proc_sort_by_rss;
pd->sorters[SORT_BY_CMD].sort_cb = proc_sort_by_cmd;
pd->sorters[SORT_BY_STATE].sort_cb = proc_sort_by_state;
pd->sorters[SORT_BY_TIME].sort_cb = proc_sort_by_time;
pd->sorters[SORT_BY_CPU_USAGE].sort_cb = proc_sort_by_cpu_usage;
}
2020-11-09 05:40:00 -08:00
void
ui_process_list_win_add(Ui *ui)
2020-11-09 05:40:00 -08:00
{
Evas_Object *win, *icon;
2020-12-17 05:15:43 -08:00
Evas_Object *obj;
2020-11-09 05:40:00 -08:00
if (ui->proc.win)
2020-11-09 05:40:00 -08:00
{
elm_win_raise(ui->proc.win);
2020-11-09 05:40:00 -08:00
return;
}
2020-12-16 11:20:32 -08:00
Ui_Data *pd = _pd = calloc(1, sizeof(Ui_Data));
if (!pd) return;
2020-12-24 04:45:16 -08:00
pd->selected_pid = -1;
pd->ui = ui;
pd->handler[0] = ecore_event_handler_add(EVISUM_EVENT_CONFIG_CHANGED,
_evisum_config_changed_cb, pd);
_init(pd);
2020-12-17 05:15:43 -08:00
ui->proc.win = pd->win = win = elm_win_util_standard_add("evisum", "evisum");
2021-01-24 05:48:40 -08:00
elm_win_autodel_set(win, 1);
2020-12-31 12:17:02 -08:00
elm_win_title_set(win, _("Process Explorer"));
2020-11-09 05:40:00 -08:00
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "evisum");
elm_win_icon_object_set(win, icon);
evisum_ui_background_add(win, evisum_ui_backgrounds_enabled_get());
if (ui->proc.width > 1 && ui->proc.height > 1)
evas_object_resize(win, ui->proc.width, ui->proc.height);
2020-11-09 05:40:00 -08:00
else
evas_object_resize(win, EVISUM_WIN_WIDTH * elm_config_scale_get(),
EVISUM_WIN_HEIGHT * elm_config_scale_get());
if (ui->proc.x > 0 && ui->proc.y > 0)
evas_object_move(win, ui->proc.x, ui->proc.y);
else
elm_win_center(win, 1, 1);
2020-12-24 04:45:16 -08:00
2020-12-17 05:15:43 -08:00
obj = _ui_content_system_add(pd, win);
elm_object_content_set(win, obj);
2020-12-17 12:11:13 -08:00
_search_add(pd);
pd->cache = evisum_ui_item_cache_new(pd->genlist, _item_create, 40);
pd->cpu_times = eina_hash_int64_new(_cpu_times_free_cb);
2020-12-17 03:12:15 -08:00
evas_object_event_callback_add(win, EVAS_CALLBACK_DEL,
_win_del_cb, pd);
2020-12-17 05:15:43 -08:00
evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE,
_win_resize_cb, pd);
2020-12-30 11:31:50 -08:00
evas_object_event_callback_add(win, EVAS_CALLBACK_MOVE,
_win_move_cb, pd);
2020-12-17 05:15:43 -08:00
evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
2020-12-17 03:12:15 -08:00
_win_key_down_cb, pd);
2020-12-17 05:15:43 -08:00
evas_object_show(win);
2020-12-17 03:12:15 -08:00
2021-02-04 11:48:20 -08:00
_win_resize_cb(pd, NULL, win, NULL);
2020-12-17 03:12:15 -08:00
pd->thread = ecore_thread_feedback_run(_process_list,
_process_list_feedback_cb,
NULL,
2021-01-23 14:30:51 -08:00
NULL,
2021-01-24 05:48:40 -08:00
pd, 0);
2020-11-09 05:40:00 -08:00
}