Added clock module - read notes at top of e_mod_main.c to try it out

SVN revision: 12271
This commit is contained in:
handyande 2004-11-26 10:53:38 +00:00 committed by handyande
parent a031379afe
commit 8d87a9f379
4 changed files with 406 additions and 0 deletions

View File

@ -0,0 +1,26 @@
MAINTAINERCLEANFILES = Makefile.in
MODULE = clock
# data files for the module
filesdir = $(libdir)/enlightenment/modules/$(MODULE)
files_DATA = \
module_icon.png
EXTRA_DIST = $(files_DATA)
# the module .so file
INCLUDES = -I. \
-I$(top_srcdir) \
-I$(includedir) \
-I$(top_srcdir)$(MODULE) \
-I$(top_srcdir)/src/bin \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/modules \
@e_cflags@
pkgdir = $(libdir)/enlightenment/modules/$(MODULE)
pkg_LTLIBRARIES = module.la
module_la_SOURCES = e_mod_main.c \
e_mod_main.h
module_la_LIBADD = @e_libs@ @dlopen_libs@
module_la_LDFLAGS = -module -avoid-version
module_la_DEPENDENCIES = $(top_builddir)/config.h

View File

@ -0,0 +1,340 @@
#include "e.h"
#include "e_mod_main.h"
/* NOTE:
*
* currently the edje data to display the clock is not in CVS, to use the clock
* you must:
* a) set up expedition to get mouse events - in parts/bg.edc set part "bg"'s
* mouse_events to 1
* b) build expedition.eet with this change
* c) copy your "expedition.eet" to
* $PREFIX/lib/enlightenment/modules/clock/default.eet
* d) in src/bin/e_module.c uncomment the lines:
* m = e_module_new("clock");
* e_module_enable(m);
*/
/* TODO List:
*
* Add checking for screen edges - do not want to drag off screen
*
*/
/* module private routines */
static Clock *_clock_init(E_Module *m);
static void _clock_shutdown(Clock *e);
static E_Menu *_clock_config_menu_new(Clock *e);
static void _clock_config_menu_del(Clock *e, E_Menu *m);
static void _clock_face_init(Clock_Face *ef);
static void _clock_face_free(Clock_Face *ef);
static void _clock_face_reconfigure(Clock_Face *ef);
static void _clock_cb_face_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _clock_cb_face_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _clock_cb_face_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
char *_clock_module_dir;
/* public module routines. all modules must have these */
void *
init(E_Module *m)
{
Clock *e;
/* check module api version */
if (m->api->version < E_MODULE_API_VERSION)
{
e_error_dialog_show("Module API Error",
"Error initializing Module: IBar\n"
"It requires a minimum module API version of: %i.\n"
"The module API advertized by Enlightenment is: %i.\n"
"Aborting module.",
E_MODULE_API_VERSION,
m->api->version);
return NULL;
}
/* actually init clock */
e = _clock_init(m);
m->config_menu = _clock_config_menu_new(e);
return e;
}
int
shutdown(E_Module *m)
{
Clock *e;
e = m->data;
if (e)
{
if (m->config_menu)
{
_clock_config_menu_del(e, m->config_menu);
m->config_menu = NULL;
}
_clock_shutdown(e);
}
return 1;
}
int
save(E_Module *m)
{
Clock *e;
e = m->data;
ecore_config_int_set("e.module.clock.x", e->face->fx);
ecore_config_int_set("e.module.clock.y", e->face->fy);
ecore_config_int_set("e.module.clock.width", e->face->fw);
return 1;
}
int
info(E_Module *m)
{
char buf[4096];
m->label = strdup("Clock");
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;
}
int
about(E_Module *m)
{
e_error_dialog_show("Enlightenment Clock Module",
"A simple module to give E17 a clock.");
return 1;
}
/* module private routines */
static
Clock *_clock_init(E_Module *m)
{
Clock *e;
char buf[4096];
Evas_List *managers, *l, *l2;
e = calloc(1, sizeof(Clock));
if (!e) return NULL;
ecore_config_int_create
("e.module.clock.x", 50, 0, "",
"Clock module: X start position");
ecore_config_int_create
("e.module.clock.y", 50, 0, "",
"Clock module: Y start position");
ecore_config_int_create
("e.module.clock.width", 64, 0, "",
"Clock module: Start width");
ecore_config_load();
e->conf.width = ecore_config_int_get("e.module.clock.width");
e->conf.x = ecore_config_int_get("e.module.clock.x");
e->conf.y = ecore_config_int_get("e.module.clock.y");
_clock_module_dir = e_module_dir_get(m);
managers = e_manager_list();
for (l = managers; l; l = l->next)
{
E_Manager *man;
man = l->data;
for (l2 = man->containers; l2; l2 = l2->next)
{
E_Container *con;
Clock_Face *ef;
con = l2->data;
ef = calloc(1, sizeof(Clock_Face));
if (ef)
{
ef->clock = e;
ef->con = con;
ef->evas = con->bg_evas;
_clock_face_init(ef);
e->face = ef;
}
}
}
return e;
}
static void
_clock_shutdown(Clock *e)
{
_clock_face_free(e->face);
free(e);
}
static E_Menu *
_clock_config_menu_new(Clock *e)
{
E_Menu *mn;
E_Menu_Item *mi;
/* FIXME: hook callbacks to each menu item */
mn = e_menu_new();
mi = e_menu_item_new(mn);
e_menu_item_label_set(mi, "Set Time");
// e_menu_item_callback_set(mi, _clock_cb_time_set, e);
/*
mi = e_menu_item_new(mn);
e_menu_item_label_set(mi, "More Options...");
*/
e->config_menu = mn;
return mn;
}
static void
_clock_config_menu_del(Clock *e, E_Menu *m)
{
e_object_del(E_OBJECT(m));
}
static void
_clock_face_init(Clock_Face *ef)
{
Evas_List *l;
Evas_Coord ww, hh, bw, bh;
Evas_Object *o;
char buf[4096];
ef->fx = ef->clock->conf.x;
ef->fy = ef->clock->conf.y;
evas_event_freeze(ef->evas);
o = edje_object_add(ef->evas);
ef->clock_object = o;
snprintf(buf, sizeof(buf), "%s/default.eet", _clock_module_dir);
edje_object_file_set(o,
/* FIXME: "default.eet" needs to come from conf */
/*e_path_find(path_themes, "default.eet"),
"modules/ibar/main");*/
/* FIXME - hard coded, bad */
buf, "Main");
evas_object_show(o);
o = evas_object_rectangle_add(ef->evas);
ef->event_object = 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, _clock_cb_face_down, ef);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _clock_cb_face_up, ef);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _clock_cb_face_move, ef);
evas_object_show(o);
edje_object_size_min_calc(ef->clock_object, &bw, &bh);
ef->minsize = bh;
ef->minsize = bw;
_clock_face_reconfigure(ef);
evas_event_thaw(ef->evas);
}
static void
_clock_face_free(Clock_Face *ef)
{
evas_object_del(ef->clock_object);
evas_object_del(ef->event_object);
free(ef);
}
static void
_clock_face_reconfigure(Clock_Face *ef)
{
Evas_Coord minw, minh, maxw, maxh;
edje_object_size_min_calc(ef->clock_object, &minw, &maxh);
edje_object_size_max_get(ef->clock_object, &maxw, &minh);
ef->fx = ef->clock->conf.x;
ef->fy = ef->clock->conf.y;
ef->fw = ef->clock->conf.width;
ef->minsize = minw;
ef->maxsize = maxw;
evas_object_move(ef->clock_object, ef->clock->conf.x, ef->clock->conf.y);
evas_object_resize(ef->clock_object, ef->clock->conf.width, ef->clock->conf.width);
evas_object_move(ef->event_object, ef->clock->conf.x, ef->clock->conf.y);
evas_object_resize(ef->event_object, ef->clock->conf.width, ef->clock->conf.width);
}
static void
_clock_cb_face_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Down *ev;
Clock_Face *ef;
ev = event_info;
ef = data;
if (ev->button == 3)
{
e_menu_activate_mouse(ef->clock->config_menu, ef->con,
ev->output.x, ev->output.y, 1, 1,
E_MENU_POP_DIRECTION_DOWN);
e_util_container_fake_mouse_up_all_later(ef->con);
}
else if (ev->button == 2)
{
ef->resize = 1;
}
else if (ev->button == 1)
{
ef->move = 1;
}
evas_pointer_canvas_xy_get(e, &ef->xx, &ef->yy);
}
static void
_clock_cb_face_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Up *ev;
Clock_Face *ef;
ev = event_info;
ef = data;
ef->move = 0;
ef->resize = 0;
}
static void
_clock_cb_face_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Move *ev;
Clock_Face *ef;
Evas_Coord x, y, w, h, cx, cy;
evas_pointer_canvas_xy_get(e, &cx, &cy);
ev = event_info;
ef = data;
if (ef->move)
{
ef->fx += cx - ef->xx;
ef->fy += cy - ef->yy;
evas_object_move(ef->clock_object, ef->fx, ef->fy);
evas_object_move(ef->event_object, ef->fx, ef->fy);
}
else if (ef->resize)
{
Evas_Coord d;
d = cx - ef->xx;
ef->fw += d;
if (ef->fw < ef->minsize) ef->fw = ef->minsize;
if (ef->fw > ef->maxsize) ef->fw = ef->maxsize;
evas_object_resize(ef->clock_object, ef->fw, ef->fw);
evas_object_resize(ef->event_object, ef->fw, ef->fw);
}
ef->xx = ev->cur.canvas.x;
ef->yy = ev->cur.canvas.y;
}

View File

@ -0,0 +1,40 @@
#ifndef E_MOD_MAIN_H
#define E_MOD_MAIN_H
typedef struct _Clock Clock;
typedef struct _Clock_Face Clock_Face;
struct _Clock
{
E_Menu *config_menu;
Clock_Face *face;
struct {
int width;
int x, y;
} conf;
};
struct _Clock_Face
{
Clock *clock;
E_Container *con;
Evas *evas;
Evas_Object *clock_object;
Evas_Object *event_object;
Evas_Coord minsize, maxsize;
unsigned char move : 1;
unsigned char resize : 1;
Evas_Coord xx, yy;
Evas_Coord fx, fy, fw;
};
EAPI void *init (E_Module *m);
EAPI int shutdown (E_Module *m);
EAPI int save (E_Module *m);
EAPI int info (E_Module *m);
EAPI int about (E_Module *m);
#endif

Binary file not shown.