2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
20 #include "timeout_handler.h"
23 #define NUM_EVENT_HANDLERS 7
25 struct timeout_handler {
26 Eina_List *eventhandler_list;
29 timeout_event_cb event_cb;
32 timeout_event_cb timeout_cb;
38 static Eina_Bool _timer_cb(void *data)
40 struct timeout_handler *handle;
45 handle = (timeout_handler *)data;
47 handle->timeout_cb(handle->timeout_data, 0, NULL);
53 static Eina_Bool _event_occured(void *data, int type, void *event)
55 struct timeout_handler *handle;
58 return ECORE_CALLBACK_PASS_ON;
60 handle = (timeout_handler *)data;
62 if (type == ECORE_EVENT_KEY_UP ||
63 type == ECORE_EVENT_MOUSE_MOVE)
64 handle->event_cb(handle->event_data, type, event);
67 ecore_timer_reset(handle->timer);
69 handle->timer = ecore_timer_add(handle->timeout,
72 return ECORE_CALLBACK_PASS_ON;
75 void timeout_handler_reset(struct timeout_handler *handle)
78 ecore_timer_reset(handle->timer);
80 handle->timer = ecore_timer_add(handle->timeout,
84 struct timeout_handler *timeout_handler_init(double timeout,
85 timeout_event_cb timeout_cb, void *timeout_data,
86 timeout_event_cb event_cb, void *event_data)
88 struct timeout_handler *handle;
89 Ecore_Event_Handler *event_handler;
91 int event_type[NUM_EVENT_HANDLERS] = {
93 ECORE_EVENT_MOUSE_BUTTON_DOWN,
94 ECORE_EVENT_MOUSE_BUTTON_UP,
95 ECORE_EVENT_MOUSE_MOVE,
96 ECORE_EVENT_MOUSE_WHEEL,
101 handle = (timeout_handler *)calloc(1, sizeof(*handle));
105 for (i = 0; i < NUM_EVENT_HANDLERS; i++) {
106 event_handler = ecore_event_handler_add(
107 event_type[i], _event_occured, handle);
111 handle->eventhandler_list = eina_list_append(
112 handle->eventhandler_list, event_handler);
115 handle->timer = ecore_timer_add(timeout, _timer_cb, handle);
119 handle->event_cb = event_cb;
120 handle->event_data = event_data;
121 handle->timeout_cb = timeout_cb;
122 handle->timeout_data = timeout_data;
123 handle->timeout = timeout;
128 timeout_handler_fini(handle);
133 void timeout_handler_fini(struct timeout_handler *handle)
135 Ecore_Event_Handler *event_handler;
141 EINA_LIST_FREE(handle->eventhandler_list, o) {
142 event_handler = (Ecore_Event_Handler *)o;
143 ecore_event_handler_del(event_handler);
147 ecore_timer_del(handle->timer);
148 handle->timer = NULL;