From f805cf241a9d1fb9765892f0af48ede8359e9b65 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 1 Aug 2004 10:18:39 +0000 Subject: [PATCH] We now use real structs to wrap objects. This way we can get rid of rb_global_variable()'s. Also put headers in their own subdirectory. --- src/ecore/rb_ecore.h | 22 ++-- src/ecore/rb_idler.c | 43 +++---- src/ecore/rb_timer.c | 45 ++++---- src/ecore_evas/Makefile.am | 4 +- src/ecore_evas/rb_ecore_evas.c | 189 +++++++++++++++---------------- src/ecore_evas/rb_ecore_evas.h | 19 +++- src/ecore_evas/rb_fb.c | 21 ++-- src/ecore_evas/rb_gl_x11.c | 21 ++-- src/ecore_evas/rb_software_x11.c | 53 +++++---- src/ecore_job/rb_job.c | 41 ++++--- src/ecore_x/Makefile.am | 5 +- src/ecore_x/rb_window.c | 37 +++--- src/ecore_x/rb_window.h | 11 +- 13 files changed, 275 insertions(+), 236 deletions(-) diff --git a/src/ecore/rb_ecore.h b/src/ecore/rb_ecore.h index 2c5d816..0c46a43 100644 --- a/src/ecore/rb_ecore.h +++ b/src/ecore/rb_ecore.h @@ -1,5 +1,5 @@ /* - * $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) * @@ -24,14 +24,7 @@ #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) { \ @@ -41,6 +34,15 @@ 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]; \ \ @@ -48,7 +50,7 @@ \ snprintf (buf, sizeof (buf), \ "#<%s:%p ptr=%p>", rb_obj_classname ((obj)), \ - (void *) obj, *o); \ + (void *) obj, o->real); \ \ return rb_str_new2 (buf); diff --git a/src/ecore/rb_idler.c b/src/ecore/rb_idler.c index ce6bc03..b890ef5 100644 --- a/src/ecore/rb_idler.c +++ b/src/ecore/rb_idler.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -19,24 +19,24 @@ */ #include +#include #include -#include #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 @@ -47,10 +47,15 @@ static int on_idler (void *data) 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 (); @@ -60,17 +65,17 @@ static void c_free (RbEcoreIdler *idler) 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); @@ -79,13 +84,11 @@ static VALUE c_new (VALUE klass) 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!"); diff --git a/src/ecore/rb_timer.c b/src/ecore/rb_timer.c index 543a541..fa9ab15 100644 --- a/src/ecore/rb_timer.c +++ b/src/ecore/rb_timer.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -19,24 +19,24 @@ */ #include +#include #include -#include #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 @@ -47,10 +47,15 @@ static int on_timer (void *data) 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 (); @@ -60,18 +65,18 @@ static void c_free (RbEcoreTimer *timer) 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); @@ -80,13 +85,11 @@ static VALUE c_new (VALUE klass, VALUE interval) 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!"); diff --git a/src/ecore_evas/Makefile.am b/src/ecore_evas/Makefile.am index 9b4b71a..355e99d 100644 --- a/src/ecore_evas/Makefile.am +++ b/src/ecore_evas/Makefile.am @@ -1,4 +1,4 @@ -## $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) @@ -15,5 +15,5 @@ ecore_evas_la_SOURCES = rb_ecore_evas_main.c rb_ecore_evas_main.h \ 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 diff --git a/src/ecore_evas/rb_ecore_evas.c b/src/ecore_evas/rb_ecore_evas.c index 5362cf8..057b5be 100644 --- a/src/ecore_evas/rb_ecore_evas.c +++ b/src/ecore_evas/rb_ecore_evas.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -19,10 +19,11 @@ */ #include +#include #include #include -#include +#include #define __RB_ECORE_EVAS_C #include "../ecore/rb_ecore.h" @@ -30,34 +31,28 @@ #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; \ } @@ -66,122 +61,124 @@ 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)); @@ -191,21 +188,21 @@ static VALUE c_get_size_min (VALUE self) { 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; } @@ -214,45 +211,45 @@ static VALUE c_get_size_max (VALUE self) { 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; } @@ -261,9 +258,9 @@ static VALUE c_title_get (VALUE self) { 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); @@ -271,83 +268,83 @@ static VALUE c_title_get (VALUE self) 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; } @@ -355,14 +352,14 @@ static VALUE c_rotation_set (VALUE self, VALUE val) /* 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; } @@ -386,7 +383,7 @@ void Init_EcoreEvas (void) 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); @@ -428,12 +425,6 @@ void Init_EcoreEvas (void) 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); } diff --git a/src/ecore_evas/rb_ecore_evas.h b/src/ecore_evas/rb_ecore_evas.h index 25d4209..8f9bff0 100644 --- a/src/ecore_evas/rb_ecore_evas.h +++ b/src/ecore_evas/rb_ecore_evas.h @@ -1,5 +1,5 @@ /* - * $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) * @@ -21,12 +21,21 @@ #ifndef __RB_ECORE_EVAS_H #define __RB_ECORE_EVAS_H -#ifndef __RB_ECORE_EVAS_C -VALUE cEcoreEvas; -#endif +#include + +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 diff --git a/src/ecore_evas/rb_fb.c b/src/ecore_evas/rb_fb.c index 8359ef2..42412ee 100644 --- a/src/ecore_evas/rb_fb.c +++ b/src/ecore_evas/rb_fb.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -26,15 +26,20 @@ #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); @@ -45,23 +50,23 @@ static VALUE c_new (int argc, VALUE *argv, VALUE klass) 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); diff --git a/src/ecore_evas/rb_gl_x11.c b/src/ecore_evas/rb_gl_x11.c index 274230e..c143ea7 100644 --- a/src/ecore_evas/rb_gl_x11.c +++ b/src/ecore_evas/rb_gl_x11.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -26,15 +26,20 @@ #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]); @@ -47,15 +52,15 @@ static VALUE c_new (int argc, VALUE *argv, VALUE klass) 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); diff --git a/src/ecore_evas/rb_software_x11.c b/src/ecore_evas/rb_software_x11.c index 055c17e..f694e3e 100644 --- a/src/ecore_evas/rb_software_x11.c +++ b/src/ecore_evas/rb_software_x11.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -28,17 +29,35 @@ #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]); @@ -51,15 +70,16 @@ static VALUE c_new (int argc, VALUE *argv, VALUE klass) 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); @@ -68,18 +88,16 @@ static VALUE c_new (int argc, VALUE *argv, VALUE klass) 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) @@ -92,7 +110,4 @@ 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); } diff --git a/src/ecore_job/rb_job.c b/src/ecore_job/rb_job.c index 0ef669b..d4348cf 100644 --- a/src/ecore_job/rb_job.c +++ b/src/ecore_job/rb_job.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -27,23 +27,28 @@ #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 (); @@ -53,17 +58,17 @@ static void c_free (RbEcoreJob *job) 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); @@ -73,14 +78,14 @@ static VALUE c_new (VALUE klass) 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; } diff --git a/src/ecore_x/Makefile.am b/src/ecore_x/Makefile.am index 0969ccc..5632d00 100644 --- a/src/ecore_x/Makefile.am +++ b/src/ecore_x/Makefile.am @@ -1,4 +1,4 @@ -## $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) @@ -11,3 +11,6 @@ ecore_x_la_SOURCES = rb_ecore_x.c rb_ecore_x.h \ ecore_x_la_LIBADD = -lruby $(ECORE_LIBS) ecore_x_la_LDFLAGS = -module -avoid-version + +pkgincludedir = $(RUBYSITEDIR)/ecore +pkginclude_HEADERS = rb_window.h diff --git a/src/ecore_x/rb_window.c b/src/ecore_x/rb_window.c index 2d7e3c0..e046b6f 100644 --- a/src/ecore_x/rb_window.c +++ b/src/ecore_x/rb_window.c @@ -1,5 +1,5 @@ /* - * $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) * @@ -23,39 +23,31 @@ #include #include +#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); @@ -69,7 +61,4 @@ void Init_Window (void) /* not publically instantiable yet */ rb_define_private_method (rb_singleton_class (cWindow), "new", NULL, 0); - - parents = rb_hash_new (); - rb_global_variable (&parents); } diff --git a/src/ecore_x/rb_window.h b/src/ecore_x/rb_window.h index 198244f..3dd8e3e 100644 --- a/src/ecore_x/rb_window.h +++ b/src/ecore_x/rb_window.h @@ -1,5 +1,5 @@ /* - * $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) * @@ -21,7 +21,16 @@ #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 -- 2.30.2