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>
34 #include <Ecore_Wayland.h>
35 #include <wayland-client.h>
36 #include <wayland-tbm-client.h>
37 #include <tizen-extension-client-protocol.h>
38 #include <screenshooter-client-protocol.h>
45 #define LOG_TAG "TIZEN_N_EFL_UTIL"
48 /* callback handler index */
49 #define CBH_NOTI_LEV 0
50 #define CBH_SCR_MODE 1
53 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
55 typedef struct _Efl_Util_Callback_Info
60 } Efl_Util_Callback_Info;
62 typedef struct _Efl_Util_Wl_Surface_Lv_Info
64 void *surface; /* wl_surface */
66 Eina_Bool wait_for_done;
68 } Efl_Util_Wl_Surface_Lv_Info;
70 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
72 void *surface; /* wl_surface */
74 Eina_Bool wait_for_done;
76 } Efl_Util_Wl_Surface_Scr_Mode_Info;
78 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
80 void *surface; /* wl_surface */
82 Eina_Bool wait_for_done;
84 } Efl_Util_Wl_Surface_Brightness_Info;
86 typedef struct _Efl_Util_Wl_Output_Info
88 struct wl_output *output;
89 int offset_x, offset_y, width, height;
90 } Efl_Util_Wl_Output_Info;
92 typedef struct _Efl_Util_Data
94 /* wayland related stuffs */
98 struct wl_display *dpy;
99 struct wl_event_queue *queue;
103 struct tizen_policy *proto;
104 Eina_Hash *hash_noti_lv;
105 Eina_Hash *hash_scr_mode;
109 struct screenshooter *screenshooter;
110 struct tizen_screenshooter *tz_screenshooter;
111 struct wayland_tbm_client *tbm_client;
112 Eina_List *output_list;
117 struct tizen_input_device_manager *devicemgr;
118 int request_notified;
122 struct tizen_display_policy *proto;
123 Eina_Hash *hash_brightness;
129 Eina_List *info_list; /* list of callback info */
130 unsigned int atom; /* x11 atom */
131 } cb_handler[CBH_MAX];
134 static Efl_Util_Data _eflutil =
139 { NULL, NULL, NULL }, /* tizen_policy protocol */
140 { NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
141 { NULL, -1 } /* tizen_input_device_manager protocol */
144 { NULL, 0 }, /* handler for notification level */
145 { NULL, 0 } /* handler for screen mode */
149 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
150 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
151 static Eina_List *_cb_info_list_get(int idx);
152 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
153 static Eina_Bool _wl_init(void);
154 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
155 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
156 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
157 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
158 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
159 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
160 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);
161 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);
162 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
163 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);
164 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);
165 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);
166 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
167 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);
169 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);
171 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);
172 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);
173 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
174 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
176 static const struct wl_registry_listener _wl_reg_listener =
179 _cb_wl_reg_global_remove
182 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
184 _cb_wl_reg_screenshooter_global,
185 _cb_wl_reg_screenshooter_global_remove
188 struct tizen_policy_listener _wl_tz_policy_listener =
190 _cb_wl_tz_policy_conformant,
191 _cb_wl_tz_policy_conformant_area,
192 _cb_wl_tz_policy_notification_done,
193 _cb_wl_tz_policy_transient_for_done,
194 _cb_wl_tz_policy_scr_mode_done,
195 _cb_wl_tz_policy_iconify_state_changed,
196 _cb_wl_tz_policy_supported_aux_hints,
197 _cb_wl_tz_policy_allowed_aux_hint,
198 _cb_wl_tz_policy_aux_message,
201 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
209 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
211 _cb_wl_tz_display_policy_brightness_done,
215 _cb_info_add(Evas_Object *win,
220 Efl_Util_Callback_Info *info;
222 info = _cb_info_find_by_win(win, idx);
225 _eflutil.cb_handler[idx].info_list
226 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
231 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
232 if (!info) return EINA_FALSE;
238 _eflutil.cb_handler[idx].info_list
239 = eina_list_append(_eflutil.cb_handler[idx].info_list,
246 _cb_info_del_by_win(Evas_Object *win,
249 Efl_Util_Callback_Info *info;
251 info = _cb_info_find_by_win(win, idx);
252 if (!info) return EINA_FALSE;
254 _eflutil.cb_handler[idx].info_list
255 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
263 _cb_info_list_get(int idx)
265 return _eflutil.cb_handler[idx].info_list;
268 static Efl_Util_Callback_Info *
269 _cb_info_find_by_win(Evas_Object *win,
273 Efl_Util_Callback_Info *info;
275 l = _cb_info_list_get(idx);
276 EINA_LIST_FOREACH(l, ll, info)
278 if (info->win == win) return info;
287 struct wl_registry *reg = NULL;
289 if (_eflutil.wl.init) return EINA_TRUE;
293 _eflutil.wl.dpy = ecore_wl_display_get();
294 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
296 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
297 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
299 reg = wl_display_get_registry(_eflutil.wl.dpy);
300 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
302 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
303 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
305 _eflutil.wl.init = EINA_TRUE;
309 if (_eflutil.wl.queue)
311 wl_event_queue_destroy(_eflutil.wl.queue);
312 _eflutil.wl.queue = NULL;
320 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
321 int physical_width, int physical_height, int subpixel,
322 const char *make, const char *model, int transform)
324 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
325 if (wl_output == output->output)
327 output->offset_x = x;
328 output->offset_y = y;
333 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
334 int width, int height, int refresh)
336 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
337 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
339 output->width = width;
340 output->height = height;
345 _cb_wl_output_done(void *data, struct wl_output *wl_output)
350 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
354 static const struct wl_output_listener output_listener =
356 _cb_wl_output_geometry,
363 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
365 Eina_Bool *shot_done = (Eina_Bool*)data;
367 *shot_done = EINA_TRUE;
370 static const struct screenshooter_listener screenshooter_listener =
372 _cb_wl_screenshot_done
376 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
381 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
383 _eflutil.wl.shot.noti = noti;
386 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
388 _cb_tz_screenshot_format,
389 _cb_tz_screenshot_noti
393 _cb_wl_reg_global(void *data,
394 struct wl_registry *reg,
396 const char *interface,
397 unsigned int version)
399 if (!strcmp(interface, "tizen_policy"))
401 struct tizen_policy *proto;
402 proto = wl_registry_bind(reg,
404 &tizen_policy_interface,
408 tizen_policy_add_listener(proto,
409 &_wl_tz_policy_listener,
412 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
413 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
414 _eflutil.wl.policy.proto = proto;
416 else if (strcmp(interface, "wl_output") == 0)
418 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
419 EINA_SAFETY_ON_NULL_RETURN(output);
421 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
423 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
424 wl_output_add_listener(output->output, &output_listener, output);
426 else if (strcmp(interface, "tizen_input_device_manager") == 0)
428 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
429 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
431 else if (!strcmp(interface, "tizen_display_policy"))
433 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
434 if (!_eflutil.wl.display_policy.proto) return;
436 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
437 &_wl_tz_display_policy_listener,
440 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
444 /* LCOV_EXCL_START */
446 _cb_wl_reg_global_remove(void *data,
447 struct wl_registry *reg,
450 _eflutil.wl.policy.proto = NULL;
451 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
452 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
454 _eflutil.wl.display_policy.proto = NULL;
455 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
460 _cb_wl_reg_screenshooter_global(void *data,
461 struct wl_registry *reg,
463 const char *interface,
464 unsigned int version)
466 if (strcmp(interface, "screenshooter") == 0)
468 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
469 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
471 else if (strcmp(interface, "tizen_screenshooter") == 0)
473 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
474 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
478 /* LCOV_EXCL_START */
480 _cb_wl_reg_screenshooter_global_remove(void *data,
481 struct wl_registry *reg,
486 static Efl_Util_Callback_Info *
487 _cb_info_find_by_wlsurf(void *wlsurf,
491 Efl_Util_Callback_Info *info;
492 Ecore_Wl_Window *wlwin2 = NULL;
493 void *wlsurf2 = NULL;
495 l = _cb_info_list_get(idx);
496 EINA_LIST_FOREACH(l, ll, info)
498 wlwin2 = elm_win_wl_window_get(info->win);
499 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
500 if (wlsurf== wlsurf2) return info;
507 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
508 struct wl_surface *surface, uint32_t is_conformant)
513 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
514 struct wl_surface *surface, uint32_t conformant_part,
515 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
521 _cb_wl_tz_policy_notification_done(void *data,
522 struct tizen_policy *tizen_policy,
523 struct wl_surface *surface,
527 Efl_Util_Wl_Surface_Lv_Info *lv_info;
528 Efl_Util_Callback_Info *cb_info;
530 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
533 lv_info->level = level;
534 lv_info->wait_for_done = EINA_FALSE;
535 lv_info->state = state;
538 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
540 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
541 if (!cb_info) return;
542 if (!cb_info->cb) return;
544 cb_info->cb(cb_info->win,
545 EFL_UTIL_ERROR_PERMISSION_DENIED,
549 /* LCOV_EXCL_START */
551 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
557 _cb_wl_tz_policy_scr_mode_done(void *data,
558 struct tizen_policy *tizen_policy,
559 struct wl_surface *surface,
564 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
565 Efl_Util_Callback_Info *cb_info;
567 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
570 scr_mode_info->mode = mode;
571 scr_mode_info->wait_for_done = EINA_FALSE;
572 scr_mode_info->state = state;
575 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
577 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
578 if (!cb_info) return;
579 if (!cb_info->cb) return;
581 cb_info->cb(cb_info->win,
582 EFL_UTIL_ERROR_PERMISSION_DENIED,
586 /* LCOV_EXCL_START */
587 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)
591 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)
595 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
599 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)
605 _cb_wl_tz_display_policy_brightness_done(void *data,
606 struct tizen_display_policy *tizen_display_policy,
607 struct wl_surface *surface,
611 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
613 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
616 brightness_info->brightness = brightness;
617 brightness_info->wait_for_done = EINA_FALSE;
618 brightness_info->state = state;
623 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
625 Efl_Util_Wl_Surface_Lv_Info *lv_info;
628 if (EINA_UNLIKELY(!lv_info))
631 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
635 efl_util_set_notification_window_level(Evas_Object *window,
636 efl_util_notification_level_e level)
640 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
641 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
642 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
643 EFL_UTIL_ERROR_INVALID_PARAMETER);
645 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
647 dlog_print(DLOG_WARN, LOG_TAG,
648 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
650 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
652 dlog_print(DLOG_WARN, LOG_TAG,
653 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
655 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
657 dlog_print(DLOG_WARN, LOG_TAG,
658 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
662 Ecore_Wl_Window *wlwin;
663 struct wl_surface *surface;
664 Efl_Util_Wl_Surface_Lv_Info *lv_info;
665 Ecore_Wl_Window_Type wl_type;
668 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
670 wlwin = elm_win_wl_window_get(window);
671 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
673 type = elm_win_type_get(window);
674 if (type != ELM_WIN_NOTIFICATION)
676 wl_type = ecore_wl_window_type_get(wlwin);
677 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
678 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
681 while (!_eflutil.wl.policy.proto)
682 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
684 surface = ecore_wl_window_surface_get(wlwin);
685 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
686 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
688 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
691 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
692 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
694 lv_info->surface = surface;
695 lv_info->level = (int)level;
696 lv_info->wait_for_done = EINA_TRUE;
697 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
698 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
702 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
703 _cb_window_del, lv_info);
707 lv_info->level = (int)level;
708 lv_info->wait_for_done = EINA_TRUE;
709 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
713 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
714 surface, (int)level);
716 if (lv_info->wait_for_done)
719 while (lv_info->wait_for_done && (count < 3))
722 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
726 if (lv_info->wait_for_done)
728 return EFL_UTIL_ERROR_INVALID_PARAMETER;
732 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
734 return EFL_UTIL_ERROR_PERMISSION_DENIED;
739 return EFL_UTIL_ERROR_NONE;
743 efl_util_get_notification_window_level(Evas_Object *window,
744 efl_util_notification_level_e *level)
748 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
749 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
752 Ecore_Wl_Window *wlwin;
753 struct wl_surface *surface;
754 Efl_Util_Wl_Surface_Lv_Info *lv_info;
755 Ecore_Wl_Window_Type wl_type;
758 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
760 wlwin = elm_win_wl_window_get(window);
761 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
763 type = elm_win_type_get(window);
764 if (type != ELM_WIN_NOTIFICATION)
766 wl_type = ecore_wl_window_type_get(wlwin);
767 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
768 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
771 while (!_eflutil.wl.policy.proto)
772 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
774 surface = ecore_wl_window_surface_get(wlwin);
775 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
776 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
778 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
781 if (lv_info->wait_for_done)
784 while ((lv_info->wait_for_done) && (count < 3))
787 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
791 if (lv_info->wait_for_done)
793 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
794 return EFL_UTIL_ERROR_INVALID_PARAMETER;
798 switch (lv_info->level)
800 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
801 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
802 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
803 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
804 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
805 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
806 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
807 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
808 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
809 return EFL_UTIL_ERROR_INVALID_PARAMETER;
811 return EFL_UTIL_ERROR_NONE;
814 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
816 return EFL_UTIL_ERROR_NONE;
820 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
821 efl_util_notification_window_level_error_cb callback,
824 dlog_print(DLOG_WARN, LOG_TAG,
825 "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.");
827 Eina_Bool ret = EINA_FALSE;
829 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
830 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
832 ret = _cb_info_add(window,
833 (Efl_Util_Cb)callback,
836 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
838 return EFL_UTIL_ERROR_NONE;
842 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
844 dlog_print(DLOG_WARN, LOG_TAG,
845 "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.");
847 Eina_Bool ret = EINA_FALSE;
849 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
851 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
852 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
854 return EFL_UTIL_ERROR_NONE;
858 efl_util_set_window_opaque_state(Evas_Object *window,
863 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
864 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
865 EFL_UTIL_ERROR_INVALID_PARAMETER);
867 Ecore_Wl_Window *wlwin;
868 struct wl_surface *surface;
870 if (!_eflutil.wl.policy.proto)
875 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
877 while (!_eflutil.wl.policy.proto && ret != -1)
878 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
880 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
883 wlwin = elm_win_wl_window_get(window);
885 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
887 surface = ecore_wl_window_surface_get(wlwin);
889 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
891 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
893 return EFL_UTIL_ERROR_NONE;
897 efl_util_set_window_screen_mode(Evas_Object *window,
898 efl_util_screen_mode_e mode)
900 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
901 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
902 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
903 EFL_UTIL_ERROR_INVALID_PARAMETER);
905 Ecore_Wl_Window *wlwin;
906 struct wl_surface *surface;
907 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
911 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
913 wlwin = elm_win_wl_window_get(window);
916 while (!_eflutil.wl.policy.proto)
917 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
919 surface = ecore_wl_window_surface_get(wlwin);
920 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
921 EFL_UTIL_ERROR_INVALID_PARAMETER);
923 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
926 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
927 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
929 scr_mode_info->surface = surface;
930 scr_mode_info->mode = (unsigned int)mode;
931 scr_mode_info->wait_for_done = EINA_TRUE;
932 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
934 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
940 scr_mode_info->mode = (unsigned int)mode;
941 scr_mode_info->wait_for_done = EINA_TRUE;
942 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
945 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
946 surface, (unsigned int)mode);
947 if (scr_mode_info->wait_for_done)
950 while (scr_mode_info->wait_for_done && (count < 3))
953 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
957 if (scr_mode_info->wait_for_done)
959 return EFL_UTIL_ERROR_INVALID_PARAMETER;
963 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
965 return EFL_UTIL_ERROR_PERMISSION_DENIED;
970 return EFL_UTIL_ERROR_NONE;
973 return EFL_UTIL_ERROR_INVALID_PARAMETER;
977 efl_util_get_window_screen_mode(Evas_Object *window,
978 efl_util_screen_mode_e *mode)
980 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
981 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
983 Ecore_Wl_Window *wlwin;
984 struct wl_surface *surface;
985 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
989 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
991 wlwin = elm_win_wl_window_get(window);
994 while (!_eflutil.wl.policy.proto)
995 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
997 surface = ecore_wl_window_surface_get(wlwin);
998 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
999 EFL_UTIL_ERROR_INVALID_PARAMETER);
1001 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1004 if (scr_mode_info->wait_for_done)
1006 while (scr_mode_info->wait_for_done)
1009 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1013 switch (scr_mode_info->mode)
1015 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1016 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1017 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1018 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1020 return EFL_UTIL_ERROR_NONE;
1024 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1025 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1029 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1032 #ifndef TIZEN_WEARABLE
1034 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1035 efl_util_window_screen_mode_error_cb callback,
1038 dlog_print(DLOG_WARN, LOG_TAG,
1039 "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.");
1041 Eina_Bool ret = EINA_FALSE;
1043 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1044 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1046 ret = _cb_info_add(window,
1047 (Efl_Util_Cb)callback,
1050 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1052 return EFL_UTIL_ERROR_NONE;
1056 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1058 dlog_print(DLOG_WARN, LOG_TAG,
1059 "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.");
1061 Eina_Bool ret = EINA_FALSE;
1063 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1065 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1066 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1068 return EFL_UTIL_ERROR_NONE;
1073 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1075 Ecore_Wl_Window *wlwin;
1076 struct wl_surface *surface;
1077 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1080 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1081 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1084 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1086 wlwin = elm_win_wl_window_get(window);
1089 while (!_eflutil.wl.display_policy.proto)
1090 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1092 surface = ecore_wl_window_surface_get(wlwin);
1093 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1094 EFL_UTIL_ERROR_INVALID_PARAMETER);
1096 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1097 if (!brightness_info)
1099 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1100 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1102 brightness_info->surface = surface;
1103 brightness_info->brightness = brightness;
1104 brightness_info->wait_for_done = EINA_TRUE;
1105 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1107 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1113 brightness_info->brightness = brightness;
1114 brightness_info->wait_for_done = EINA_TRUE;
1115 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1118 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1119 surface, brightness);
1120 if (brightness_info->wait_for_done)
1123 while (brightness_info->wait_for_done && (count < 3))
1126 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1130 if (brightness_info->wait_for_done)
1132 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1136 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1138 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1142 return EFL_UTIL_ERROR_NONE;
1145 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1149 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1151 Ecore_Wl_Window *wlwin;
1152 struct wl_surface *surface;
1153 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1156 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1157 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1160 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1162 wlwin = elm_win_wl_window_get(window);
1163 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1165 while (!_eflutil.wl.display_policy.proto)
1166 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1168 surface = ecore_wl_window_surface_get(wlwin);
1169 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1170 EFL_UTIL_ERROR_INVALID_PARAMETER);
1172 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1173 if (brightness_info)
1175 if (brightness_info->wait_for_done)
1177 while (brightness_info->wait_for_done)
1180 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1183 *brightness = brightness_info->brightness;
1188 return EFL_UTIL_ERROR_NONE;
1192 struct _efl_util_inputgen_h
1194 unsigned int init_type;
1198 _cb_device_add(void *data EINA_UNUSED,
1199 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1200 uint32_t serial EINA_UNUSED,
1201 const char *identifier EINA_UNUSED,
1202 struct tizen_input_device *device EINA_UNUSED,
1203 struct wl_seat *seat EINA_UNUSED)
1208 /* LCOV_EXCL_START */
1210 _cb_device_remove(void *data EINA_UNUSED,
1211 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1212 uint32_t serial EINA_UNUSED,
1213 const char *identifier EINA_UNUSED,
1214 struct tizen_input_device *device EINA_UNUSED,
1215 struct wl_seat *seat EINA_UNUSED)
1219 /* LCOV_EXCL_STOP */
1222 _cb_error(void *data EINA_UNUSED,
1223 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1226 _eflutil.wl.devmgr.request_notified = errorcode;
1229 /* LCOV_EXCL_START */
1231 _cb_block_expired(void *data EINA_UNUSED,
1232 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1236 /* LCOV_EXCL_STOP */
1238 static efl_util_error_e
1239 _efl_util_input_convert_input_generator_error(int ret)
1243 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1244 return EFL_UTIL_ERROR_NONE;
1245 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1246 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1247 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1248 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1249 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1250 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1252 return EFL_UTIL_ERROR_NONE;
1256 API efl_util_inputgen_h
1257 efl_util_input_initialize_generator(unsigned int dev_type)
1259 int ret = EFL_UTIL_ERROR_NONE;
1260 efl_util_inputgen_h inputgen_h = NULL;
1263 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1264 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1265 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1267 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1271 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1274 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1278 inputgen_h->init_type |= dev_type;
1281 if (ret == (int)EINA_FALSE)
1283 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1287 while (!_eflutil.wl.devmgr.devicemgr)
1288 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1290 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
1292 while (_eflutil.wl.devmgr.request_notified == -1)
1293 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1295 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1296 _eflutil.wl.devmgr.request_notified = -1;
1298 set_last_result(ret);
1299 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1314 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1316 int ret = EFL_UTIL_ERROR_NONE;
1317 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1322 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1324 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
1326 while (_eflutil.wl.devmgr.request_notified == -1)
1327 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1329 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1330 _eflutil.wl.devmgr.request_notified = -1;
1336 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1338 int ret = EFL_UTIL_ERROR_NONE;
1340 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1341 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1342 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1343 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1345 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1347 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1349 while (_eflutil.wl.devmgr.request_notified == -1)
1350 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1352 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1353 _eflutil.wl.devmgr.request_notified = -1;
1359 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1360 efl_util_input_touch_type_e touch_type, int x, int y)
1363 enum tizen_input_device_manager_pointer_event_type type;
1365 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1366 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1367 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1368 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1370 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1374 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1375 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1377 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1378 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1380 case EFL_UTIL_INPUT_TOUCH_END:
1381 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1384 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1387 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1389 while (_eflutil.wl.devmgr.request_notified == -1)
1390 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1392 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1393 _eflutil.wl.devmgr.request_notified = -1;
1399 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)
1402 enum tizen_input_device_manager_pointer_event_type type;
1404 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1405 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1406 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1407 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1409 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1411 switch(pointer_type)
1413 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1414 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1416 case EFL_UTIL_INPUT_POINTER_MOVE:
1417 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1419 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1420 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1423 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1426 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1428 while (_eflutil.wl.devmgr.request_notified == -1)
1429 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1431 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1432 _eflutil.wl.devmgr.request_notified = -1;
1438 struct _efl_util_screenshot_h
1443 Eina_Bool shot_done;
1449 /* scrrenshot handle */
1450 static efl_util_screenshot_h g_screenshot;
1452 API efl_util_screenshot_h
1453 efl_util_screenshot_initialize(int width, int height)
1455 efl_util_screenshot_h screenshot = NULL;
1456 struct wl_display *display_wrapper = NULL;
1457 struct wl_registry *reg = NULL;
1460 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1461 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1463 if (!_eflutil.wl.shot.screenshooter)
1467 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1468 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
1470 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
1472 reg = wl_display_get_registry(display_wrapper);
1473 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1475 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1477 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1478 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1479 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1480 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1482 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1483 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1486 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1487 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1489 if (_eflutil.wl.shot.noti == 0)
1491 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1497 if (g_screenshot->width != width || g_screenshot->height != height)
1499 g_screenshot->width = width;
1500 g_screenshot->height = height;
1503 return g_screenshot;
1506 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1507 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1509 screenshot->width = width;
1510 screenshot->height = height;
1512 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1513 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1515 g_screenshot = screenshot;
1516 set_last_result(EFL_UTIL_ERROR_NONE);
1518 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1520 return g_screenshot;
1523 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1526 /* LCOV_EXCL_START */
1527 if (display_wrapper)
1528 wl_proxy_wrapper_destroy(display_wrapper);
1529 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1531 /* LCOV_EXCL_STOP */
1534 efl_util_screenshot_deinitialize(screenshot);
1535 if (display_wrapper)
1536 wl_proxy_wrapper_destroy(display_wrapper);
1537 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1542 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1545 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1548 g_screenshot = NULL;
1550 if (_eflutil.wl.shot.screenshooter)
1552 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1553 _eflutil.wl.shot.screenshooter = NULL;
1555 if (_eflutil.wl.shot.tz_screenshooter)
1557 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1558 _eflutil.wl.shot.tz_screenshooter = NULL;
1561 return EFL_UTIL_ERROR_NONE;
1566 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1568 tbm_surface_h t_surface = NULL;
1569 struct wl_buffer *buffer = NULL;
1570 Efl_Util_Wl_Output_Info *output;
1573 if (!screenshot || (screenshot != g_screenshot))
1575 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1579 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1582 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1586 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1589 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1593 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1596 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1600 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1602 screenshot->shot_done = EINA_FALSE;
1603 while (!screenshot->shot_done && ret != -1)
1604 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1608 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1612 wl_buffer_destroy(buffer);
1614 /* reset shot_done for next screenshot */
1615 screenshot->shot_done = EINA_FALSE;
1621 tbm_surface_destroy(t_surface);
1623 wl_buffer_destroy(buffer);
1625 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);