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_registry *reg = NULL;
293 if (_eflutil.wl.init) return EINA_TRUE;
297 _eflutil.wl.dpy = ecore_wl_display_get();
298 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
300 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
301 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
303 reg = wl_display_get_registry(_eflutil.wl.dpy);
304 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
306 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
307 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
309 _eflutil.wl.init = EINA_TRUE;
313 if (_eflutil.wl.queue)
315 wl_event_queue_destroy(_eflutil.wl.queue);
316 _eflutil.wl.queue = NULL;
324 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
325 int physical_width, int physical_height, int subpixel,
326 const char *make, const char *model, int transform)
328 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
329 if (wl_output == output->output)
331 output->offset_x = x;
332 output->offset_y = y;
337 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
338 int width, int height, int refresh)
340 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
341 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
343 output->width = width;
344 output->height = height;
349 _cb_wl_output_done(void *data, struct wl_output *wl_output)
354 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
358 static const struct wl_output_listener output_listener =
360 _cb_wl_output_geometry,
367 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
369 Eina_Bool *shot_done = (Eina_Bool*)data;
371 *shot_done = EINA_TRUE;
374 static const struct screenshooter_listener screenshooter_listener =
376 _cb_wl_screenshot_done
380 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
385 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
387 _eflutil.wl.shot.noti = noti;
390 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
392 _cb_tz_screenshot_format,
393 _cb_tz_screenshot_noti
397 _cb_wl_reg_global(void *data,
398 struct wl_registry *reg,
400 const char *interface,
401 unsigned int version)
403 if (!strcmp(interface, "tizen_policy"))
405 struct tizen_policy *proto;
406 proto = wl_registry_bind(reg,
408 &tizen_policy_interface,
412 tizen_policy_add_listener(proto,
413 &_wl_tz_policy_listener,
416 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
417 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
418 _eflutil.wl.policy.proto = proto;
420 else if (strcmp(interface, "wl_output") == 0)
422 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
423 EINA_SAFETY_ON_NULL_RETURN(output);
425 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
427 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
428 wl_output_add_listener(output->output, &output_listener, output);
430 else if (strcmp(interface, "tizen_input_device_manager") == 0)
432 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
433 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
435 else if (!strcmp(interface, "tizen_display_policy"))
437 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
438 if (!_eflutil.wl.display_policy.proto) return;
440 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
441 &_wl_tz_display_policy_listener,
444 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
448 /* LCOV_EXCL_START */
450 _cb_wl_reg_global_remove(void *data,
451 struct wl_registry *reg,
454 _eflutil.wl.policy.proto = NULL;
455 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
456 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
458 _eflutil.wl.display_policy.proto = NULL;
459 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
464 _cb_wl_reg_screenshooter_global(void *data,
465 struct wl_registry *reg,
467 const char *interface,
468 unsigned int version)
470 if (strcmp(interface, "screenshooter") == 0)
472 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
473 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
475 else if (strcmp(interface, "tizen_screenshooter") == 0)
477 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
478 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
480 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
484 /* LCOV_EXCL_START */
486 _cb_wl_reg_screenshooter_global_remove(void *data,
487 struct wl_registry *reg,
492 static Efl_Util_Callback_Info *
493 _cb_info_find_by_wlsurf(void *wlsurf,
497 Efl_Util_Callback_Info *info;
498 Ecore_Wl_Window *wlwin2 = NULL;
499 void *wlsurf2 = NULL;
501 l = _cb_info_list_get(idx);
502 EINA_LIST_FOREACH(l, ll, info)
504 wlwin2 = elm_win_wl_window_get(info->win);
505 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
506 if (wlsurf== wlsurf2) return info;
513 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
514 struct wl_surface *surface, uint32_t is_conformant)
519 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
520 struct wl_surface *surface, uint32_t conformant_part,
521 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
527 _cb_wl_tz_policy_notification_done(void *data,
528 struct tizen_policy *tizen_policy,
529 struct wl_surface *surface,
533 Efl_Util_Wl_Surface_Lv_Info *lv_info;
534 Efl_Util_Callback_Info *cb_info;
536 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
539 lv_info->level = level;
540 lv_info->wait_for_done = EINA_FALSE;
541 lv_info->state = state;
544 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
546 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
547 if (!cb_info) return;
548 if (!cb_info->cb) return;
550 cb_info->cb(cb_info->win,
551 EFL_UTIL_ERROR_PERMISSION_DENIED,
555 /* LCOV_EXCL_START */
557 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
563 _cb_wl_tz_policy_scr_mode_done(void *data,
564 struct tizen_policy *tizen_policy,
565 struct wl_surface *surface,
570 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
571 Efl_Util_Callback_Info *cb_info;
573 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
576 scr_mode_info->mode = mode;
577 scr_mode_info->wait_for_done = EINA_FALSE;
578 scr_mode_info->state = state;
581 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
583 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
584 if (!cb_info) return;
585 if (!cb_info->cb) return;
587 cb_info->cb(cb_info->win,
588 EFL_UTIL_ERROR_PERMISSION_DENIED,
592 /* LCOV_EXCL_START */
593 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)
597 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)
601 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
605 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)
611 _cb_wl_tz_display_policy_brightness_done(void *data,
612 struct tizen_display_policy *tizen_display_policy,
613 struct wl_surface *surface,
617 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
619 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
622 brightness_info->brightness = brightness;
623 brightness_info->wait_for_done = EINA_FALSE;
624 brightness_info->state = state;
629 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
631 Efl_Util_Wl_Surface_Lv_Info *lv_info;
634 if (EINA_UNLIKELY(!lv_info))
637 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
641 efl_util_set_notification_window_level(Evas_Object *window,
642 efl_util_notification_level_e level)
646 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
647 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
648 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
649 EFL_UTIL_ERROR_INVALID_PARAMETER);
651 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
653 dlog_print(DLOG_WARN, LOG_TAG,
654 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
656 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
658 dlog_print(DLOG_WARN, LOG_TAG,
659 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
661 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
663 dlog_print(DLOG_WARN, LOG_TAG,
664 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
668 Ecore_Wl_Window *wlwin;
669 struct wl_surface *surface;
670 Efl_Util_Wl_Surface_Lv_Info *lv_info;
671 Ecore_Wl_Window_Type wl_type;
674 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
676 wlwin = elm_win_wl_window_get(window);
677 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
679 type = elm_win_type_get(window);
680 if (type != ELM_WIN_NOTIFICATION)
682 wl_type = ecore_wl_window_type_get(wlwin);
683 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
684 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
687 while (!_eflutil.wl.policy.proto)
688 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
690 surface = ecore_wl_window_surface_get(wlwin);
691 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
692 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
694 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
697 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
698 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
700 lv_info->surface = surface;
701 lv_info->level = (int)level;
702 lv_info->wait_for_done = EINA_TRUE;
703 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
704 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
708 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
709 _cb_window_del, lv_info);
713 lv_info->level = (int)level;
714 lv_info->wait_for_done = EINA_TRUE;
715 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
719 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
720 surface, (int)level);
722 if (lv_info->wait_for_done)
725 while (lv_info->wait_for_done && (count < 3))
728 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
732 if (lv_info->wait_for_done)
734 return EFL_UTIL_ERROR_INVALID_PARAMETER;
738 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
740 return EFL_UTIL_ERROR_PERMISSION_DENIED;
745 return EFL_UTIL_ERROR_NONE;
749 efl_util_get_notification_window_level(Evas_Object *window,
750 efl_util_notification_level_e *level)
754 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
755 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
758 Ecore_Wl_Window *wlwin;
759 struct wl_surface *surface;
760 Efl_Util_Wl_Surface_Lv_Info *lv_info;
761 Ecore_Wl_Window_Type wl_type;
764 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
766 wlwin = elm_win_wl_window_get(window);
767 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
769 type = elm_win_type_get(window);
770 if (type != ELM_WIN_NOTIFICATION)
772 wl_type = ecore_wl_window_type_get(wlwin);
773 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
774 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
777 while (!_eflutil.wl.policy.proto)
778 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
780 surface = ecore_wl_window_surface_get(wlwin);
781 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
782 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
784 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
787 if (lv_info->wait_for_done)
790 while ((lv_info->wait_for_done) && (count < 3))
793 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
797 if (lv_info->wait_for_done)
799 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
800 return EFL_UTIL_ERROR_INVALID_PARAMETER;
804 switch (lv_info->level)
806 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
807 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
808 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
809 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
810 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
811 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
812 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
813 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
814 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
815 return EFL_UTIL_ERROR_INVALID_PARAMETER;
817 return EFL_UTIL_ERROR_NONE;
820 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
822 return EFL_UTIL_ERROR_NONE;
826 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
827 efl_util_notification_window_level_error_cb callback,
830 dlog_print(DLOG_WARN, LOG_TAG,
831 "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.");
833 Eina_Bool ret = EINA_FALSE;
835 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
836 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
838 ret = _cb_info_add(window,
839 (Efl_Util_Cb)callback,
842 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
844 return EFL_UTIL_ERROR_NONE;
848 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
850 dlog_print(DLOG_WARN, LOG_TAG,
851 "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.");
853 Eina_Bool ret = EINA_FALSE;
855 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
857 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
858 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
860 return EFL_UTIL_ERROR_NONE;
864 efl_util_set_window_opaque_state(Evas_Object *window,
869 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
870 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
871 EFL_UTIL_ERROR_INVALID_PARAMETER);
873 Ecore_Wl_Window *wlwin;
874 struct wl_surface *surface;
876 if (!_eflutil.wl.policy.proto)
881 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
883 while (!_eflutil.wl.policy.proto && ret != -1)
884 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
886 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
889 wlwin = elm_win_wl_window_get(window);
891 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
893 surface = ecore_wl_window_surface_get(wlwin);
895 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
897 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
899 return EFL_UTIL_ERROR_NONE;
903 efl_util_set_window_screen_mode(Evas_Object *window,
904 efl_util_screen_mode_e mode)
906 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
907 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
908 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
909 EFL_UTIL_ERROR_INVALID_PARAMETER);
911 Ecore_Wl_Window *wlwin;
912 struct wl_surface *surface;
913 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
917 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
919 wlwin = elm_win_wl_window_get(window);
922 while (!_eflutil.wl.policy.proto)
923 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
925 surface = ecore_wl_window_surface_get(wlwin);
926 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
927 EFL_UTIL_ERROR_INVALID_PARAMETER);
929 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
932 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
933 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
935 scr_mode_info->surface = surface;
936 scr_mode_info->mode = (unsigned int)mode;
937 scr_mode_info->wait_for_done = EINA_TRUE;
938 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
940 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
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;
951 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
952 surface, (unsigned int)mode);
953 if (scr_mode_info->wait_for_done)
956 while (scr_mode_info->wait_for_done && (count < 3))
959 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
963 if (scr_mode_info->wait_for_done)
965 return EFL_UTIL_ERROR_INVALID_PARAMETER;
969 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
971 return EFL_UTIL_ERROR_PERMISSION_DENIED;
976 return EFL_UTIL_ERROR_NONE;
979 return EFL_UTIL_ERROR_INVALID_PARAMETER;
983 efl_util_get_window_screen_mode(Evas_Object *window,
984 efl_util_screen_mode_e *mode)
986 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
987 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
989 Ecore_Wl_Window *wlwin;
990 struct wl_surface *surface;
991 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
995 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
997 wlwin = elm_win_wl_window_get(window);
1000 while (!_eflutil.wl.policy.proto)
1001 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1003 surface = ecore_wl_window_surface_get(wlwin);
1004 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1005 EFL_UTIL_ERROR_INVALID_PARAMETER);
1007 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1010 if (scr_mode_info->wait_for_done)
1012 while (scr_mode_info->wait_for_done)
1015 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1019 switch (scr_mode_info->mode)
1021 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1022 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1023 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1024 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1026 return EFL_UTIL_ERROR_NONE;
1030 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1031 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1035 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1038 #ifndef TIZEN_WEARABLE
1040 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1041 efl_util_window_screen_mode_error_cb callback,
1044 dlog_print(DLOG_WARN, LOG_TAG,
1045 "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.");
1047 Eina_Bool ret = EINA_FALSE;
1049 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1050 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1052 ret = _cb_info_add(window,
1053 (Efl_Util_Cb)callback,
1056 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1058 return EFL_UTIL_ERROR_NONE;
1062 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1064 dlog_print(DLOG_WARN, LOG_TAG,
1065 "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.");
1067 Eina_Bool ret = EINA_FALSE;
1069 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1071 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1072 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1074 return EFL_UTIL_ERROR_NONE;
1079 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1081 Ecore_Wl_Window *wlwin;
1082 struct wl_surface *surface;
1083 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1086 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1087 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1090 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1092 wlwin = elm_win_wl_window_get(window);
1095 while (!_eflutil.wl.display_policy.proto)
1096 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1098 surface = ecore_wl_window_surface_get(wlwin);
1099 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1100 EFL_UTIL_ERROR_INVALID_PARAMETER);
1102 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1103 if (!brightness_info)
1105 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1106 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1108 brightness_info->surface = surface;
1109 brightness_info->brightness = brightness;
1110 brightness_info->wait_for_done = EINA_TRUE;
1111 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1113 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1119 brightness_info->brightness = brightness;
1120 brightness_info->wait_for_done = EINA_TRUE;
1121 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1124 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1125 surface, brightness);
1126 if (brightness_info->wait_for_done)
1129 while (brightness_info->wait_for_done && (count < 3))
1132 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1136 if (brightness_info->wait_for_done)
1138 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1142 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1144 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1148 return EFL_UTIL_ERROR_NONE;
1151 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1155 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1157 Ecore_Wl_Window *wlwin;
1158 struct wl_surface *surface;
1159 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1162 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1163 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1166 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1168 wlwin = elm_win_wl_window_get(window);
1169 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1171 while (!_eflutil.wl.display_policy.proto)
1172 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1174 surface = ecore_wl_window_surface_get(wlwin);
1175 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1176 EFL_UTIL_ERROR_INVALID_PARAMETER);
1178 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1179 if (brightness_info)
1181 if (brightness_info->wait_for_done)
1183 while (brightness_info->wait_for_done)
1186 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1189 *brightness = brightness_info->brightness;
1194 return EFL_UTIL_ERROR_NONE;
1198 struct _efl_util_inputgen_h
1200 unsigned int init_type;
1204 _cb_device_add(void *data EINA_UNUSED,
1205 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1206 uint32_t serial EINA_UNUSED,
1207 const char *identifier EINA_UNUSED,
1208 struct tizen_input_device *device EINA_UNUSED,
1209 struct wl_seat *seat EINA_UNUSED)
1214 /* LCOV_EXCL_START */
1216 _cb_device_remove(void *data EINA_UNUSED,
1217 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1218 uint32_t serial EINA_UNUSED,
1219 const char *identifier EINA_UNUSED,
1220 struct tizen_input_device *device EINA_UNUSED,
1221 struct wl_seat *seat EINA_UNUSED)
1225 /* LCOV_EXCL_STOP */
1228 _cb_error(void *data EINA_UNUSED,
1229 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1232 _eflutil.wl.devmgr.request_notified = errorcode;
1235 /* LCOV_EXCL_START */
1237 _cb_block_expired(void *data EINA_UNUSED,
1238 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1242 /* LCOV_EXCL_STOP */
1244 static efl_util_error_e
1245 _efl_util_input_convert_input_generator_error(int ret)
1249 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1250 return EFL_UTIL_ERROR_NONE;
1251 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1252 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1253 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1254 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1255 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1256 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1258 return EFL_UTIL_ERROR_NONE;
1262 API efl_util_inputgen_h
1263 efl_util_input_initialize_generator(unsigned int dev_type)
1265 int ret = EFL_UTIL_ERROR_NONE;
1266 efl_util_inputgen_h inputgen_h = NULL;
1269 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1270 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1271 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1273 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1277 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1280 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1284 inputgen_h->init_type |= dev_type;
1287 if (ret == (int)EINA_FALSE)
1289 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1293 while (!_eflutil.wl.devmgr.devicemgr)
1294 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1296 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
1298 while (_eflutil.wl.devmgr.request_notified == -1)
1299 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1301 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1302 _eflutil.wl.devmgr.request_notified = -1;
1304 set_last_result(ret);
1305 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1320 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1322 int ret = EFL_UTIL_ERROR_NONE;
1323 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1328 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1330 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
1332 while (_eflutil.wl.devmgr.request_notified == -1)
1333 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1335 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1336 _eflutil.wl.devmgr.request_notified = -1;
1342 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1344 int ret = EFL_UTIL_ERROR_NONE;
1346 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1347 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1348 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1349 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1351 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1353 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1355 while (_eflutil.wl.devmgr.request_notified == -1)
1356 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1358 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1359 _eflutil.wl.devmgr.request_notified = -1;
1365 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1366 efl_util_input_touch_type_e touch_type, int x, int y)
1369 enum tizen_input_device_manager_pointer_event_type type;
1371 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1372 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1373 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1374 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1376 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1380 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1381 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1383 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1384 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1386 case EFL_UTIL_INPUT_TOUCH_END:
1387 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1390 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1393 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1395 while (_eflutil.wl.devmgr.request_notified == -1)
1396 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1398 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1399 _eflutil.wl.devmgr.request_notified = -1;
1405 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)
1408 enum tizen_input_device_manager_pointer_event_type type;
1410 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1411 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1412 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1413 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1415 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1417 switch(pointer_type)
1419 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1420 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1422 case EFL_UTIL_INPUT_POINTER_MOVE:
1423 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1425 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1426 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1429 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1432 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1434 while (_eflutil.wl.devmgr.request_notified == -1)
1435 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1437 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1438 _eflutil.wl.devmgr.request_notified = -1;
1444 struct _efl_util_screenshot_h
1449 Eina_Bool shot_done;
1454 Eina_Bool auto_rotation;
1457 /* scrrenshot handle */
1458 static efl_util_screenshot_h g_screenshot;
1459 static Eina_Bool shot_mutex_init;
1460 static pthread_mutex_t shot_lock;
1463 _screenshot_mutex_init(void)
1465 if (shot_mutex_init)
1468 if (pthread_mutex_init(&shot_lock, NULL))
1470 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1471 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1474 shot_mutex_init = EINA_TRUE;
1480 _screenshot_mutex_destory(void)
1482 if (!shot_mutex_init)
1485 if (pthread_mutex_destroy(&shot_lock))
1487 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1488 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1491 shot_mutex_init = EINA_FALSE;
1497 _screenshot_mutex_lock(void)
1499 if (!_screenshot_mutex_init())
1502 pthread_mutex_lock(&shot_lock);
1506 _screenshot_mutex_unlock(void)
1508 pthread_mutex_unlock(&shot_lock);
1511 API efl_util_screenshot_h
1512 efl_util_screenshot_initialize(int width, int height)
1514 efl_util_screenshot_h screenshot = NULL;
1515 struct wl_display *display_wrapper = NULL;
1516 struct wl_registry *reg = NULL;
1519 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1520 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1522 _screenshot_mutex_lock();
1524 if (!_eflutil.wl.shot.screenshooter)
1527 if (ret == (int)EINA_FALSE)
1529 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1530 _screenshot_mutex_unlock();
1533 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1535 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1536 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
1538 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1539 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_init);
1541 reg = wl_display_get_registry(display_wrapper);
1542 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1544 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.shot.queue);
1546 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1548 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1549 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1550 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1551 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1553 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1554 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1557 if (_eflutil.wl.shot.noti == 0)
1559 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1565 if (g_screenshot->width != width || g_screenshot->height != height)
1567 g_screenshot->width = width;
1568 g_screenshot->height = height;
1571 _screenshot_mutex_unlock();
1573 return g_screenshot;
1576 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1577 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1579 screenshot->width = width;
1580 screenshot->height = height;
1581 screenshot->auto_rotation = EINA_TRUE;
1583 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1584 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1586 g_screenshot = screenshot;
1587 set_last_result(EFL_UTIL_ERROR_NONE);
1589 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1591 _screenshot_mutex_unlock();
1593 return g_screenshot;
1596 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1599 /* LCOV_EXCL_START */
1600 if (display_wrapper)
1601 wl_proxy_wrapper_destroy(display_wrapper);
1602 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1604 /* LCOV_EXCL_STOP */
1607 efl_util_screenshot_deinitialize(screenshot);
1608 _screenshot_mutex_unlock();
1609 if (display_wrapper)
1610 wl_proxy_wrapper_destroy(display_wrapper);
1611 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1616 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1618 _screenshot_mutex_lock();
1622 _screenshot_mutex_unlock();
1623 _screenshot_mutex_destory();
1624 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1628 g_screenshot = NULL;
1630 if (_eflutil.wl.shot.queue)
1632 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1633 _eflutil.wl.shot.queue = NULL;
1636 if (_eflutil.wl.shot.screenshooter)
1638 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1639 _eflutil.wl.shot.screenshooter = NULL;
1641 if (_eflutil.wl.shot.tz_screenshooter)
1643 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1644 _eflutil.wl.shot.tz_screenshooter = NULL;
1647 _screenshot_mutex_unlock();
1648 _screenshot_mutex_destory();
1650 return EFL_UTIL_ERROR_NONE;
1655 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1657 tbm_surface_h t_surface = NULL;
1658 struct wl_buffer *buffer = NULL;
1659 Efl_Util_Wl_Output_Info *output;
1662 _screenshot_mutex_lock();
1664 if (!screenshot || (screenshot != g_screenshot))
1666 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1667 _screenshot_mutex_unlock();
1671 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1674 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1678 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1681 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1685 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1688 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1692 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1694 screenshot->shot_done = EINA_FALSE;
1695 while (!screenshot->shot_done && ret != -1)
1696 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1700 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1704 wl_buffer_destroy(buffer);
1706 /* reset shot_done for next screenshot */
1707 screenshot->shot_done = EINA_FALSE;
1709 set_last_result(EFL_UTIL_ERROR_NONE);
1711 _screenshot_mutex_unlock();
1717 tbm_surface_destroy(t_surface);
1719 wl_buffer_destroy(buffer);
1721 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1723 _screenshot_mutex_unlock();
1729 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1731 if (!screenshot || (screenshot != g_screenshot))
1732 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1734 if (!(set == 0 || set == 1))
1735 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1738 g_screenshot->auto_rotation = EINA_TRUE;
1740 g_screenshot->auto_rotation = EINA_FALSE;
1742 tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1744 return EFL_UTIL_ERROR_NONE;
1748 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1750 if (!screenshot || (screenshot != g_screenshot) || !set)
1751 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1753 *set = g_screenshot->auto_rotation;
1755 return EFL_UTIL_ERROR_NONE;