Added new cpu module.
-Another module seperated from monitor. -TODO: Add Config -TODO: Add Graph SVN revision: 20620
This commit is contained in:
commit
7f9bfedc45
|
@ -0,0 +1,2 @@
|
|||
Originally by Matthew Mullins.
|
||||
Recoded into seperate modules by Christopher 'devilhorns' Michael <devilhorns@comcast.net>
|
|
@ -0,0 +1,28 @@
|
|||
Copyright (C) 2000 Christopher Michael and various contributors (see AUTHORS)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies of the Software and its Copyright notices. In addition publicly
|
||||
documented acknowledgment must be given that this software has been used if no
|
||||
source code of this software is made available publicly. This includes
|
||||
acknowledgments in either Copyright notices, Manuals, Publicity and Marketing
|
||||
documents or any documentation provided with any product containing this
|
||||
software. This License does not apply to any software that links to the
|
||||
libraries provided by this software (statically or dynamically), but only to
|
||||
the software provided.
|
||||
|
||||
Please see the COPYING.PLAIN for a plain-english explanation of this notice
|
||||
and it's intent.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,33 @@
|
|||
Plain English Copyright Notice
|
||||
|
||||
This file is not intended to be the actual License. The reason this file
|
||||
exists is that we here are programmers and engineers. We aren't lawyers. We
|
||||
provide licenses that we THINK say the right things, but we have our own
|
||||
intentions at heart. This is a plain-english explanation of what those
|
||||
intentions are, and if you follow them you will be within the "spirit" of
|
||||
the license.
|
||||
|
||||
The intent is for us to enjoy writing software that is useful to us (the
|
||||
AUTHORS) and allow others to use it freely and also benefit from the work we
|
||||
put into making it. We don't want to restrict others using it. They should
|
||||
not *HAVE* to make the source code of the applications they write that
|
||||
simply link to these libraries (be that statically or dynamically), or for
|
||||
them to be limited as to what license they choose to use (be it open, closed
|
||||
or anything else). But we would like to know you are using these libraries.
|
||||
We simply would like to know that it has been useful to someone. This is why
|
||||
we ask for acknowledgement of some sort.
|
||||
|
||||
You can do what you want with the source of this software - it doesn't
|
||||
matter. We still have it here for ourselves and it is open and free to use
|
||||
and download and play with. It can't be taken away. We don't really mind what
|
||||
you do with the source to your software. We would simply like to know that
|
||||
you are using it - especially if it makes it to a commerical product. If you
|
||||
simply e-mail all the AUTHORS (see COPYING and AUTHORS files) telling us, and
|
||||
then make sure you include a paragraph or page in the manual for the product
|
||||
with the copyright notice and state that you used this software, we will be
|
||||
very happy. If you want to contribute back modifications and fixes you may have
|
||||
made we will welcome those too with open arms (generally). If you want help
|
||||
with changes needed, ports needed or features to be added, arrangements can
|
||||
be easily made with some dialogue.
|
||||
|
||||
Christopher Michael <devilhorns@comcast.net>
|
|
@ -0,0 +1,11 @@
|
|||
COMPILING and INSTALLING:
|
||||
|
||||
If you got a official release tar archive do:
|
||||
./autogen.sh
|
||||
|
||||
Then to compile:
|
||||
make
|
||||
|
||||
To install:
|
||||
make install
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
EDJE_CC = @edje_cc@
|
||||
EDJE_FLAGS = -v
|
||||
|
||||
# data files for the module
|
||||
filesdir = $(datadir)
|
||||
|
||||
files_DATA = \
|
||||
module_icon.png \
|
||||
cpu.edj \
|
||||
cpu.edc \
|
||||
VeraMono.ttf
|
||||
|
||||
# the module .so file
|
||||
INCLUDES = -I. \
|
||||
-I$(top_srcdir) \
|
||||
-I$(includedir) \
|
||||
@e_cflags@
|
||||
|
||||
pkgdir = $(datadir)/$(MODULE_ARCH)
|
||||
pkg_LTLIBRARIES = module.la
|
||||
module_la_SOURCES = e_mod_main.c \
|
||||
e_mod_main.h
|
||||
|
||||
module_la_LIBADD = @e_libs@ -lm
|
||||
module_la_LDFLAGS = -module -avoid-version
|
||||
module_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||
|
||||
cpu.edj: Makefile cpu.edc
|
||||
$(EDJE_CC) $(EDJE_FLAGS) \
|
||||
cpu.edc \
|
||||
cpu.edj
|
||||
|
||||
clean-local:
|
||||
rm -rf *.edj *~
|
||||
|
Binary file not shown.
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
rm -rf autom4te.cache
|
||||
rm -f aclocal.m4 ltmain.sh
|
||||
|
||||
touch README
|
||||
|
||||
echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1
|
||||
echo "Running autoheader..." ; autoheader || exit 1
|
||||
echo "Running autoconf..." ; autoconf || exit 1
|
||||
echo "Running libtoolize..." ; (libtoolize --copy --automake || glibtoolize --automake) || exit 1
|
||||
echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
|
||||
|
||||
if [ -z "$NOCONFIGURE" ]; then
|
||||
./configure "$@"
|
||||
fi
|
|
@ -0,0 +1,200 @@
|
|||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
# get rid of that stupid cache mechanism
|
||||
rm -f config.cache
|
||||
|
||||
AC_INIT(configure.in)
|
||||
AC_CANONICAL_BUILD
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
AM_INIT_AUTOMAKE(cpu, 0.0.1)
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AC_ISC_POSIX
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_STDC
|
||||
AC_HEADER_STDC
|
||||
AC_C_CONST
|
||||
AM_ENABLE_SHARED
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
MODULE_ARCH="$host_os-$host_cpu"
|
||||
AC_SUBST(MODULE_ARCH)
|
||||
AC_DEFINE_UNQUOTED(MODULE_ARCH, "$MODULE_ARCH", "Module architecture")
|
||||
|
||||
if test "x${bindir}" = 'x${exec_prefix}/bin'; then
|
||||
if test "x${exec_prefix}" = "xNONE"; then
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
bindir="${ac_default_prefix}/bin";
|
||||
else
|
||||
bindir="${prefix}/bin";
|
||||
fi
|
||||
else
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
bindir="${ac_default_prefix}/bin";
|
||||
else
|
||||
bindir="${prefix}/bin";
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x${libdir}" = 'x${exec_prefix}/lib'; then
|
||||
if test "x${exec_prefix}" = "xNONE"; then
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
libdir="${ac_default_prefix}/lib";
|
||||
else
|
||||
libdir="${prefix}/lib";
|
||||
fi
|
||||
else
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
libdir="${ac_default_prefix}/lib";
|
||||
else
|
||||
libdir="${prefix}/lib";
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl Set PACKAGE_BIN_DIR in config.h.
|
||||
if test "x${bindir}" = 'xNONE'; then
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${ac_default_prefix}/bin", "Package installed binaries destination")
|
||||
else
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${prefix}/bin", "Package installed binaries destination")
|
||||
fi
|
||||
else
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, "${bindir}", "Package installed binaries destination")
|
||||
fi
|
||||
|
||||
dnl Set PACKAGE_LIB_DIR in config.h.
|
||||
if test "x${libdir}" = 'xNONE'; then
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${ac_default_prefix}/lib", "Package installed libraries destination")
|
||||
else
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${prefix}/lib", "Package installed libraries destination")
|
||||
fi
|
||||
else
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, "${libdir}", "Package installed libraries destination")
|
||||
fi
|
||||
|
||||
dnl Set PACKAGE_DATA_DIR in config.h.
|
||||
if test "x${prefix}" = "xNONE"; then
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${HOME}/.e/e/modules/${PACKAGE}", "Package installed data destination")
|
||||
datadir="${HOME}/.e/e/modules/${PACKAGE}"
|
||||
else
|
||||
AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${prefix}/lib/enlightenment/modules/${PACKAGE}", "Package installed data destination")
|
||||
datadir="${prefix}/lib/enlightenment/modules/${PACKAGE}"
|
||||
fi
|
||||
|
||||
AC_PREFIX_DEFAULT(${HOME}/.e/e)
|
||||
if test "x$prefix" = "xNONE"; then
|
||||
datarootdir=${ac_default_prefix}
|
||||
else
|
||||
datarootdir=${prefix}/share
|
||||
fi
|
||||
|
||||
#AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl)
|
||||
#AC_SUBST(dlopen_libs)
|
||||
|
||||
AC_ARG_WITH(ecore-config,
|
||||
[ --with-ecore-config=ECORE_CONFIG use ecore-config specified ],
|
||||
[
|
||||
ECORE_CONFIG=$withval;
|
||||
echo "using "$ECORE_CONFIG" for ecore-config";
|
||||
],[
|
||||
PROG="ecore-config";
|
||||
AC_PATH_PROG(ECORE_CONFIG, $PROG, "", $PATH)
|
||||
])
|
||||
ecore_cflags=`$ECORE_CONFIG --cflags`
|
||||
ecore_libs=`$ECORE_CONFIG --libs`
|
||||
AC_SUBST(ecore_cflags)
|
||||
AC_SUBST(ecore_libs)
|
||||
|
||||
AC_ARG_WITH(evas-config,
|
||||
[ --with-evas-config=EVAS_CONFIG use evas-config specified ],
|
||||
[
|
||||
EVAS_CONFIG=$withval;
|
||||
echo "using "$EVAS_CONFIG" for evas-config";
|
||||
],[
|
||||
PROG="evas-config";
|
||||
AC_PATH_PROG(EVAS_CONFIG, $PROG, "", $PATH)
|
||||
])
|
||||
evas_cflags=`$EVAS_CONFIG --cflags`
|
||||
evas_libs=`$EVAS_CONFIG --libs`
|
||||
AC_SUBST(evas_cflags)
|
||||
AC_SUBST(evas_libs)
|
||||
|
||||
AC_ARG_WITH(esmart-config,
|
||||
[ --with-esmart-config=ESMART_CONFIG use esmart-config specified ],
|
||||
[
|
||||
ESMART_CONFIG=$withval;
|
||||
echo "using "$ESMART_CONFIG" for esmart-config";
|
||||
],[
|
||||
PROG="esmart-config";
|
||||
AC_PATH_PROG(ESMART_CONFIG, $PROG, "", $PATH)
|
||||
])
|
||||
esmart_cflags=`$ESMART_CONFIG --cflags`
|
||||
esmart_libs=`$ESMART_CONFIG --libs`
|
||||
AC_SUBST(esmart_cflags)
|
||||
AC_SUBST(esmart_libs)
|
||||
|
||||
AC_ARG_WITH(edje-config,
|
||||
[ --with-edje-config=EDJE_CONFIG use edje-config specified ],
|
||||
[
|
||||
EDJE_CONFIG=$withval;
|
||||
echo "using "$EDJE_CONFIG" for edje-config";
|
||||
/
|
||||
],[
|
||||
PROG="edje-config";
|
||||
AC_PATH_PROG(EDJE_CONFIG, $PROG, "", $PATH)
|
||||
])
|
||||
edje_cflags=`$EDJE_CONFIG --cflags`
|
||||
edje_libs=`$EDJE_CONFIG --libs`
|
||||
AC_SUBST(edje_cflags)
|
||||
AC_SUBST(edje_libs)
|
||||
|
||||
edje_cc="`$EDJE_CONFIG --prefix`/bin/edje_cc"
|
||||
AC_ARG_WITH(edje-cc,
|
||||
[ --with-edje-cc=PATH specify a specific path to edje_cc],
|
||||
[
|
||||
v=$withval;
|
||||
edje_cc=$v
|
||||
echo " Enlightenment edje_cc explicitly set to "$edje_cc;
|
||||
],[
|
||||
edje_cc="`$EDJE_CONFIG --prefix`/bin/edje_cc"
|
||||
])
|
||||
AC_SUBST(edje_cc)
|
||||
|
||||
AC_ARG_WITH(eet-config,
|
||||
[ --with-eet-config=EET_CONFIG use eet-config specified ],
|
||||
[
|
||||
EET_CONFIG=$withval;
|
||||
echo "using "$EET_CONFIG" for eet-config";
|
||||
],[
|
||||
PROG="eet-config";
|
||||
AC_PATH_PROG(EET_CONFIG, $PROG, "", $PATH)
|
||||
])
|
||||
eet_cflags=`$EET_CONFIG --cflags`
|
||||
eet_libs=`$EET_CONFIG --libs`
|
||||
AC_SUBST(eet_cflags)
|
||||
AC_SUBST(eet_libs)
|
||||
|
||||
AC_ARG_WITH(enlightenment-config,
|
||||
[ --with-enlightenment-config=E_CONFIG use enlightenment-config specified ],
|
||||
[
|
||||
E_CONFIG=$withval;
|
||||
echo "using "$E_CONFIG" for enlightenment-config";
|
||||
],[
|
||||
PROG="enlightenment-config";
|
||||
AC_PATH_PROG(E_CONFIG, $PROG, "", $PATH)
|
||||
])
|
||||
e_cflags=`$E_CONFIG --cflags`
|
||||
e_libs=`$E_CONFIG --libs`
|
||||
e_modules=`$E_CONFIG --module-dir`
|
||||
AC_SUBST(e_cflags)
|
||||
AC_SUBST(e_libs)
|
||||
AC_SUBST(e_modules)
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
],[
|
||||
])
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
images
|
||||
{
|
||||
image: "cpu.png" COMP;
|
||||
}
|
||||
|
||||
fonts
|
||||
{
|
||||
font: "VeraMono.ttf" "VeraMono";
|
||||
}
|
||||
|
||||
collections
|
||||
{
|
||||
group
|
||||
{
|
||||
name: "modules/cpu/main";
|
||||
script {
|
||||
public message(Msg_Type:type, id, ...) {
|
||||
if (type == MSG_STRING_SET) {
|
||||
new in_str[100];
|
||||
getsarg(2, in_str, sizeof(in_str));
|
||||
set_text(PART:"in-text", in_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parts{
|
||||
part {
|
||||
name: "cpu";
|
||||
mouse_events: 0;
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
color: 255 255 255 255;
|
||||
aspect: 1.0 1.0;
|
||||
rel1 {
|
||||
offset: 0 0;
|
||||
}
|
||||
rel2 {
|
||||
offset: -1 -1;
|
||||
}
|
||||
image {
|
||||
normal: "cpu.png";
|
||||
}
|
||||
fill {
|
||||
smooth: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
part
|
||||
{
|
||||
name: "in-text";
|
||||
type: TEXT;
|
||||
effect: SOFT_SHADOW;
|
||||
mouse_events: 0;
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
align: 1.0 0.0;
|
||||
rel1 {
|
||||
relative: 1.0 0.0;
|
||||
to_x: "cpu";
|
||||
offset: -2 1;
|
||||
}
|
||||
rel2 {
|
||||
relative: 1.0 0.0;
|
||||
}
|
||||
color: 255 255 255 255;
|
||||
color3: 0 0 0 100;
|
||||
text {
|
||||
text: "%";
|
||||
font: "VeraMono";
|
||||
size: 10;
|
||||
min: 1 1;
|
||||
align: 1.0 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//close group net
|
||||
}
|
||||
|
|
@ -0,0 +1,500 @@
|
|||
#include <e.h>
|
||||
#include "e_mod_main.h"
|
||||
//#include "e_mod_config.h"
|
||||
#include "config.h"
|
||||
|
||||
static Cpu *_cpu_init (E_Module *m);
|
||||
static void _cpu_shutdown (Cpu *n);
|
||||
static void _cpu_config_menu_new (Cpu *n);
|
||||
static int _cpu_face_init (Cpu_Face *cf);
|
||||
static void _cpu_face_menu_new (Cpu_Face *cf);
|
||||
static void _cpu_face_enable (Cpu_Face *cf);
|
||||
static void _cpu_face_disable (Cpu_Face *cf);
|
||||
static void _cpu_face_free (Cpu_Face *cf);
|
||||
static void _cpu_face_cb_gmc_change (void *data, E_Gadman_Client *gmc, E_Gadman_Change change);
|
||||
static void _cpu_face_cb_mouse_down (void *data, Evas *evas, Evas_Object *obj, void *event_info);
|
||||
static void _cpu_face_cb_menu_edit (void *data, E_Menu *mn, E_Menu_Item *mi);
|
||||
static void _cpu_face_cb_menu_configure (void *data, E_Menu *mn, E_Menu_Item *mi);
|
||||
static int _cpu_face_update_values (void *data);
|
||||
static int _cpu_face_get_cpu_count (Cpu_Face *cf);
|
||||
static int _cpu_face_get_load (Cpu_Face *cf);
|
||||
|
||||
static int cpu_count;
|
||||
|
||||
EAPI E_Module_Api e_modapi =
|
||||
{
|
||||
E_MODULE_API_VERSION,
|
||||
"Cpu"
|
||||
};
|
||||
|
||||
EAPI void *
|
||||
e_modapi_init(E_Module *m)
|
||||
{
|
||||
Cpu *c;
|
||||
|
||||
c = _cpu_init(m);
|
||||
if (!c)
|
||||
return NULL;
|
||||
|
||||
m->config_menu = c->config_menu;
|
||||
return c;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_modapi_shutdown(E_Module *m)
|
||||
{
|
||||
Cpu *c;
|
||||
|
||||
c = m->data;
|
||||
if (!c)
|
||||
return 0;
|
||||
|
||||
if (m->config_menu)
|
||||
{
|
||||
e_menu_deactivate(m->config_menu);
|
||||
e_object_del(E_OBJECT(m->config_menu));
|
||||
m->config_menu = NULL;
|
||||
}
|
||||
if (c->cfd)
|
||||
{
|
||||
e_object_del(E_OBJECT(c->cfd));
|
||||
c->cfd = NULL;
|
||||
}
|
||||
_cpu_shutdown(c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_modapi_save(E_Module *m)
|
||||
{
|
||||
Cpu *c;
|
||||
|
||||
c = m->data;
|
||||
if (!c)
|
||||
return 0;
|
||||
e_config_domain_save("module.cpu", c->conf_edd, c->conf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_modapi_info(E_Module *m)
|
||||
{
|
||||
m->icon_file = strdup(PACKAGE_DATA_DIR"/module_icon.png");
|
||||
return 1;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_modapi_about(E_Module *m)
|
||||
{
|
||||
e_module_dialog_show(_("Enlightenment Cpu Monitor Module"),
|
||||
_("This module is used to monitor a cpu."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_modapi_config(E_Module *m)
|
||||
{
|
||||
Cpu *c;
|
||||
E_Container *con;
|
||||
|
||||
c = m->data;
|
||||
if (!c)
|
||||
return 0;
|
||||
if (!c->face)
|
||||
return 0;
|
||||
|
||||
con = e_container_current_get(e_manager_current_get());
|
||||
|
||||
/* if (c->face->con == con)
|
||||
_configure_cpu_module(con, c);
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Cpu *
|
||||
_cpu_init(E_Module *m)
|
||||
{
|
||||
Cpu *c;
|
||||
E_Menu_Item *mi;
|
||||
Evas_List *mans, *l, *l2;
|
||||
|
||||
c = E_NEW(Cpu, 1);
|
||||
if (!c)
|
||||
return NULL;
|
||||
|
||||
c->conf_edd = E_CONFIG_DD_NEW("Cpu_Config", Config);
|
||||
#undef T
|
||||
#undef D
|
||||
#define T Config
|
||||
#define D c->conf_edd
|
||||
E_CONFIG_VAL(D, T, check_interval, INT);
|
||||
|
||||
c->conf = e_config_domain_load("module.cpu", c->conf_edd);
|
||||
if (!c->conf)
|
||||
{
|
||||
c->conf = E_NEW(Config, 1);
|
||||
c->conf->check_interval = 1;
|
||||
}
|
||||
E_CONFIG_LIMIT(c->conf->check_interval, 0, 60);
|
||||
|
||||
_cpu_config_menu_new(c);
|
||||
|
||||
mans = e_manager_list();
|
||||
for (l = mans; l; l = l->next)
|
||||
{
|
||||
E_Manager *man;
|
||||
|
||||
man = l->data;
|
||||
for (l2 = man->containers; l2; l2 = l2->next)
|
||||
{
|
||||
E_Container *con;
|
||||
Cpu_Face *cf;
|
||||
|
||||
con = l2->data;
|
||||
cf = E_NEW(Cpu_Face, 1);
|
||||
if (cf)
|
||||
{
|
||||
cf->conf_face_edd = E_CONFIG_DD_NEW("Cpu_Face_Config", Config_Face);
|
||||
#undef T
|
||||
#undef D
|
||||
#define T Config_Face
|
||||
#define D cf->conf_face_edd
|
||||
E_CONFIG_VAL(D, T, enabled, UCHAR);
|
||||
|
||||
c->face = cf;
|
||||
cf->cpu = c;
|
||||
cf->con = con;
|
||||
cf->evas = con->bg_evas;
|
||||
|
||||
cf->conf = E_NEW(Config_Face, 1);
|
||||
cf->conf->enabled = 1;
|
||||
|
||||
if (!_cpu_face_init(cf))
|
||||
return NULL;
|
||||
|
||||
_cpu_face_menu_new(cf);
|
||||
|
||||
mi = e_menu_item_new(c->config_menu);
|
||||
e_menu_item_label_set(mi, _("Configuration"));
|
||||
//e_menu_item_callback_set(mi, _cpu_face_cb_menu_configure, cf);
|
||||
|
||||
mi = e_menu_item_new(c->config_menu);
|
||||
e_menu_item_label_set(mi, con->name);
|
||||
e_menu_item_submenu_set(mi, cf->menu);
|
||||
|
||||
if (!cf->conf->enabled)
|
||||
_cpu_face_disable(cf);
|
||||
else
|
||||
_cpu_face_enable(cf);
|
||||
}
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_shutdown(Cpu *c)
|
||||
{
|
||||
_cpu_face_free(c->face);
|
||||
|
||||
E_FREE(c->conf);
|
||||
E_CONFIG_DD_FREE(c->conf_edd);
|
||||
E_FREE(c);
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_config_menu_new(Cpu *c)
|
||||
{
|
||||
E_Menu *mn;
|
||||
|
||||
mn = e_menu_new();
|
||||
c->config_menu = mn;
|
||||
}
|
||||
|
||||
static int
|
||||
_cpu_face_init(Cpu_Face *cf)
|
||||
{
|
||||
Evas_Object *o;
|
||||
char buf[4096];
|
||||
|
||||
evas_event_freeze(cf->evas);
|
||||
|
||||
o = edje_object_add(cf->evas);
|
||||
cf->cpu_obj = o;
|
||||
|
||||
if (!e_theme_edje_object_set(o, "base/theme/modules/cpu",
|
||||
"modules/cpu/main"))
|
||||
{
|
||||
snprintf(buf, sizeof(buf), PACKAGE_DATA_DIR"/cpu.edj");
|
||||
edje_object_file_set(o, buf, "modules/cpu/main");
|
||||
}
|
||||
|
||||
evas_object_show(o);
|
||||
|
||||
/*
|
||||
o = evas_object_rectangle_add(cf->evas);
|
||||
cf->chart_obj = o;
|
||||
evas_object_layer_set(o, 2);
|
||||
evas_object_repeat_events_set(o, 0);
|
||||
evas_object_color_set(o, 0, 0, 0, 255);
|
||||
evas_object_show(o);
|
||||
*/
|
||||
|
||||
o = evas_object_rectangle_add(cf->evas);
|
||||
cf->event_obj = o;
|
||||
evas_object_layer_set(o, 2);
|
||||
evas_object_repeat_events_set(o, 1);
|
||||
evas_object_color_set(o, 0, 0, 0, 0);
|
||||
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
|
||||
_cpu_face_cb_mouse_down, cf);
|
||||
evas_object_show(o);
|
||||
|
||||
cf->gmc = e_gadman_client_new(cf->con->gadman);
|
||||
e_gadman_client_domain_set(cf->gmc, "module.cpu", cpu_count++);
|
||||
e_gadman_client_policy_set(cf->gmc,
|
||||
E_GADMAN_POLICY_ANYWHERE |
|
||||
E_GADMAN_POLICY_HMOVE |
|
||||
E_GADMAN_POLICY_HSIZE |
|
||||
E_GADMAN_POLICY_VMOVE |
|
||||
E_GADMAN_POLICY_VSIZE);
|
||||
e_gadman_client_min_size_set(cf->gmc, 4, 4);
|
||||
e_gadman_client_max_size_set(cf->gmc, 128, 128);
|
||||
e_gadman_client_auto_size_set(cf->gmc, 40, 40);
|
||||
e_gadman_client_align_set(cf->gmc, 1.0, 1.0);
|
||||
e_gadman_client_aspect_set(cf->gmc, 1.0, 1.0);
|
||||
e_gadman_client_resize(cf->gmc, 40, 40);
|
||||
e_gadman_client_change_func_set(cf->gmc, _cpu_face_cb_gmc_change, cf);
|
||||
e_gadman_client_load(cf->gmc);
|
||||
evas_event_thaw(cf->evas);
|
||||
|
||||
cf->monitor = ecore_timer_add((double)cf->cpu->conf->check_interval, _cpu_face_update_values, cf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_menu_new(Cpu_Face *cf)
|
||||
{
|
||||
E_Menu *mn;
|
||||
E_Menu_Item *mi;
|
||||
|
||||
mn = e_menu_new();
|
||||
cf->menu = mn;
|
||||
|
||||
mi = e_menu_item_new(mn);
|
||||
e_menu_item_label_set(mi, _("Configuration"));
|
||||
//e_menu_item_callback_set(mi, _cpu_face_cb_menu_configure, cf);
|
||||
|
||||
mi = e_menu_item_new(mn);
|
||||
e_menu_item_label_set(mi, _("Edit Mode"));
|
||||
e_menu_item_callback_set(mi, _cpu_face_cb_menu_edit, cf);
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_enable(Cpu_Face *cf)
|
||||
{
|
||||
cf->conf->enabled = 1;
|
||||
e_config_save_queue();
|
||||
evas_object_show(cf->cpu_obj);
|
||||
/* evas_object_show(cf->chart_obj); */
|
||||
evas_object_show(cf->event_obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_disable(Cpu_Face *cf)
|
||||
{
|
||||
cf->conf->enabled = 0;
|
||||
e_config_save_queue();
|
||||
evas_object_hide(cf->event_obj);
|
||||
/* evas_object_hide(cf->chart_obj); */
|
||||
evas_object_hide(cf->cpu_obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_free(Cpu_Face *cf)
|
||||
{
|
||||
if (cf->monitor)
|
||||
ecore_timer_del(cf->monitor);
|
||||
if (cf->menu)
|
||||
e_object_del(E_OBJECT(cf->menu));
|
||||
if (cf->event_obj)
|
||||
evas_object_del(cf->event_obj);
|
||||
if (cf->cpu_obj)
|
||||
evas_object_del(cf->cpu_obj);
|
||||
|
||||
/*
|
||||
if (cf->chart_obj)
|
||||
evas_object_del(cf->chart_obj);
|
||||
*/
|
||||
|
||||
if (cf->gmc)
|
||||
{
|
||||
e_gadman_client_save(cf->gmc);
|
||||
e_object_del(E_OBJECT(cf->gmc));
|
||||
}
|
||||
|
||||
E_FREE(cf->conf);
|
||||
E_FREE(cf);
|
||||
cpu_count--;
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_cb_gmc_change(void *data, E_Gadman_Client *gmc, E_Gadman_Change change)
|
||||
{
|
||||
Cpu_Face *cf;
|
||||
Evas_Coord x, y, w, h;
|
||||
|
||||
cf = data;
|
||||
switch (change)
|
||||
{
|
||||
case E_GADMAN_CHANGE_MOVE_RESIZE:
|
||||
e_gadman_client_geometry_get(cf->gmc, &x, &y, &w, &h);
|
||||
evas_object_move(cf->cpu_obj, x, y);
|
||||
/* evas_object_move(cf->chart_obj, x, y); */
|
||||
evas_object_move(cf->event_obj, x, y);
|
||||
evas_object_resize(cf->cpu_obj, w, h);
|
||||
/* evas_object_resize(cf->chart_obj, w, h); */
|
||||
evas_object_resize(cf->event_obj, w, h);
|
||||
break;
|
||||
case E_GADMAN_CHANGE_RAISE:
|
||||
evas_object_raise(cf->cpu_obj);
|
||||
/* evas_object_raise(cf->chart_obj); */
|
||||
evas_object_raise(cf->event_obj);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_cb_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
Cpu_Face *cf;
|
||||
Evas_Event_Mouse_Down *ev;
|
||||
|
||||
ev = event_info;
|
||||
cf = data;
|
||||
if (ev->button == 3)
|
||||
{
|
||||
e_menu_activate_mouse(cf->menu, e_zone_current_get(cf->con),
|
||||
ev->output.x, ev->output.y, 1, 1,
|
||||
E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
|
||||
e_util_container_fake_mouse_up_all_later(cf->con);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_cb_menu_edit(void *data, E_Menu *mn, E_Menu_Item *mi)
|
||||
{
|
||||
Cpu_Face *cf;
|
||||
|
||||
cf = data;
|
||||
e_gadman_mode_set(cf->gmc->gadman, E_GADMAN_MODE_EDIT);
|
||||
}
|
||||
|
||||
static void
|
||||
_cpu_face_cb_menu_configure(void *data, E_Menu *mn, E_Menu_Item *mi)
|
||||
{
|
||||
Cpu_Face *cf;
|
||||
|
||||
cf = data;
|
||||
//_configure_cpu_module(cf->con, cf->cpu);
|
||||
}
|
||||
|
||||
static int
|
||||
_cpu_face_update_values(void *data)
|
||||
{
|
||||
Cpu_Face *cf;
|
||||
int val;
|
||||
Edje_Message_String_Set *msg;
|
||||
char str[100];
|
||||
|
||||
cf = data;
|
||||
val = _cpu_face_get_load(cf);
|
||||
if (val == -1)
|
||||
return 1;
|
||||
|
||||
snprintf(str, sizeof(str), "%d %%", val);
|
||||
msg = malloc(sizeof(Edje_Message_String_Set) - sizeof(char *) + (1 + sizeof(char *)));
|
||||
msg->count = 1;
|
||||
msg->str[0] = str;
|
||||
edje_object_message_send(cf->cpu_obj, EDJE_MESSAGE_STRING_SET, 1, msg);
|
||||
free(msg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
_cpu_face_get_cpu_count(Cpu_Face *cf)
|
||||
{
|
||||
char tmp[4];
|
||||
FILE *f;
|
||||
int cpu = -1;
|
||||
|
||||
if (!(f = fopen("/proc/stat", "r")))
|
||||
return -1;
|
||||
|
||||
while (fscanf(f, "cp%s %*u %*u %*u %*u %*u %*u %*u %*u\n", (char *)&tmp) == 1)
|
||||
cpu++;
|
||||
|
||||
fclose(f);
|
||||
return cpu;
|
||||
}
|
||||
|
||||
static int
|
||||
_cpu_face_get_load(Cpu_Face *cf)
|
||||
{
|
||||
static unsigned long old_u, old_n, old_s, old_i, old_wa, old_hi, old_si;
|
||||
unsigned long new_u, new_n, new_s, new_i, new_wa = 0, new_hi = 0, new_si = 0, ticks_past;
|
||||
int tmp_u, tmp_n, tmp_s, tmp_i;
|
||||
char dummy[16];
|
||||
FILE *stat;
|
||||
int load, cpu_count;
|
||||
|
||||
cpu_count = _cpu_face_get_cpu_count(cf);
|
||||
if (cpu_count == -1)
|
||||
return -1;
|
||||
|
||||
if (!(stat = fopen("/proc/stat", "r")))
|
||||
return -1;
|
||||
|
||||
if (fscanf(stat, "%s %lu %lu %lu %lu %lu %lu %lu", dummy,
|
||||
&new_u, &new_n, &new_s, &new_i, &new_wa, &new_hi, &new_si) < 5)
|
||||
{
|
||||
fclose(stat);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(stat);
|
||||
|
||||
ticks_past = ((new_u + new_n + new_s + new_i + new_wa + new_hi + new_si) -
|
||||
(old_u + old_n + old_s + old_i + old_wa + old_hi + old_si));
|
||||
|
||||
if (ticks_past)
|
||||
{
|
||||
tmp_u = ((new_u - old_u));
|
||||
tmp_n = ((new_n - old_n));
|
||||
tmp_s = ((new_s - old_s));
|
||||
tmp_i = ((new_i - old_i));
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_u = 0;
|
||||
tmp_n = 0;
|
||||
tmp_s = 0;
|
||||
tmp_i = 0;
|
||||
}
|
||||
|
||||
/* Update the values */
|
||||
load = (tmp_u + tmp_n + tmp_s) / cpu_count;
|
||||
|
||||
old_u = new_u;
|
||||
old_n = new_n;
|
||||
old_s = new_s;
|
||||
old_i = new_i;
|
||||
old_wa = new_wa;
|
||||
old_hi = new_hi;
|
||||
old_si = new_si;
|
||||
|
||||
if (load >= 100)
|
||||
return 100;
|
||||
return load;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef E_MOD_MAIN_H
|
||||
#define E_MOD_MAIN_H
|
||||
|
||||
typedef struct _Config Config;
|
||||
typedef struct _Config_Face Config_Face;
|
||||
typedef struct _Cpu Cpu;
|
||||
typedef struct _Cpu_Face Cpu_Face;
|
||||
|
||||
struct _Config
|
||||
{
|
||||
char *device;
|
||||
int check_interval;
|
||||
};
|
||||
|
||||
struct _Config_Face
|
||||
{
|
||||
unsigned char enabled;
|
||||
};
|
||||
|
||||
struct _Cpu
|
||||
{
|
||||
E_Menu *config_menu;
|
||||
Cpu_Face *face;
|
||||
Config *conf;
|
||||
|
||||
E_Config_DD *conf_edd;
|
||||
E_Config_Dialog *cfd;
|
||||
};
|
||||
|
||||
struct _Cpu_Face
|
||||
{
|
||||
Evas *evas;
|
||||
E_Container *con;
|
||||
E_Menu *menu;
|
||||
Cpu *cpu;
|
||||
|
||||
Config_Face *conf;
|
||||
E_Config_DD *conf_face_edd;
|
||||
|
||||
Evas_Object *cpu_obj;
|
||||
Evas_Object *event_obj;
|
||||
|
||||
Ecore_Timer *monitor;
|
||||
|
||||
E_Gadman_Client *gmc;
|
||||
};
|
||||
|
||||
EAPI extern E_Module_Api e_modapi;
|
||||
|
||||
EAPI void *e_modapi_init (E_Module *m);
|
||||
EAPI int e_modapi_shutdown (E_Module *m);
|
||||
EAPI int e_modapi_save (E_Module *m);
|
||||
EAPI int e_modapi_info (E_Module *m);
|
||||
EAPI int e_modapi_about (E_Module *m);
|
||||
EAPI int e_modapi_config (E_Module *m);
|
||||
|
||||
#endif
|
Binary file not shown.
Loading…
Reference in New Issue