2 * Copyright (c) 2011-2015 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 #define LOG_TAG "TIZEN_N_EFL_UTIL"
24 #include <sys/types.h>
28 #include <tbm_bufmgr.h>
29 #include <tbm_surface.h>
30 #include <tbm_surface_internal.h>
31 #include <Elementary.h>
32 #include <Ecore_Evas.h>
36 #include <X11/extensions/Xvlib.h>
37 #include <X11/extensions/Xvproto.h>
38 #include <X11/extensions/Xdamage.h>
42 #endif /* end of X11 */
45 #include <Ecore_Wayland.h>
46 #include <wayland-client.h>
47 #include <wayland-tbm-client.h>
48 #include <tizen-extension-client-protocol.h>
49 #include <screenshooter-client-protocol.h>
50 #endif /* end of WAYLAND */
52 /* callback handler index */
53 #define CBH_NOTI_LEV 0
54 #define CBH_SCR_MODE 1
57 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
59 typedef struct _Efl_Util_Callback_Info
64 } Efl_Util_Callback_Info;
67 typedef struct _Efl_Util_Wl_Surface_Lv_Info
69 void *surface; /* wl_surface */
71 Eina_Bool wait_for_done;
73 } Efl_Util_Wl_Surface_Lv_Info;
75 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
77 void *surface; /* wl_surface */
79 Eina_Bool wait_for_done;
81 } Efl_Util_Wl_Surface_Scr_Mode_Info;
83 typedef struct _Efl_Util_Wl_Output_Info
85 struct wl_output *output;
86 int offset_x, offset_y, width, height;
87 } Efl_Util_Wl_Output_Info;
90 typedef struct _Efl_Util_Data
93 /* x11 related stuffs */
97 Ecore_Event_Handler *handler; /* x11 client message handler */
100 #endif /* end of X11 */
103 /* wayland related stuffs */
107 struct wl_display *dpy;
108 struct wl_event_queue *queue;
112 struct tizen_policy *proto;
113 Eina_Hash *hash_noti_lv;
114 Eina_Hash *hash_scr_mode;
118 struct screenshooter *screenshooter;
119 struct wayland_tbm_client *tbm_client;
120 Eina_List *output_list;
124 struct tizen_input_device_manager *devicemgr;
125 int request_notified;
128 #endif /* end of WAYLAND */
132 Eina_List *info_list; /* list of callback info */
133 unsigned int atom; /* x11 atom */
134 } cb_handler[CBH_MAX];
137 static Efl_Util_Data _eflutil =
145 #endif /* end of X11 */
150 { NULL, NULL, NULL }, /* tizen_policy protocol */
151 { NULL, NULL, NULL }, /* screenshooter protocol */
152 { NULL, -1 } /* tizen_input_device_manager protocol */
154 #endif /* end of WAYLAND */
156 { NULL, 0 }, /* handler for notification level */
157 { NULL, 0 } /* handler for screen mode */
161 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
162 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
163 static Eina_List *_cb_info_list_get(int idx);
164 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
166 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin, int idx);
167 static Eina_Bool _cb_x11_client_msg(void *data, int type, void *event);
168 static Eina_Bool _x11_init(void);
169 #endif /* end of X11 */
171 static Eina_Bool _wl_init(void);
172 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
173 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
174 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
175 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
176 static void _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h);
177 static void _cb_wl_tz_policy_notification_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, int32_t level, uint32_t state);
178 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
179 static void _cb_wl_tz_policy_scr_mode_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t mode, uint32_t state);
180 static void _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force);
181 static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints);
182 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
184 static void _cb_device_add(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
185 static void _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
186 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
187 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
189 static const struct wl_registry_listener _wl_reg_listener =
192 _cb_wl_reg_global_remove
195 struct tizen_policy_listener _wl_tz_policy_listener =
197 _cb_wl_tz_policy_conformant,
198 _cb_wl_tz_policy_conformant_area,
199 _cb_wl_tz_policy_notification_done,
200 _cb_wl_tz_policy_transient_for_done,
201 _cb_wl_tz_policy_scr_mode_done,
202 _cb_wl_tz_policy_iconify_state_changed,
203 _cb_wl_tz_policy_supported_aux_hints,
204 _cb_wl_tz_policy_allowed_aux_hint,
207 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
215 #endif /* end of WAYLAND */
218 _cb_info_add(Evas_Object *win,
223 Efl_Util_Callback_Info *info;
225 info = _cb_info_find_by_win(win, idx);
228 _eflutil.cb_handler[idx].info_list
229 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
234 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
235 if (!info) return EINA_FALSE;
241 _eflutil.cb_handler[idx].info_list
242 = eina_list_append(_eflutil.cb_handler[idx].info_list,
246 if (!_eflutil.x11.handler)
247 _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
250 #endif /* end of X11 */
256 _cb_info_del_by_win(Evas_Object *win,
259 Efl_Util_Callback_Info *info;
261 info = _cb_info_find_by_win(win, idx);
262 if (!info) return EINA_FALSE;
264 _eflutil.cb_handler[idx].info_list
265 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
270 unsigned int count = eina_list_count(_eflutil.cb_handler[idx].info_list);
271 if ((count == 0) && (_eflutil.x11.handler))
273 ecore_event_handler_del(_eflutil.x11.handler);
274 _eflutil.x11.handler = NULL;
282 _cb_info_list_get(int idx)
284 return _eflutil.cb_handler[idx].info_list;
287 static Efl_Util_Callback_Info *
288 _cb_info_find_by_win(Evas_Object *win,
292 Efl_Util_Callback_Info *info;
294 l = _cb_info_list_get(idx);
295 EINA_LIST_FOREACH(l, ll, info)
297 if (info->win == win) return info;
304 static Efl_Util_Callback_Info *
305 _cb_info_find_by_xwin(unsigned int xwin,
309 Efl_Util_Callback_Info *info;
312 l = _cb_info_list_get(idx);
313 EINA_LIST_FOREACH(l, ll, info)
315 xwin2 = elm_win_xwindow_get(info->win);
316 if (xwin == xwin2) return info;
323 _cb_x11_client_msg(void *data,
327 Ecore_X_Event_Client_Message *ev;
329 Efl_Util_Callback_Info *info;
332 if (!ev) return ECORE_CALLBACK_PASS_ON;
335 if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
337 if (ev->message_type == _eflutil.cb_handler[CBH_NOTI_LEV].atom)
339 info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
341 /* permission denied */
342 if ((ev->data.l[1] == 0) &&
347 EFL_UTIL_ERROR_PERMISSION_DENIED,
351 else if (ev->message_type == _eflutil.cb_handler[CBH_SCR_MODE].atom)
353 info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
355 /* permission denied */
356 if ((ev->data.l[1] == 0) &&
361 EFL_UTIL_ERROR_PERMISSION_DENIED,
365 return ECORE_CALLBACK_PASS_ON;
371 if (_eflutil.x11.init) return EINA_TRUE;
373 _eflutil.x11.dpy = ecore_x_display_get();
374 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE);
376 _eflutil.x11.init = EINA_TRUE;
380 #endif /* end of X11 */
386 struct wl_registry *reg = NULL;
388 if (_eflutil.wl.init) return EINA_TRUE;
392 _eflutil.wl.dpy = ecore_wl_display_get();
393 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
395 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
396 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
398 reg = wl_display_get_registry(_eflutil.wl.dpy);
399 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
401 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
402 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
404 _eflutil.wl.init = EINA_TRUE;
408 if (_eflutil.wl.queue)
410 wl_event_queue_destroy(_eflutil.wl.queue);
411 _eflutil.wl.queue = NULL;
415 wl_registry_destroy(reg);
421 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
422 int physical_width, int physical_height, int subpixel,
423 const char *make, const char *model, int transform)
425 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
426 if (wl_output == output->output)
428 output->offset_x = x;
429 output->offset_y = y;
434 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
435 int width, int height, int refresh)
437 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
438 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
440 output->width = width;
441 output->height = height;
446 _cb_wl_output_done(void *data, struct wl_output *wl_output)
451 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
455 static const struct wl_output_listener output_listener =
457 _cb_wl_output_geometry,
464 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
466 Eina_Bool *shot_done = (Eina_Bool*)data;
468 *shot_done = EINA_TRUE;
471 static const struct screenshooter_listener screenshooter_listener =
473 _cb_wl_screenshot_done
477 _cb_wl_reg_global(void *data,
478 struct wl_registry *reg,
480 const char *interface,
481 unsigned int version)
483 if (!strcmp(interface, "tizen_policy"))
485 struct tizen_policy *proto;
486 proto = wl_registry_bind(reg,
488 &tizen_policy_interface,
492 tizen_policy_add_listener(proto,
493 &_wl_tz_policy_listener,
496 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
497 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
498 _eflutil.wl.policy.proto = proto;
500 else if (strcmp(interface, "wl_output") == 0)
502 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
503 EINA_SAFETY_ON_NULL_RETURN(output);
505 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
507 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
508 wl_output_add_listener(output->output, &output_listener, output);
510 else if (strcmp(interface, "screenshooter") == 0)
512 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
513 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
515 else if (strcmp(interface, "tizen_input_device_manager") == 0)
517 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
518 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
523 _cb_wl_reg_global_remove(void *data,
524 struct wl_registry *reg,
527 _eflutil.wl.policy.proto = NULL;
528 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
529 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
532 static Efl_Util_Callback_Info *
533 _cb_info_find_by_wlsurf(void *wlsurf,
537 Efl_Util_Callback_Info *info;
538 Ecore_Wl_Window *wlwin2 = NULL;
539 void *wlsurf2 = NULL;
541 l = _cb_info_list_get(idx);
542 EINA_LIST_FOREACH(l, ll, info)
544 wlwin2 = elm_win_wl_window_get(info->win);
545 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
546 if (wlsurf== wlsurf2) return info;
553 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
554 struct wl_surface *surface, uint32_t is_conformant)
559 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
560 struct wl_surface *surface, uint32_t conformant_part,
561 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
566 _cb_wl_tz_policy_notification_done(void *data,
567 struct tizen_policy *tizen_policy,
568 struct wl_surface *surface,
572 Efl_Util_Wl_Surface_Lv_Info *lv_info;
573 Efl_Util_Callback_Info *cb_info;
575 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
578 lv_info->level = level;
579 lv_info->wait_for_done = EINA_FALSE;
580 lv_info->state = state;
583 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
585 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
586 if (!cb_info) return;
587 if (!cb_info->cb) return;
589 cb_info->cb(cb_info->win,
590 EFL_UTIL_ERROR_PERMISSION_DENIED,
595 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
600 _cb_wl_tz_policy_scr_mode_done(void *data,
601 struct tizen_policy *tizen_policy,
602 struct wl_surface *surface,
607 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
608 Efl_Util_Callback_Info *cb_info;
610 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
613 scr_mode_info->mode = mode;
614 scr_mode_info->wait_for_done = EINA_FALSE;
615 scr_mode_info->state = state;
618 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
620 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
621 if (!cb_info) return;
622 if (!cb_info->cb) return;
624 cb_info->cb(cb_info->win,
625 EFL_UTIL_ERROR_PERMISSION_DENIED,
629 static void _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force)
633 static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints)
637 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
642 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
644 Efl_Util_Wl_Surface_Lv_Info *lv_info;
647 if (EINA_UNLIKELY(!lv_info))
650 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
652 #endif /* end of WAYLAND */
655 efl_util_set_notification_window_level(Evas_Object *window,
656 efl_util_notification_level_e level)
660 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
661 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
662 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
663 EFL_UTIL_ERROR_INVALID_PARAMETER);
666 Ecore_X_Window_Type window_type;
670 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
672 xwin = elm_win_xwindow_get(window);
675 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
677 // success to get window type
678 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
680 // given EFL window's type is not notification type.
681 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
685 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
687 utilx_set_system_notification_level(_eflutil.x11.dpy,
690 return EFL_UTIL_ERROR_NONE;
693 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
694 #endif /* end of X11 */
698 Ecore_Wl_Window *wlwin;
699 struct wl_surface *surface;
700 Efl_Util_Wl_Surface_Lv_Info *lv_info;
701 Ecore_Wl_Window_Type wl_type;
704 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
706 wlwin = elm_win_wl_window_get(window);
707 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
709 type = elm_win_type_get(window);
710 if (type != ELM_WIN_NOTIFICATION)
712 wl_type = ecore_wl_window_type_get(wlwin);
713 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
714 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
717 while (!_eflutil.wl.policy.proto)
718 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
720 surface = ecore_wl_window_surface_get(wlwin);
721 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
722 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
724 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
727 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
728 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
730 lv_info->surface = surface;
731 lv_info->level = (int)level;
732 lv_info->wait_for_done = EINA_TRUE;
733 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
734 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
738 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
739 _cb_window_del, lv_info);
743 lv_info->level = (int)level;
744 lv_info->wait_for_done = EINA_TRUE;
745 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
749 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
750 surface, (int)level);
752 if (lv_info->wait_for_done)
755 while (lv_info->wait_for_done && (count < 3))
758 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
762 if (lv_info->wait_for_done)
764 return EFL_UTIL_ERROR_INVALID_PARAMETER;
768 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
770 return EFL_UTIL_ERROR_PERMISSION_DENIED;
775 return EFL_UTIL_ERROR_NONE;
776 #endif /* end of WAYLAND */
780 efl_util_get_notification_window_level(Evas_Object *window,
781 efl_util_notification_level_e *level)
785 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
786 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
789 Ecore_X_Window_Type window_type;
790 Utilx_Notification_Level utilx_level;
794 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
796 xwin = elm_win_xwindow_get(window);
799 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
801 // success to get window type
802 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
804 // given EFL window's type is not notification type.
805 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
808 utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin);
809 if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
810 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
811 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
812 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
813 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
814 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
816 return EFL_UTIL_ERROR_INVALID_PARAMETER;
819 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
821 return EFL_UTIL_ERROR_NONE;
824 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
825 #endif /* end of X11 */
829 Ecore_Wl_Window *wlwin;
830 struct wl_surface *surface;
831 Efl_Util_Wl_Surface_Lv_Info *lv_info;
832 Ecore_Wl_Window_Type wl_type;
835 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
837 wlwin = elm_win_wl_window_get(window);
838 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
840 type = elm_win_type_get(window);
841 if (type != ELM_WIN_NOTIFICATION)
843 wl_type = ecore_wl_window_type_get(wlwin);
844 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
845 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
848 while (!_eflutil.wl.policy.proto)
849 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
851 surface = ecore_wl_window_surface_get(wlwin);
852 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
853 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
855 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
858 if (lv_info->wait_for_done)
861 while ((lv_info->wait_for_done) && (count < 3))
864 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
868 if (lv_info->wait_for_done)
870 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
871 return EFL_UTIL_ERROR_INVALID_PARAMETER;
875 switch (lv_info->level)
877 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
878 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
879 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
880 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
881 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
882 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
883 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
884 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
885 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
886 return EFL_UTIL_ERROR_INVALID_PARAMETER;
888 return EFL_UTIL_ERROR_NONE;
891 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
893 return EFL_UTIL_ERROR_NONE;
894 #endif /* end of WAYLAND */
898 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
899 efl_util_notification_window_level_error_cb callback,
902 Eina_Bool ret = EINA_FALSE;
904 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
905 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
907 ret = _cb_info_add(window,
908 (Efl_Util_Cb)callback,
911 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
914 if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom)
915 _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
916 #endif /* end of X11 */
918 return EFL_UTIL_ERROR_NONE;
922 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
924 Eina_Bool ret = EINA_FALSE;
926 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
928 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
929 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
931 return EFL_UTIL_ERROR_NONE;
935 efl_util_set_window_opaque_state(Evas_Object *window,
940 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
941 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
942 EFL_UTIL_ERROR_INVALID_PARAMETER);
946 Utilx_Opaque_State state;
950 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
952 xwin = elm_win_xwindow_get(window);
953 EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
956 state = UTILX_OPAQUE_STATE_ON;
958 state = UTILX_OPAQUE_STATE_OFF;
960 ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
965 return EFL_UTIL_ERROR_INVALID_PARAMETER;
967 return EFL_UTIL_ERROR_NONE;
968 #endif /* end of X11 */
971 Ecore_Wl_Window *wlwin;
972 struct wl_surface *surface;
974 if (!_eflutil.wl.policy.proto)
979 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
981 while (!_eflutil.wl.policy.proto && ret != -1)
982 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
984 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
987 wlwin = elm_win_wl_window_get(window);
989 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
991 surface = ecore_wl_window_surface_get(wlwin);
993 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
995 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
997 return EFL_UTIL_ERROR_NONE;
998 #endif /* end of WAYLAND */
1002 efl_util_set_window_screen_mode(Evas_Object *window,
1003 efl_util_screen_mode_e mode)
1005 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1006 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
1007 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
1008 EFL_UTIL_ERROR_INVALID_PARAMETER);
1015 e = evas_object_evas_get(window);
1016 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
1018 ee = ecore_evas_ecore_evas_get(e);
1019 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
1021 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1022 if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
1025 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
1027 ecore_evas_aux_hint_val_set(ee, id, "1");
1029 else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
1032 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
1034 ecore_evas_aux_hint_val_set(ee, id, "0");
1037 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1039 return EFL_UTIL_ERROR_NONE;
1040 #endif /* end of X11 */
1043 Ecore_Wl_Window *wlwin;
1044 struct wl_surface *surface;
1045 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1049 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1051 wlwin = elm_win_wl_window_get(window);
1054 while (!_eflutil.wl.policy.proto)
1055 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1057 surface = ecore_wl_window_surface_get(wlwin);
1058 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1059 EFL_UTIL_ERROR_INVALID_PARAMETER);
1061 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1064 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
1065 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1067 scr_mode_info->surface = surface;
1068 scr_mode_info->mode = (unsigned int)mode;
1069 scr_mode_info->wait_for_done = EINA_TRUE;
1070 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1072 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
1078 scr_mode_info->mode = (unsigned int)mode;
1079 scr_mode_info->wait_for_done = EINA_TRUE;
1080 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1083 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
1084 surface, (unsigned int)mode);
1085 if (scr_mode_info->wait_for_done)
1088 while (scr_mode_info->wait_for_done && (count < 3))
1091 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1095 if (scr_mode_info->wait_for_done)
1097 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1101 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1103 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1108 return EFL_UTIL_ERROR_NONE;
1111 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1112 #endif /* end of WAYLAND */
1116 efl_util_get_window_screen_mode(Evas_Object *window,
1117 efl_util_screen_mode_e *mode)
1119 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1120 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1128 e = evas_object_evas_get(window);
1129 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
1131 ee = ecore_evas_ecore_evas_get(e);
1132 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
1134 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1135 EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
1137 str = ecore_evas_aux_hint_val_get(ee, id);
1138 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
1140 if (strncmp(str, "1", strlen("1")) == 0)
1141 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1143 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1145 return EFL_UTIL_ERROR_NONE;
1146 #endif /* end of X11 */
1149 Ecore_Wl_Window *wlwin;
1150 struct wl_surface *surface;
1151 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1155 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1157 wlwin = elm_win_wl_window_get(window);
1160 while (!_eflutil.wl.policy.proto)
1161 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1163 surface = ecore_wl_window_surface_get(wlwin);
1164 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1165 EFL_UTIL_ERROR_INVALID_PARAMETER);
1167 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1170 if (scr_mode_info->wait_for_done)
1172 while (scr_mode_info->wait_for_done)
1175 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1179 switch (scr_mode_info->mode)
1181 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1182 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1183 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1184 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1186 return EFL_UTIL_ERROR_NONE;
1190 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1191 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1195 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1196 #endif /* end of WAYLAND */
1200 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1201 efl_util_window_screen_mode_error_cb callback,
1204 Eina_Bool ret = EINA_FALSE;
1206 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1207 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1209 ret = _cb_info_add(window,
1210 (Efl_Util_Cb)callback,
1213 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1216 if (!_eflutil.cb_handler[CBH_SCR_MODE].atom)
1217 _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
1218 #endif /* end of X11 */
1220 return EFL_UTIL_ERROR_NONE;
1224 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1226 Eina_Bool ret = EINA_FALSE;
1228 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1230 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1231 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1233 return EFL_UTIL_ERROR_NONE;
1236 struct _efl_util_inputgen_h
1238 unsigned int init_type;
1243 _cb_device_add(void *data EINA_UNUSED,
1244 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1245 uint32_t serial EINA_UNUSED,
1246 const char *identifier EINA_UNUSED,
1247 struct tizen_input_device *device EINA_UNUSED,
1248 struct wl_seat *seat EINA_UNUSED)
1254 _cb_device_remove(void *data EINA_UNUSED,
1255 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1256 uint32_t serial EINA_UNUSED,
1257 const char *identifier EINA_UNUSED,
1258 struct tizen_input_device *device EINA_UNUSED,
1259 struct wl_seat *seat EINA_UNUSED)
1265 _cb_error(void *data EINA_UNUSED,
1266 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1269 _eflutil.wl.devmgr.request_notified = errorcode;
1273 _cb_block_expired(void *data EINA_UNUSED,
1274 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1278 #endif /* end of WAYLAND */
1280 static efl_util_error_e
1281 _efl_util_input_convert_input_generator_error(int ret)
1285 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1286 return EFL_UTIL_ERROR_NONE;
1287 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1288 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1289 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1290 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1291 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1292 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1294 return EFL_UTIL_ERROR_NONE;
1298 API efl_util_inputgen_h
1299 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1301 int ret = EFL_UTIL_ERROR_NONE;
1302 efl_util_inputgen_h inputgen_h = NULL;
1304 if ((dev_type <= EFL_UTIL_INPUT_DEVTYPE_NONE) ||
1305 (dev_type >= EFL_UTIL_INPUT_DEVTYPE_MAX))
1307 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1311 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1314 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1318 inputgen_h->init_type |= dev_type;
1321 if (ret == (int)EINA_FALSE)
1323 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1327 while (!_eflutil.wl.devmgr.devicemgr)
1328 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1330 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
1332 while (_eflutil.wl.devmgr.request_notified == -1)
1333 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1335 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1336 _eflutil.wl.devmgr.request_notified = -1;
1338 set_last_result(ret);
1339 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1355 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1357 int ret = EFL_UTIL_ERROR_NONE;
1358 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1364 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1366 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
1368 while (_eflutil.wl.devmgr.request_notified == -1)
1369 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1371 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1372 _eflutil.wl.devmgr.request_notified = -1;
1379 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1381 int ret = EFL_UTIL_ERROR_NONE;
1383 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1384 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1385 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1386 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1389 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1391 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1393 while (_eflutil.wl.devmgr.request_notified == -1)
1394 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1396 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1397 _eflutil.wl.devmgr.request_notified = -1;
1404 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1405 efl_util_input_touch_type_e touch_type, int x, int y)
1409 enum tizen_input_device_manager_pointer_event_type type;
1412 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1413 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1414 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1415 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1418 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1422 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1423 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1425 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1426 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1428 case EFL_UTIL_INPUT_TOUCH_END:
1429 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1432 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1435 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1437 while (_eflutil.wl.devmgr.request_notified == -1)
1438 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1440 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1441 _eflutil.wl.devmgr.request_notified = -1;
1447 struct _efl_util_screenshot_h
1453 Ecore_X_Display *dpy;
1454 int internal_display;
1469 int eventBase, errorBase;
1470 int dri2Major, dri2Minor;
1471 char *driver_name, *device_name;
1478 Eina_Bool shot_done;
1484 /* scrrenshot handle */
1485 static efl_util_screenshot_h g_screenshot;
1488 #define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff))
1489 #define FOURCC_RGB32 FOURCC('R','G','B','4')
1490 #define TIMEOUT_CAPTURE 3
1492 /* x error handling */
1493 static Bool g_efl_util_x_error_caught;
1496 _efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev)
1498 if (!g_screenshot || (dpy != g_screenshot->dpy))
1501 g_efl_util_x_error_caught = True;
1507 _efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win)
1509 unsigned int ver, rev, req_base, evt_base, err_base;
1510 unsigned int adaptors;
1511 XvAdaptorInfo *ai = NULL;
1512 XvImageFormatValues *fo = NULL;
1516 if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success)
1518 fprintf(stderr, "[screenshot] fail: no XV extension. \n");
1522 if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success)
1524 fprintf(stderr, "[screenshot] fail: query adaptors. \n");
1528 EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1);
1530 for (i = 0; i < adaptors; i++)
1532 int support_format = False;
1534 if (!(ai[i].type & XvInputMask) ||
1535 !(ai[i].type & XvStillMask))
1540 fo = XvListImageFormats(dpy, p, &formats);
1541 for (j = 0; j < formats; j++)
1542 if (fo[j].id == (int)id)
1543 support_format = True;
1548 if (!support_format)
1551 for (; p < ai[i].base_id + ai[i].num_ports; p++)
1553 if (XvGrabPort(dpy, p, 0) == Success)
1555 XvFreeAdaptorInfo(ai);
1561 XvFreeAdaptorInfo(ai);
1569 _efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height)
1571 XErrorHandler old_handler = NULL;
1573 Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
1575 g_efl_util_x_error_caught = False;
1576 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1578 XvSetPortAttribute(dpy, port, atom_capture, 1);
1581 g_efl_util_x_error_caught = False;
1582 XSetErrorHandler(old_handler);
1584 XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height);
1585 if (best_width <= 0 || best_height <= 0)
1592 API efl_util_screenshot_h
1593 efl_util_screenshot_initialize(int width, int height)
1596 efl_util_screenshot_h screenshot = NULL;
1598 int damage_err_base = 0;
1599 unsigned int best_width = 0;
1600 unsigned int best_height = 0;
1602 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1603 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1605 if (g_screenshot != NULL)
1607 if (g_screenshot->width != width || g_screenshot->height != height)
1609 // TODO: recreate pixmap and update information
1610 if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height))
1612 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1616 g_screenshot->width = width;
1617 g_screenshot->height = height;
1620 return g_screenshot;
1623 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1624 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1627 screenshot->dpy = ecore_x_display_get();
1628 if (!screenshot->dpy)
1630 screenshot->dpy = XOpenDisplay(0);
1631 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init);
1633 /* for XCloseDisplay at denitialization */
1634 screenshot->internal_display = 1;
1638 screenshot->screen = DefaultScreen(screenshot->dpy);
1640 /* set root window */
1641 screenshot->root = DefaultRootWindow(screenshot->dpy);
1643 /* initialize capture adaptor */
1644 screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root);
1645 EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init);
1647 /* get the best size */
1648 _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height);
1649 EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init);
1650 EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init);
1652 /* set the width and the height */
1653 screenshot->width = best_width;
1654 screenshot->height = best_height;
1656 /* create a pixmap */
1657 depth = DefaultDepth(screenshot->dpy, screenshot->screen);
1658 screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth);
1659 EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init);
1661 screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0);
1662 EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init);
1664 XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000);
1665 XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height);
1667 /* initialize damage */
1668 if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base))
1671 screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty);
1672 EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init);
1674 /* initialize dri3 and dri2 */
1675 if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase))
1677 fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n");
1681 if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor))
1683 fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n");
1687 if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name))
1689 fprintf(stderr, "[screenshot] fail: DRI2Connect\n");
1693 screenshot->drm_fd = open(screenshot->device_name, O_RDWR);
1694 EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init);
1696 if (drmGetMagic(screenshot->drm_fd, &screenshot->magic))
1698 fprintf(stderr, "[screenshot] fail: drmGetMagic\n");
1702 if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic))
1704 fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n");
1708 if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic))
1710 fprintf(stderr, "[screenshot] fail: drmAuthMagic\n");
1714 DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap);
1717 screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd);
1718 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1720 XFlush(screenshot->dpy);
1722 g_screenshot = screenshot;
1723 set_last_result(EFL_UTIL_ERROR_NONE);
1725 return g_screenshot;
1729 efl_util_screenshot_h screenshot = NULL;
1731 if (!_eflutil.wl.shot.screenshooter)
1735 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1736 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1737 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1739 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1740 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1743 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1744 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1748 if (g_screenshot->width != width || g_screenshot->height != height)
1750 g_screenshot->width = width;
1751 g_screenshot->height = height;
1754 return g_screenshot;
1757 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1758 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1760 screenshot->width = width;
1761 screenshot->height = height;
1763 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1764 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1766 g_screenshot = screenshot;
1767 set_last_result(EFL_UTIL_ERROR_NONE);
1769 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1771 return g_screenshot;
1775 efl_util_screenshot_deinitialize(screenshot);
1776 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1780 efl_util_screenshot_deinitialize(screenshot);
1781 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1785 efl_util_screenshot_deinitialize(screenshot);
1786 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1791 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1795 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1798 if (screenshot->bufmgr)
1799 tbm_bufmgr_deinit(screenshot->bufmgr);
1801 DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap);
1804 if (screenshot->drm_fd)
1805 close(screenshot->drm_fd);
1806 if (screenshot->driver_name)
1807 free(screenshot->driver_name);
1808 if (screenshot->device_name)
1809 free(screenshot->device_name);
1812 if (screenshot->port > 0 && screenshot->pixmap > 0)
1813 XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap);
1816 if (screenshot->damage)
1817 XDamageDestroy(screenshot->dpy, screenshot->damage);
1821 XFreeGC(screenshot->dpy, screenshot->gc);
1824 if (screenshot->pixmap > 0)
1825 XFreePixmap(screenshot->dpy, screenshot->pixmap);
1828 if (screenshot->port > 0)
1829 XvUngrabPort(screenshot->dpy, screenshot->port, 0);
1831 XSync(screenshot->dpy, False);
1834 if (screenshot->internal_display ==1 && screenshot->dpy)
1835 XCloseDisplay(screenshot->dpy);
1838 g_screenshot = NULL;
1840 return EFL_UTIL_ERROR_NONE;
1844 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1847 g_screenshot = NULL;
1849 if (_eflutil.wl.shot.screenshooter)
1850 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1852 return EFL_UTIL_ERROR_NONE;
1858 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1862 XErrorHandler old_handler = NULL;
1863 unsigned int attachment = DRI2BufferFrontLeft;
1865 DRI2Buffer *bufs = NULL;
1867 tbm_surface_h t_surface = NULL;
1870 tbm_surface_info_s surf_info;
1873 if (screenshot != g_screenshot)
1875 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1879 /* for flush other pending requests and pending events */
1880 XSync(screenshot->dpy, 0);
1882 g_efl_util_x_error_caught = False;
1883 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1886 XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc,
1887 0, 0, screenshot->width, screenshot->height,
1888 0, 0, screenshot->width, screenshot->height);
1890 XSync(screenshot->dpy, 0);
1892 if (g_efl_util_x_error_caught)
1894 g_efl_util_x_error_caught = False;
1895 XSetErrorHandler(old_handler);
1899 g_efl_util_x_error_caught = False;
1900 XSetErrorHandler(old_handler);
1902 if (XPending(screenshot->dpy))
1903 XNextEvent(screenshot->dpy, &ev);
1906 int fd = ConnectionNumber(screenshot->dpy);
1915 tv.tv_sec = TIMEOUT_CAPTURE;
1917 ret = select(fd + 1, &mask, 0, 0, &tv);
1919 fprintf(stderr, "[screenshot] fail: select.\n");
1921 fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE);
1922 else if (XPending(screenshot->dpy))
1923 XNextEvent(screenshot->dpy, &ev);
1925 fprintf(stderr, "[screenshot] fail: not passed a event!\n");
1928 /* check if the capture is done by xserver and pixmap has got the captured image */
1929 if (ev.type == (screenshot->damage_base + XDamageNotify))
1931 XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
1932 if (damage_ev->drawable == screenshot->pixmap)
1934 /* Get DRI2 FrontLeft buffer of the pixmap */
1935 bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs);
1938 fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n");
1942 t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name);
1945 fprintf(stderr, "[screenshot] fail: import tbm_bo!\n");
1949 surf_info.width = buf_width;
1950 surf_info.height = buf_height;
1951 surf_info.format = TBM_FORMAT_XRGB8888;
1953 surf_info.size = bufs->pitch * surf_info.height;
1954 surf_info.num_planes = 1;
1955 for (i = 0; i < surf_info.num_planes; i++)
1957 surf_info.planes[i].size = bufs->pitch * surf_info.height;
1958 surf_info.planes[i].stride = bufs->pitch;
1959 surf_info.planes[i].offset = 0;
1961 t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1);
1964 fprintf(stderr, "[screenshot] fail: get tbm_surface!\n");
1971 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1973 set_last_result(EFL_UTIL_ERROR_NONE);
1978 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1988 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1994 tbm_surface_h t_surface = NULL;
1995 struct wl_buffer *buffer = NULL;
1996 Efl_Util_Wl_Output_Info *output;
1999 if (screenshot != g_screenshot)
2001 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2005 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
2008 fprintf(stderr, "[screenshot] fail: no output for screenshot\n");
2012 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
2015 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n");
2019 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
2022 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n");
2026 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
2028 screenshot->shot_done = EINA_FALSE;
2029 while (!screenshot->shot_done && ret != -1)
2030 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2034 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n");
2038 wl_buffer_destroy(buffer);
2040 /* reset shot_done for next screenshot */
2041 screenshot->shot_done = EINA_FALSE;
2047 tbm_surface_destroy(t_surface);
2049 wl_buffer_destroy(buffer);
2051 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);