summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2020-06-30 13:05:35 +0100
committerAlastair Poole <netstar@gmail.com>2020-06-30 13:05:35 +0100
commitd2a72510cb79a83f1b03aa1bfad57f2fe6e1abbb (patch)
treee65d1d3084ddb315fa76c0c85be7e0a9223adf58
parent1f0d8827b84908164c1490a05c1e96cb01e09116 (diff)
evisum: Clean up orderly.
Whether this is meritted, I don't know. It might be useful in the future.
-rw-r--r--src/bin/main.c6
-rw-r--r--src/bin/ui/ui.c35
-rw-r--r--src/bin/ui/ui.h15
-rw-r--r--src/bin/ui/ui_cpu.c17
-rw-r--r--src/bin/ui/ui_disk.c7
-rw-r--r--src/bin/ui/ui_memory.c8
-rw-r--r--src/bin/ui/ui_misc.c7
-rw-r--r--src/bin/ui/ui_util.c8
8 files changed, 53 insertions, 50 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index 83278ce..6ef07e6 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -21,7 +21,9 @@ static void
21_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 21_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
22 void *event_info EINA_UNUSED) 22 void *event_info EINA_UNUSED)
23{ 23{
24 exit(0); 24 Ui *ui = data;
25
26 evisum_ui_shutdown(ui);
25} 27}
26 28
27static Ui * 29static Ui *
@@ -131,7 +133,7 @@ main(int argc, char **argv)
131 if (ui) 133 if (ui)
132 { 134 {
133 ecore_main_loop_begin(); 135 ecore_main_loop_begin();
134 evisum_ui_shutdown(ui); 136 evisum_ui_del(ui);
135 } 137 }
136 138
137 elm_shutdown(); 139 elm_shutdown();
diff --git a/src/bin/ui/ui.c b/src/bin/ui/ui.c
index 3d8993d..f503767 100644
--- a/src/bin/ui/ui.c
+++ b/src/bin/ui/ui.c
@@ -743,9 +743,12 @@ _btn_state_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
743 743
744static void 744static void
745_quit_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 745_quit_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
746 void *event_info EINA_UNUSED) 746 void *event_info EINA_UNUSED)
747{ 747{
748 exit(0); 748 Ui *ui = data;
749
750 evas_object_hide(ui->win);
751 evisum_ui_shutdown(ui);
749} 752}
750 753
751static void 754static void
@@ -1279,6 +1282,23 @@ _evisum_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1279void 1282void
1280evisum_ui_shutdown(Ui *ui) 1283evisum_ui_shutdown(Ui *ui)
1281{ 1284{
1285 if (ui->win_cpu)
1286 evas_object_smart_callback_call(ui->win_cpu, "delete,request", NULL);
1287 if (ui->win_mem)
1288 evas_object_smart_callback_call(ui->win_mem, "delete,request", NULL);
1289 if (ui->win_disk)
1290 evas_object_smart_callback_call(ui->win_disk, "delete,request", NULL);
1291 if (ui->win_misc)
1292 evas_object_smart_callback_call(ui->win_misc, "delete,request", NULL);
1293 if (ui->win_about)
1294 evas_object_smart_callback_call(ui->win_about, "delete,request", NULL);
1295
1296 ecore_main_loop_quit();
1297}
1298
1299void
1300evisum_ui_del(Ui *ui)
1301{
1282 evas_object_del(ui->win); 1302 evas_object_del(ui->win);
1283 1303
1284 if (ui->timer_pid) 1304 if (ui->timer_pid)
@@ -1287,9 +1307,6 @@ evisum_ui_shutdown(Ui *ui)
1287 if (ui->thread_system) 1307 if (ui->thread_system)
1288 ecore_thread_cancel(ui->thread_system); 1308 ecore_thread_cancel(ui->thread_system);
1289 1309
1290 if (ui->thread_cpu)
1291 ecore_thread_cancel(ui->thread_cpu);
1292
1293 if (ui->thread_process) 1310 if (ui->thread_process)
1294 ecore_thread_cancel(ui->thread_process); 1311 ecore_thread_cancel(ui->thread_process);
1295 1312
@@ -1299,14 +1316,8 @@ evisum_ui_shutdown(Ui *ui)
1299 if (ui->thread_process) 1316 if (ui->thread_process)
1300 ecore_thread_wait(ui->thread_process, 1.0); 1317 ecore_thread_wait(ui->thread_process, 1.0);
1301 1318
1302 if (ui->thread_cpu)
1303 ecore_thread_wait(ui->thread_cpu, 1.0);
1304
1305 _proc_pid_cpu_times_free(ui); 1319 _proc_pid_cpu_times_free(ui);
1306 1320
1307 if (ui->cpu_list)
1308 eina_list_free(ui->cpu_list);
1309
1310 if (ui->cache) 1321 if (ui->cache)
1311 evisum_ui_item_cache_free(ui->cache); 1322 evisum_ui_item_cache_free(ui->cache);
1312 1323
@@ -1426,7 +1437,7 @@ _menu_setup(Ui *ui)
1426 1437
1427 menu = elm_win_main_menu_get(ui->win); 1438 menu = elm_win_main_menu_get(ui->win);
1428 menu_it = elm_menu_item_add(menu, NULL, NULL, _("File"), NULL, NULL); 1439 menu_it = elm_menu_item_add(menu, NULL, NULL, _("File"), NULL, NULL);
1429 elm_menu_item_add(menu, menu_it, "exit", _("Quit"), _quit_cb, NULL); 1440 elm_menu_item_add(menu, menu_it, "exit", _("Quit"), _quit_cb, ui);
1430 menu_it = elm_menu_item_add(menu, NULL, NULL, _("View"), NULL, NULL); 1441 menu_it = elm_menu_item_add(menu, NULL, NULL, _("View"), NULL, NULL);
1431 elm_menu_item_add(menu, menu_it, NULL, _("CPU"), _menu_cpu_activity_clicked_cb, ui); 1442 elm_menu_item_add(menu, menu_it, NULL, _("CPU"), _menu_cpu_activity_clicked_cb, ui);
1432 elm_menu_item_add(menu, menu_it, NULL, _("Memory"), 1443 elm_menu_item_add(menu, menu_it, NULL, _("Memory"),
diff --git a/src/bin/ui/ui.h b/src/bin/ui/ui.h
index 3cea3a3..8964dc5 100644
--- a/src/bin/ui/ui.h
+++ b/src/bin/ui/ui.h
@@ -37,16 +37,16 @@ typedef struct Ui
37 Evas_Object *scroller; 37 Evas_Object *scroller;
38 Evas_Object *content; 38 Evas_Object *content;
39 39
40 Evas_Object *win_cpu;
41 Evas_Object *win_mem;
42 Evas_Object *win_disk;
43 Evas_Object *win_misc;
44 Evas_Object *win_about;
45
40 Evas_Object *disk_activity; 46 Evas_Object *disk_activity;
41 Evas_Object *misc_activity; 47 Evas_Object *misc_activity;
42 Evas_Object *system_activity; 48 Evas_Object *system_activity;
43 49
44 Eina_Bool cpu_visible;
45 Eina_Bool misc_visible;
46 Eina_Bool disk_visible;
47 Eina_Bool mem_visible;
48 Eina_Bool about_visible;
49
50 Evas_Object *progress_cpu; 50 Evas_Object *progress_cpu;
51 Evas_Object *progress_mem; 51 Evas_Object *progress_mem;
52 52
@@ -99,6 +99,9 @@ Ui *
99evisum_ui_add(Evas_Object *win); 99evisum_ui_add(Evas_Object *win);
100 100
101void 101void
102evisum_ui_del(Ui *ui);
103
104void
102evisum_ui_shutdown(Ui *ui); 105evisum_ui_shutdown(Ui *ui);
103 106
104#endif 107#endif
diff --git a/src/bin/ui/ui_cpu.c b/src/bin/ui/ui_cpu.c
index f9c6871..01adbad 100644
--- a/src/bin/ui/ui_cpu.c
+++ b/src/bin/ui/ui_cpu.c
@@ -163,12 +163,6 @@ _core_times_cb(void *data, Ecore_Thread *thread)
163 163
164 for (int i = 0; !ecore_thread_check(thread); i = 0) 164 for (int i = 0; !ecore_thread_check(thread); i = 0)
165 { 165 {
166 if (!ui->cpu_visible)
167 {
168 usleep(1000000);
169 continue;
170 }
171
172 cores = system_cpu_usage_get(&ncpu); 166 cores = system_cpu_usage_get(&ncpu);
173 167
174 EINA_LIST_FOREACH(ui->cpu_list, l, progress) 168 EINA_LIST_FOREACH(ui->cpu_list, l, progress)
@@ -190,8 +184,8 @@ _win_del_cb(void *data, Evas_Object *obj,
190 Progress *progress; 184 Progress *progress;
191 Ui *ui = data; 185 Ui *ui = data;
192 186
187 evas_object_hide(obj);
193 ecore_thread_cancel(ui->thread_cpu); 188 ecore_thread_cancel(ui->thread_cpu);
194 evas_object_del(obj);
195 189
196 EINA_LIST_FREE(ui->cpu_list, progress) 190 EINA_LIST_FREE(ui->cpu_list, progress)
197 { 191 {
@@ -201,7 +195,8 @@ _win_del_cb(void *data, Evas_Object *obj,
201 } 195 }
202 196
203 ecore_thread_wait(ui->thread_cpu, 1.0); 197 ecore_thread_wait(ui->thread_cpu, 1.0);
204 ui->cpu_visible = EINA_FALSE; 198 evas_object_del(obj);
199 ui->win_cpu = NULL;
205} 200}
206 201
207void 202void
@@ -212,11 +207,9 @@ ui_win_cpu_add(Ui *ui)
212 Evas_Object *bg, *line, *obj; 207 Evas_Object *bg, *line, *obj;
213 int cpu_count; 208 int cpu_count;
214 209
215 if (ui->cpu_visible) return; 210 if (ui->win_cpu) return;
216
217 ui->cpu_visible = EINA_TRUE;
218 211
219 win = elm_win_util_standard_add("evisum", _("CPU Usage")); 212 ui->win_cpu = win = elm_win_util_standard_add("evisum", _("CPU Usage"));
220 evas_object_size_hint_weight_set(win, EXPAND, EXPAND); 213 evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
221 evas_object_size_hint_align_set(win, FILL, FILL); 214 evas_object_size_hint_align_set(win, FILL, FILL);
222 215
diff --git a/src/bin/ui/ui_disk.c b/src/bin/ui/ui_disk.c
index de6700f..0acb787 100644
--- a/src/bin/ui/ui_disk.c
+++ b/src/bin/ui/ui_disk.c
@@ -161,8 +161,8 @@ _win_del_cb(void *data, Evas_Object *obj EINA_UNUSED,
161 ecore_timer_del(ui->timer_disk); 161 ecore_timer_del(ui->timer_disk);
162 ui->timer_disk = NULL; 162 ui->timer_disk = NULL;
163 163
164 ui->disk_visible = EINA_FALSE;
165 evas_object_del(obj); 164 evas_object_del(obj);
165 ui->win_disk = NULL;
166} 166}
167 167
168void 168void
@@ -171,10 +171,9 @@ ui_win_disk_add(Ui *ui)
171 Evas_Object *win, *box, *vbox, *scroller; 171 Evas_Object *win, *box, *vbox, *scroller;
172 Evas_Object *table, *rect; 172 Evas_Object *table, *rect;
173 173
174 if (ui->disk_visible) return; 174 if (ui->win_disk) return;
175 ui->disk_visible = EINA_TRUE;
176 175
177 win = elm_win_util_standard_add("evisum", _("Storage")); 176 ui->win_disk = win = elm_win_util_standard_add("evisum", _("Storage"));
178 evas_object_size_hint_weight_set(win, EXPAND, EXPAND); 177 evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
179 evas_object_size_hint_align_set(win, FILL, FILL); 178 evas_object_size_hint_align_set(win, FILL, FILL);
180 179
diff --git a/src/bin/ui/ui_memory.c b/src/bin/ui/ui_memory.c
index 4816e41..49c613f 100644
--- a/src/bin/ui/ui_memory.c
+++ b/src/bin/ui/ui_memory.c
@@ -116,7 +116,7 @@ _win_del_cb(void *data, Evas_Object *obj,
116 if (widgets) free(widgets); 116 if (widgets) free(widgets);
117 117
118 evas_object_del(obj); 118 evas_object_del(obj);
119 ui->mem_visible = EINA_FALSE; 119 ui->win_mem = NULL;
120} 120}
121 121
122void 122void
@@ -125,14 +125,12 @@ ui_win_memory_add(Ui *ui)
125 Evas_Object *win, *frame, *pb; 125 Evas_Object *win, *frame, *pb;
126 Evas_Object *border, *rect, *label, *table; 126 Evas_Object *border, *rect, *label, *table;
127 127
128 if (ui->mem_visible) return; 128 if (ui->win_mem) return;
129
130 ui->mem_visible = EINA_TRUE;
131 129
132 Widgets *widgets = calloc(1, sizeof(Widgets)); 130 Widgets *widgets = calloc(1, sizeof(Widgets));
133 if (!widgets) return; 131 if (!widgets) return;
134 132
135 win = elm_win_util_standard_add("evisum", _("Memory Usage")); 133 ui->win_mem = win = elm_win_util_standard_add("evisum", _("Memory Usage"));
136 evas_object_size_hint_weight_set(win, EXPAND, EXPAND); 134 evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
137 evas_object_size_hint_align_set(win, FILL, FILL); 135 evas_object_size_hint_align_set(win, FILL, FILL);
138 136
diff --git a/src/bin/ui/ui_misc.c b/src/bin/ui/ui_misc.c
index bfd6212..4f3aa89 100644
--- a/src/bin/ui/ui_misc.c
+++ b/src/bin/ui/ui_misc.c
@@ -335,7 +335,7 @@ _win_del_cb(void *data, Evas_Object *obj EINA_UNUSED,
335 ui->timer_misc = NULL; 335 ui->timer_misc = NULL;
336 336
337 evas_object_del(obj); 337 evas_object_del(obj);
338 ui->misc_visible = EINA_FALSE; 338 ui->win_misc = NULL;
339} 339}
340 340
341void 341void
@@ -344,10 +344,9 @@ ui_win_misc_add(Ui *ui)
344 Evas_Object *win, *box, *hbox, *frame, *scroller; 344 Evas_Object *win, *box, *hbox, *frame, *scroller;
345 Evas_Object *table, *border, *rect; 345 Evas_Object *table, *border, *rect;
346 346
347 if (ui->misc_visible) return; 347 if (ui->win_misc) return;
348 ui->misc_visible = EINA_TRUE;
349 348
350 win = elm_win_util_standard_add("evisum", _("Stuff")); 349 ui->win_misc = win = elm_win_util_standard_add("evisum", _("Stuff"));
351 evas_object_size_hint_weight_set(win, EXPAND, EXPAND); 350 evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
352 evas_object_size_hint_align_set(win, FILL, FILL); 351 evas_object_size_hint_align_set(win, FILL, FILL);
353 352
diff --git a/src/bin/ui/ui_util.c b/src/bin/ui/ui_util.c
index 9522f47..ece0ba0 100644
--- a/src/bin/ui/ui_util.c
+++ b/src/bin/ui/ui_util.c
@@ -231,8 +231,8 @@ _win_del_cb(void *data, Evas_Object *obj,
231 _animator = NULL; 231 _animator = NULL;
232 ui = evas_object_data_get(win, "ui"); 232 ui = evas_object_data_get(win, "ui");
233 if (!ui) return; 233 if (!ui) return;
234 ui->about_visible = EINA_FALSE;
235 evas_object_del(win); 234 evas_object_del(win);
235 ui->win_about = NULL;
236} 236}
237 237
238static Eina_Bool 238static Eina_Bool
@@ -282,11 +282,9 @@ evisum_about_window_show(void *data)
282 282
283 ui = data; 283 ui = data;
284 284
285 if (ui->about_visible) return; 285 if (ui->win_about) return;
286 286
287 ui->about_visible = EINA_TRUE; 287 ui->win_about = win = elm_win_add(ui->win, "evisum", ELM_WIN_DIALOG_BASIC);
288
289 win = elm_win_add(ui->win, "evisum", ELM_WIN_DIALOG_BASIC);
290 elm_win_title_set(win, "About Evisum"); 288 elm_win_title_set(win, "About Evisum");
291 evas_object_smart_callback_add(win, "delete,request", _win_del_cb, win); 289 evas_object_smart_callback_add(win, "delete,request", _win_del_cb, win);
292 evas_object_data_set(win, "ui", ui); 290 evas_object_data_set(win, "ui", ui);