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>
35 #include <Ecore_Wayland.h>
36 #include <wayland-client.h>
37 #include <wayland-tbm-client.h>
38 #include <tizen-extension-client-protocol.h>
39 #include <screenshooter-client-protocol.h>
46 #define LOG_TAG "TIZEN_N_EFL_UTIL"
49 /* callback handler index */
50 #define CBH_NOTI_LEV 0
51 #define CBH_SCR_MODE 1
54 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
56 typedef struct _Efl_Util_Callback_Info
61 } Efl_Util_Callback_Info;
63 typedef struct _Efl_Util_Wl_Surface_Lv_Info
65 void *surface; /* wl_surface */
67 Eina_Bool wait_for_done;
69 } Efl_Util_Wl_Surface_Lv_Info;
71 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
73 void *surface; /* wl_surface */
75 Eina_Bool wait_for_done;
77 } Efl_Util_Wl_Surface_Scr_Mode_Info;
79 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
81 void *surface; /* wl_surface */
83 Eina_Bool wait_for_done;
85 } Efl_Util_Wl_Surface_Brightness_Info;
87 typedef struct _Efl_Util_Wl_Output_Info
89 struct wl_output *output;
90 int offset_x, offset_y, width, height;
91 } Efl_Util_Wl_Output_Info;
93 typedef struct _Efl_Util_Data
95 /* wayland related stuffs */
99 struct wl_display *dpy;
100 struct wl_event_queue *queue;
104 struct tizen_policy *proto;
105 Eina_Hash *hash_noti_lv;
106 Eina_Hash *hash_scr_mode;
110 struct wl_event_queue *queue;
111 struct screenshooter *screenshooter;
112 struct tizen_screenshooter *tz_screenshooter;
113 struct wayland_tbm_client *tbm_client;
114 Eina_List *output_list;
119 struct tizen_input_device_manager *devicemgr;
120 int request_notified;
124 struct tizen_display_policy *proto;
125 Eina_Hash *hash_brightness;
131 Eina_List *info_list; /* list of callback info */
132 unsigned int atom; /* x11 atom */
133 } cb_handler[CBH_MAX];
136 static Efl_Util_Data _eflutil =
141 { NULL, NULL, NULL }, /* tizen_policy protocol */
142 { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
143 { NULL, -1 } /* tizen_input_device_manager protocol */
146 { NULL, 0 }, /* handler for notification level */
147 { NULL, 0 } /* handler for screen mode */
151 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
152 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
153 static Eina_List *_cb_info_list_get(int idx);
154 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
155 static Eina_Bool _wl_init(void);
156 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
157 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
158 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
159 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
160 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
161 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
162 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);
163 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);
164 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
165 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);
166 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);
167 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);
168 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
169 static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options);
171 static void _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state);
173 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);
174 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);
175 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
176 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
178 static const struct wl_registry_listener _wl_reg_listener =
181 _cb_wl_reg_global_remove
184 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
186 _cb_wl_reg_screenshooter_global,
187 _cb_wl_reg_screenshooter_global_remove
190 struct tizen_policy_listener _wl_tz_policy_listener =
192 _cb_wl_tz_policy_conformant,
193 _cb_wl_tz_policy_conformant_area,
194 _cb_wl_tz_policy_notification_done,
195 _cb_wl_tz_policy_transient_for_done,
196 _cb_wl_tz_policy_scr_mode_done,
197 _cb_wl_tz_policy_iconify_state_changed,
198 _cb_wl_tz_policy_supported_aux_hints,
199 _cb_wl_tz_policy_allowed_aux_hint,
200 _cb_wl_tz_policy_aux_message,
203 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
211 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
213 _cb_wl_tz_display_policy_brightness_done,
217 _cb_info_add(Evas_Object *win,
222 Efl_Util_Callback_Info *info;
224 info = _cb_info_find_by_win(win, idx);
227 _eflutil.cb_handler[idx].info_list
228 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
233 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
234 if (!info) return EINA_FALSE;
240 _eflutil.cb_handler[idx].info_list
241 = eina_list_append(_eflutil.cb_handler[idx].info_list,
248 _cb_info_del_by_win(Evas_Object *win,
251 Efl_Util_Callback_Info *info;
253 info = _cb_info_find_by_win(win, idx);
254 if (!info) return EINA_FALSE;
256 _eflutil.cb_handler[idx].info_list
257 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
265 _cb_info_list_get(int idx)
267 return _eflutil.cb_handler[idx].info_list;
270 static Efl_Util_Callback_Info *
271 _cb_info_find_by_win(Evas_Object *win,
275 Efl_Util_Callback_Info *info;
277 l = _cb_info_list_get(idx);
278 EINA_LIST_FOREACH(l, ll, info)
280 if (info->win == win) return info;
289 struct wl_registry *reg = NULL;
291 if (_eflutil.wl.init) return EINA_TRUE;
295 _eflutil.wl.dpy = ecore_wl_display_get();
296 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
298 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
299 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
301 reg = wl_display_get_registry(_eflutil.wl.dpy);
302 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
304 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
305 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
307 _eflutil.wl.init = EINA_TRUE;
311 if (_eflutil.wl.queue)
313 wl_event_queue_destroy(_eflutil.wl.queue);
314 _eflutil.wl.queue = NULL;
322 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
323 int physical_width, int physical_height, int subpixel,
324 const char *make, const char *model, int transform)
326 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
327 if (wl_output == output->output)
329 output->offset_x = x;
330 output->offset_y = y;
335 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
336 int width, int height, int refresh)
338 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
339 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
341 output->width = width;
342 output->height = height;
347 _cb_wl_output_done(void *data, struct wl_output *wl_output)
352 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
356 static const struct wl_output_listener output_listener =
358 _cb_wl_output_geometry,
365 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
367 Eina_Bool *shot_done = (Eina_Bool*)data;
369 *shot_done = EINA_TRUE;
372 static const struct screenshooter_listener screenshooter_listener =
374 _cb_wl_screenshot_done
378 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
383 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
385 _eflutil.wl.shot.noti = noti;
388 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
390 _cb_tz_screenshot_format,
391 _cb_tz_screenshot_noti
395 _cb_wl_reg_global(void *data,
396 struct wl_registry *reg,
398 const char *interface,
399 unsigned int version)
401 if (!strcmp(interface, "tizen_policy"))
403 struct tizen_policy *proto;
404 proto = wl_registry_bind(reg,
406 &tizen_policy_interface,
410 tizen_policy_add_listener(proto,
411 &_wl_tz_policy_listener,
414 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
415 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
416 _eflutil.wl.policy.proto = proto;
418 else if (strcmp(interface, "wl_output") == 0)
420 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
421 EINA_SAFETY_ON_NULL_RETURN(output);
423 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
425 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
426 wl_output_add_listener(output->output, &output_listener, output);
428 else if (strcmp(interface, "tizen_input_device_manager") == 0)
430 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
431 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
433 else if (!strcmp(interface, "tizen_display_policy"))
435 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
436 if (!_eflutil.wl.display_policy.proto) return;
438 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
439 &_wl_tz_display_policy_listener,
442 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
446 /* LCOV_EXCL_START */
448 _cb_wl_reg_global_remove(void *data,
449 struct wl_registry *reg,
452 _eflutil.wl.policy.proto = NULL;
453 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
454 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
456 _eflutil.wl.display_policy.proto = NULL;
457 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
462 _cb_wl_reg_screenshooter_global(void *data,
463 struct wl_registry *reg,
465 const char *interface,
466 unsigned int version)
468 if (strcmp(interface, "screenshooter") == 0)
470 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
471 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
473 else if (strcmp(interface, "tizen_screenshooter") == 0)
475 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
476 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
478 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
482 /* LCOV_EXCL_START */
484 _cb_wl_reg_screenshooter_global_remove(void *data,
485 struct wl_registry *reg,
490 static Efl_Util_Callback_Info *
491 _cb_info_find_by_wlsurf(void *wlsurf,
495 Efl_Util_Callback_Info *info;
496 Ecore_Wl_Window *wlwin2 = NULL;
497 void *wlsurf2 = NULL;
499 l = _cb_info_list_get(idx);
500 EINA_LIST_FOREACH(l, ll, info)
502 wlwin2 = elm_win_wl_window_get(info->win);
503 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
504 if (wlsurf== wlsurf2) return info;
511 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
512 struct wl_surface *surface, uint32_t is_conformant)
517 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
518 struct wl_surface *surface, uint32_t conformant_part,
519 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
525 _cb_wl_tz_policy_notification_done(void *data,
526 struct tizen_policy *tizen_policy,
527 struct wl_surface *surface,
531 Efl_Util_Wl_Surface_Lv_Info *lv_info;
532 Efl_Util_Callback_Info *cb_info;
534 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
537 lv_info->level = level;
538 lv_info->wait_for_done = EINA_FALSE;
539 lv_info->state = state;
542 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
544 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
545 if (!cb_info) return;
546 if (!cb_info->cb) return;
548 cb_info->cb(cb_info->win,
549 EFL_UTIL_ERROR_PERMISSION_DENIED,
553 /* LCOV_EXCL_START */
555 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
561 _cb_wl_tz_policy_scr_mode_done(void *data,
562 struct tizen_policy *tizen_policy,
563 struct wl_surface *surface,
568 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
569 Efl_Util_Callback_Info *cb_info;
571 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
574 scr_mode_info->mode = mode;
575 scr_mode_info->wait_for_done = EINA_FALSE;
576 scr_mode_info->state = state;
579 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
581 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
582 if (!cb_info) return;
583 if (!cb_info->cb) return;
585 cb_info->cb(cb_info->win,
586 EFL_UTIL_ERROR_PERMISSION_DENIED,
590 /* LCOV_EXCL_START */
591 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)
595 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)
599 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
603 static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options)
609 _cb_wl_tz_display_policy_brightness_done(void *data,
610 struct tizen_display_policy *tizen_display_policy,
611 struct wl_surface *surface,
615 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
617 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
620 brightness_info->brightness = brightness;
621 brightness_info->wait_for_done = EINA_FALSE;
622 brightness_info->state = state;
627 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
629 Efl_Util_Wl_Surface_Lv_Info *lv_info;
632 if (EINA_UNLIKELY(!lv_info))
635 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
639 efl_util_set_notification_window_level(Evas_Object *window,
640 efl_util_notification_level_e level)
644 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
645 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
646 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
647 EFL_UTIL_ERROR_INVALID_PARAMETER);
649 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
651 dlog_print(DLOG_WARN, LOG_TAG,
652 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
654 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
656 dlog_print(DLOG_WARN, LOG_TAG,
657 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
659 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
661 dlog_print(DLOG_WARN, LOG_TAG,
662 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
666 Ecore_Wl_Window *wlwin;
667 struct wl_surface *surface;
668 Efl_Util_Wl_Surface_Lv_Info *lv_info;
669 Ecore_Wl_Window_Type wl_type;
672 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
674 wlwin = elm_win_wl_window_get(window);
675 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
677 type = elm_win_type_get(window);
678 if (type != ELM_WIN_NOTIFICATION)
680 wl_type = ecore_wl_window_type_get(wlwin);
681 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
682 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
685 while (!_eflutil.wl.policy.proto)
686 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
688 surface = ecore_wl_window_surface_get(wlwin);
689 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
690 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
692 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
695 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
696 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
698 lv_info->surface = surface;
699 lv_info->level = (int)level;
700 lv_info->wait_for_done = EINA_TRUE;
701 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
702 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
706 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
707 _cb_window_del, lv_info);
711 lv_info->level = (int)level;
712 lv_info->wait_for_done = EINA_TRUE;
713 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
717 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
718 surface, (int)level);
720 if (lv_info->wait_for_done)
723 while (lv_info->wait_for_done && (count < 3))
726 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
730 if (lv_info->wait_for_done)
732 return EFL_UTIL_ERROR_INVALID_PARAMETER;
736 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
738 return EFL_UTIL_ERROR_PERMISSION_DENIED;
743 return EFL_UTIL_ERROR_NONE;
747 efl_util_get_notification_window_level(Evas_Object *window,
748 efl_util_notification_level_e *level)
752 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
753 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
756 Ecore_Wl_Window *wlwin;
757 struct wl_surface *surface;
758 Efl_Util_Wl_Surface_Lv_Info *lv_info;
759 Ecore_Wl_Window_Type wl_type;
762 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
764 wlwin = elm_win_wl_window_get(window);
765 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
767 type = elm_win_type_get(window);
768 if (type != ELM_WIN_NOTIFICATION)
770 wl_type = ecore_wl_window_type_get(wlwin);
771 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
772 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
775 while (!_eflutil.wl.policy.proto)
776 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
778 surface = ecore_wl_window_surface_get(wlwin);
779 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
780 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
782 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
785 if (lv_info->wait_for_done)
788 while ((lv_info->wait_for_done) && (count < 3))
791 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
795 if (lv_info->wait_for_done)
797 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
798 return EFL_UTIL_ERROR_INVALID_PARAMETER;
802 switch (lv_info->level)
804 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
805 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
806 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
807 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
808 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
809 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
810 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
811 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
812 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
813 return EFL_UTIL_ERROR_INVALID_PARAMETER;
815 return EFL_UTIL_ERROR_NONE;
818 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
820 return EFL_UTIL_ERROR_NONE;
824 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
825 efl_util_notification_window_level_error_cb callback,
828 dlog_print(DLOG_WARN, LOG_TAG,
829 "DEPRECATION WARNING: efl_util_set_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead.");
831 Eina_Bool ret = EINA_FALSE;
833 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
834 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
836 ret = _cb_info_add(window,
837 (Efl_Util_Cb)callback,
840 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
842 return EFL_UTIL_ERROR_NONE;
846 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
848 dlog_print(DLOG_WARN, LOG_TAG,
849 "DEPRECATION WARNING: efl_util_unset_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead.");
851 Eina_Bool ret = EINA_FALSE;
853 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
855 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
856 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
858 return EFL_UTIL_ERROR_NONE;
862 efl_util_set_window_opaque_state(Evas_Object *window,
867 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
868 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
869 EFL_UTIL_ERROR_INVALID_PARAMETER);
871 Ecore_Wl_Window *wlwin;
872 struct wl_surface *surface;
874 if (!_eflutil.wl.policy.proto)
879 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
881 while (!_eflutil.wl.policy.proto && ret != -1)
882 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
884 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
887 wlwin = elm_win_wl_window_get(window);
889 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
891 surface = ecore_wl_window_surface_get(wlwin);
893 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
895 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
897 return EFL_UTIL_ERROR_NONE;
901 efl_util_set_window_screen_mode(Evas_Object *window,
902 efl_util_screen_mode_e mode)
904 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
905 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
906 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
907 EFL_UTIL_ERROR_INVALID_PARAMETER);
909 Ecore_Wl_Window *wlwin;
910 struct wl_surface *surface;
911 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
915 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
917 wlwin = elm_win_wl_window_get(window);
920 while (!_eflutil.wl.policy.proto)
921 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
923 surface = ecore_wl_window_surface_get(wlwin);
924 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
925 EFL_UTIL_ERROR_INVALID_PARAMETER);
927 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
930 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
931 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
933 scr_mode_info->surface = surface;
934 scr_mode_info->mode = (unsigned int)mode;
935 scr_mode_info->wait_for_done = EINA_TRUE;
936 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
938 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
944 scr_mode_info->mode = (unsigned int)mode;
945 scr_mode_info->wait_for_done = EINA_TRUE;
946 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
949 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
950 surface, (unsigned int)mode);
951 if (scr_mode_info->wait_for_done)
954 while (scr_mode_info->wait_for_done && (count < 3))
957 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
961 if (scr_mode_info->wait_for_done)
963 return EFL_UTIL_ERROR_INVALID_PARAMETER;
967 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
969 return EFL_UTIL_ERROR_PERMISSION_DENIED;
974 return EFL_UTIL_ERROR_NONE;
977 return EFL_UTIL_ERROR_INVALID_PARAMETER;
981 efl_util_get_window_screen_mode(Evas_Object *window,
982 efl_util_screen_mode_e *mode)
984 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
985 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
987 Ecore_Wl_Window *wlwin;
988 struct wl_surface *surface;
989 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
993 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
995 wlwin = elm_win_wl_window_get(window);
998 while (!_eflutil.wl.policy.proto)
999 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1001 surface = ecore_wl_window_surface_get(wlwin);
1002 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1003 EFL_UTIL_ERROR_INVALID_PARAMETER);
1005 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1008 if (scr_mode_info->wait_for_done)
1010 while (scr_mode_info->wait_for_done)
1013 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1017 switch (scr_mode_info->mode)
1019 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1020 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1021 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1022 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1024 return EFL_UTIL_ERROR_NONE;
1028 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1029 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1033 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1036 #ifndef TIZEN_WEARABLE
1038 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1039 efl_util_window_screen_mode_error_cb callback,
1042 dlog_print(DLOG_WARN, LOG_TAG,
1043 "DEPRECATION WARNING: efl_util_set_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
1045 Eina_Bool ret = EINA_FALSE;
1047 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1048 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1050 ret = _cb_info_add(window,
1051 (Efl_Util_Cb)callback,
1054 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1056 return EFL_UTIL_ERROR_NONE;
1060 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1062 dlog_print(DLOG_WARN, LOG_TAG,
1063 "DEPRECATION WARNING: efl_util_unset_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
1065 Eina_Bool ret = EINA_FALSE;
1067 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1069 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1070 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1072 return EFL_UTIL_ERROR_NONE;
1077 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1079 Ecore_Wl_Window *wlwin;
1080 struct wl_surface *surface;
1081 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1084 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1085 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1088 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1090 wlwin = elm_win_wl_window_get(window);
1093 while (!_eflutil.wl.display_policy.proto)
1094 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1096 surface = ecore_wl_window_surface_get(wlwin);
1097 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1098 EFL_UTIL_ERROR_INVALID_PARAMETER);
1100 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1101 if (!brightness_info)
1103 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1104 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1106 brightness_info->surface = surface;
1107 brightness_info->brightness = brightness;
1108 brightness_info->wait_for_done = EINA_TRUE;
1109 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1111 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1117 brightness_info->brightness = brightness;
1118 brightness_info->wait_for_done = EINA_TRUE;
1119 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1122 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1123 surface, brightness);
1124 if (brightness_info->wait_for_done)
1127 while (brightness_info->wait_for_done && (count < 3))
1130 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1134 if (brightness_info->wait_for_done)
1136 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1140 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1142 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1146 return EFL_UTIL_ERROR_NONE;
1149 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1153 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1155 Ecore_Wl_Window *wlwin;
1156 struct wl_surface *surface;
1157 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1160 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1161 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1164 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1166 wlwin = elm_win_wl_window_get(window);
1167 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1169 while (!_eflutil.wl.display_policy.proto)
1170 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1172 surface = ecore_wl_window_surface_get(wlwin);
1173 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1174 EFL_UTIL_ERROR_INVALID_PARAMETER);
1176 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1177 if (brightness_info)
1179 if (brightness_info->wait_for_done)
1181 while (brightness_info->wait_for_done)
1184 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1187 *brightness = brightness_info->brightness;
1192 return EFL_UTIL_ERROR_NONE;
1196 struct _efl_util_inputgen_h
1198 unsigned int init_type;
1202 _cb_device_add(void *data EINA_UNUSED,
1203 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1204 uint32_t serial EINA_UNUSED,
1205 const char *identifier EINA_UNUSED,
1206 struct tizen_input_device *device EINA_UNUSED,
1207 struct wl_seat *seat EINA_UNUSED)
1212 /* LCOV_EXCL_START */
1214 _cb_device_remove(void *data EINA_UNUSED,
1215 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1216 uint32_t serial EINA_UNUSED,
1217 const char *identifier EINA_UNUSED,
1218 struct tizen_input_device *device EINA_UNUSED,
1219 struct wl_seat *seat EINA_UNUSED)
1223 /* LCOV_EXCL_STOP */
1226 _cb_error(void *data EINA_UNUSED,
1227 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1230 _eflutil.wl.devmgr.request_notified = errorcode;
1233 /* LCOV_EXCL_START */
1235 _cb_block_expired(void *data EINA_UNUSED,
1236 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1240 /* LCOV_EXCL_STOP */
1242 static efl_util_error_e
1243 _efl_util_input_convert_input_generator_error(int ret)
1247 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1248 return EFL_UTIL_ERROR_NONE;
1249 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1250 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1251 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1252 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1253 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1254 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1256 return EFL_UTIL_ERROR_NONE;
1260 API efl_util_inputgen_h
1261 efl_util_input_initialize_generator(unsigned int dev_type)
1263 int ret = EFL_UTIL_ERROR_NONE;
1264 efl_util_inputgen_h inputgen_h = NULL;
1267 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1268 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1269 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1271 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1275 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1278 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1282 inputgen_h->init_type |= dev_type;
1285 if (ret == (int)EINA_FALSE)
1287 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1291 while (!_eflutil.wl.devmgr.devicemgr)
1292 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1294 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
1296 while (_eflutil.wl.devmgr.request_notified == -1)
1297 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1299 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1300 _eflutil.wl.devmgr.request_notified = -1;
1302 set_last_result(ret);
1303 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1318 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1320 int ret = EFL_UTIL_ERROR_NONE;
1321 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1326 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1328 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
1330 while (_eflutil.wl.devmgr.request_notified == -1)
1331 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1333 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1334 _eflutil.wl.devmgr.request_notified = -1;
1340 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1342 int ret = EFL_UTIL_ERROR_NONE;
1344 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1345 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1346 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1347 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1349 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1351 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1353 while (_eflutil.wl.devmgr.request_notified == -1)
1354 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1356 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1357 _eflutil.wl.devmgr.request_notified = -1;
1363 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1364 efl_util_input_touch_type_e touch_type, int x, int y)
1367 enum tizen_input_device_manager_pointer_event_type type;
1369 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1370 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1371 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1372 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1374 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1378 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1379 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1381 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1382 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1384 case EFL_UTIL_INPUT_TOUCH_END:
1385 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1388 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1391 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
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;
1403 efl_util_input_generate_pointer(efl_util_inputgen_h inputgen_h, int buttons, efl_util_input_pointer_type_e pointer_type, int x, int y)
1406 enum tizen_input_device_manager_pointer_event_type type;
1408 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1409 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1410 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1411 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1413 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1415 switch(pointer_type)
1417 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1418 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1420 case EFL_UTIL_INPUT_POINTER_MOVE:
1421 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1423 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1424 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1427 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1430 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1432 while (_eflutil.wl.devmgr.request_notified == -1)
1433 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1435 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1436 _eflutil.wl.devmgr.request_notified = -1;
1442 struct _efl_util_screenshot_h
1447 Eina_Bool shot_done;
1453 /* scrrenshot handle */
1454 static efl_util_screenshot_h g_screenshot;
1455 static Eina_Bool shot_mutex_init;
1456 static pthread_mutex_t shot_lock;
1459 _screenshot_mutex_init(void)
1461 if (shot_mutex_init)
1464 if (pthread_mutex_init(&shot_lock, NULL))
1466 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1467 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1470 shot_mutex_init = EINA_TRUE;
1476 _screenshot_mutex_destory(void)
1478 if (!shot_mutex_init)
1481 if (pthread_mutex_destroy(&shot_lock))
1483 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1484 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1487 shot_mutex_init = EINA_FALSE;
1493 _screenshot_mutex_lock(void)
1495 if (!_screenshot_mutex_init())
1498 pthread_mutex_lock(&shot_lock);
1502 _screenshot_mutex_unlock(void)
1504 pthread_mutex_unlock(&shot_lock);
1507 API efl_util_screenshot_h
1508 efl_util_screenshot_initialize(int width, int height)
1510 efl_util_screenshot_h screenshot = NULL;
1511 struct wl_display *display_wrapper = NULL;
1512 struct wl_registry *reg = NULL;
1515 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1516 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1518 _screenshot_mutex_lock();
1520 if (!_eflutil.wl.shot.screenshooter)
1523 if (ret == (int)EINA_FALSE)
1525 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1526 _screenshot_mutex_unlock();
1529 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1531 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1532 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
1534 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1535 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_init);
1537 reg = wl_display_get_registry(display_wrapper);
1538 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1540 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.shot.queue);
1542 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1544 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1545 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1546 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1547 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1549 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1550 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1553 if (_eflutil.wl.shot.noti == 0)
1555 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1561 if (g_screenshot->width != width || g_screenshot->height != height)
1563 g_screenshot->width = width;
1564 g_screenshot->height = height;
1567 _screenshot_mutex_unlock();
1569 return g_screenshot;
1572 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1573 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1575 screenshot->width = width;
1576 screenshot->height = height;
1578 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1579 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1581 g_screenshot = screenshot;
1582 set_last_result(EFL_UTIL_ERROR_NONE);
1584 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1586 _screenshot_mutex_unlock();
1588 return g_screenshot;
1591 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1594 /* LCOV_EXCL_START */
1595 if (display_wrapper)
1596 wl_proxy_wrapper_destroy(display_wrapper);
1597 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1599 /* LCOV_EXCL_STOP */
1602 efl_util_screenshot_deinitialize(screenshot);
1603 _screenshot_mutex_unlock();
1604 if (display_wrapper)
1605 wl_proxy_wrapper_destroy(display_wrapper);
1606 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1611 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1613 _screenshot_mutex_lock();
1617 _screenshot_mutex_unlock();
1618 _screenshot_mutex_destory();
1619 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1623 g_screenshot = NULL;
1625 if (_eflutil.wl.shot.queue)
1627 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1628 _eflutil.wl.shot.queue = NULL;
1631 if (_eflutil.wl.shot.screenshooter)
1633 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1634 _eflutil.wl.shot.screenshooter = NULL;
1636 if (_eflutil.wl.shot.tz_screenshooter)
1638 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1639 _eflutil.wl.shot.tz_screenshooter = NULL;
1642 _screenshot_mutex_unlock();
1643 _screenshot_mutex_destory();
1645 return EFL_UTIL_ERROR_NONE;
1650 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1652 tbm_surface_h t_surface = NULL;
1653 struct wl_buffer *buffer = NULL;
1654 Efl_Util_Wl_Output_Info *output;
1657 _screenshot_mutex_lock();
1659 if (!screenshot || (screenshot != g_screenshot))
1661 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1662 _screenshot_mutex_unlock();
1666 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1669 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1673 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1676 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1680 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1683 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1687 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1689 screenshot->shot_done = EINA_FALSE;
1690 while (!screenshot->shot_done && ret != -1)
1691 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1695 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1699 wl_buffer_destroy(buffer);
1701 /* reset shot_done for next screenshot */
1702 screenshot->shot_done = EINA_FALSE;
1704 _screenshot_mutex_unlock();
1710 tbm_surface_destroy(t_surface);
1712 wl_buffer_destroy(buffer);
1714 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1716 _screenshot_mutex_unlock();