evisum: let there be choice

soo...let's create a little ipc server and server the minions
whatever they want. So add CPU and memory and Generic thing to the
application menu (desktop). Means you don't have to load up the
main EXE each time you want only one minor feature. Also use the
same process for all of this so we don't eat up resources and
because we can.
This commit is contained in:
Alastair Poole 2020-10-27 01:33:20 +00:00
parent 366cefdb4d
commit 7f05af18d6
13 changed files with 300 additions and 136 deletions

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=CPU
GenericName=Monitor
Exec=evisum -c
Icon=evisum_cpu
Categories=System;Monitor;
StartupWMClass=evisum

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=Memory
GenericName=Monitor
Exec=evisum -m
Icon=evisum_mem
Categories=System;Monitor;
StartupWMClass=evisum

View File

@ -1,2 +1,6 @@
install_data('evisum.desktop',
install_dir: join_paths(dir_data, 'applications'))
install_data('evisum_cpu.desktop',
install_dir: join_paths(dir_data, 'applications'))
install_data('evisum_mem.desktop',
install_dir: join_paths(dir_data, 'applications'))

BIN
data/icons/evisum_cpu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
data/icons/evisum_mem.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -1,2 +1,6 @@
install_data('evisum.png',
install_dir: join_paths(dir_data, 'icons/hicolor/256x256/apps'))
install_data('evisum_cpu.png',
install_dir: join_paths(dir_data, 'icons/hicolor/256x256/apps'))
install_data('evisum_mem.png',
install_dir: join_paths(dir_data, 'icons/hicolor/256x256/apps'))

14
src/bin/evisum_actions.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef _EVISUM_H_
#define _EVISUM_H_
typedef enum
{
EVISUM_ACTION_DEFAULT = 0,
EVISUM_ACTION_PROCESS = 1,
EVISUM_ACTION_CPU = 2,
EVISUM_ACTION_MEM = 3,
EVISUM_ACTION_STORAGE = 4,
EVISUM_ACTION_SENSORS = 5,
} Evisum_Action;
#endif

150
src/bin/evisum_server.c Normal file
View File

@ -0,0 +1,150 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <Eina.h>
#include <Ecore.h>
#include <Ecore_Con.h>
#include "evisum_server.h"
#include "src/bin/ui/ui.h"
#include "src/bin/ui/ui_cpu.h"
#include "src/bin/ui/ui_memory.h"
#include "src/bin/ui/ui_disk.h"
#include "src/bin/ui/ui_sensors.h"
#define LISTEN_SOCKET_NAME "evisum_server"
typedef struct _Evisum_Server {
Ecore_Event_Handler *handler;
Ecore_Con_Server *srv;
} Evisum_Server;
static void *_evisum_server = NULL;
static Eina_Bool
_evisum_server_server_client_connect_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
Ecore_Con_Event_Client_Data *ev;
Evisum_Action *action;
Ui *ui;
ev = event;
action = ev->data;
ui = data;
evisum_ui_activate(ui, *action);
ecore_con_client_del(ev->client);
return ECORE_CALLBACK_RENEW;
}
void
evisum_server_shutdown(void)
{
Evisum_Server *server = _evisum_server;
if (!server) return;
ecore_event_handler_del(server->handler);
ecore_con_server_del(server->srv);
free(server);
}
Eina_Bool
evisum_server_init(void *data)
{
Ui *ui = data;
Evisum_Server *server = calloc(1, sizeof(Evisum_Server));
if (!server) return EINA_FALSE;
server->srv = ecore_con_server_add(ECORE_CON_LOCAL_USER, LISTEN_SOCKET_NAME, 0, NULL);
if (!server->srv) return EINA_FALSE;
server->handler = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, _evisum_server_server_client_connect_cb, ui);
_evisum_server = server;
return EINA_TRUE;
}
typedef struct _Evisum_Server_Client {
Ecore_Con_Server *srv;
Evisum_Action action;
Eina_Bool success;
} Evisum_Server_Client;
static Eina_Bool
_evisum_server_client_closed_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
{
Ecore_Con_Event_Server_Del *ev;
Evisum_Server_Client *client = data;
ev = event;
if (client->srv != ev->server) return ECORE_CALLBACK_RENEW;
client->success = EINA_TRUE;
return ECORE_CALLBACK_DONE;
}
static Eina_Bool
_evisum_server_client_check_timer_cb(void *data EINA_UNUSED)
{
Evisum_Server_Client *client;
static double total = 0.0;
client = data;
total += 0.1;
if (total < 1.0)
return ECORE_CALLBACK_RENEW;
free(client);
ecore_main_loop_quit();
return ECORE_CALLBACK_DONE;
}
static Eina_Bool
_evisum_server_client_connect_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
{
Ecore_Con_Event_Server_Add *ev;
Ecore_Con_Server *srv;
Evisum_Server_Client *client;
ev = event;
srv = ev->server;
client = data;
if (client->srv != srv) return ECORE_CALLBACK_RENEW;
ecore_con_server_send(srv, &client->action, sizeof(Evisum_Action));
ecore_con_server_flush(srv);
return ECORE_CALLBACK_DONE;
}
Eina_Bool
evisum_server_client_add(Evisum_Action action)
{
Evisum_Server_Client *client;
Ecore_Con_Server *srv = ecore_con_server_connect(ECORE_CON_LOCAL_USER, LISTEN_SOCKET_NAME, 0, NULL);
if (!srv)
{
return EINA_FALSE;
}
client = calloc(1, sizeof(Evisum_Server_Client));
if (!client) return EINA_FALSE;
client->action = action;
client->srv = srv;
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _evisum_server_client_connect_cb, client);
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _evisum_server_client_closed_cb, client);
ecore_timer_add(0.1, _evisum_server_client_check_timer_cb, client);
return EINA_TRUE;
}

16
src/bin/evisum_server.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef EVISUM_SERVER_H
#define EVISUM_SERVER_H
#include <Eina.h>
#include "evisum_actions.h"
Eina_Bool
evisum_server_init(void *data);
void
evisum_server_shutdown(void);
Eina_Bool
evisum_server_client_add(Evisum_Action action);
#endif

View File

@ -8,108 +8,15 @@
#include "config.h"
#include "evisum_config.h"
#include "evisum_server.h"
#include "ui/ui.h"
#if defined(DEVELOPMENT)
# include "system/machine.h"
# include "system/process.h"
# include "system/disks.h"
# include "system/filesystems.h"
#endif
static void
_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui *ui = data;
evisum_ui_shutdown(ui);
}
static Ui *
_win_add(void)
{
Ui *ui;
Evas_Object *win, *icon;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("evisum", "evisum");
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "evisum");
elm_win_icon_object_set(win, icon);
evas_object_resize(win, EVISUM_WIN_WIDTH * elm_config_scale_get(),
EVISUM_WIN_HEIGHT * elm_config_scale_get());
elm_win_title_set(win, _("EFL System Monitor"));
elm_win_center(win, EINA_TRUE, EINA_TRUE);
ui = evisum_ui_add(win);
if (!ui)
return NULL;
ui->state.shutdown_now = EINA_TRUE;
evas_object_smart_callback_add(win, "delete,request", _win_del_cb, ui);
evas_object_show(win);
return ui;
}
#if defined(DEVELOPMENT)
static void
_test(int all)
{
Sys_Info *inf;
Eina_List *procs, *disks;
Proc_Info *proc;
File_System *fs;
char *path, *mount;
printf("Starting testing\n");
inf = system_info_all_get();
int cpu_count = system_cpu_count_get();
for (int i = 0; i < cpu_count; i++)
{
int temp = system_cpu_n_temperature_get(i);
if (temp != -1) printf(" cpu %d temp %d C\n", i, temp);
}
system_info_all_free(inf);
if (!all) goto out;
eina_init();
ecore_init();
procs = proc_info_all_get();
EINA_LIST_FREE(procs, proc)
proc_info_free(proc);
disks = disks_get();
EINA_LIST_FREE(disks, path)
{
mount = disk_mount_point_get(path);
if (mount)
{
fs = file_system_info_get(mount);
if (fs)
file_system_info_free(fs);
free(mount);
}
free(path);
}
ecore_shutdown();
eina_shutdown();
out:
printf("Ending testing\n");
}
#endif
int
main(int argc, char **argv)
{
Ui *ui;
int i;
Evisum_Action action = EVISUM_ACTION_DEFAULT;
for (i = 0; i < argc; i++)
{
@ -120,18 +27,14 @@ main(int argc, char **argv)
printf("Evisum version: %s\n", PACKAGE_VERSION);
exit(0);
}
#if defined(DEVELOPMENT)
else if (!strcmp(argv[i], "-t"))
{
_test(1);
exit(0);
}
else if (!strcmp(argv[i], "-T"))
{
_test(0);
exit(0);
}
#endif
else if (!strcmp(argv[i], "-c"))
action = EVISUM_ACTION_CPU;
else if (!strcmp(argv[i], "-m"))
action = EVISUM_ACTION_MEM;
else if (!strcmp(argv[i], "-d"))
action = EVISUM_ACTION_STORAGE;
else if (!strcmp(argv[i], "-s"))
action = EVISUM_ACTION_SENSORS;
}
eina_init();
@ -146,13 +49,23 @@ main(int argc, char **argv)
textdomain(PACKAGE);
#endif
ui = _win_add();
if (ui)
if (evisum_server_client_add(action))
{
ecore_main_loop_begin();
evisum_ui_del(ui);
return 0;
}
ui = evisum_ui_init();
if (!ui) return 1;
evisum_server_init(ui);
evisum_ui_activate(ui, action);
ecore_main_loop_begin();
evisum_ui_del(ui);
evisum_server_shutdown();
elm_shutdown();
config_shutdown();
ecore_shutdown();

View File

@ -9,6 +9,8 @@ src += files([
'main.c',
'evisum_config.c',
'evisum_config.h',
'evisum_server.c',
'evisum_server.h',
])
executable('evisum', src,

View File

@ -1,4 +1,5 @@
#include "config.h"
#include "evisum_actions.h"
#include "ui.h"
#include "ui/ui_cpu.h"
#include "ui/ui_memory.h"
@ -1634,11 +1635,6 @@ _evisum_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
void
evisum_ui_shutdown(Ui *ui)
{
if (ui->state.shutdown_now)
exit(0);
evas_object_del(ui->win);
if (ui->thread_system)
ecore_thread_cancel(ui->thread_system);
@ -1646,10 +1642,10 @@ evisum_ui_shutdown(Ui *ui)
ecore_thread_cancel(ui->thread_process);
if (ui->thread_system)
ecore_thread_wait(ui->thread_system, 1.0);
ecore_thread_wait(ui->thread_system, 0.1);
if (ui->thread_process)
ecore_thread_wait(ui->thread_process, 1.0);
ecore_thread_wait(ui->thread_process, 0.1);
if (ui->cpu.win)
evas_object_smart_callback_call(ui->cpu.win, "delete,request", NULL);
@ -1767,13 +1763,47 @@ _elm_config_change_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
}
static void
_ui_launch(Ui *ui)
_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ui *ui = data;
evisum_ui_shutdown(ui);
}
void
ui_main_win_add(Ui *ui)
{
Evas_Object *win, *icon;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("evisum", "evisum");
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "evisum");
elm_win_icon_object_set(win, icon);
evas_object_resize(win, EVISUM_WIN_WIDTH * elm_config_scale_get(),
EVISUM_WIN_HEIGHT * elm_config_scale_get());
elm_win_title_set(win, _("EFL System Monitor"));
elm_win_center(win, EINA_TRUE, EINA_TRUE);
evas_object_smart_callback_add(win, "delete,request", _win_del_cb, ui);
evas_object_show(win);
ui->win = win;
_process_list_update(ui);
ecore_timer_add(2.0, _bring_in, ui);
elm_object_focus_set(ui->entry_search, EINA_TRUE);
if (evisum_ui_effects_enabled_get() || evisum_ui_backgrounds_enabled_get())
evisum_ui_background_random_add(ui->win, 1);
_ui_content_add(win, ui);
if (evisum_ui_effects_enabled_get())
evisum_ui_animate(ui);
ui->cache = evisum_ui_item_cache_new(ui->genlist_procs, _item_create, 50);
ui->thread_system =
ecore_thread_feedback_run(_system_info_all_poll,
_system_info_all_poll_feedback_cb,
@ -1799,13 +1829,36 @@ _ui_init_system_probe(Ui *ui)
ui->mem.zfs_mounted = file_system_in_use("ZFS");
}
void
evisum_ui_activate(Ui *ui, Evisum_Action action)
{
switch (action)
{
case EVISUM_ACTION_DEFAULT:
case EVISUM_ACTION_PROCESS:
ui_main_win_add(ui);
break;
case EVISUM_ACTION_CPU:
ui_win_cpu_add(ui);
break;
case EVISUM_ACTION_MEM:
ui_win_memory_add(ui);
break;
case EVISUM_ACTION_STORAGE:
ui_win_disk_add(ui);
break;
case EVISUM_ACTION_SENSORS:
ui_win_sensors_add(ui);
break;
}
}
static Ui *
_ui_init(Evas_Object *parent)
_ui_init(void)
{
Ui *ui = calloc(1, sizeof(Ui));
if (!ui) return NULL;
ui->win = parent;
ui->settings.poll_delay = 3;
ui->settings.sort_reverse = EINA_FALSE;
ui->settings.sort_type = SORT_BY_PID;
@ -1821,29 +1874,17 @@ _ui_init(Evas_Object *parent)
_config_load(ui);
if (evisum_ui_effects_enabled_get() || evisum_ui_backgrounds_enabled_get())
evisum_ui_background_random_add(ui->win, 1);
_ui_content_add(parent, ui);
if (evisum_ui_effects_enabled_get())
evisum_ui_animate(ui);
ui->cache = evisum_ui_item_cache_new(ui->genlist_procs, _item_create, 50);
return ui;
}
Ui *
evisum_ui_add(Evas_Object *parent)
evisum_ui_init(void)
{
eina_lock_new(&_lock);
Ui *ui = _ui = _ui_init(parent);
Ui *ui = _ui = _ui_init();
if (!ui) return NULL;
_ui_launch(ui);
return ui;
}

View File

@ -6,6 +6,7 @@
#include "system/machine.h"
#include "system/process.h"
#include "../evisum_config.h"
#include "../evisum_server.h"
#include "ui/ui_util.h"
#include "ui/ui_cache.h"
@ -116,7 +117,7 @@ typedef struct Ui
} Ui;
Ui *
evisum_ui_add(Evas_Object *win);
evisum_ui_init(void);
void
evisum_ui_del(Ui *ui);
@ -124,4 +125,7 @@ evisum_ui_del(Ui *ui);
void
evisum_ui_shutdown(Ui *ui);
void
evisum_ui_activate(Ui *ui, Evisum_Action action);
#endif