diff options
author | Mike Blumenkrantz <zmike@osg.samsung.com> | 2018-01-29 13:56:28 -0500 |
---|---|---|
committer | Mike Blumenkrantz <zmike@osg.samsung.com> | 2018-01-30 13:02:07 -0500 |
commit | da9eef6027489fd0555e61860646fc9ca91f5695 (patch) | |
tree | d36a6293ccb3fff5a5156091299da9778e389fcc | |
parent | 5651b2e586e9a9836ebe4f50f9223e237099cf86 (diff) | |
download | efl-da9eef6027489fd0555e61860646fc9ca91f5695.tar.gz |
ecore: add function for prepending an event handler
@feature
-rw-r--r-- | src/lib/ecore/Ecore_Common.h | 23 | ||||
-rw-r--r-- | src/lib/ecore/ecore_event_message_handler.c | 32 | ||||
-rw-r--r-- | src/lib/ecore/ecore_event_message_handler.eo | 9 | ||||
-rw-r--r-- | src/lib/ecore/ecore_events.c | 9 |
4 files changed, 66 insertions, 7 deletions
diff --git a/src/lib/ecore/Ecore_Common.h b/src/lib/ecore/Ecore_Common.h index 6102341446..90df3cb02a 100644 --- a/src/lib/ecore/Ecore_Common.h +++ b/src/lib/ecore/Ecore_Common.h @@ -698,6 +698,19 @@ struct _Ecore_Event_Signal_Realtime EAPI Ecore_Event_Handler *ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data); /** + * @brief Adds an event handler to the beginning of the handler list. + * @param type The type of the event this handler will get called for + * @param func The function to call when the event is found in the queue + * @param data A data pointer to pass to the called function @p func + * @return A new Event handler, or @c NULL on failure. + * + * This function is identical to ecore_event_handler_add() except that it + * creates the handler at the start of the list. Do not use this function. + * @since 1.21 + */ +EAPI Ecore_Event_Handler *ecore_event_handler_prepend(int type, Ecore_Event_Handler_Cb func, const void *data); + +/** * @brief Deletes an event handler. * @param event_handler Event handler handle to delete * @return Data passed to handler @@ -1597,9 +1610,9 @@ EAPI double ecore_loop_time_get(void); /** * Sets the loop time. - * + * * @param t The new loop time - * + * * You should never need/call this, unless you are implementing a custom * tick source for an ecore animator. Only then inside your function that * calls ecore_animator_custom_tick(), just before it, if you are able to @@ -1611,7 +1624,7 @@ EAPI double ecore_loop_time_get(void); * you get from ecore_time_get() and ecore_loop_time_get() (same 0 point). * What this point is is undefined, sou unless your source uses the same * 0 time, then you may have to adjust and do some guessing. - * + * * @see ecore_animator_custom_tick() * @see ecore_loop_time_get() * @since 1.11 @@ -2402,14 +2415,14 @@ EAPI Ecore_Pipe *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data); /** * Creates a pipe with more parameters. - * + * * @param handler Same as ecore_pipe_add() * @param data Same as ecore_pipe_add() * @param fd_read An fd to use for reading or @c -1 otherwise * @param fd_write An fd to use for writing or @c -1 otherwise * @param read_survive_fork Should read fd survive a fork * @param write_survive_fork Should write fd survive a fork - * + * * This is the same as ecore_pipe_add() but with some added parameters. * * @return A pointer to the new Ecore_Pipe object on success, else NULL. diff --git a/src/lib/ecore/ecore_event_message_handler.c b/src/lib/ecore/ecore_event_message_handler.c index cab87a1743..39f5dfe5a8 100644 --- a/src/lib/ecore/ecore_event_message_handler.c +++ b/src/lib/ecore/ecore_event_message_handler.c @@ -21,6 +21,7 @@ struct _Handler int type; Eina_Bool delete_me : 1; Eina_Bool to_add : 1; + Eina_Bool prepend : 1; }; struct _Filter @@ -161,6 +162,29 @@ _ecore_event_message_handler_handler_add(Eo *obj EINA_UNUSED, Ecore_Event_Messag } EOLIAN static void * +_ecore_event_message_handler_handler_prepend(Eo *obj EINA_UNUSED, Ecore_Event_Message_Handler_Data *pd, int type, void *func, void *data) +{ + Handler *h; + + if ((type < 0) || (type > pd->event_type_count) || (!func)) return NULL; + h = calloc(1, sizeof(Handler)); + if (!h) return NULL; + h->func = func; + h->data = data; + h->type = type; + if (pd->current_event_type == type) + { + h->to_add = EINA_TRUE; + h->prepend = EINA_TRUE; + pd->handlers_add = eina_list_append(pd->handlers_add, h); + } + else + pd->handlers[type] = eina_inlist_prepend(pd->handlers[type], + EINA_INLIST_GET(h)); + return h; +} + +EOLIAN static void * _ecore_event_message_handler_handler_del(Eo *obj EINA_UNUSED, Ecore_Event_Message_Handler_Data *pd, void *handler) { Handler *h = handler; @@ -344,8 +368,12 @@ _ecore_event_message_handler_efl_loop_message_handler_message_call(Eo *obj, Ecor h->to_add = EINA_FALSE; pd->handlers_add = eina_list_remove_list(pd->handlers_add, l); - pd->handlers[type] = - eina_inlist_append(pd->handlers[type], EINA_INLIST_GET(h)); + if (h->prepend) + pd->handlers[type] = + eina_inlist_prepend(pd->handlers[type], EINA_INLIST_GET(h)); + else + pd->handlers[type] = + eina_inlist_append(pd->handlers[type], EINA_INLIST_GET(h)); } } if (pd->handlers_walking == 0) diff --git a/src/lib/ecore/ecore_event_message_handler.eo b/src/lib/ecore/ecore_event_message_handler.eo index 78047164ca..7854c4113c 100644 --- a/src/lib/ecore/ecore_event_message_handler.eo +++ b/src/lib/ecore/ecore_event_message_handler.eo @@ -28,6 +28,15 @@ class Ecore.Event.Message.Handler (Efl.Loop.Message.Handler) } return: void_ptr; [[ Lazy return handle ]] } + handler_prepend { + [[ Legacy list of callback handlers so they can return false ]] + params { + type: int; + func: void_ptr; + data: void_ptr; + } + return: void_ptr; [[ Lazy return handle ]] + } handler_del { params { handler: void_ptr; [[ handler returned from handler_add() ]] diff --git a/src/lib/ecore/ecore_events.c b/src/lib/ecore/ecore_events.c index 3911abeb67..de0f16dfb7 100644 --- a/src/lib/ecore/ecore_events.c +++ b/src/lib/ecore/ecore_events.c @@ -36,6 +36,15 @@ ecore_event_handler_add(int type, type, func, (void *)data); } +EAPI Ecore_Event_Handler * +ecore_event_handler_prepend(int type, + Ecore_Event_Handler_Cb func, + const void *data) +{ + return ecore_event_message_handler_prepend(_event_msg_handler, + type, func, (void *)data); +} + EAPI void * ecore_event_handler_del(Ecore_Event_Handler *event_handler) { |