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 /* Determine Tizen profile at runtime */
49 #include <system_info.h>
51 TIZEN_PROFILE_UNKNOWN = 0,
52 TIZEN_PROFILE_MOBILE = 0x1,
53 TIZEN_PROFILE_WEARABLE = 0x2,
54 TIZEN_PROFILE_TV = 0x4,
55 TIZEN_PROFILE_IVI = 0x8,
56 TIZEN_PROFILE_COMMON = 0x10,
58 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
59 static tizen_profile_t _get_tizen_profile()
62 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
63 switch (*profileName) {
66 profile = TIZEN_PROFILE_MOBILE;
70 profile = TIZEN_PROFILE_WEARABLE;
74 profile = TIZEN_PROFILE_TV;
78 profile = TIZEN_PROFILE_IVI;
80 default: // common or unknown ==> ALL ARE COMMON.
81 profile = TIZEN_PROFILE_COMMON;
87 static inline tizen_profile_t get_tizen_profile()
89 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
91 return _get_tizen_profile();
95 #define LOG_TAG "TIZEN_N_EFL_UTIL"
98 /* callback handler index */
99 #define CBH_NOTI_LEV 0
100 #define CBH_SCR_MODE 1
103 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
105 typedef struct _Efl_Util_Callback_Info
110 } Efl_Util_Callback_Info;
112 typedef struct _Efl_Util_Wl_Surface_Lv_Info
114 void *surface; /* wl_surface */
116 Eina_Bool wait_for_done;
118 } Efl_Util_Wl_Surface_Lv_Info;
120 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
122 void *surface; /* wl_surface */
124 Eina_Bool wait_for_done;
126 } Efl_Util_Wl_Surface_Scr_Mode_Info;
128 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
130 void *surface; /* wl_surface */
132 Eina_Bool wait_for_done;
134 } Efl_Util_Wl_Surface_Brightness_Info;
136 typedef struct _Efl_Util_Wl_Output_Info
138 struct wl_output *output;
139 int offset_x, offset_y, width, height;
140 } Efl_Util_Wl_Output_Info;
142 typedef struct _Efl_Util_Data
144 /* wayland related stuffs */
148 struct wl_display *dpy;
149 struct wl_event_queue *queue;
153 struct tizen_policy *proto;
154 Eina_Hash *hash_noti_lv;
155 Eina_Hash *hash_scr_mode;
159 struct wl_event_queue *queue;
160 struct screenshooter *screenshooter;
161 struct tizen_screenshooter *tz_screenshooter;
162 struct wayland_tbm_client *tbm_client;
163 Eina_List *output_list;
168 struct tizen_input_device_manager *devicemgr;
169 int request_notified;
173 struct tizen_display_policy *proto;
174 Eina_Hash *hash_brightness;
180 Eina_List *info_list; /* list of callback info */
181 unsigned int atom; /* x11 atom */
182 } cb_handler[CBH_MAX];
185 static Efl_Util_Data _eflutil =
190 { NULL, NULL, NULL }, /* tizen_policy protocol */
191 { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
192 { NULL, -1 }, /* tizen_input_device_manager protocol */
193 { NULL, NULL } /* display_policy protocol */
196 { NULL, 0 }, /* handler for notification level */
197 { NULL, 0 } /* handler for screen mode */
201 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
202 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
203 static Eina_List *_cb_info_list_get(int idx);
204 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
205 static Eina_Bool _wl_init(void);
206 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
207 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
208 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
209 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
210 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
211 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
212 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);
213 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);
214 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
215 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);
216 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);
217 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);
218 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
219 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);
221 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);
223 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);
224 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);
225 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
226 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
228 static const struct wl_registry_listener _wl_reg_listener =
231 _cb_wl_reg_global_remove
234 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
236 _cb_wl_reg_screenshooter_global,
237 _cb_wl_reg_screenshooter_global_remove
240 struct tizen_policy_listener _wl_tz_policy_listener =
242 _cb_wl_tz_policy_conformant,
243 _cb_wl_tz_policy_conformant_area,
244 _cb_wl_tz_policy_notification_done,
245 _cb_wl_tz_policy_transient_for_done,
246 _cb_wl_tz_policy_scr_mode_done,
247 _cb_wl_tz_policy_iconify_state_changed,
248 _cb_wl_tz_policy_supported_aux_hints,
249 _cb_wl_tz_policy_allowed_aux_hint,
250 _cb_wl_tz_policy_aux_message,
253 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
261 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
263 _cb_wl_tz_display_policy_brightness_done,
267 _cb_info_add(Evas_Object *win,
272 Efl_Util_Callback_Info *info;
274 info = _cb_info_find_by_win(win, idx);
277 _eflutil.cb_handler[idx].info_list
278 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
283 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
284 if (!info) return EINA_FALSE;
290 _eflutil.cb_handler[idx].info_list
291 = eina_list_append(_eflutil.cb_handler[idx].info_list,
298 _cb_info_del_by_win(Evas_Object *win,
301 Efl_Util_Callback_Info *info;
303 info = _cb_info_find_by_win(win, idx);
304 if (!info) return EINA_FALSE;
306 _eflutil.cb_handler[idx].info_list
307 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
315 _cb_info_list_get(int idx)
317 return _eflutil.cb_handler[idx].info_list;
320 static Efl_Util_Callback_Info *
321 _cb_info_find_by_win(Evas_Object *win,
325 Efl_Util_Callback_Info *info;
327 l = _cb_info_list_get(idx);
328 EINA_LIST_FOREACH(l, ll, info)
330 if (info->win == win) return info;
339 struct wl_display *display_wrapper = NULL;
340 struct wl_registry *reg = NULL;
342 if (_eflutil.wl.init) return EINA_TRUE;
346 _eflutil.wl.dpy = ecore_wl_display_get();
347 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
349 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
350 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail);
352 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
353 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
355 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
357 reg = wl_display_get_registry(display_wrapper);
358 wl_proxy_wrapper_destroy(display_wrapper);
359 display_wrapper = NULL;
360 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
362 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
364 _eflutil.wl.init = EINA_TRUE;
369 wl_proxy_wrapper_destroy(display_wrapper);
371 if (_eflutil.wl.queue)
373 wl_event_queue_destroy(_eflutil.wl.queue);
374 _eflutil.wl.queue = NULL;
382 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
383 int physical_width, int physical_height, int subpixel,
384 const char *make, const char *model, int transform)
386 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
387 if (wl_output == output->output)
389 output->offset_x = x;
390 output->offset_y = y;
395 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
396 int width, int height, int refresh)
398 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
399 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
401 output->width = width;
402 output->height = height;
407 _cb_wl_output_done(void *data, struct wl_output *wl_output)
412 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
416 static const struct wl_output_listener output_listener =
418 _cb_wl_output_geometry,
425 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
427 Eina_Bool *shot_done = (Eina_Bool*)data;
429 *shot_done = EINA_TRUE;
432 static const struct screenshooter_listener screenshooter_listener =
434 _cb_wl_screenshot_done
438 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
443 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
445 _eflutil.wl.shot.noti = noti;
448 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
450 _cb_tz_screenshot_format,
451 _cb_tz_screenshot_noti
455 _cb_wl_reg_global(void *data,
456 struct wl_registry *reg,
458 const char *interface,
459 unsigned int version)
461 if (!strcmp(interface, "tizen_policy"))
463 struct tizen_policy *proto;
464 proto = wl_registry_bind(reg,
466 &tizen_policy_interface,
470 tizen_policy_add_listener(proto,
471 &_wl_tz_policy_listener,
474 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
475 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
476 _eflutil.wl.policy.proto = proto;
478 else if (strcmp(interface, "wl_output") == 0)
480 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
481 EINA_SAFETY_ON_NULL_RETURN(output);
483 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
485 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
486 wl_output_add_listener(output->output, &output_listener, output);
488 else if (strcmp(interface, "tizen_input_device_manager") == 0)
490 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
491 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
493 else if (!strcmp(interface, "tizen_display_policy"))
495 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
496 if (!_eflutil.wl.display_policy.proto) return;
498 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
499 &_wl_tz_display_policy_listener,
502 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
506 /* LCOV_EXCL_START */
508 _cb_wl_reg_global_remove(void *data,
509 struct wl_registry *reg,
512 _eflutil.wl.policy.proto = NULL;
513 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
514 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
516 _eflutil.wl.display_policy.proto = NULL;
517 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
522 _cb_wl_reg_screenshooter_global(void *data,
523 struct wl_registry *reg,
525 const char *interface,
526 unsigned int version)
528 if (strcmp(interface, "screenshooter") == 0)
530 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
531 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
533 else if (strcmp(interface, "tizen_screenshooter") == 0)
535 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
536 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
538 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
542 /* LCOV_EXCL_START */
544 _cb_wl_reg_screenshooter_global_remove(void *data,
545 struct wl_registry *reg,
550 static Efl_Util_Callback_Info *
551 _cb_info_find_by_wlsurf(void *wlsurf,
555 Efl_Util_Callback_Info *info;
556 Ecore_Wl_Window *wlwin2 = NULL;
557 void *wlsurf2 = NULL;
559 l = _cb_info_list_get(idx);
560 EINA_LIST_FOREACH(l, ll, info)
562 wlwin2 = elm_win_wl_window_get(info->win);
563 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
564 if (wlsurf== wlsurf2) return info;
571 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
572 struct wl_surface *surface, uint32_t is_conformant)
577 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
578 struct wl_surface *surface, uint32_t conformant_part,
579 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
585 _cb_wl_tz_policy_notification_done(void *data,
586 struct tizen_policy *tizen_policy,
587 struct wl_surface *surface,
591 Efl_Util_Wl_Surface_Lv_Info *lv_info;
592 Efl_Util_Callback_Info *cb_info;
594 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
597 lv_info->level = level;
598 lv_info->wait_for_done = EINA_FALSE;
599 lv_info->state = state;
602 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
604 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
605 if (!cb_info) return;
606 if (!cb_info->cb) return;
608 cb_info->cb(cb_info->win,
609 EFL_UTIL_ERROR_PERMISSION_DENIED,
613 /* LCOV_EXCL_START */
615 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
621 _cb_wl_tz_policy_scr_mode_done(void *data,
622 struct tizen_policy *tizen_policy,
623 struct wl_surface *surface,
628 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
629 Efl_Util_Callback_Info *cb_info;
631 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
634 scr_mode_info->mode = mode;
635 scr_mode_info->wait_for_done = EINA_FALSE;
636 scr_mode_info->state = state;
639 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
641 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
642 if (!cb_info) return;
643 if (!cb_info->cb) return;
645 cb_info->cb(cb_info->win,
646 EFL_UTIL_ERROR_PERMISSION_DENIED,
650 /* LCOV_EXCL_START */
651 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)
655 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)
659 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
663 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)
669 _cb_wl_tz_display_policy_brightness_done(void *data,
670 struct tizen_display_policy *tizen_display_policy,
671 struct wl_surface *surface,
675 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
677 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
680 brightness_info->brightness = brightness;
681 brightness_info->wait_for_done = EINA_FALSE;
682 brightness_info->state = state;
687 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
689 Efl_Util_Wl_Surface_Lv_Info *lv_info;
692 if (EINA_UNLIKELY(!lv_info))
695 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
699 efl_util_set_notification_window_level(Evas_Object *window,
700 efl_util_notification_level_e level)
704 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
705 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
706 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
707 EFL_UTIL_ERROR_INVALID_PARAMETER);
709 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
711 dlog_print(DLOG_WARN, LOG_TAG,
712 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
714 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
716 dlog_print(DLOG_WARN, LOG_TAG,
717 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
719 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
721 dlog_print(DLOG_WARN, LOG_TAG,
722 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
726 Ecore_Wl_Window *wlwin;
727 struct wl_surface *surface;
728 Efl_Util_Wl_Surface_Lv_Info *lv_info;
729 Ecore_Wl_Window_Type wl_type;
732 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
734 wlwin = elm_win_wl_window_get(window);
735 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
737 type = elm_win_type_get(window);
738 if (type != ELM_WIN_NOTIFICATION)
740 wl_type = ecore_wl_window_type_get(wlwin);
741 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
742 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
745 while (!_eflutil.wl.policy.proto)
746 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
748 surface = ecore_wl_window_surface_get(wlwin);
749 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
750 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
752 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
755 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
756 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
758 lv_info->surface = surface;
759 lv_info->level = (int)level;
760 lv_info->wait_for_done = EINA_TRUE;
761 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
762 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
766 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
767 _cb_window_del, lv_info);
771 lv_info->level = (int)level;
772 lv_info->wait_for_done = EINA_TRUE;
773 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
777 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
778 surface, (int)level);
780 if (lv_info->wait_for_done)
783 while (lv_info->wait_for_done && (count < 3))
786 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
790 if (lv_info->wait_for_done)
792 return EFL_UTIL_ERROR_INVALID_PARAMETER;
796 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
798 return EFL_UTIL_ERROR_PERMISSION_DENIED;
803 return EFL_UTIL_ERROR_NONE;
807 efl_util_get_notification_window_level(Evas_Object *window,
808 efl_util_notification_level_e *level)
812 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
813 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
816 Ecore_Wl_Window *wlwin;
817 struct wl_surface *surface;
818 Efl_Util_Wl_Surface_Lv_Info *lv_info;
819 Ecore_Wl_Window_Type wl_type;
822 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
824 wlwin = elm_win_wl_window_get(window);
825 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
827 type = elm_win_type_get(window);
828 if (type != ELM_WIN_NOTIFICATION)
830 wl_type = ecore_wl_window_type_get(wlwin);
831 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
832 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
835 while (!_eflutil.wl.policy.proto)
836 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
838 surface = ecore_wl_window_surface_get(wlwin);
839 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
840 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
842 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
845 if (lv_info->wait_for_done)
848 while ((lv_info->wait_for_done) && (count < 3))
851 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
855 if (lv_info->wait_for_done)
857 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
858 return EFL_UTIL_ERROR_INVALID_PARAMETER;
862 switch (lv_info->level)
864 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
865 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
866 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
867 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
868 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
869 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
870 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
871 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
872 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
873 return EFL_UTIL_ERROR_INVALID_PARAMETER;
875 return EFL_UTIL_ERROR_NONE;
878 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
880 return EFL_UTIL_ERROR_NONE;
884 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
885 efl_util_notification_window_level_error_cb callback,
888 dlog_print(DLOG_WARN, LOG_TAG,
889 "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.");
891 Eina_Bool ret = EINA_FALSE;
893 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
894 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
896 ret = _cb_info_add(window,
897 (Efl_Util_Cb)callback,
900 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
902 return EFL_UTIL_ERROR_NONE;
906 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
908 dlog_print(DLOG_WARN, LOG_TAG,
909 "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.");
911 Eina_Bool ret = EINA_FALSE;
913 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
915 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
916 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
918 return EFL_UTIL_ERROR_NONE;
922 efl_util_set_window_opaque_state(Evas_Object *window,
927 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
928 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
929 EFL_UTIL_ERROR_INVALID_PARAMETER);
931 Ecore_Wl_Window *wlwin;
932 struct wl_surface *surface;
934 if (!_eflutil.wl.policy.proto)
939 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
941 while (!_eflutil.wl.policy.proto && ret != -1)
942 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
944 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
947 wlwin = elm_win_wl_window_get(window);
949 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
951 surface = ecore_wl_window_surface_get(wlwin);
953 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
955 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
957 return EFL_UTIL_ERROR_NONE;
961 efl_util_set_window_screen_mode(Evas_Object *window,
962 efl_util_screen_mode_e mode)
964 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
965 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
966 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
967 EFL_UTIL_ERROR_INVALID_PARAMETER);
969 Ecore_Wl_Window *wlwin;
970 struct wl_surface *surface;
971 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
975 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
977 wlwin = elm_win_wl_window_get(window);
980 while (!_eflutil.wl.policy.proto)
981 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
983 surface = ecore_wl_window_surface_get(wlwin);
984 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
985 EFL_UTIL_ERROR_INVALID_PARAMETER);
987 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
990 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
991 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
993 scr_mode_info->surface = surface;
994 scr_mode_info->mode = (unsigned int)mode;
995 scr_mode_info->wait_for_done = EINA_TRUE;
996 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
998 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
1004 scr_mode_info->mode = (unsigned int)mode;
1005 scr_mode_info->wait_for_done = EINA_TRUE;
1006 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1009 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
1010 surface, (unsigned int)mode);
1011 if (scr_mode_info->wait_for_done)
1014 while (scr_mode_info->wait_for_done && (count < 3))
1017 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1021 if (scr_mode_info->wait_for_done)
1023 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1027 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1029 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1034 return EFL_UTIL_ERROR_NONE;
1037 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1041 efl_util_get_window_screen_mode(Evas_Object *window,
1042 efl_util_screen_mode_e *mode)
1044 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1045 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1047 Ecore_Wl_Window *wlwin;
1048 struct wl_surface *surface;
1049 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1053 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1055 wlwin = elm_win_wl_window_get(window);
1058 while (!_eflutil.wl.policy.proto)
1059 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1061 surface = ecore_wl_window_surface_get(wlwin);
1062 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1063 EFL_UTIL_ERROR_INVALID_PARAMETER);
1065 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1068 if (scr_mode_info->wait_for_done)
1070 while (scr_mode_info->wait_for_done)
1073 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1077 switch (scr_mode_info->mode)
1079 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1080 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1081 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1082 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1084 return EFL_UTIL_ERROR_NONE;
1088 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1089 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1093 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1097 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1098 efl_util_window_screen_mode_error_cb callback,
1101 /* Wearable device cannot use this. */
1102 if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
1103 return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
1105 dlog_print(DLOG_WARN, LOG_TAG,
1106 "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.");
1108 Eina_Bool ret = EINA_FALSE;
1110 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1111 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1113 ret = _cb_info_add(window,
1114 (Efl_Util_Cb)callback,
1117 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1119 return EFL_UTIL_ERROR_NONE;
1123 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1125 /* Wearable device cannot use this. */
1126 if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
1127 return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
1129 dlog_print(DLOG_WARN, LOG_TAG,
1130 "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.");
1132 Eina_Bool ret = EINA_FALSE;
1134 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1136 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1137 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1139 return EFL_UTIL_ERROR_NONE;
1143 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1145 Ecore_Wl_Window *wlwin;
1146 struct wl_surface *surface;
1147 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1150 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1151 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1154 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1156 wlwin = elm_win_wl_window_get(window);
1159 while (!_eflutil.wl.display_policy.proto)
1160 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1162 surface = ecore_wl_window_surface_get(wlwin);
1163 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1164 EFL_UTIL_ERROR_INVALID_PARAMETER);
1166 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1167 if (!brightness_info)
1169 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1170 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1172 brightness_info->surface = surface;
1173 brightness_info->brightness = brightness;
1174 brightness_info->wait_for_done = EINA_TRUE;
1175 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1177 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1183 brightness_info->brightness = brightness;
1184 brightness_info->wait_for_done = EINA_TRUE;
1185 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1188 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1189 surface, brightness);
1190 if (brightness_info->wait_for_done)
1193 while (brightness_info->wait_for_done && (count < 3))
1196 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1200 if (brightness_info->wait_for_done)
1202 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1206 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1208 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1212 return EFL_UTIL_ERROR_NONE;
1215 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1219 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1221 Ecore_Wl_Window *wlwin;
1222 struct wl_surface *surface;
1223 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1226 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1227 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1230 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1232 wlwin = elm_win_wl_window_get(window);
1233 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1235 while (!_eflutil.wl.display_policy.proto)
1236 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1238 surface = ecore_wl_window_surface_get(wlwin);
1239 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1240 EFL_UTIL_ERROR_INVALID_PARAMETER);
1242 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1243 if (brightness_info)
1245 if (brightness_info->wait_for_done)
1247 while (brightness_info->wait_for_done)
1250 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1253 *brightness = brightness_info->brightness;
1258 return EFL_UTIL_ERROR_NONE;
1262 struct _efl_util_inputgen_h
1264 unsigned int init_type;
1269 _cb_device_add(void *data EINA_UNUSED,
1270 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1271 uint32_t serial EINA_UNUSED,
1272 const char *identifier EINA_UNUSED,
1273 struct tizen_input_device *device EINA_UNUSED,
1274 struct wl_seat *seat EINA_UNUSED)
1279 /* LCOV_EXCL_START */
1281 _cb_device_remove(void *data EINA_UNUSED,
1282 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1283 uint32_t serial EINA_UNUSED,
1284 const char *identifier EINA_UNUSED,
1285 struct tizen_input_device *device EINA_UNUSED,
1286 struct wl_seat *seat EINA_UNUSED)
1290 /* LCOV_EXCL_STOP */
1293 _cb_error(void *data EINA_UNUSED,
1294 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1297 _eflutil.wl.devmgr.request_notified = errorcode;
1300 /* LCOV_EXCL_START */
1302 _cb_block_expired(void *data EINA_UNUSED,
1303 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1307 /* LCOV_EXCL_STOP */
1309 static efl_util_error_e
1310 _efl_util_input_convert_input_generator_error(int ret)
1314 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1315 return EFL_UTIL_ERROR_NONE;
1316 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1317 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1318 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1319 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1320 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1321 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1323 return EFL_UTIL_ERROR_NONE;
1327 API efl_util_inputgen_h
1328 efl_util_input_initialize_generator(unsigned int dev_type)
1330 int ret = EFL_UTIL_ERROR_NONE;
1331 efl_util_inputgen_h inputgen_h = NULL;
1332 unsigned int clas = 0x0;
1335 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1336 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1337 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1339 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1343 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1346 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1350 inputgen_h->init_type |= dev_type;
1353 if (ret == (int)EINA_FALSE)
1355 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1359 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1360 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1361 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1362 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1363 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1364 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1366 while (!_eflutil.wl.devmgr.devicemgr)
1367 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1369 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
1371 while (_eflutil.wl.devmgr.request_notified == -1)
1372 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1374 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1375 _eflutil.wl.devmgr.request_notified = -1;
1377 set_last_result(ret);
1378 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1392 API efl_util_inputgen_h
1393 efl_util_input_initialize_generator_with_name(unsigned int dev_type, const char *name)
1395 int ret = EFL_UTIL_ERROR_NONE;
1396 efl_util_inputgen_h inputgen_h = NULL;
1397 unsigned int clas = 0x0;
1400 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1401 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1402 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1404 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1408 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1411 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1415 inputgen_h->init_type |= dev_type;
1416 strncpy(inputgen_h->name, name, 31);
1419 if (ret == (int)EINA_FALSE)
1421 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1425 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1426 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1427 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1428 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1429 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1430 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1432 while (!_eflutil.wl.devmgr.devicemgr)
1433 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1435 tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name);
1437 while (_eflutil.wl.devmgr.request_notified == -1)
1438 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1440 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1441 _eflutil.wl.devmgr.request_notified = -1;
1443 set_last_result(ret);
1444 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1460 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1462 int ret = EFL_UTIL_ERROR_NONE;
1463 unsigned int clas = 0x0;
1464 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1466 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1467 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1468 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1469 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1470 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1471 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1476 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1478 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas);
1480 while (_eflutil.wl.devmgr.request_notified == -1)
1481 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1483 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1484 _eflutil.wl.devmgr.request_notified = -1;
1490 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1492 int ret = EFL_UTIL_ERROR_NONE;
1494 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1495 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1496 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1497 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1499 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1501 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1503 while (_eflutil.wl.devmgr.request_notified == -1)
1504 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1506 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1507 _eflutil.wl.devmgr.request_notified = -1;
1513 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1514 efl_util_input_touch_type_e touch_type, int x, int y)
1517 enum tizen_input_device_manager_pointer_event_type type;
1519 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1520 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1521 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1522 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1524 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1528 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1529 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1531 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1532 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1534 case EFL_UTIL_INPUT_TOUCH_END:
1535 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1538 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1541 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1543 while (_eflutil.wl.devmgr.request_notified == -1)
1544 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1546 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1547 _eflutil.wl.devmgr.request_notified = -1;
1553 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)
1556 enum tizen_input_device_manager_pointer_event_type type;
1558 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1559 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1560 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1561 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1563 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1565 switch(pointer_type)
1567 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1568 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1570 case EFL_UTIL_INPUT_POINTER_MOVE:
1571 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1573 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1574 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1577 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1580 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1582 while (_eflutil.wl.devmgr.request_notified == -1)
1583 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1585 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1586 _eflutil.wl.devmgr.request_notified = -1;
1592 struct _efl_util_screenshot_h
1597 Eina_Bool shot_done;
1602 Eina_Bool auto_rotation;
1605 /* scrrenshot handle */
1606 static efl_util_screenshot_h g_screenshot;
1607 static Eina_Bool shot_mutex_init;
1608 static pthread_mutex_t shot_lock;
1611 _screenshot_mutex_init(void)
1613 if (shot_mutex_init)
1616 if (pthread_mutex_init(&shot_lock, NULL))
1618 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1619 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1622 shot_mutex_init = EINA_TRUE;
1628 _screenshot_mutex_destory(void)
1630 if (!shot_mutex_init)
1633 if (pthread_mutex_destroy(&shot_lock))
1635 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1636 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1639 shot_mutex_init = EINA_FALSE;
1645 _screenshot_mutex_lock(void)
1647 if (!_screenshot_mutex_init())
1650 pthread_mutex_lock(&shot_lock);
1654 _screenshot_mutex_unlock(void)
1656 pthread_mutex_unlock(&shot_lock);
1659 API efl_util_screenshot_h
1660 efl_util_screenshot_initialize(int width, int height)
1662 efl_util_screenshot_h screenshot = NULL;
1663 struct wl_display *display_wrapper = NULL;
1664 struct wl_registry *reg = NULL;
1667 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1668 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1670 _screenshot_mutex_lock();
1672 if (!_eflutil.wl.shot.screenshooter)
1675 if (ret == (int)EINA_FALSE)
1677 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1678 _screenshot_mutex_unlock();
1681 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1683 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1684 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory);
1686 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1687 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory);
1689 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
1691 reg = wl_display_get_registry(display_wrapper);
1692 wl_proxy_wrapper_destroy(display_wrapper);
1693 display_wrapper = NULL;
1694 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1696 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1698 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1699 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1700 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1701 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1703 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1704 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1707 if (_eflutil.wl.shot.noti == 0)
1709 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1715 if (g_screenshot->width != width || g_screenshot->height != height)
1717 g_screenshot->width = width;
1718 g_screenshot->height = height;
1721 _screenshot_mutex_unlock();
1723 return g_screenshot;
1726 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1727 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1729 screenshot->width = width;
1730 screenshot->height = height;
1731 screenshot->auto_rotation = EINA_TRUE;
1733 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1734 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1736 g_screenshot = screenshot;
1737 set_last_result(EFL_UTIL_ERROR_NONE);
1739 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1741 _screenshot_mutex_unlock();
1743 return g_screenshot;
1746 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1749 /* LCOV_EXCL_START */
1750 if (display_wrapper)
1751 wl_proxy_wrapper_destroy(display_wrapper);
1752 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1756 efl_util_screenshot_deinitialize(screenshot);
1757 _screenshot_mutex_unlock();
1758 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1760 /* LCOV_EXCL_STOP */
1764 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1766 _screenshot_mutex_lock();
1770 _screenshot_mutex_unlock();
1771 _screenshot_mutex_destory();
1772 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1776 g_screenshot = NULL;
1778 if (_eflutil.wl.shot.queue)
1780 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1781 _eflutil.wl.shot.queue = NULL;
1784 if (_eflutil.wl.shot.screenshooter)
1786 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1787 _eflutil.wl.shot.screenshooter = NULL;
1789 if (_eflutil.wl.shot.tz_screenshooter)
1791 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1792 _eflutil.wl.shot.tz_screenshooter = NULL;
1795 _screenshot_mutex_unlock();
1796 _screenshot_mutex_destory();
1798 return EFL_UTIL_ERROR_NONE;
1803 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1805 tbm_surface_h t_surface = NULL;
1806 struct wl_buffer *buffer = NULL;
1807 Efl_Util_Wl_Output_Info *output;
1810 _screenshot_mutex_lock();
1812 if (!screenshot || (screenshot != g_screenshot))
1814 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1815 _screenshot_mutex_unlock();
1819 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1822 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1826 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1829 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1833 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1836 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1840 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1842 screenshot->shot_done = EINA_FALSE;
1843 while (!screenshot->shot_done && ret != -1)
1844 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1848 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1852 wl_buffer_destroy(buffer);
1854 /* reset shot_done for next screenshot */
1855 screenshot->shot_done = EINA_FALSE;
1857 set_last_result(EFL_UTIL_ERROR_NONE);
1859 _screenshot_mutex_unlock();
1865 tbm_surface_destroy(t_surface);
1867 wl_buffer_destroy(buffer);
1869 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1871 _screenshot_mutex_unlock();
1877 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1879 if (!screenshot || (screenshot != g_screenshot))
1880 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1882 if (!(set == 0 || set == 1))
1883 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1886 g_screenshot->auto_rotation = EINA_TRUE;
1888 g_screenshot->auto_rotation = EINA_FALSE;
1890 tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1892 return EFL_UTIL_ERROR_NONE;
1896 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1898 if (!screenshot || (screenshot != g_screenshot) || !set)
1899 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1901 *set = g_screenshot->auto_rotation;
1903 return EFL_UTIL_ERROR_NONE;