[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] evas object event callback API



Context: writing foreign language bindings to Evas

I've encountered some snags with Evas callbacks and thought I'd ask
for advice (and possibly suggest a better API).

Overall, the problem is that Evas assumes in a number of places that
one object event callback == exactly one C function.

When writing bindings for any dynamic language one would usually want
to pass all events through one or two C-level callback functions, so
as to decode and convert the event structures. But the current API
pretty much requires that there be exactly one C function per event
handled: event type is not passed to the callback, so the function
called needs to be specialized in advance for that one particular
type.

In dynamic languages there is usually no "compile" step (or it is
optional), so there is no way of knowing ahead if time which callbacks
will be needed. At a certain point in time the program may request a
certain type of callback to be added. It would be good to be able to
do it without necessarily needing to create a completely separate C
function to handle just this one particular callback case.

The other issue is how to delete unwanted callbacks. At present
callbacks are uniquely identified by the C function pointer. This
makes it impossible to have one function handle several events --
evas_object_event_callback_delete removes by comparing function
pointers.

So, on to humble suggestions:

1. IMHO evas object event callbacks should be uniquely identified by
the triplet (Evas_Object, Event_Type, function_ptr). That's what you
pass in when you call evas_object_event_callback_add, so that's what
you should pass when deleting the callback. I'm not sure if an object
can belong to multiple Evases, so I don't know if Evas should be used
as well.

2. IMHO the callback function should receive the event type as one of
its parameters.

3. Overall, IMHO we should not assume that one callback always equals
one C function. I can imagine a number of cases where I'd want to have
a dispatching function handling multiple event types or events from
multiple objects (or even Evases).

--J.