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>
41 #include <efl_util_screenshot_extension.h>
48 #define LOG_TAG "TIZEN_N_EFL_UTIL"
51 /* callback handler index */
52 #define CBH_NOTI_LEV 0
53 #define CBH_SCR_MODE 1
56 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
58 typedef struct _Efl_Util_Callback_Info
63 } Efl_Util_Callback_Info;
65 typedef struct _Efl_Util_Wl_Surface_Lv_Info
67 void *surface; /* wl_surface */
69 Eina_Bool wait_for_done;
71 } Efl_Util_Wl_Surface_Lv_Info;
73 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
75 void *surface; /* wl_surface */
77 Eina_Bool wait_for_done;
79 } Efl_Util_Wl_Surface_Scr_Mode_Info;
81 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
83 void *surface; /* wl_surface */
85 Eina_Bool wait_for_done;
87 } Efl_Util_Wl_Surface_Brightness_Info;
89 typedef struct _Efl_Util_Wl_Output_Info
91 struct wl_output *output;
92 int offset_x, offset_y, width, height;
93 } Efl_Util_Wl_Output_Info;
95 typedef struct _Efl_Util_Data
97 /* wayland related stuffs */
101 struct wl_display *dpy;
102 struct wl_event_queue *queue;
106 struct tizen_policy *proto;
107 Eina_Hash *hash_noti_lv;
108 Eina_Hash *hash_scr_mode;
112 struct wl_event_queue *queue;
113 struct screenshooter *screenshooter;
114 struct tizen_screenshooter *tz_screenshooter;
115 struct wayland_tbm_client *tbm_client;
116 Eina_List *output_list;
121 struct tizen_input_device_manager *devicemgr;
122 int request_notified;
126 struct tizen_display_policy *proto;
127 Eina_Hash *hash_brightness;
133 Eina_List *info_list; /* list of callback info */
134 unsigned int atom; /* x11 atom */
135 } cb_handler[CBH_MAX];
138 static Efl_Util_Data _eflutil =
143 { NULL, NULL, NULL }, /* tizen_policy protocol */
144 { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
145 { NULL, -1 } /* tizen_input_device_manager protocol */
148 { NULL, 0 }, /* handler for notification level */
149 { NULL, 0 } /* handler for screen mode */
153 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
154 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
155 static Eina_List *_cb_info_list_get(int idx);
156 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
157 static Eina_Bool _wl_init(void);
158 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
159 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
160 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
161 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
162 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
163 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
164 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);
165 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);
166 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
167 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);
168 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);
169 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);
170 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
171 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);
173 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);
175 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);
176 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);
177 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
178 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
180 static const struct wl_registry_listener _wl_reg_listener =
183 _cb_wl_reg_global_remove
186 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
188 _cb_wl_reg_screenshooter_global,
189 _cb_wl_reg_screenshooter_global_remove
192 struct tizen_policy_listener _wl_tz_policy_listener =
194 _cb_wl_tz_policy_conformant,
195 _cb_wl_tz_policy_conformant_area,
196 _cb_wl_tz_policy_notification_done,
197 _cb_wl_tz_policy_transient_for_done,
198 _cb_wl_tz_policy_scr_mode_done,
199 _cb_wl_tz_policy_iconify_state_changed,
200 _cb_wl_tz_policy_supported_aux_hints,
201 _cb_wl_tz_policy_allowed_aux_hint,
202 _cb_wl_tz_policy_aux_message,
205 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
213 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
215 _cb_wl_tz_display_policy_brightness_done,
219 _cb_info_add(Evas_Object *win,
224 Efl_Util_Callback_Info *info;
226 info = _cb_info_find_by_win(win, idx);
229 _eflutil.cb_handler[idx].info_list
230 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
235 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
236 if (!info) return EINA_FALSE;
242 _eflutil.cb_handler[idx].info_list
243 = eina_list_append(_eflutil.cb_handler[idx].info_list,
250 _cb_info_del_by_win(Evas_Object *win,
253 Efl_Util_Callback_Info *info;
255 info = _cb_info_find_by_win(win, idx);
256 if (!info) return EINA_FALSE;
258 _eflutil.cb_handler[idx].info_list
259 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
267 _cb_info_list_get(int idx)
269 return _eflutil.cb_handler[idx].info_list;
272 static Efl_Util_Callback_Info *
273 _cb_info_find_by_win(Evas_Object *win,
277 Efl_Util_Callback_Info *info;
279 l = _cb_info_list_get(idx);
280 EINA_LIST_FOREACH(l, ll, info)
282 if (info->win == win) return info;
291 struct wl_display *display_wrapper = NULL;
292 struct wl_registry *reg = NULL;
294 if (_eflutil.wl.init) return EINA_TRUE;
298 _eflutil.wl.dpy = ecore_wl_display_get();
299 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
301 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
302 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail);
304 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
305 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
307 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
309 reg = wl_display_get_registry(display_wrapper);
310 wl_proxy_wrapper_destroy(display_wrapper);
311 display_wrapper = NULL;
312 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
314 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
316 _eflutil.wl.init = EINA_TRUE;
321 wl_proxy_wrapper_destroy(display_wrapper);
323 if (_eflutil.wl.queue)
325 wl_event_queue_destroy(_eflutil.wl.queue);
326 _eflutil.wl.queue = NULL;
334 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
335 int physical_width, int physical_height, int subpixel,
336 const char *make, const char *model, int transform)
338 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
339 if (wl_output == output->output)
341 output->offset_x = x;
342 output->offset_y = y;
347 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
348 int width, int height, int refresh)
350 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
351 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
353 output->width = width;
354 output->height = height;
359 _cb_wl_output_done(void *data, struct wl_output *wl_output)
364 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
368 static const struct wl_output_listener output_listener =
370 _cb_wl_output_geometry,
377 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
379 Eina_Bool *shot_done = (Eina_Bool*)data;
381 *shot_done = EINA_TRUE;
384 static const struct screenshooter_listener screenshooter_listener =
386 _cb_wl_screenshot_done
390 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
395 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
397 _eflutil.wl.shot.noti = noti;
400 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
402 _cb_tz_screenshot_format,
403 _cb_tz_screenshot_noti
407 _cb_wl_reg_global(void *data,
408 struct wl_registry *reg,
410 const char *interface,
411 unsigned int version)
413 if (!strcmp(interface, "tizen_policy"))
415 struct tizen_policy *proto;
416 proto = wl_registry_bind(reg,
418 &tizen_policy_interface,
422 tizen_policy_add_listener(proto,
423 &_wl_tz_policy_listener,
426 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
427 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
428 _eflutil.wl.policy.proto = proto;
430 else if (strcmp(interface, "wl_output") == 0)
432 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
433 EINA_SAFETY_ON_NULL_RETURN(output);
435 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
437 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
438 wl_output_add_listener(output->output, &output_listener, output);
440 else if (strcmp(interface, "tizen_input_device_manager") == 0)
442 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
443 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
445 else if (!strcmp(interface, "tizen_display_policy"))
447 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
448 if (!_eflutil.wl.display_policy.proto) return;
450 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
451 &_wl_tz_display_policy_listener,
454 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
458 /* LCOV_EXCL_START */
460 _cb_wl_reg_global_remove(void *data,
461 struct wl_registry *reg,
464 _eflutil.wl.policy.proto = NULL;
465 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
466 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
468 _eflutil.wl.display_policy.proto = NULL;
469 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
474 _cb_wl_reg_screenshooter_global(void *data,
475 struct wl_registry *reg,
477 const char *interface,
478 unsigned int version)
480 if (strcmp(interface, "screenshooter") == 0)
482 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
483 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
485 else if (strcmp(interface, "tizen_screenshooter") == 0)
487 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
488 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
490 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
494 /* LCOV_EXCL_START */
496 _cb_wl_reg_screenshooter_global_remove(void *data,
497 struct wl_registry *reg,
502 static Efl_Util_Callback_Info *
503 _cb_info_find_by_wlsurf(void *wlsurf,
507 Efl_Util_Callback_Info *info;
508 Ecore_Wl_Window *wlwin2 = NULL;
509 void *wlsurf2 = NULL;
511 l = _cb_info_list_get(idx);
512 EINA_LIST_FOREACH(l, ll, info)
514 wlwin2 = elm_win_wl_window_get(info->win);
515 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
516 if (wlsurf== wlsurf2) return info;
523 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
524 struct wl_surface *surface, uint32_t is_conformant)
529 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
530 struct wl_surface *surface, uint32_t conformant_part,
531 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
537 _cb_wl_tz_policy_notification_done(void *data,
538 struct tizen_policy *tizen_policy,
539 struct wl_surface *surface,
543 Efl_Util_Wl_Surface_Lv_Info *lv_info;
544 Efl_Util_Callback_Info *cb_info;
546 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
549 lv_info->level = level;
550 lv_info->wait_for_done = EINA_FALSE;
551 lv_info->state = state;
554 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
556 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
557 if (!cb_info) return;
558 if (!cb_info->cb) return;
560 cb_info->cb(cb_info->win,
561 EFL_UTIL_ERROR_PERMISSION_DENIED,
565 /* LCOV_EXCL_START */
567 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
573 _cb_wl_tz_policy_scr_mode_done(void *data,
574 struct tizen_policy *tizen_policy,
575 struct wl_surface *surface,
580 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
581 Efl_Util_Callback_Info *cb_info;
583 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
586 scr_mode_info->mode = mode;
587 scr_mode_info->wait_for_done = EINA_FALSE;
588 scr_mode_info->state = state;
591 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
593 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
594 if (!cb_info) return;
595 if (!cb_info->cb) return;
597 cb_info->cb(cb_info->win,
598 EFL_UTIL_ERROR_PERMISSION_DENIED,
602 /* LCOV_EXCL_START */
603 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)
607 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)
611 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
615 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)
621 _cb_wl_tz_display_policy_brightness_done(void *data,
622 struct tizen_display_policy *tizen_display_policy,
623 struct wl_surface *surface,
627 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
629 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
632 brightness_info->brightness = brightness;
633 brightness_info->wait_for_done = EINA_FALSE;
634 brightness_info->state = state;
639 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
641 Efl_Util_Wl_Surface_Lv_Info *lv_info;
644 if (EINA_UNLIKELY(!lv_info))
647 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
651 efl_util_set_notification_window_level(Evas_Object *window,
652 efl_util_notification_level_e level)
656 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
657 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
658 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
659 EFL_UTIL_ERROR_INVALID_PARAMETER);
661 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
663 dlog_print(DLOG_WARN, LOG_TAG,
664 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
666 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
668 dlog_print(DLOG_WARN, LOG_TAG,
669 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
671 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
673 dlog_print(DLOG_WARN, LOG_TAG,
674 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
678 Ecore_Wl_Window *wlwin;
679 struct wl_surface *surface;
680 Efl_Util_Wl_Surface_Lv_Info *lv_info;
681 Ecore_Wl_Window_Type wl_type;
684 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
686 wlwin = elm_win_wl_window_get(window);
687 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
689 type = elm_win_type_get(window);
690 if (type != ELM_WIN_NOTIFICATION)
692 wl_type = ecore_wl_window_type_get(wlwin);
693 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
694 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
697 while (!_eflutil.wl.policy.proto)
698 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
700 surface = ecore_wl_window_surface_get(wlwin);
701 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
702 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
704 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
707 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
708 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
710 lv_info->surface = surface;
711 lv_info->level = (int)level;
712 lv_info->wait_for_done = EINA_TRUE;
713 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
714 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
718 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
719 _cb_window_del, lv_info);
723 lv_info->level = (int)level;
724 lv_info->wait_for_done = EINA_TRUE;
725 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
729 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
730 surface, (int)level);
732 if (lv_info->wait_for_done)
735 while (lv_info->wait_for_done && (count < 3))
738 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
742 if (lv_info->wait_for_done)
744 return EFL_UTIL_ERROR_INVALID_PARAMETER;
748 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
750 return EFL_UTIL_ERROR_PERMISSION_DENIED;
755 return EFL_UTIL_ERROR_NONE;
759 efl_util_get_notification_window_level(Evas_Object *window,
760 efl_util_notification_level_e *level)
764 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
765 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
768 Ecore_Wl_Window *wlwin;
769 struct wl_surface *surface;
770 Efl_Util_Wl_Surface_Lv_Info *lv_info;
771 Ecore_Wl_Window_Type wl_type;
774 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
776 wlwin = elm_win_wl_window_get(window);
777 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
779 type = elm_win_type_get(window);
780 if (type != ELM_WIN_NOTIFICATION)
782 wl_type = ecore_wl_window_type_get(wlwin);
783 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
784 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
787 while (!_eflutil.wl.policy.proto)
788 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
790 surface = ecore_wl_window_surface_get(wlwin);
791 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
792 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
794 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
797 if (lv_info->wait_for_done)
800 while ((lv_info->wait_for_done) && (count < 3))
803 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
807 if (lv_info->wait_for_done)
809 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
810 return EFL_UTIL_ERROR_INVALID_PARAMETER;
814 switch (lv_info->level)
816 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
817 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
818 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
819 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
820 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
821 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
822 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
823 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
824 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
825 return EFL_UTIL_ERROR_INVALID_PARAMETER;
827 return EFL_UTIL_ERROR_NONE;
830 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
832 return EFL_UTIL_ERROR_NONE;
836 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
837 efl_util_notification_window_level_error_cb callback,
840 dlog_print(DLOG_WARN, LOG_TAG,
841 "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.");
843 Eina_Bool ret = EINA_FALSE;
845 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
846 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
848 ret = _cb_info_add(window,
849 (Efl_Util_Cb)callback,
852 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
854 return EFL_UTIL_ERROR_NONE;
858 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
860 dlog_print(DLOG_WARN, LOG_TAG,
861 "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.");
863 Eina_Bool ret = EINA_FALSE;
865 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
867 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
868 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
870 return EFL_UTIL_ERROR_NONE;
874 efl_util_set_window_opaque_state(Evas_Object *window,
879 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
880 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
881 EFL_UTIL_ERROR_INVALID_PARAMETER);
883 Ecore_Wl_Window *wlwin;
884 struct wl_surface *surface;
886 if (!_eflutil.wl.policy.proto)
891 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
893 while (!_eflutil.wl.policy.proto && ret != -1)
894 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
896 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
899 wlwin = elm_win_wl_window_get(window);
901 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
903 surface = ecore_wl_window_surface_get(wlwin);
905 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
907 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
909 return EFL_UTIL_ERROR_NONE;
913 efl_util_set_window_screen_mode(Evas_Object *window,
914 efl_util_screen_mode_e mode)
916 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
917 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
918 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
919 EFL_UTIL_ERROR_INVALID_PARAMETER);
921 Ecore_Wl_Window *wlwin;
922 struct wl_surface *surface;
923 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
927 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
929 wlwin = elm_win_wl_window_get(window);
932 while (!_eflutil.wl.policy.proto)
933 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
935 surface = ecore_wl_window_surface_get(wlwin);
936 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
937 EFL_UTIL_ERROR_INVALID_PARAMETER);
939 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
942 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
943 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
945 scr_mode_info->surface = surface;
946 scr_mode_info->mode = (unsigned int)mode;
947 scr_mode_info->wait_for_done = EINA_TRUE;
948 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
950 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
956 scr_mode_info->mode = (unsigned int)mode;
957 scr_mode_info->wait_for_done = EINA_TRUE;
958 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
961 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
962 surface, (unsigned int)mode);
963 if (scr_mode_info->wait_for_done)
966 while (scr_mode_info->wait_for_done && (count < 3))
969 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
973 if (scr_mode_info->wait_for_done)
975 return EFL_UTIL_ERROR_INVALID_PARAMETER;
979 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
981 return EFL_UTIL_ERROR_PERMISSION_DENIED;
986 return EFL_UTIL_ERROR_NONE;
989 return EFL_UTIL_ERROR_INVALID_PARAMETER;
993 efl_util_get_window_screen_mode(Evas_Object *window,
994 efl_util_screen_mode_e *mode)
996 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
997 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
999 Ecore_Wl_Window *wlwin;
1000 struct wl_surface *surface;
1001 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1005 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1007 wlwin = elm_win_wl_window_get(window);
1010 while (!_eflutil.wl.policy.proto)
1011 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1013 surface = ecore_wl_window_surface_get(wlwin);
1014 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1015 EFL_UTIL_ERROR_INVALID_PARAMETER);
1017 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1020 if (scr_mode_info->wait_for_done)
1022 while (scr_mode_info->wait_for_done)
1025 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1029 switch (scr_mode_info->mode)
1031 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1032 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1033 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1034 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1036 return EFL_UTIL_ERROR_NONE;
1040 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1041 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1045 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1048 #ifndef TIZEN_WEARABLE
1050 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1051 efl_util_window_screen_mode_error_cb callback,
1054 dlog_print(DLOG_WARN, LOG_TAG,
1055 "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.");
1057 Eina_Bool ret = EINA_FALSE;
1059 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1060 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1062 ret = _cb_info_add(window,
1063 (Efl_Util_Cb)callback,
1066 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1068 return EFL_UTIL_ERROR_NONE;
1072 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1074 dlog_print(DLOG_WARN, LOG_TAG,
1075 "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.");
1077 Eina_Bool ret = EINA_FALSE;
1079 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1081 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1082 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1084 return EFL_UTIL_ERROR_NONE;
1089 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1091 Ecore_Wl_Window *wlwin;
1092 struct wl_surface *surface;
1093 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1096 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1097 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1100 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1102 wlwin = elm_win_wl_window_get(window);
1105 while (!_eflutil.wl.display_policy.proto)
1106 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1108 surface = ecore_wl_window_surface_get(wlwin);
1109 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1110 EFL_UTIL_ERROR_INVALID_PARAMETER);
1112 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1113 if (!brightness_info)
1115 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1116 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1118 brightness_info->surface = surface;
1119 brightness_info->brightness = brightness;
1120 brightness_info->wait_for_done = EINA_TRUE;
1121 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1123 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1129 brightness_info->brightness = brightness;
1130 brightness_info->wait_for_done = EINA_TRUE;
1131 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1134 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1135 surface, brightness);
1136 if (brightness_info->wait_for_done)
1139 while (brightness_info->wait_for_done && (count < 3))
1142 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1146 if (brightness_info->wait_for_done)
1148 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1152 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1154 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1158 return EFL_UTIL_ERROR_NONE;
1161 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1165 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1167 Ecore_Wl_Window *wlwin;
1168 struct wl_surface *surface;
1169 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1172 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1173 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1176 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1178 wlwin = elm_win_wl_window_get(window);
1179 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1181 while (!_eflutil.wl.display_policy.proto)
1182 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1184 surface = ecore_wl_window_surface_get(wlwin);
1185 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1186 EFL_UTIL_ERROR_INVALID_PARAMETER);
1188 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1189 if (brightness_info)
1191 if (brightness_info->wait_for_done)
1193 while (brightness_info->wait_for_done)
1196 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1199 *brightness = brightness_info->brightness;
1204 return EFL_UTIL_ERROR_NONE;
1208 struct _efl_util_inputgen_h
1210 unsigned int init_type;
1214 _cb_device_add(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)
1224 /* LCOV_EXCL_START */
1226 _cb_device_remove(void *data EINA_UNUSED,
1227 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1228 uint32_t serial EINA_UNUSED,
1229 const char *identifier EINA_UNUSED,
1230 struct tizen_input_device *device EINA_UNUSED,
1231 struct wl_seat *seat EINA_UNUSED)
1235 /* LCOV_EXCL_STOP */
1238 _cb_error(void *data EINA_UNUSED,
1239 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1242 _eflutil.wl.devmgr.request_notified = errorcode;
1245 /* LCOV_EXCL_START */
1247 _cb_block_expired(void *data EINA_UNUSED,
1248 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1252 /* LCOV_EXCL_STOP */
1254 static efl_util_error_e
1255 _efl_util_input_convert_input_generator_error(int ret)
1259 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1260 return EFL_UTIL_ERROR_NONE;
1261 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1262 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1263 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1264 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1265 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1266 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1268 return EFL_UTIL_ERROR_NONE;
1272 API efl_util_inputgen_h
1273 efl_util_input_initialize_generator(unsigned int dev_type)
1275 int ret = EFL_UTIL_ERROR_NONE;
1276 efl_util_inputgen_h inputgen_h = NULL;
1277 unsigned int clas = 0x0;
1280 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1281 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1282 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1284 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1288 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1291 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1295 inputgen_h->init_type |= dev_type;
1298 if (ret == (int)EINA_FALSE)
1300 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1304 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1305 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1306 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1307 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1308 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1309 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1311 while (!_eflutil.wl.devmgr.devicemgr)
1312 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1314 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
1316 while (_eflutil.wl.devmgr.request_notified == -1)
1317 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1319 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1320 _eflutil.wl.devmgr.request_notified = -1;
1322 set_last_result(ret);
1323 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1338 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1340 int ret = EFL_UTIL_ERROR_NONE;
1341 unsigned int clas = 0x0;
1342 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1344 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1345 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1346 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1347 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1348 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1349 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1354 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1356 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas);
1358 while (_eflutil.wl.devmgr.request_notified == -1)
1359 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1361 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1362 _eflutil.wl.devmgr.request_notified = -1;
1368 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1370 int ret = EFL_UTIL_ERROR_NONE;
1372 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1373 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1374 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1375 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1377 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1379 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1381 while (_eflutil.wl.devmgr.request_notified == -1)
1382 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1384 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1385 _eflutil.wl.devmgr.request_notified = -1;
1391 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1392 efl_util_input_touch_type_e touch_type, int x, int y)
1395 enum tizen_input_device_manager_pointer_event_type type;
1397 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1398 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1399 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1400 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1402 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1406 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1407 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1409 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1410 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1412 case EFL_UTIL_INPUT_TOUCH_END:
1413 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1416 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1419 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1421 while (_eflutil.wl.devmgr.request_notified == -1)
1422 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1424 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1425 _eflutil.wl.devmgr.request_notified = -1;
1431 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)
1434 enum tizen_input_device_manager_pointer_event_type type;
1436 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1437 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1438 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1439 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1441 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1443 switch(pointer_type)
1445 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1446 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1448 case EFL_UTIL_INPUT_POINTER_MOVE:
1449 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1451 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1452 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1455 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1458 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1460 while (_eflutil.wl.devmgr.request_notified == -1)
1461 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1463 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1464 _eflutil.wl.devmgr.request_notified = -1;
1470 struct _efl_util_screenshot_h
1475 Eina_Bool shot_done;
1480 Eina_Bool auto_rotation;
1483 /* scrrenshot handle */
1484 static efl_util_screenshot_h g_screenshot;
1485 static Eina_Bool shot_mutex_init;
1486 static pthread_mutex_t shot_lock;
1489 _screenshot_mutex_init(void)
1491 if (shot_mutex_init)
1494 if (pthread_mutex_init(&shot_lock, NULL))
1496 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1497 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1500 shot_mutex_init = EINA_TRUE;
1506 _screenshot_mutex_destory(void)
1508 if (!shot_mutex_init)
1511 if (pthread_mutex_destroy(&shot_lock))
1513 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1514 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1517 shot_mutex_init = EINA_FALSE;
1523 _screenshot_mutex_lock(void)
1525 if (!_screenshot_mutex_init())
1528 pthread_mutex_lock(&shot_lock);
1532 _screenshot_mutex_unlock(void)
1534 pthread_mutex_unlock(&shot_lock);
1537 API efl_util_screenshot_h
1538 efl_util_screenshot_initialize(int width, int height)
1540 efl_util_screenshot_h screenshot = NULL;
1541 struct wl_display *display_wrapper = NULL;
1542 struct wl_registry *reg = NULL;
1545 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1546 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1548 _screenshot_mutex_lock();
1550 if (!_eflutil.wl.shot.screenshooter)
1553 if (ret == (int)EINA_FALSE)
1555 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1556 _screenshot_mutex_unlock();
1559 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1561 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1562 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory);
1564 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1565 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory);
1567 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
1569 reg = wl_display_get_registry(display_wrapper);
1570 wl_proxy_wrapper_destroy(display_wrapper);
1571 display_wrapper = NULL;
1572 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1574 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1576 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1577 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1578 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1579 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1581 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1582 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1585 if (_eflutil.wl.shot.noti == 0)
1587 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1593 if (g_screenshot->width != width || g_screenshot->height != height)
1595 g_screenshot->width = width;
1596 g_screenshot->height = height;
1599 _screenshot_mutex_unlock();
1601 return g_screenshot;
1604 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1605 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1607 screenshot->width = width;
1608 screenshot->height = height;
1609 screenshot->auto_rotation = EINA_TRUE;
1611 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1612 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1614 g_screenshot = screenshot;
1615 set_last_result(EFL_UTIL_ERROR_NONE);
1617 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1619 _screenshot_mutex_unlock();
1621 return g_screenshot;
1624 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1627 /* LCOV_EXCL_START */
1628 if (display_wrapper)
1629 wl_proxy_wrapper_destroy(display_wrapper);
1630 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1634 efl_util_screenshot_deinitialize(screenshot);
1635 _screenshot_mutex_unlock();
1636 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1638 /* LCOV_EXCL_STOP */
1642 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1644 _screenshot_mutex_lock();
1648 _screenshot_mutex_unlock();
1649 _screenshot_mutex_destory();
1650 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1654 g_screenshot = NULL;
1656 if (_eflutil.wl.shot.queue)
1658 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1659 _eflutil.wl.shot.queue = NULL;
1662 if (_eflutil.wl.shot.screenshooter)
1664 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1665 _eflutil.wl.shot.screenshooter = NULL;
1667 if (_eflutil.wl.shot.tz_screenshooter)
1669 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1670 _eflutil.wl.shot.tz_screenshooter = NULL;
1673 _screenshot_mutex_unlock();
1674 _screenshot_mutex_destory();
1676 return EFL_UTIL_ERROR_NONE;
1681 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1683 tbm_surface_h t_surface = NULL;
1684 struct wl_buffer *buffer = NULL;
1685 Efl_Util_Wl_Output_Info *output;
1688 _screenshot_mutex_lock();
1690 if (!screenshot || (screenshot != g_screenshot))
1692 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1693 _screenshot_mutex_unlock();
1697 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1700 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1704 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1707 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1711 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1714 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1718 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1720 screenshot->shot_done = EINA_FALSE;
1721 while (!screenshot->shot_done && ret != -1)
1722 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1726 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1730 wl_buffer_destroy(buffer);
1732 /* reset shot_done for next screenshot */
1733 screenshot->shot_done = EINA_FALSE;
1735 set_last_result(EFL_UTIL_ERROR_NONE);
1737 _screenshot_mutex_unlock();
1743 tbm_surface_destroy(t_surface);
1745 wl_buffer_destroy(buffer);
1747 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1749 _screenshot_mutex_unlock();
1755 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1757 if (!screenshot || (screenshot != g_screenshot))
1758 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1760 if (!(set == 0 || set == 1))
1761 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1764 g_screenshot->auto_rotation = EINA_TRUE;
1766 g_screenshot->auto_rotation = EINA_FALSE;
1768 tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1770 return EFL_UTIL_ERROR_NONE;
1774 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1776 if (!screenshot || (screenshot != g_screenshot) || !set)
1777 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1779 *set = g_screenshot->auto_rotation;
1781 return EFL_UTIL_ERROR_NONE;