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 */
195 { NULL, 0 }, /* handler for notification level */
196 { NULL, 0 } /* handler for screen mode */
200 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
201 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
202 static Eina_List *_cb_info_list_get(int idx);
203 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
204 static Eina_Bool _wl_init(void);
205 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
206 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
207 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
208 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
209 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
210 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
211 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);
212 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);
213 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
214 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);
215 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);
216 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);
217 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
218 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);
220 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);
222 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);
223 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);
224 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
225 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
227 static const struct wl_registry_listener _wl_reg_listener =
230 _cb_wl_reg_global_remove
233 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
235 _cb_wl_reg_screenshooter_global,
236 _cb_wl_reg_screenshooter_global_remove
239 struct tizen_policy_listener _wl_tz_policy_listener =
241 _cb_wl_tz_policy_conformant,
242 _cb_wl_tz_policy_conformant_area,
243 _cb_wl_tz_policy_notification_done,
244 _cb_wl_tz_policy_transient_for_done,
245 _cb_wl_tz_policy_scr_mode_done,
246 _cb_wl_tz_policy_iconify_state_changed,
247 _cb_wl_tz_policy_supported_aux_hints,
248 _cb_wl_tz_policy_allowed_aux_hint,
249 _cb_wl_tz_policy_aux_message,
252 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
260 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
262 _cb_wl_tz_display_policy_brightness_done,
266 _cb_info_add(Evas_Object *win,
271 Efl_Util_Callback_Info *info;
273 info = _cb_info_find_by_win(win, idx);
276 _eflutil.cb_handler[idx].info_list
277 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
282 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
283 if (!info) return EINA_FALSE;
289 _eflutil.cb_handler[idx].info_list
290 = eina_list_append(_eflutil.cb_handler[idx].info_list,
297 _cb_info_del_by_win(Evas_Object *win,
300 Efl_Util_Callback_Info *info;
302 info = _cb_info_find_by_win(win, idx);
303 if (!info) return EINA_FALSE;
305 _eflutil.cb_handler[idx].info_list
306 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
314 _cb_info_list_get(int idx)
316 return _eflutil.cb_handler[idx].info_list;
319 static Efl_Util_Callback_Info *
320 _cb_info_find_by_win(Evas_Object *win,
324 Efl_Util_Callback_Info *info;
326 l = _cb_info_list_get(idx);
327 EINA_LIST_FOREACH(l, ll, info)
329 if (info->win == win) return info;
338 struct wl_display *display_wrapper = NULL;
339 struct wl_registry *reg = NULL;
341 if (_eflutil.wl.init) return EINA_TRUE;
345 _eflutil.wl.dpy = ecore_wl_display_get();
346 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
348 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
349 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail);
351 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
352 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
354 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
356 reg = wl_display_get_registry(display_wrapper);
357 wl_proxy_wrapper_destroy(display_wrapper);
358 display_wrapper = NULL;
359 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
361 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
363 _eflutil.wl.init = EINA_TRUE;
368 wl_proxy_wrapper_destroy(display_wrapper);
370 if (_eflutil.wl.queue)
372 wl_event_queue_destroy(_eflutil.wl.queue);
373 _eflutil.wl.queue = NULL;
381 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
382 int physical_width, int physical_height, int subpixel,
383 const char *make, const char *model, int transform)
385 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
386 if (wl_output == output->output)
388 output->offset_x = x;
389 output->offset_y = y;
394 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
395 int width, int height, int refresh)
397 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
398 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
400 output->width = width;
401 output->height = height;
406 _cb_wl_output_done(void *data, struct wl_output *wl_output)
411 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
415 static const struct wl_output_listener output_listener =
417 _cb_wl_output_geometry,
424 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
426 Eina_Bool *shot_done = (Eina_Bool*)data;
428 *shot_done = EINA_TRUE;
431 static const struct screenshooter_listener screenshooter_listener =
433 _cb_wl_screenshot_done
437 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
442 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
444 _eflutil.wl.shot.noti = noti;
447 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
449 _cb_tz_screenshot_format,
450 _cb_tz_screenshot_noti
454 _cb_wl_reg_global(void *data,
455 struct wl_registry *reg,
457 const char *interface,
458 unsigned int version)
460 if (!strcmp(interface, "tizen_policy"))
462 struct tizen_policy *proto;
463 proto = wl_registry_bind(reg,
465 &tizen_policy_interface,
469 tizen_policy_add_listener(proto,
470 &_wl_tz_policy_listener,
473 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
474 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
475 _eflutil.wl.policy.proto = proto;
477 else if (strcmp(interface, "wl_output") == 0)
479 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
480 EINA_SAFETY_ON_NULL_RETURN(output);
482 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
484 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
485 wl_output_add_listener(output->output, &output_listener, output);
487 else if (strcmp(interface, "tizen_input_device_manager") == 0)
489 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
490 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
492 else if (!strcmp(interface, "tizen_display_policy"))
494 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
495 if (!_eflutil.wl.display_policy.proto) return;
497 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
498 &_wl_tz_display_policy_listener,
501 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
505 /* LCOV_EXCL_START */
507 _cb_wl_reg_global_remove(void *data,
508 struct wl_registry *reg,
511 _eflutil.wl.policy.proto = NULL;
512 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
513 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
515 _eflutil.wl.display_policy.proto = NULL;
516 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
521 _cb_wl_reg_screenshooter_global(void *data,
522 struct wl_registry *reg,
524 const char *interface,
525 unsigned int version)
527 if (strcmp(interface, "screenshooter") == 0)
529 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
530 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
532 else if (strcmp(interface, "tizen_screenshooter") == 0)
534 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
535 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
537 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
541 /* LCOV_EXCL_START */
543 _cb_wl_reg_screenshooter_global_remove(void *data,
544 struct wl_registry *reg,
549 static Efl_Util_Callback_Info *
550 _cb_info_find_by_wlsurf(void *wlsurf,
554 Efl_Util_Callback_Info *info;
555 Ecore_Wl_Window *wlwin2 = NULL;
556 void *wlsurf2 = NULL;
558 l = _cb_info_list_get(idx);
559 EINA_LIST_FOREACH(l, ll, info)
561 wlwin2 = elm_win_wl_window_get(info->win);
562 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
563 if (wlsurf== wlsurf2) return info;
570 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
571 struct wl_surface *surface, uint32_t is_conformant)
576 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
577 struct wl_surface *surface, uint32_t conformant_part,
578 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
584 _cb_wl_tz_policy_notification_done(void *data,
585 struct tizen_policy *tizen_policy,
586 struct wl_surface *surface,
590 Efl_Util_Wl_Surface_Lv_Info *lv_info;
591 Efl_Util_Callback_Info *cb_info;
593 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
596 lv_info->level = level;
597 lv_info->wait_for_done = EINA_FALSE;
598 lv_info->state = state;
601 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
603 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
604 if (!cb_info) return;
605 if (!cb_info->cb) return;
607 cb_info->cb(cb_info->win,
608 EFL_UTIL_ERROR_PERMISSION_DENIED,
612 /* LCOV_EXCL_START */
614 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
620 _cb_wl_tz_policy_scr_mode_done(void *data,
621 struct tizen_policy *tizen_policy,
622 struct wl_surface *surface,
627 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
628 Efl_Util_Callback_Info *cb_info;
630 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
633 scr_mode_info->mode = mode;
634 scr_mode_info->wait_for_done = EINA_FALSE;
635 scr_mode_info->state = state;
638 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
640 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
641 if (!cb_info) return;
642 if (!cb_info->cb) return;
644 cb_info->cb(cb_info->win,
645 EFL_UTIL_ERROR_PERMISSION_DENIED,
649 /* LCOV_EXCL_START */
650 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)
654 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)
658 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
662 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)
668 _cb_wl_tz_display_policy_brightness_done(void *data,
669 struct tizen_display_policy *tizen_display_policy,
670 struct wl_surface *surface,
674 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
676 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
679 brightness_info->brightness = brightness;
680 brightness_info->wait_for_done = EINA_FALSE;
681 brightness_info->state = state;
686 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
688 Efl_Util_Wl_Surface_Lv_Info *lv_info;
691 if (EINA_UNLIKELY(!lv_info))
694 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
698 efl_util_set_notification_window_level(Evas_Object *window,
699 efl_util_notification_level_e level)
703 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
704 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
705 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
706 EFL_UTIL_ERROR_INVALID_PARAMETER);
708 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
710 dlog_print(DLOG_WARN, LOG_TAG,
711 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
713 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
715 dlog_print(DLOG_WARN, LOG_TAG,
716 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
718 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
720 dlog_print(DLOG_WARN, LOG_TAG,
721 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
725 Ecore_Wl_Window *wlwin;
726 struct wl_surface *surface;
727 Efl_Util_Wl_Surface_Lv_Info *lv_info;
728 Ecore_Wl_Window_Type wl_type;
731 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
733 wlwin = elm_win_wl_window_get(window);
734 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
736 type = elm_win_type_get(window);
737 if (type != ELM_WIN_NOTIFICATION)
739 wl_type = ecore_wl_window_type_get(wlwin);
740 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
741 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
744 while (!_eflutil.wl.policy.proto)
745 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
747 surface = ecore_wl_window_surface_get(wlwin);
748 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
749 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
751 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
754 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
755 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
757 lv_info->surface = surface;
758 lv_info->level = (int)level;
759 lv_info->wait_for_done = EINA_TRUE;
760 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
761 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
765 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
766 _cb_window_del, lv_info);
770 lv_info->level = (int)level;
771 lv_info->wait_for_done = EINA_TRUE;
772 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
776 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
777 surface, (int)level);
779 if (lv_info->wait_for_done)
782 while (lv_info->wait_for_done && (count < 3))
785 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
789 if (lv_info->wait_for_done)
791 return EFL_UTIL_ERROR_INVALID_PARAMETER;
795 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
797 return EFL_UTIL_ERROR_PERMISSION_DENIED;
802 return EFL_UTIL_ERROR_NONE;
806 efl_util_get_notification_window_level(Evas_Object *window,
807 efl_util_notification_level_e *level)
811 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
812 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
815 Ecore_Wl_Window *wlwin;
816 struct wl_surface *surface;
817 Efl_Util_Wl_Surface_Lv_Info *lv_info;
818 Ecore_Wl_Window_Type wl_type;
821 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
823 wlwin = elm_win_wl_window_get(window);
824 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
826 type = elm_win_type_get(window);
827 if (type != ELM_WIN_NOTIFICATION)
829 wl_type = ecore_wl_window_type_get(wlwin);
830 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
831 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
834 while (!_eflutil.wl.policy.proto)
835 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
837 surface = ecore_wl_window_surface_get(wlwin);
838 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
839 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
841 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
844 if (lv_info->wait_for_done)
847 while ((lv_info->wait_for_done) && (count < 3))
850 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
854 if (lv_info->wait_for_done)
856 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
857 return EFL_UTIL_ERROR_INVALID_PARAMETER;
861 switch (lv_info->level)
863 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
864 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
865 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
866 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
867 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
868 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
869 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
870 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
871 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
872 return EFL_UTIL_ERROR_INVALID_PARAMETER;
874 return EFL_UTIL_ERROR_NONE;
877 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
879 return EFL_UTIL_ERROR_NONE;
883 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
884 efl_util_notification_window_level_error_cb callback,
887 dlog_print(DLOG_WARN, LOG_TAG,
888 "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.");
890 Eina_Bool ret = EINA_FALSE;
892 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
893 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
895 ret = _cb_info_add(window,
896 (Efl_Util_Cb)callback,
899 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
901 return EFL_UTIL_ERROR_NONE;
905 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
907 dlog_print(DLOG_WARN, LOG_TAG,
908 "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.");
910 Eina_Bool ret = EINA_FALSE;
912 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
914 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
915 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
917 return EFL_UTIL_ERROR_NONE;
921 efl_util_set_window_opaque_state(Evas_Object *window,
926 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
927 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
928 EFL_UTIL_ERROR_INVALID_PARAMETER);
930 Ecore_Wl_Window *wlwin;
931 struct wl_surface *surface;
933 if (!_eflutil.wl.policy.proto)
938 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
940 while (!_eflutil.wl.policy.proto && ret != -1)
941 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
943 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
946 wlwin = elm_win_wl_window_get(window);
948 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
950 surface = ecore_wl_window_surface_get(wlwin);
952 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
954 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
956 return EFL_UTIL_ERROR_NONE;
960 efl_util_set_window_screen_mode(Evas_Object *window,
961 efl_util_screen_mode_e mode)
963 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
964 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
965 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
966 EFL_UTIL_ERROR_INVALID_PARAMETER);
968 Ecore_Wl_Window *wlwin;
969 struct wl_surface *surface;
970 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
974 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
976 wlwin = elm_win_wl_window_get(window);
979 while (!_eflutil.wl.policy.proto)
980 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
982 surface = ecore_wl_window_surface_get(wlwin);
983 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
984 EFL_UTIL_ERROR_INVALID_PARAMETER);
986 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
989 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
990 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
992 scr_mode_info->surface = surface;
993 scr_mode_info->mode = (unsigned int)mode;
994 scr_mode_info->wait_for_done = EINA_TRUE;
995 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
997 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
1003 scr_mode_info->mode = (unsigned int)mode;
1004 scr_mode_info->wait_for_done = EINA_TRUE;
1005 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1008 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
1009 surface, (unsigned int)mode);
1010 if (scr_mode_info->wait_for_done)
1013 while (scr_mode_info->wait_for_done && (count < 3))
1016 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1020 if (scr_mode_info->wait_for_done)
1022 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1026 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1028 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1033 return EFL_UTIL_ERROR_NONE;
1036 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1040 efl_util_get_window_screen_mode(Evas_Object *window,
1041 efl_util_screen_mode_e *mode)
1043 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1044 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1046 Ecore_Wl_Window *wlwin;
1047 struct wl_surface *surface;
1048 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1052 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1054 wlwin = elm_win_wl_window_get(window);
1057 while (!_eflutil.wl.policy.proto)
1058 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1060 surface = ecore_wl_window_surface_get(wlwin);
1061 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1062 EFL_UTIL_ERROR_INVALID_PARAMETER);
1064 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1067 if (scr_mode_info->wait_for_done)
1069 while (scr_mode_info->wait_for_done)
1072 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1076 switch (scr_mode_info->mode)
1078 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1079 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1080 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1081 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1083 return EFL_UTIL_ERROR_NONE;
1087 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1088 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1092 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1096 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1097 efl_util_window_screen_mode_error_cb callback,
1100 /* Wearable device cannot use this. */
1101 if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
1102 return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
1104 dlog_print(DLOG_WARN, LOG_TAG,
1105 "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.");
1107 Eina_Bool ret = EINA_FALSE;
1109 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1110 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1112 ret = _cb_info_add(window,
1113 (Efl_Util_Cb)callback,
1116 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1118 return EFL_UTIL_ERROR_NONE;
1122 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1124 /* Wearable device cannot use this. */
1125 if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
1126 return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
1128 dlog_print(DLOG_WARN, LOG_TAG,
1129 "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.");
1131 Eina_Bool ret = EINA_FALSE;
1133 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1135 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1136 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1138 return EFL_UTIL_ERROR_NONE;
1142 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1144 Ecore_Wl_Window *wlwin;
1145 struct wl_surface *surface;
1146 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1149 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1150 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1153 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1155 wlwin = elm_win_wl_window_get(window);
1158 while (!_eflutil.wl.display_policy.proto)
1159 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1161 surface = ecore_wl_window_surface_get(wlwin);
1162 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1163 EFL_UTIL_ERROR_INVALID_PARAMETER);
1165 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1166 if (!brightness_info)
1168 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1169 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1171 brightness_info->surface = surface;
1172 brightness_info->brightness = brightness;
1173 brightness_info->wait_for_done = EINA_TRUE;
1174 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1176 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1182 brightness_info->brightness = brightness;
1183 brightness_info->wait_for_done = EINA_TRUE;
1184 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1187 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1188 surface, brightness);
1189 if (brightness_info->wait_for_done)
1192 while (brightness_info->wait_for_done && (count < 3))
1195 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1199 if (brightness_info->wait_for_done)
1201 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1205 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1207 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1211 return EFL_UTIL_ERROR_NONE;
1214 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1218 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1220 Ecore_Wl_Window *wlwin;
1221 struct wl_surface *surface;
1222 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1225 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1226 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1229 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1231 wlwin = elm_win_wl_window_get(window);
1232 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1234 while (!_eflutil.wl.display_policy.proto)
1235 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1237 surface = ecore_wl_window_surface_get(wlwin);
1238 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1239 EFL_UTIL_ERROR_INVALID_PARAMETER);
1241 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1242 if (brightness_info)
1244 if (brightness_info->wait_for_done)
1246 while (brightness_info->wait_for_done)
1249 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1252 *brightness = brightness_info->brightness;
1257 return EFL_UTIL_ERROR_NONE;
1261 struct _efl_util_inputgen_h
1263 unsigned int init_type;
1268 _cb_device_add(void *data EINA_UNUSED,
1269 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1270 uint32_t serial EINA_UNUSED,
1271 const char *identifier EINA_UNUSED,
1272 struct tizen_input_device *device EINA_UNUSED,
1273 struct wl_seat *seat EINA_UNUSED)
1278 /* LCOV_EXCL_START */
1280 _cb_device_remove(void *data EINA_UNUSED,
1281 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1282 uint32_t serial EINA_UNUSED,
1283 const char *identifier EINA_UNUSED,
1284 struct tizen_input_device *device EINA_UNUSED,
1285 struct wl_seat *seat EINA_UNUSED)
1289 /* LCOV_EXCL_STOP */
1292 _cb_error(void *data EINA_UNUSED,
1293 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1296 _eflutil.wl.devmgr.request_notified = errorcode;
1299 /* LCOV_EXCL_START */
1301 _cb_block_expired(void *data EINA_UNUSED,
1302 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1306 /* LCOV_EXCL_STOP */
1308 static efl_util_error_e
1309 _efl_util_input_convert_input_generator_error(int ret)
1313 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1314 return EFL_UTIL_ERROR_NONE;
1315 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1316 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1317 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1318 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1319 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1320 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1322 return EFL_UTIL_ERROR_NONE;
1326 API efl_util_inputgen_h
1327 efl_util_input_initialize_generator(unsigned int dev_type)
1329 int ret = EFL_UTIL_ERROR_NONE;
1330 efl_util_inputgen_h inputgen_h = NULL;
1331 unsigned int clas = 0x0;
1334 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1335 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1336 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1338 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1342 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1345 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1349 inputgen_h->init_type |= dev_type;
1352 if (ret == (int)EINA_FALSE)
1354 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1358 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1359 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1360 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1361 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1362 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1363 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1365 while (!_eflutil.wl.devmgr.devicemgr)
1366 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1368 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
1370 while (_eflutil.wl.devmgr.request_notified == -1)
1371 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1373 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1374 _eflutil.wl.devmgr.request_notified = -1;
1376 set_last_result(ret);
1377 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1391 API efl_util_inputgen_h
1392 efl_util_input_initialize_generator_with_name(unsigned int dev_type, const char *name)
1394 int ret = EFL_UTIL_ERROR_NONE;
1395 efl_util_inputgen_h inputgen_h = NULL;
1396 unsigned int clas = 0x0;
1399 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1400 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1401 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1403 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1407 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1410 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1414 inputgen_h->init_type |= dev_type;
1415 strncpy(inputgen_h->name, name, 31);
1418 if (ret == (int)EINA_FALSE)
1420 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1424 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1425 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1426 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1427 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1428 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1429 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1431 while (!_eflutil.wl.devmgr.devicemgr)
1432 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1434 tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name);
1436 while (_eflutil.wl.devmgr.request_notified == -1)
1437 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1439 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1440 _eflutil.wl.devmgr.request_notified = -1;
1442 set_last_result(ret);
1443 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1459 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1461 int ret = EFL_UTIL_ERROR_NONE;
1462 unsigned int clas = 0x0;
1463 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1465 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1466 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1467 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1468 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1469 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1470 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1475 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1477 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas);
1479 while (_eflutil.wl.devmgr.request_notified == -1)
1480 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1482 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1483 _eflutil.wl.devmgr.request_notified = -1;
1489 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1491 int ret = EFL_UTIL_ERROR_NONE;
1493 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1494 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1495 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1496 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1498 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1500 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1502 while (_eflutil.wl.devmgr.request_notified == -1)
1503 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1505 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1506 _eflutil.wl.devmgr.request_notified = -1;
1512 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1513 efl_util_input_touch_type_e touch_type, int x, int y)
1516 enum tizen_input_device_manager_pointer_event_type type;
1518 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1519 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1520 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1521 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1523 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1527 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1528 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1530 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1531 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1533 case EFL_UTIL_INPUT_TOUCH_END:
1534 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1537 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1540 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1542 while (_eflutil.wl.devmgr.request_notified == -1)
1543 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1545 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1546 _eflutil.wl.devmgr.request_notified = -1;
1552 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)
1555 enum tizen_input_device_manager_pointer_event_type type;
1557 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1558 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1559 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1560 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1562 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1564 switch(pointer_type)
1566 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1567 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1569 case EFL_UTIL_INPUT_POINTER_MOVE:
1570 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1572 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1573 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1576 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1579 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1581 while (_eflutil.wl.devmgr.request_notified == -1)
1582 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1584 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1585 _eflutil.wl.devmgr.request_notified = -1;
1591 struct _efl_util_screenshot_h
1596 Eina_Bool shot_done;
1601 Eina_Bool auto_rotation;
1604 /* scrrenshot handle */
1605 static efl_util_screenshot_h g_screenshot;
1606 static Eina_Bool shot_mutex_init;
1607 static pthread_mutex_t shot_lock;
1610 _screenshot_mutex_init(void)
1612 if (shot_mutex_init)
1615 if (pthread_mutex_init(&shot_lock, NULL))
1617 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1618 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1621 shot_mutex_init = EINA_TRUE;
1627 _screenshot_mutex_destory(void)
1629 if (!shot_mutex_init)
1632 if (pthread_mutex_destroy(&shot_lock))
1634 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1635 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1638 shot_mutex_init = EINA_FALSE;
1644 _screenshot_mutex_lock(void)
1646 if (!_screenshot_mutex_init())
1649 pthread_mutex_lock(&shot_lock);
1653 _screenshot_mutex_unlock(void)
1655 pthread_mutex_unlock(&shot_lock);
1658 API efl_util_screenshot_h
1659 efl_util_screenshot_initialize(int width, int height)
1661 efl_util_screenshot_h screenshot = NULL;
1662 struct wl_display *display_wrapper = NULL;
1663 struct wl_registry *reg = NULL;
1666 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1667 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1669 _screenshot_mutex_lock();
1671 if (!_eflutil.wl.shot.screenshooter)
1674 if (ret == (int)EINA_FALSE)
1676 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1677 _screenshot_mutex_unlock();
1680 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1682 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1683 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory);
1685 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1686 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory);
1688 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
1690 reg = wl_display_get_registry(display_wrapper);
1691 wl_proxy_wrapper_destroy(display_wrapper);
1692 display_wrapper = NULL;
1693 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1695 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1697 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1698 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1699 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1700 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1702 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1703 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1706 if (_eflutil.wl.shot.noti == 0)
1708 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1714 if (g_screenshot->width != width || g_screenshot->height != height)
1716 g_screenshot->width = width;
1717 g_screenshot->height = height;
1720 _screenshot_mutex_unlock();
1722 return g_screenshot;
1725 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1726 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1728 screenshot->width = width;
1729 screenshot->height = height;
1730 screenshot->auto_rotation = EINA_TRUE;
1732 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1733 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1735 g_screenshot = screenshot;
1736 set_last_result(EFL_UTIL_ERROR_NONE);
1738 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1740 _screenshot_mutex_unlock();
1742 return g_screenshot;
1745 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1748 /* LCOV_EXCL_START */
1749 if (display_wrapper)
1750 wl_proxy_wrapper_destroy(display_wrapper);
1751 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1755 efl_util_screenshot_deinitialize(screenshot);
1756 _screenshot_mutex_unlock();
1757 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1759 /* LCOV_EXCL_STOP */
1763 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1765 _screenshot_mutex_lock();
1769 _screenshot_mutex_unlock();
1770 _screenshot_mutex_destory();
1771 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1775 g_screenshot = NULL;
1777 if (_eflutil.wl.shot.queue)
1779 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1780 _eflutil.wl.shot.queue = NULL;
1783 if (_eflutil.wl.shot.screenshooter)
1785 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1786 _eflutil.wl.shot.screenshooter = NULL;
1788 if (_eflutil.wl.shot.tz_screenshooter)
1790 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1791 _eflutil.wl.shot.tz_screenshooter = NULL;
1794 _screenshot_mutex_unlock();
1795 _screenshot_mutex_destory();
1797 return EFL_UTIL_ERROR_NONE;
1802 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1804 tbm_surface_h t_surface = NULL;
1805 struct wl_buffer *buffer = NULL;
1806 Efl_Util_Wl_Output_Info *output;
1809 _screenshot_mutex_lock();
1811 if (!screenshot || (screenshot != g_screenshot))
1813 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1814 _screenshot_mutex_unlock();
1818 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1821 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1825 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1828 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1832 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1835 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1839 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1841 screenshot->shot_done = EINA_FALSE;
1842 while (!screenshot->shot_done && ret != -1)
1843 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1847 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1851 wl_buffer_destroy(buffer);
1853 /* reset shot_done for next screenshot */
1854 screenshot->shot_done = EINA_FALSE;
1856 set_last_result(EFL_UTIL_ERROR_NONE);
1858 _screenshot_mutex_unlock();
1864 tbm_surface_destroy(t_surface);
1866 wl_buffer_destroy(buffer);
1868 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1870 _screenshot_mutex_unlock();
1876 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1878 if (!screenshot || (screenshot != g_screenshot))
1879 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1881 if (!(set == 0 || set == 1))
1882 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1885 g_screenshot->auto_rotation = EINA_TRUE;
1887 g_screenshot->auto_rotation = EINA_FALSE;
1889 tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1891 return EFL_UTIL_ERROR_NONE;
1895 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1897 if (!screenshot || (screenshot != g_screenshot) || !set)
1898 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1900 *set = g_screenshot->auto_rotation;
1902 return EFL_UTIL_ERROR_NONE;