This way we can get rid of rb_global_variable()'s.
Also put headers in their own subdirectory.
/*
- * $Id: rb_ecore.h 45 2004-07-26 11:00:14Z tilman $
+ * $Id: rb_ecore.h 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#define GET_OBJ(obj, type, o) \
type *(o) = NULL; \
\
- Data_Get_Struct ((obj), type, (o)); \
-\
- if (!*(o)) { \
- rb_raise (rb_eException, \
- "%s destroyed already", \
- rb_obj_classname ((obj))); \
- return Qnil; \
- }
+ Data_Get_Struct ((obj), type, (o));
#define CHECK_BOOL(val) \
if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
return Qnil; \
}
+#define CHECK_CLASS(val, klass) \
+ if (!rb_obj_is_kind_of ((val), (klass))) { \
+ rb_raise (rb_eTypeError, \
+ "wrong argument type %s (expected %s)", \
+ rb_obj_classname ((val)), \
+ rb_class2name ((klass))); \
+ return Qnil; \
+ }
+
#define INSPECT(obj, type) \
char buf[128]; \
\
\
snprintf (buf, sizeof (buf), \
"#<%s:%p ptr=%p>", rb_obj_classname ((obj)), \
- (void *) obj, *o); \
+ (void *) obj, o->real); \
\
return rb_str_new2 (buf);
/*
- * $Id: rb_idler.c 40 2004-07-25 13:14:34Z tilman $
+ * $Id: rb_idler.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
*/
#include <ruby.h>
+#include <stdbool.h>
#include <Ecore.h>
-#include <stdbool.h>
#include "rb_ecore.h"
typedef struct {
- Ecore_Idler *idler;
- void *cb;
+ Ecore_Idler *real;
+ VALUE callback;
bool deleted;
-} RbEcoreIdler;
+} RbIdler;
static int on_idler (void *data)
{
VALUE r;
- RbEcoreIdler *idler = data;
+ RbIdler *idler = data;
- r = rb_funcall ((VALUE) idler->cb, rb_intern ("call"), 0);
+ r = rb_funcall (idler->callback, rb_intern ("call"), 0);
/* if the callback returns false, we return 0 and Ecore
* will remove the idler
return (r != Qfalse);
}
-static void c_free (RbEcoreIdler *idler)
+static void c_mark (RbIdler *idler)
+{
+ rb_gc_mark (idler->callback);
+}
+
+static void c_free (RbIdler *idler)
{
- if (idler->idler && !idler->deleted)
- ecore_idler_del (idler->idler);
+ if (idler->real && !idler->deleted)
+ ecore_idler_del (idler->real);
ecore_shutdown ();
static VALUE c_new (VALUE klass)
{
VALUE self;
- RbEcoreIdler *idler;
+ RbIdler *idler;
if (!rb_block_given_p ())
return Qnil;
- self = Data_Make_Struct (klass, RbEcoreIdler, NULL, c_free, idler);
+ self = Data_Make_Struct (klass, RbIdler, c_mark, c_free, idler);
ecore_init ();
- idler->cb = (void *) rb_block_proc ();
- idler->idler = ecore_idler_add (on_idler, idler);
+ idler->callback = rb_block_proc ();
+ idler->real = ecore_idler_add (on_idler, idler);
rb_obj_call_init (self, 0, NULL);
static VALUE c_delete (VALUE self)
{
- RbEcoreIdler *idler = NULL;
-
- Data_Get_Struct (self, RbEcoreIdler, idler);
+ GET_OBJ (self, RbIdler, idler);
- if (idler->idler && !idler->deleted) {
- ecore_idler_del (idler->idler);
- idler->idler = NULL;
+ if (idler->real && !idler->deleted) {
+ ecore_idler_del (idler->real);
+ idler->real = NULL;
idler->deleted = true;
} else
rb_raise (rb_eException, "Idler already deleted!");
/*
- * $Id: rb_timer.c 40 2004-07-25 13:14:34Z tilman $
+ * $Id: rb_timer.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
*/
#include <ruby.h>
+#include <stdbool.h>
#include <Ecore.h>
-#include <stdbool.h>
#include "rb_ecore.h"
typedef struct {
- Ecore_Timer *timer;
- void *cb;
+ Ecore_Timer *real;
+ VALUE callback;
bool deleted;
-} RbEcoreTimer;
+} RbTimer;
static int on_timer (void *data)
{
VALUE r;
- RbEcoreTimer *timer = data;
+ RbTimer *timer = data;
- r = rb_funcall ((VALUE) timer->cb, rb_intern ("call"), 0);
+ r = rb_funcall (timer->callback, rb_intern ("call"), 0);
/* if the callback returns false, we return 0 and Ecore
* will remove the timer
return (r != Qfalse);
}
-static void c_free (RbEcoreTimer *timer)
+static void c_mark (RbTimer *timer)
+{
+ rb_gc_mark (timer->callback);
+}
+
+static void c_free (RbTimer *timer)
{
- if (timer->timer && !timer->deleted)
- ecore_timer_del (timer->timer);
+ if (timer->real && !timer->deleted)
+ ecore_timer_del (timer->real);
ecore_shutdown ();
static VALUE c_new (VALUE klass, VALUE interval)
{
VALUE self;
- RbEcoreTimer *timer;
+ RbTimer *timer = NULL;
if (!rb_block_given_p ())
return Qnil;
- self = Data_Make_Struct (klass, RbEcoreTimer, NULL, c_free, timer);
+ self = Data_Make_Struct (klass, RbTimer, c_mark, c_free, timer);
ecore_init ();
- timer->cb = (void *) rb_block_proc ();
- timer->timer = ecore_timer_add (NUM2DBL (interval),
- on_timer, timer);
+ timer->callback = rb_block_proc ();
+ timer->real = ecore_timer_add (NUM2DBL (interval),
+ on_timer, timer);
rb_obj_call_init (self, 0, NULL);
static VALUE c_delete (VALUE self)
{
- RbEcoreTimer *timer = NULL;
-
- Data_Get_Struct (self, RbEcoreTimer, timer);
+ GET_OBJ (self, RbTimer, timer);
- if (timer->timer && !timer->deleted) {
- ecore_timer_del (timer->timer);
- timer->timer = NULL;
+ if (timer->real && !timer->deleted) {
+ ecore_timer_del (timer->real);
+ timer->real = NULL;
timer->deleted = true;
} else
rb_raise (rb_eException, "Timer already deleted!");
-## $Id: Makefile.am 40 2004-07-25 13:14:34Z tilman $
+## $Id: Makefile.am 50 2004-08-01 10:18:39Z tilman $
AM_CFLAGS = $(ECORE_CFLAGS) $(EVAS_CFLAGS)
INCLUDES = -I$(RUBYDIR) -I$(RUBYSITEDIR)
ecore_evas_la_LIBADD = -lruby $(ECORE_LIBS) $(EVAS_LIBS)
ecore_evas_la_LDFLAGS = -module -avoid-version
-pkgincludedir = $(RUBYSITEDIR)
+pkgincludedir = $(RUBYSITEDIR)/ecore
pkginclude_HEADERS = rb_ecore_evas.h
/*
- * $Id: rb_ecore_evas.c 45 2004-07-26 11:00:14Z tilman $
+ * $Id: rb_ecore_evas.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
*/
#include <ruby.h>
+#include <stdbool.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
-#include <rb_evas.h>
+#include <evas/rb_evas.h>
#define __RB_ECORE_EVAS_C
#include "../ecore/rb_ecore.h"
#include "rb_ecore_evas.h"
#define CALLBACK_ADD_HANDLER(name) \
- static void on_##name (Ecore_Evas *ee) \
+ static void on_##name (Ecore_Evas *real) \
{ \
- VALUE self = rb_hash_aref (objects, INT2NUM ((long) ee)); \
- VALUE hash = rb_hash_aref (callbacks, self); \
+ VALUE self = rb_hash_aref (objects, INT2NUM ((long) real)); \
+ VALUE cb; \
\
- rb_funcall (rb_hash_aref (hash, rb_str_new2 (#name)), \
- rb_intern ("call"), 0); \
+ GET_OBJ (self, RbEcoreEvas, ee); \
+\
+ cb = rb_hash_aref (ee->callbacks, rb_str_new2 (#name)); \
+ rb_funcall (cb, rb_intern ("call"), 0); \
} \
\
static VALUE c_on_##name (VALUE self) \
{ \
- VALUE hash; \
-\
- GET_OBJ (self, Ecore_Evas *, ee); \
+ GET_OBJ (self, RbEcoreEvas, ee); \
\
if (!rb_block_given_p ()) \
return Qnil; \
\
- if (NIL_P ((hash = rb_hash_aref (callbacks, self)))) { \
- hash = rb_hash_new (); \
-\
- rb_global_variable (&hash); \
- rb_hash_aset (callbacks, self, hash); \
- } \
+ rb_hash_aset (ee->callbacks, rb_str_new2 (#name), \
+ rb_block_proc ()); \
\
- rb_hash_aset (hash, rb_str_new2 (#name), rb_block_proc ()); \
-\
- ecore_evas_callback_##name##_set (*ee, on_##name); \
+ ecore_evas_callback_##name##_set (ee->real, on_##name); \
\
return Qnil; \
}
rb_define_method ((mod), "on_"#name, c_on_##name, 0);
VALUE cEcoreEvas;
-static VALUE evases, callbacks, objects;
+static VALUE objects;
/* called by the child classes */
-void c_ecore_evas_free (Ecore_Evas **ee)
+void c_ecore_evas_mark (RbEcoreEvas *ee)
{
- if (*ee) {
- rb_hash_aset (objects, INT2NUM ((long) *ee), Qnil);
- ecore_evas_free (*ee);
- }
+ if (!NIL_P (ee->evas))
+ rb_gc_mark (ee->evas);
+
+ rb_gc_mark (ee->callbacks);
+}
- rb_hash_aset (evases, INT2NUM ((long) ee), Qnil);
+void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem)
+{
+ if (ee->real)
+ ecore_evas_free (ee->real);
ecore_evas_shutdown ();
ecore_shutdown ();
- free (ee);
+ if (free_mem)
+ free (ee);
}
-static VALUE c_initialize (int argc, VALUE *argv, VALUE self)
+static VALUE c_init (int argc, VALUE *argv, VALUE self)
{
- Ecore_Evas **ee = NULL;
+ GET_OBJ (self, RbEcoreEvas, ee);
- Data_Get_Struct (self, Ecore_Evas *, ee);
+ ee->evas = Qnil;
+ ee->callbacks = rb_hash_new ();
- rb_hash_aset (objects, INT2NUM ((long) *ee), self);
+ rb_hash_aset (objects, INT2NUM ((long) ee->real), self);
return Qnil;
}
static VALUE c_inspect (VALUE self)
{
- INSPECT (self, Ecore_Evas *);
+ INSPECT (self, RbEcoreEvas);
}
static VALUE c_show (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_show (*ee);
+ ecore_evas_show (ee->real);
return Qnil;
}
static VALUE c_hide (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_hide (*ee);
+ ecore_evas_hide (ee->real);
return Qnil;
}
static VALUE c_visible_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
+ return ecore_evas_visibility_get (ee->real) ? Qtrue : Qfalse;
}
static VALUE c_raise (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_raise (*ee);
+ ecore_evas_raise (ee->real);
return Qnil;
}
static VALUE c_lower (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_lower (*ee);
+ ecore_evas_lower (ee->real);
return Qnil;
}
static VALUE c_layer_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return INT2FIX (ecore_evas_layer_get (*ee));
+ return INT2FIX (ecore_evas_layer_get (ee->real));
}
static VALUE c_layer_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (val, T_FIXNUM);
- ecore_evas_layer_set (*ee, FIX2INT (val));
+ ecore_evas_layer_set (ee->real, FIX2INT (val));
return Qnil;
}
static VALUE c_evas_get (VALUE self)
{
- VALUE evas;
-
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- if (NIL_P (evas = rb_hash_aref (evases, INT2NUM ((long) (ee))))) {
- evas = TO_EVAS (self, ecore_evas_get (*ee));
- rb_hash_aset (evases, INT2NUM ((long) ee), evas);
- }
+ if (NIL_P (ee->evas))
+ ee->evas = TO_EVAS (self, ecore_evas_get (ee->real));
- return evas;
+ return ee->evas;
}
static VALUE c_geometry_get (VALUE self)
{
int x = 0, y = 0, w = 0, h = 0;
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_geometry_get (*ee, &x, &y, &w, &h);
+ ecore_evas_geometry_get (ee->real, &x, &y, &w, &h);
return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
INT2FIX (w), INT2FIX (h));
{
int w = 0, h = 0;
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_size_min_get (*ee, &w, &h);
+ ecore_evas_size_min_get (ee->real, &w, &h);
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
- ecore_evas_size_min_set (*ee, FIX2INT (w), FIX2INT (h));
+ ecore_evas_size_min_set (ee->real, FIX2INT (w), FIX2INT (h));
return Qnil;
}
{
int w = 0, h = 0;
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_size_max_get (*ee, &w, &h);
+ ecore_evas_size_max_get (ee->real, &w, &h);
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
- ecore_evas_size_max_set (*ee, FIX2INT (w), FIX2INT (h));
+ ecore_evas_size_max_set (ee->real, FIX2INT (w), FIX2INT (h));
return Qnil;
}
static VALUE c_move (VALUE self, VALUE x, VALUE y)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (x, T_FIXNUM);
Check_Type (y, T_FIXNUM);
- ecore_evas_move (*ee, FIX2INT (x), FIX2INT (y));
+ ecore_evas_move (ee->real, FIX2INT (x), FIX2INT (y));
return Qnil;
}
static VALUE c_resize (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
- ecore_evas_resize (*ee, FIX2INT (w), FIX2INT (h));
+ ecore_evas_resize (ee->real, FIX2INT (w), FIX2INT (h));
return Qnil;
}
{
const char *tmp;
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- if (!(tmp = ecore_evas_title_get (*ee)))
+ if (!(tmp = ecore_evas_title_get (ee->real)))
return Qnil;
else
return rb_str_new2 (tmp);
static VALUE c_title_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (val, T_STRING);
- ecore_evas_title_set (*ee, StringValuePtr (val));
+ ecore_evas_title_set (ee->real, StringValuePtr (val));
return Qnil;
}
static VALUE c_borderless_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return ecore_evas_borderless_get (*ee) ? Qtrue : Qfalse;
+ return ecore_evas_borderless_get (ee->real) ? Qtrue : Qfalse;
}
static VALUE c_borderless_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
CHECK_BOOL (val);
- ecore_evas_borderless_set (*ee, val == Qtrue ? 1 : 0);
+ ecore_evas_borderless_set (ee->real, val == Qtrue);
return Qnil;
}
static VALUE c_shaped_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return ecore_evas_shaped_get (*ee) ? Qtrue : Qfalse;
+ return ecore_evas_shaped_get (ee->real) ? Qtrue : Qfalse;
}
static VALUE c_shaped_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
CHECK_BOOL (val);
- ecore_evas_shaped_set (*ee, val == Qtrue ? 1 : 0);
+ ecore_evas_shaped_set (ee->real, val == Qtrue);
return Qnil;
}
static VALUE c_sticky_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return ecore_evas_sticky_get (*ee) ? Qtrue : Qfalse;
+ return ecore_evas_sticky_get (ee->real) ? Qtrue : Qfalse;
}
static VALUE c_sticky_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
CHECK_BOOL (val);
- ecore_evas_sticky_set (*ee, val == Qtrue ? 1 : 0);
+ ecore_evas_sticky_set (ee->real, val == Qtrue);
return Qnil;
}
static VALUE c_rotation_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return INT2FIX (ecore_evas_rotation_get (*ee));
+ return INT2FIX (ecore_evas_rotation_get (ee->real));
}
static VALUE c_rotation_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (val, T_FIXNUM);
- ecore_evas_rotation_set (*ee, FIX2INT (val));
+ ecore_evas_rotation_set (ee->real, FIX2INT (val));
return Qnil;
}
/* FIXME: this is unsafe! */
static VALUE c_delete (VALUE self)
{
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
/* reap our children */
rb_gc_start ();
- ecore_evas_free (*ee);
- rb_hash_aset (objects, INT2NUM ((long) *ee), Qnil);
- *ee = NULL;
+ ecore_evas_free (ee->real);
+ rb_hash_aset (objects, INT2NUM ((long) ee->real), Qnil);
+ ee->real = NULL;
return Qnil;
}
rb_define_private_method (rb_singleton_class (cEcoreEvas),
"new", NULL, 0);
- rb_define_method (cEcoreEvas, "initialize", c_initialize, -1);
+ rb_define_method (cEcoreEvas, "initialize", c_init, -1);
rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
rb_define_method (cEcoreEvas, "delete", c_delete, 0);
rb_define_method (cEcoreEvas, "show", c_show, 0);
CALLBACK_ADD (cEcoreEvas, pre_render);
CALLBACK_ADD (cEcoreEvas, post_render);
- evases = rb_hash_new ();
- rb_global_variable (&evases);
-
objects = rb_hash_new ();
rb_global_variable (&objects);
-
- callbacks = rb_hash_new ();
- rb_global_variable (&callbacks);
}
/*
- * $Id: rb_ecore_evas.h 45 2004-07-26 11:00:14Z tilman $
+ * $Id: rb_ecore_evas.h 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#ifndef __RB_ECORE_EVAS_H
#define __RB_ECORE_EVAS_H
-#ifndef __RB_ECORE_EVAS_C
-VALUE cEcoreEvas;
-#endif
+#include <stdbool.h>
+
+typedef struct {
+ Ecore_Evas *real;
+ VALUE evas;
+ VALUE callbacks;
+} RbEcoreEvas;
void Init_EcoreEvas (void);
-void c_ecore_evas_free (Ecore_Evas **ee);
+void c_ecore_evas_mark (RbEcoreEvas *ee);
+void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem);
+
+#ifndef __RB_ECORE_EVAS_C
+VALUE cEcoreEvas;
+#endif
#endif
/*
- * $Id: rb_fb.c 40 2004-07-25 13:14:34Z tilman $
+ * $Id: rb_fb.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include "rb_ecore_evas_main.h"
#include "rb_ecore_evas.h"
+static void c_free (RbEcoreEvas *ee)
+{
+ c_ecore_evas_free (ee, true);
+}
+
static VALUE c_new (int argc, VALUE *argv, VALUE klass)
{
VALUE self, disp, rot, w, h;
- Ecore_Evas **ee = NULL;
+ RbEcoreEvas *ee = NULL;
char *cdisp = NULL;
int irot = 0, iw = 0, ih = 0;
- self = Data_Make_Struct (klass, Ecore_Evas *,
- NULL, c_ecore_evas_free, ee);
+ self = Data_Make_Struct (klass, RbEcoreEvas,
+ c_ecore_evas_mark, c_free, ee);
rb_scan_args (argc, argv, "04", &disp, &rot, &w, &h);
if (!NIL_P (rot)) {
Check_Type (rot, T_FIXNUM);
- irot = NUM2INT (rot);
+ irot = FIX2INT (rot);
}
if (!NIL_P (w)) {
Check_Type (w, T_FIXNUM);
- iw = NUM2INT (w);
+ iw = FIX2INT (w);
}
if (!NIL_P (h)) {
Check_Type (h, T_FIXNUM);
- ih = NUM2INT (h);
+ ih = FIX2INT (h);
}
ecore_init ();
ecore_evas_init ();
- *ee = ecore_evas_fb_new (cdisp, irot, iw, ih);
+ ee->real = ecore_evas_fb_new (cdisp, irot, iw, ih);
rb_obj_call_init (self, 0, NULL);
/*
- * $Id: rb_gl_x11.c 40 2004-07-25 13:14:34Z tilman $
+ * $Id: rb_gl_x11.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include "rb_ecore_evas_main.h"
#include "rb_ecore_evas.h"
+static void c_free (RbEcoreEvas *ee)
+{
+ c_ecore_evas_free (ee, true);
+}
+
static VALUE c_new (int argc, VALUE *argv, VALUE klass)
{
VALUE self, disp, parent, geom[4];
- Ecore_Evas **ee = NULL;
+ RbEcoreEvas *ee = NULL;
char *cdisp = NULL;
int i, igeom[4] = {0, 0, 0, 0};
- self = Data_Make_Struct (klass, Ecore_Evas *,
- NULL, c_ecore_evas_free, ee);
+ self = Data_Make_Struct (klass, RbEcoreEvas,
+ c_ecore_evas_mark, c_free, ee);
rb_scan_args (argc, argv, "06", &disp, &parent,
&geom[0], &geom[1], &geom[2], &geom[3]);
for (i = 0; i < 4; i++)
if (!NIL_P (geom[i])) {
Check_Type (geom[i], T_FIXNUM);
- igeom[i] = NUM2INT (geom[i]);
+ igeom[i] = FIX2INT (geom[i]);
}
ecore_init ();
ecore_evas_init ();
- *ee = ecore_evas_gl_x11_new (cdisp, 0,
- igeom[0], igeom[1],
- igeom[2], igeom[3]);
+ ee->real = ecore_evas_gl_x11_new (cdisp, 0,
+ igeom[0], igeom[1],
+ igeom[2], igeom[3]);
rb_obj_call_init (self, 0, NULL);
/*
- * $Id: rb_software_x11.c 40 2004-07-25 13:14:34Z tilman $
+ * $Id: rb_software_x11.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
*/
#include <ruby.h>
+#include <stdbool.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include "rb_ecore_evas_main.h"
#include "rb_ecore_evas.h"
-static VALUE windows;
+typedef struct {
+ RbEcoreEvas ee;
+ VALUE window;
+} RbEcoreEvasSoftwareX11;
+
+static void c_mark (RbEcoreEvasSoftwareX11 *ee)
+{
+ c_ecore_evas_mark (&ee->ee);
+
+ if (!NIL_P (ee->window))
+ rb_gc_mark (ee->window);
+}
+
+static void c_free (RbEcoreEvasSoftwareX11 *ee)
+{
+ c_ecore_evas_free (&ee->ee, false);
+
+ free (ee);
+}
static VALUE c_new (int argc, VALUE *argv, VALUE klass)
{
VALUE self, disp, parent, geom[4];
- Ecore_Evas **ee = NULL;
+ RbEcoreEvasSoftwareX11 *ee = NULL;
char *cdisp = NULL;
int i, igeom[4] = {0, 0, 0, 0};
- self = Data_Make_Struct (klass, Ecore_Evas *,
- NULL, c_ecore_evas_free, ee);
+ self = Data_Make_Struct (klass, RbEcoreEvasSoftwareX11,
+ c_mark, c_free, ee);
rb_scan_args (argc, argv, "06", &disp, &parent,
&geom[0], &geom[1], &geom[2], &geom[3]);
for (i = 0; i < 4; i++)
if (!NIL_P (geom[i])) {
Check_Type (geom[i], T_FIXNUM);
- igeom[i] = NUM2INT (geom[i]);
+ igeom[i] = FIX2INT (geom[i]);
}
ecore_init ();
ecore_evas_init ();
- *ee = ecore_evas_software_x11_new (cdisp, 0,
- igeom[0], igeom[1],
- igeom[2], igeom[3]);
+ ee->ee.real = ecore_evas_software_x11_new (cdisp, 0,
+ igeom[0], igeom[1],
+ igeom[2], igeom[3]);
+ ee->window = Qnil;
rb_obj_call_init (self, 0, NULL);
static VALUE c_window_get (VALUE self)
{
- VALUE o;
Ecore_X_Window w;
- GET_OBJ (self, Ecore_Evas *, ee);
+ GET_OBJ (self, RbEcoreEvasSoftwareX11, ee);
- if (NIL_P (o = rb_hash_aref (windows, INT2NUM ((long) (ee))))) {
- w = ecore_evas_software_x11_window_get (*ee);
- o = TO_ECORE_X_WINDOW (self, w);
- rb_hash_aset (windows, INT2NUM ((long) ee), o);
+ if (NIL_P (ee->window)) {
+ w = ecore_evas_software_x11_window_get (ee->ee.real);
+ ee->window = TO_ECORE_X_WINDOW (self, w);
}
- return o;
+ return ee->window;
}
void Init_SoftwareX11 (void)
rb_define_singleton_method (c, "new", c_new, -1);
rb_define_method (c, "window", c_window_get, 0);
-
- windows = rb_hash_new ();
- rb_global_variable (&windows);
}
/*
- * $Id: rb_job.c 40 2004-07-25 13:14:34Z tilman $
+ * $Id: rb_job.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include "rb_ecore_job.h"
typedef struct {
- Ecore_Job *job;
- void *cb;
+ Ecore_Job *real;
+ VALUE callback;
bool deleted;
-} RbEcoreJob;
+} RbJob;
static void on_job (void *data)
{
- RbEcoreJob *job = data;
+ RbJob *job = data;
- rb_funcall ((VALUE) job->cb, rb_intern ("call"), 0);
+ rb_funcall (job->callback, rb_intern ("call"), 0);
job->deleted = true;
}
-static void c_free (RbEcoreJob *job)
+static void c_mark (RbJob *job)
{
- if (job->job && !job->deleted)
- ecore_job_del (job->job);
+ rb_gc_mark (job->callback);
+}
+
+static void c_free (RbJob *job)
+{
+ if (job->real && !job->deleted)
+ ecore_job_del (job->real);
ecore_shutdown ();
static VALUE c_new (VALUE klass)
{
VALUE self;
- RbEcoreJob *job;
+ RbJob *job;
if (!rb_block_given_p ())
return Qnil;
- self = Data_Make_Struct (klass, RbEcoreJob, NULL, c_free, job);
+ self = Data_Make_Struct (klass, RbJob, c_mark, c_free, job);
ecore_init ();
- job->cb = (void *) rb_block_proc ();
- job->job = ecore_job_add (on_job, job);
+ job->callback = rb_block_proc ();
+ job->real = ecore_job_add (on_job, job);
rb_obj_call_init (self, 0, NULL);
static VALUE c_delete (VALUE self)
{
VALUE ret = Qfalse;
- RbEcoreJob *job = NULL;
+ RbJob *job = NULL;
- Data_Get_Struct (self, RbEcoreJob, job);
+ Data_Get_Struct (self, RbJob, job);
- if (job->job && !job->deleted) {
- ecore_job_del (job->job);
+ if (job->real && !job->deleted) {
+ ecore_job_del (job->real);
job->deleted = true;
- job->job = NULL;
+ job->real = NULL;
ret = Qtrue;
}
-## $Id: Makefile.am 39 2004-07-25 13:13:57Z tilman $
+## $Id: Makefile.am 50 2004-08-01 10:18:39Z tilman $
AM_CFLAGS = $(ECORE_CFLAGS)
INCLUDES = -I$(RUBYDIR) -I$(RUBYSITEDIR)
ecore_x_la_LIBADD = -lruby $(ECORE_LIBS)
ecore_x_la_LDFLAGS = -module -avoid-version
+
+pkgincludedir = $(RUBYSITEDIR)/ecore
+pkginclude_HEADERS = rb_window.h
/*
- * $Id: rb_window.c 39 2004-07-25 13:13:57Z tilman $
+ * $Id: rb_window.c 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include <Ecore.h>
#include <Ecore_X.h>
+#define __RB_WINDOW_C
+#include "../ecore/rb_ecore.h"
#include "rb_ecore_x.h"
+#include "rb_window.h"
-static VALUE cWindow, parents;
+VALUE cWindow;
-static void c_mark (Ecore_X_Window *w)
+static void c_mark (RbWindow *w)
{
- VALUE parent;
-
- parent = rb_hash_aref (parents, INT2NUM ((long) (w)));
- if (parent != Qnil)
- rb_gc_mark (parent);
-}
-
-static void c_free (Ecore_X_Window *w)
-{
- rb_hash_aset (parents, INT2NUM ((long) w), Qnil);
-
- free (w);
+ if (!NIL_P (w->parent))
+ rb_gc_mark (w->parent);
}
VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
{
VALUE self;
- Ecore_X_Window *my_w = NULL;
+ RbWindow *window = NULL;
- if (NIL_P (parent) || !w)
+ if (!w)
return Qnil;
- self = Data_Make_Struct (cWindow, Ecore_X_Window,
- c_mark, c_free, my_w);
- *my_w = w;
+ self = Data_Make_Struct (cWindow, RbWindow, c_mark, free, window);
- rb_hash_aset (parents, INT2NUM ((long) my_w), parent);
+ window->real = w;
+ window->parent = parent;
rb_obj_call_init (self, 0, NULL);
/* not publically instantiable yet */
rb_define_private_method (rb_singleton_class (cWindow),
"new", NULL, 0);
-
- parents = rb_hash_new ();
- rb_global_variable (&parents);
}
/*
- * $Id: rb_window.h 39 2004-07-25 13:13:57Z tilman $
+ * $Id: rb_window.h 50 2004-08-01 10:18:39Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#ifndef __RB_WINDOW_H
#define __RB_WINDOW_H
+typedef struct {
+ Ecore_X_Window real;
+ VALUE parent;
+} RbWindow;
+
void Init_Window (void);
VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w);
+#ifndef __RB_WINDOW_C
+extern VALUE cWindow;
+#endif
+
#endif