1 #include <Elementary.h>
3 #include <Ecore_Evas.h>
10 #include <livebox-errno.h>
11 #include <livebox-service.h>
18 #define PUBLIC __attribute__((visibility("default")))
22 * Abstracted Data Type of Virtual Window
25 char *id; /*!< Identification */
26 struct livebox_buffer *handle; /*!< Livebox buffer handle */
27 int is_hw; /*!< 1 if a buffer is created on the H/W accelerated place or 0 */
33 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
37 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
40 ho = evas_object_data_get(o, "_elm_access_target");
46 * Every user event (mouse) on the buffer will be passed via this event callback
48 static int event_handler_cb(struct livebox_buffer *handler, struct buffer_event_data *event_info, void *data)
50 struct info *info = data;
51 Elm_Access_Action_Info action_info;
52 Elm_Access_Action_Type action_type;
54 Evas_Object *parent_elm;
59 /* Just ignore this event */
67 switch (event_info->type) {
68 case BUFFER_EVENT_ENTER:
69 evas_event_feed_mouse_in(info->e, event_info->timestamp * 1000, NULL);
71 case BUFFER_EVENT_LEAVE:
72 evas_event_feed_mouse_out(info->e, event_info->timestamp * 1000, NULL);
74 case BUFFER_EVENT_DOWN:
77 * Calculate the event occurred X & Y on the buffer
79 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, (event_info->timestamp - 0.001f) * 1000, NULL); /* + 0.1f just for fake event */
80 evas_event_feed_mouse_down(info->e, 1, EVAS_BUTTON_NONE, event_info->timestamp * 1000, NULL); /* + 0.2f just for fake event */
82 case BUFFER_EVENT_MOVE:
85 * Calculate the event occurred X & Y on the buffer
87 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, event_info->timestamp * 1000, NULL);
90 evas_event_feed_mouse_move(info->e, event_info->info.pointer.x, event_info->info.pointer.y, event_info->timestamp * 1000, NULL);
91 evas_event_feed_mouse_up(info->e, 1, EVAS_BUTTON_NONE, (event_info->timestamp + 0.001f) * 1000, NULL);
93 case BUFFER_EVENT_HIGHLIGHT:
94 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
96 ret = LB_ACCESS_STATUS_ERROR;
99 memset(&action_info, 0, sizeof(action_info));
100 action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
103 * Calculate the event occurred X & Y on the buffer
105 action_info.x = event_info->info.pointer.x;
106 action_info.y = event_info->info.pointer.y;
107 ret = elm_access_action(parent_elm, action_type, &action_info);
108 if (ret == EINA_TRUE) {
109 if (!get_highlighted_object(parent_elm)) {
110 LOGE("Highlighted object is not found\n");
111 ret = LB_ACCESS_STATUS_ERROR;
113 LOGD("Highlighted object is found\n");
114 ret = LB_ACCESS_STATUS_DONE;
117 LOGE("Action error\n");
118 ret = LB_ACCESS_STATUS_ERROR;
121 case BUFFER_EVENT_HIGHLIGHT_NEXT:
122 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
124 ret = LB_ACCESS_STATUS_ERROR;
127 memset(&action_info, 0, sizeof(action_info));
128 action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
129 action_info.highlight_cycle = EINA_FALSE;
130 ret = elm_access_action(parent_elm, action_type, &action_info);
131 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
133 case BUFFER_EVENT_HIGHLIGHT_PREV:
134 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
136 ret = LB_ACCESS_STATUS_ERROR;
139 memset(&action_info, 0, sizeof(action_info));
140 action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
141 action_info.highlight_cycle = EINA_FALSE;
142 ret = elm_access_action(parent_elm, action_type, &action_info);
143 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
145 case BUFFER_EVENT_ACTIVATE:
146 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
148 ret = LB_ACCESS_STATUS_ERROR;
151 memset(&action_info, 0, sizeof(action_info));
152 action_type = ELM_ACCESS_ACTION_ACTIVATE;
153 ret = elm_access_action(parent_elm, action_type, &action_info);
154 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
156 case BUFFER_EVENT_ACTION_UP:
157 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
159 ret = LB_ACCESS_STATUS_ERROR;
162 memset(&action_info, 0, sizeof(action_info));
163 action_type = ELM_ACCESS_ACTION_UP;
164 ret = elm_access_action(parent_elm, action_type, &action_info);
165 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
167 case BUFFER_EVENT_ACTION_DOWN:
168 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
170 ret = LB_ACCESS_STATUS_ERROR;
173 memset(&action_info, 0, sizeof(action_info));
174 action_type = ELM_ACCESS_ACTION_DOWN;
175 ret = elm_access_action(parent_elm, action_type, &action_info);
176 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
178 case BUFFER_EVENT_SCROLL_UP:
179 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
181 ret = LB_ACCESS_STATUS_ERROR;
184 memset(&action_info, 0, sizeof(action_info));
185 action_type = ELM_ACCESS_ACTION_SCROLL;
186 action_info.x = event_info->info.pointer.x;
187 action_info.y = event_info->info.pointer.y;
188 action_info.mouse_type = 2;
189 ret = elm_access_action(parent_elm, action_type, &action_info);
190 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
192 case BUFFER_EVENT_SCROLL_MOVE:
193 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
195 ret = LB_ACCESS_STATUS_ERROR;
198 memset(&action_info, 0, sizeof(action_info));
199 action_type = ELM_ACCESS_ACTION_SCROLL;
200 action_info.x = event_info->info.pointer.x;
201 action_info.y = event_info->info.pointer.y;
202 action_info.mouse_type = 1;
203 ret = elm_access_action(parent_elm, action_type, &action_info);
204 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
206 case BUFFER_EVENT_SCROLL_DOWN:
207 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
209 ret = LB_ACCESS_STATUS_ERROR;
212 memset(&action_info, 0, sizeof(action_info));
213 action_type = ELM_ACCESS_ACTION_SCROLL;
214 action_info.x = event_info->info.pointer.x;
215 action_info.y = event_info->info.pointer.y;
216 action_info.mouse_type = 0;
217 ret = elm_access_action(parent_elm, action_type, &action_info);
218 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
220 case BUFFER_EVENT_UNHIGHLIGHT:
221 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
223 ret = LB_ACCESS_STATUS_ERROR;
226 memset(&action_info, 0, sizeof(action_info));
227 action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
228 ret = elm_access_action(parent_elm, action_type, &action_info);
229 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
231 case BUFFER_EVENT_KEY_DOWN:
232 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
234 ret = LB_ACCESS_STATUS_ERROR;
238 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
243 key_string = XKeysymToString(*key_symbol);
244 key_name = XKeysymToString(*key_symbol);
245 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
249 ret = LB_KEY_STATUS_ERROR;
251 case BUFFER_EVENT_KEY_UP:
252 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
254 ret = LB_ACCESS_STATUS_ERROR;
258 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
263 key_string = XKeysymToString(*key_symbol);
264 key_name = XKeysymToString(*key_symbol);
265 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
269 ret = LB_KEY_STATUS_ERROR;
271 case BUFFER_EVENT_KEY_FOCUS_IN:
272 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
274 ret = LB_ACCESS_STATUS_ERROR;
278 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
283 key_string = XKeysymToString(*key_symbol);
284 key_name = XKeysymToString(*key_symbol);
285 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
289 ret = LB_KEY_STATUS_ERROR;
291 case BUFFER_EVENT_KEY_FOCUS_OUT:
292 parent_elm = ecore_evas_data_get(info->ee, "dynamic,box,win");
294 ret = LB_ACCESS_STATUS_ERROR;
298 key_symbol = XGetKeyboardMapping(ecore_x_display_get(), event_info->info.keycode, 1, &ret);
303 key_string = XKeysymToString(*key_symbol);
304 key_name = XKeysymToString(*key_symbol);
305 DbgPrint("Key symbol: %s, name: %s\n", key_string, key_name);
309 ret = LB_KEY_STATUS_ERROR;
312 LOGD("Unhandled buffer event (%d)\n", event_info->type);
319 static void *alloc_fb(void *data, int size)
321 struct info *info = data;
326 if (info->ee == NULL) {
330 ecore_evas_geometry_get(info->ee, NULL, NULL, &width, &height);
334 * Acquire a buffer for canvas.
336 info->handle = livebox_acquire_buffer_NEW(info->id, info->is_pd,
338 event_handler_cb, info);
341 * If it supports the H/W accelerated buffer,
344 if (livebox_support_hw_buffer(info->handle)) {
345 if (livebox_create_hw_buffer(info->handle) == 0) {
346 buffer = livebox_buffer_hw_buffer(info->handle);
348 LOGD("HW Accelerated buffer is created\n");
354 LOGE("Failed to allocate HW Accelerated buffer\n");
358 * Or use the buffer of a S/W backend.
360 buffer = livebox_ref_buffer(info->handle);
361 LOGD("SW buffer is created\n");
366 static void free_fb(void *data, void *ptr)
368 struct info *info = data;
375 if (livebox_destroy_hw_buffer(info->handle) == 0) {
376 LOGD("HW Accelerated buffer is destroyed\n");
381 livebox_unref_buffer(ptr);
382 LOGD("SW buffer is destroyed\n");
384 livebox_release_buffer(info->handle);
388 static void pre_render_cb(void *data, Evas *e, void *event_info)
390 struct info *info = data;
397 livebox_buffer_pre_render(info->handle);
401 static void post_render_cb(void *data, Evas *e, void *event_info)
403 struct info *info = data;
410 livebox_buffer_post_render(info->handle);
412 livebox_sync_buffer(info->handle);
416 PUBLIC Evas_Object *livebox_get_evas_object(const char *id, int is_pd)
422 ErrPrint("Invalid parameter\n");
426 info = calloc(1, sizeof(*info));
428 ErrPrint("Heap: %s\n", strerror(errno));
432 info->id = strdup(id);
434 ErrPrint("Heap: %s\n", strerror(errno));
441 info->ee = ecore_evas_buffer_allocfunc_new(1, 1, alloc_fb, free_fb, info);
443 ErrPrint("Failed to create ecore_evas (%dx%d)\n", 1, 1);
449 pre_render_cb(info, NULL, NULL);
450 ecore_evas_alpha_set(info->ee, EINA_TRUE);
451 post_render_cb(info, NULL, NULL);
453 ecore_evas_data_set(info->ee, "dynamic,box,info", info);
455 ecore_evas_manual_render_set(info->ee, EINA_FALSE);
456 ecore_evas_resize(info->ee, 1, 1);
458 info->e = ecore_evas_get(info->ee);
460 ErrPrint("Failed to get evas\n");
461 ecore_evas_free(info->ee);
465 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_POST, post_render_cb, info);
466 evas_event_callback_add(info->e, EVAS_CALLBACK_RENDER_PRE, pre_render_cb, info);
468 rect = evas_object_rectangle_add(info->e);
470 ErrPrint("Failed to create evas_object\n");
471 ecore_evas_free(info->ee);
475 evas_object_resize(rect, 1, 1);
476 evas_object_color_set(rect, 0, 0, 0, 0);