2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define LOG_TAG "TIZEN_N_EFL_UTIL"
24 #include <sys/types.h>
28 #include <tbm_bufmgr.h>
29 #include <tbm_surface.h>
30 #include <tbm_surface_internal.h>
31 #include <Elementary.h>
32 #include <Ecore_Evas.h>
35 #include <Ecore_Wayland.h>
36 #include <wayland-client.h>
37 #include <wayland-tbm-client.h>
38 #include <tizen-extension-client-protocol.h>
39 #include <screenshooter-client-protocol.h>
41 #include <efl_util_screenshot_extension.h>
48 #define LOG_TAG "TIZEN_N_EFL_UTIL"
51 /* callback handler index */
52 #define CBH_NOTI_LEV 0
53 #define CBH_SCR_MODE 1
56 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
58 typedef struct _Efl_Util_Callback_Info
63 } Efl_Util_Callback_Info;
65 typedef struct _Efl_Util_Wl_Surface_Lv_Info
67 void *surface; /* wl_surface */
69 Eina_Bool wait_for_done;
71 } Efl_Util_Wl_Surface_Lv_Info;
73 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
75 void *surface; /* wl_surface */
77 Eina_Bool wait_for_done;
79 } Efl_Util_Wl_Surface_Scr_Mode_Info;
81 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
83 void *surface; /* wl_surface */
85 Eina_Bool wait_for_done;
87 } Efl_Util_Wl_Surface_Brightness_Info;
89 typedef struct _Efl_Util_Wl_Output_Info
91 struct wl_output *output;
92 int offset_x, offset_y, width, height;
93 } Efl_Util_Wl_Output_Info;
95 typedef struct _Efl_Util_Data
97 /* wayland related stuffs */
101 struct wl_display *dpy;
102 struct wl_event_queue *queue;
106 struct tizen_policy *proto;
107 Eina_Hash *hash_noti_lv;
108 Eina_Hash *hash_scr_mode;
112 struct wl_event_queue *queue;
113 struct screenshooter *screenshooter;
114 struct tizen_screenshooter *tz_screenshooter;
115 struct wayland_tbm_client *tbm_client;
116 Eina_List *output_list;
121 struct tizen_input_device_manager *devicemgr;
122 int request_notified;
126 struct tizen_display_policy *proto;
127 Eina_Hash *hash_brightness;
133 Eina_List *info_list; /* list of callback info */
134 unsigned int atom; /* x11 atom */
135 } cb_handler[CBH_MAX];
138 static Efl_Util_Data _eflutil =
143 { NULL, NULL, NULL }, /* tizen_policy protocol */
144 { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
145 { NULL, -1 } /* tizen_input_device_manager protocol */
148 { NULL, 0 }, /* handler for notification level */
149 { NULL, 0 } /* handler for screen mode */
153 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
154 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
155 static Eina_List *_cb_info_list_get(int idx);
156 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
157 static Eina_Bool _wl_init(void);
158 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
159 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
160 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
161 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
162 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
163 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
164 static void _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h);
165 static void _cb_wl_tz_policy_notification_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, int32_t level, uint32_t state);
166 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
167 static void _cb_wl_tz_policy_scr_mode_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t mode, uint32_t state);
168 static void _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force);
169 static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints);
170 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
171 static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options);
173 static void _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state);
175 static void _cb_device_add(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
176 static void _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
177 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
178 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
180 static const struct wl_registry_listener _wl_reg_listener =
183 _cb_wl_reg_global_remove
186 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
188 _cb_wl_reg_screenshooter_global,
189 _cb_wl_reg_screenshooter_global_remove
192 struct tizen_policy_listener _wl_tz_policy_listener =
194 _cb_wl_tz_policy_conformant,
195 _cb_wl_tz_policy_conformant_area,
196 _cb_wl_tz_policy_notification_done,
197 _cb_wl_tz_policy_transient_for_done,
198 _cb_wl_tz_policy_scr_mode_done,
199 _cb_wl_tz_policy_iconify_state_changed,
200 _cb_wl_tz_policy_supported_aux_hints,
201 _cb_wl_tz_policy_allowed_aux_hint,
202 _cb_wl_tz_policy_aux_message,
205 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
213 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
215 _cb_wl_tz_display_policy_brightness_done,
219 _cb_info_add(Evas_Object *win,
224 Efl_Util_Callback_Info *info;
226 info = _cb_info_find_by_win(win, idx);
229 _eflutil.cb_handler[idx].info_list
230 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
235 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
236 if (!info) return EINA_FALSE;
242 _eflutil.cb_handler[idx].info_list
243 = eina_list_append(_eflutil.cb_handler[idx].info_list,
250 _cb_info_del_by_win(Evas_Object *win,
253 Efl_Util_Callback_Info *info;
255 info = _cb_info_find_by_win(win, idx);
256 if (!info) return EINA_FALSE;
258 _eflutil.cb_handler[idx].info_list
259 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
267 _cb_info_list_get(int idx)
269 return _eflutil.cb_handler[idx].info_list;
272 static Efl_Util_Callback_Info *
273 _cb_info_find_by_win(Evas_Object *win,
277 Efl_Util_Callback_Info *info;
279 l = _cb_info_list_get(idx);
280 EINA_LIST_FOREACH(l, ll, info)
282 if (info->win == win) return info;
291 struct wl_display *display_wrapper = NULL;
292 struct wl_registry *reg = NULL;
294 if (_eflutil.wl.init) return EINA_TRUE;
298 _eflutil.wl.dpy = ecore_wl_display_get();
299 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
301 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
302 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail);
304 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
305 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
307 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
309 reg = wl_display_get_registry(display_wrapper);
310 wl_proxy_wrapper_destroy(display_wrapper);
311 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
313 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
315 _eflutil.wl.init = EINA_TRUE;
320 wl_proxy_wrapper_destroy(display_wrapper);
322 if (_eflutil.wl.queue)
324 wl_event_queue_destroy(_eflutil.wl.queue);
325 _eflutil.wl.queue = NULL;
333 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
334 int physical_width, int physical_height, int subpixel,
335 const char *make, const char *model, int transform)
337 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
338 if (wl_output == output->output)
340 output->offset_x = x;
341 output->offset_y = y;
346 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
347 int width, int height, int refresh)
349 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
350 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
352 output->width = width;
353 output->height = height;
358 _cb_wl_output_done(void *data, struct wl_output *wl_output)
363 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
367 static const struct wl_output_listener output_listener =
369 _cb_wl_output_geometry,
376 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
378 Eina_Bool *shot_done = (Eina_Bool*)data;
380 *shot_done = EINA_TRUE;
383 static const struct screenshooter_listener screenshooter_listener =
385 _cb_wl_screenshot_done
389 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
394 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
396 _eflutil.wl.shot.noti = noti;
399 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
401 _cb_tz_screenshot_format,
402 _cb_tz_screenshot_noti
406 _cb_wl_reg_global(void *data,
407 struct wl_registry *reg,
409 const char *interface,
410 unsigned int version)
412 if (!strcmp(interface, "tizen_policy"))
414 struct tizen_policy *proto;
415 proto = wl_registry_bind(reg,
417 &tizen_policy_interface,
421 tizen_policy_add_listener(proto,
422 &_wl_tz_policy_listener,
425 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
426 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
427 _eflutil.wl.policy.proto = proto;
429 else if (strcmp(interface, "wl_output") == 0)
431 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
432 EINA_SAFETY_ON_NULL_RETURN(output);
434 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
436 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
437 wl_output_add_listener(output->output, &output_listener, output);
439 else if (strcmp(interface, "tizen_input_device_manager") == 0)
441 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
442 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
444 else if (!strcmp(interface, "tizen_display_policy"))
446 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
447 if (!_eflutil.wl.display_policy.proto) return;
449 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
450 &_wl_tz_display_policy_listener,
453 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
457 /* LCOV_EXCL_START */
459 _cb_wl_reg_global_remove(void *data,
460 struct wl_registry *reg,
463 _eflutil.wl.policy.proto = NULL;
464 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
465 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
467 _eflutil.wl.display_policy.proto = NULL;
468 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
473 _cb_wl_reg_screenshooter_global(void *data,
474 struct wl_registry *reg,
476 const char *interface,
477 unsigned int version)
479 if (strcmp(interface, "screenshooter") == 0)
481 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
482 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
484 else if (strcmp(interface, "tizen_screenshooter") == 0)
486 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
487 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
489 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
493 /* LCOV_EXCL_START */
495 _cb_wl_reg_screenshooter_global_remove(void *data,
496 struct wl_registry *reg,
501 static Efl_Util_Callback_Info *
502 _cb_info_find_by_wlsurf(void *wlsurf,
506 Efl_Util_Callback_Info *info;
507 Ecore_Wl_Window *wlwin2 = NULL;
508 void *wlsurf2 = NULL;
510 l = _cb_info_list_get(idx);
511 EINA_LIST_FOREACH(l, ll, info)
513 wlwin2 = elm_win_wl_window_get(info->win);
514 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
515 if (wlsurf== wlsurf2) return info;
522 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
523 struct wl_surface *surface, uint32_t is_conformant)
528 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
529 struct wl_surface *surface, uint32_t conformant_part,
530 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
536 _cb_wl_tz_policy_notification_done(void *data,
537 struct tizen_policy *tizen_policy,
538 struct wl_surface *surface,
542 Efl_Util_Wl_Surface_Lv_Info *lv_info;
543 Efl_Util_Callback_Info *cb_info;
545 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
548 lv_info->level = level;
549 lv_info->wait_for_done = EINA_FALSE;
550 lv_info->state = state;
553 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
555 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
556 if (!cb_info) return;
557 if (!cb_info->cb) return;
559 cb_info->cb(cb_info->win,
560 EFL_UTIL_ERROR_PERMISSION_DENIED,
564 /* LCOV_EXCL_START */
566 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
572 _cb_wl_tz_policy_scr_mode_done(void *data,
573 struct tizen_policy *tizen_policy,
574 struct wl_surface *surface,
579 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
580 Efl_Util_Callback_Info *cb_info;
582 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
585 scr_mode_info->mode = mode;
586 scr_mode_info->wait_for_done = EINA_FALSE;
587 scr_mode_info->state = state;
590 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
592 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
593 if (!cb_info) return;
594 if (!cb_info->cb) return;
596 cb_info->cb(cb_info->win,
597 EFL_UTIL_ERROR_PERMISSION_DENIED,
601 /* LCOV_EXCL_START */
602 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)
606 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)
610 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
614 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)
620 _cb_wl_tz_display_policy_brightness_done(void *data,
621 struct tizen_display_policy *tizen_display_policy,
622 struct wl_surface *surface,
626 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
628 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
631 brightness_info->brightness = brightness;
632 brightness_info->wait_for_done = EINA_FALSE;
633 brightness_info->state = state;
638 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
640 Efl_Util_Wl_Surface_Lv_Info *lv_info;
643 if (EINA_UNLIKELY(!lv_info))
646 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
650 efl_util_set_notification_window_level(Evas_Object *window,
651 efl_util_notification_level_e level)
655 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
656 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
657 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
658 EFL_UTIL_ERROR_INVALID_PARAMETER);
660 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
662 dlog_print(DLOG_WARN, LOG_TAG,
663 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
665 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
667 dlog_print(DLOG_WARN, LOG_TAG,
668 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
670 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
672 dlog_print(DLOG_WARN, LOG_TAG,
673 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
677 Ecore_Wl_Window *wlwin;
678 struct wl_surface *surface;
679 Efl_Util_Wl_Surface_Lv_Info *lv_info;
680 Ecore_Wl_Window_Type wl_type;
683 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
685 wlwin = elm_win_wl_window_get(window);
686 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
688 type = elm_win_type_get(window);
689 if (type != ELM_WIN_NOTIFICATION)
691 wl_type = ecore_wl_window_type_get(wlwin);
692 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
693 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
696 while (!_eflutil.wl.policy.proto)
697 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
699 surface = ecore_wl_window_surface_get(wlwin);
700 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
701 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
703 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
706 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
707 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
709 lv_info->surface = surface;
710 lv_info->level = (int)level;
711 lv_info->wait_for_done = EINA_TRUE;
712 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
713 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
717 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
718 _cb_window_del, lv_info);
722 lv_info->level = (int)level;
723 lv_info->wait_for_done = EINA_TRUE;
724 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
728 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
729 surface, (int)level);
731 if (lv_info->wait_for_done)
734 while (lv_info->wait_for_done && (count < 3))
737 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
741 if (lv_info->wait_for_done)
743 return EFL_UTIL_ERROR_INVALID_PARAMETER;
747 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
749 return EFL_UTIL_ERROR_PERMISSION_DENIED;
754 return EFL_UTIL_ERROR_NONE;
758 efl_util_get_notification_window_level(Evas_Object *window,
759 efl_util_notification_level_e *level)
763 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
764 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
767 Ecore_Wl_Window *wlwin;
768 struct wl_surface *surface;
769 Efl_Util_Wl_Surface_Lv_Info *lv_info;
770 Ecore_Wl_Window_Type wl_type;
773 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
775 wlwin = elm_win_wl_window_get(window);
776 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
778 type = elm_win_type_get(window);
779 if (type != ELM_WIN_NOTIFICATION)
781 wl_type = ecore_wl_window_type_get(wlwin);
782 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
783 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
786 while (!_eflutil.wl.policy.proto)
787 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
789 surface = ecore_wl_window_surface_get(wlwin);
790 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
791 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
793 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
796 if (lv_info->wait_for_done)
799 while ((lv_info->wait_for_done) && (count < 3))
802 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
806 if (lv_info->wait_for_done)
808 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
809 return EFL_UTIL_ERROR_INVALID_PARAMETER;
813 switch (lv_info->level)
815 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
816 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
817 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
818 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
819 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
820 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
821 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
822 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
823 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
824 return EFL_UTIL_ERROR_INVALID_PARAMETER;
826 return EFL_UTIL_ERROR_NONE;
829 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
831 return EFL_UTIL_ERROR_NONE;
835 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
836 efl_util_notification_window_level_error_cb callback,
839 dlog_print(DLOG_WARN, LOG_TAG,
840 "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.");
842 Eina_Bool ret = EINA_FALSE;
844 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
845 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
847 ret = _cb_info_add(window,
848 (Efl_Util_Cb)callback,
851 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
853 return EFL_UTIL_ERROR_NONE;
857 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
859 dlog_print(DLOG_WARN, LOG_TAG,
860 "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.");
862 Eina_Bool ret = EINA_FALSE;
864 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
866 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
867 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
869 return EFL_UTIL_ERROR_NONE;
873 efl_util_set_window_opaque_state(Evas_Object *window,
878 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
879 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
880 EFL_UTIL_ERROR_INVALID_PARAMETER);
882 Ecore_Wl_Window *wlwin;
883 struct wl_surface *surface;
885 if (!_eflutil.wl.policy.proto)
890 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
892 while (!_eflutil.wl.policy.proto && ret != -1)
893 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
895 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
898 wlwin = elm_win_wl_window_get(window);
900 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
902 surface = ecore_wl_window_surface_get(wlwin);
904 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
906 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
908 return EFL_UTIL_ERROR_NONE;
912 efl_util_set_window_screen_mode(Evas_Object *window,
913 efl_util_screen_mode_e mode)
915 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
916 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
917 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
918 EFL_UTIL_ERROR_INVALID_PARAMETER);
920 Ecore_Wl_Window *wlwin;
921 struct wl_surface *surface;
922 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
926 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
928 wlwin = elm_win_wl_window_get(window);
931 while (!_eflutil.wl.policy.proto)
932 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
934 surface = ecore_wl_window_surface_get(wlwin);
935 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
936 EFL_UTIL_ERROR_INVALID_PARAMETER);
938 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
941 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
942 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
944 scr_mode_info->surface = surface;
945 scr_mode_info->mode = (unsigned int)mode;
946 scr_mode_info->wait_for_done = EINA_TRUE;
947 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
949 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
955 scr_mode_info->mode = (unsigned int)mode;
956 scr_mode_info->wait_for_done = EINA_TRUE;
957 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
960 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
961 surface, (unsigned int)mode);
962 if (scr_mode_info->wait_for_done)
965 while (scr_mode_info->wait_for_done && (count < 3))
968 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
972 if (scr_mode_info->wait_for_done)
974 return EFL_UTIL_ERROR_INVALID_PARAMETER;
978 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
980 return EFL_UTIL_ERROR_PERMISSION_DENIED;
985 return EFL_UTIL_ERROR_NONE;
988 return EFL_UTIL_ERROR_INVALID_PARAMETER;
992 efl_util_get_window_screen_mode(Evas_Object *window,
993 efl_util_screen_mode_e *mode)
995 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
996 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
998 Ecore_Wl_Window *wlwin;
999 struct wl_surface *surface;
1000 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1004 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1006 wlwin = elm_win_wl_window_get(window);
1009 while (!_eflutil.wl.policy.proto)
1010 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1012 surface = ecore_wl_window_surface_get(wlwin);
1013 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1014 EFL_UTIL_ERROR_INVALID_PARAMETER);
1016 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1019 if (scr_mode_info->wait_for_done)
1021 while (scr_mode_info->wait_for_done)
1024 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1028 switch (scr_mode_info->mode)
1030 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1031 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1032 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1033 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1035 return EFL_UTIL_ERROR_NONE;
1039 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1040 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1044 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1047 #ifndef TIZEN_WEARABLE
1049 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1050 efl_util_window_screen_mode_error_cb callback,
1053 dlog_print(DLOG_WARN, LOG_TAG,
1054 "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.");
1056 Eina_Bool ret = EINA_FALSE;
1058 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1059 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1061 ret = _cb_info_add(window,
1062 (Efl_Util_Cb)callback,
1065 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1067 return EFL_UTIL_ERROR_NONE;
1071 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1073 dlog_print(DLOG_WARN, LOG_TAG,
1074 "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.");
1076 Eina_Bool ret = EINA_FALSE;
1078 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1080 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1081 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1083 return EFL_UTIL_ERROR_NONE;
1088 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1090 Ecore_Wl_Window *wlwin;
1091 struct wl_surface *surface;
1092 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1095 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1096 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1099 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1101 wlwin = elm_win_wl_window_get(window);
1104 while (!_eflutil.wl.display_policy.proto)
1105 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1107 surface = ecore_wl_window_surface_get(wlwin);
1108 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1109 EFL_UTIL_ERROR_INVALID_PARAMETER);
1111 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1112 if (!brightness_info)
1114 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1115 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1117 brightness_info->surface = surface;
1118 brightness_info->brightness = brightness;
1119 brightness_info->wait_for_done = EINA_TRUE;
1120 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1122 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1128 brightness_info->brightness = brightness;
1129 brightness_info->wait_for_done = EINA_TRUE;
1130 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1133 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1134 surface, brightness);
1135 if (brightness_info->wait_for_done)
1138 while (brightness_info->wait_for_done && (count < 3))
1141 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1145 if (brightness_info->wait_for_done)
1147 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1151 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1153 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1157 return EFL_UTIL_ERROR_NONE;
1160 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1164 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1166 Ecore_Wl_Window *wlwin;
1167 struct wl_surface *surface;
1168 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1171 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1172 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1175 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1177 wlwin = elm_win_wl_window_get(window);
1178 if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1180 while (!_eflutil.wl.display_policy.proto)
1181 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1183 surface = ecore_wl_window_surface_get(wlwin);
1184 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1185 EFL_UTIL_ERROR_INVALID_PARAMETER);
1187 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1188 if (brightness_info)
1190 if (brightness_info->wait_for_done)
1192 while (brightness_info->wait_for_done)
1195 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1198 *brightness = brightness_info->brightness;
1203 return EFL_UTIL_ERROR_NONE;
1207 struct _efl_util_inputgen_h
1209 unsigned int init_type;
1213 _cb_device_add(void *data EINA_UNUSED,
1214 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1215 uint32_t serial EINA_UNUSED,
1216 const char *identifier EINA_UNUSED,
1217 struct tizen_input_device *device EINA_UNUSED,
1218 struct wl_seat *seat EINA_UNUSED)
1223 /* LCOV_EXCL_START */
1225 _cb_device_remove(void *data EINA_UNUSED,
1226 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1227 uint32_t serial EINA_UNUSED,
1228 const char *identifier EINA_UNUSED,
1229 struct tizen_input_device *device EINA_UNUSED,
1230 struct wl_seat *seat EINA_UNUSED)
1234 /* LCOV_EXCL_STOP */
1237 _cb_error(void *data EINA_UNUSED,
1238 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1241 _eflutil.wl.devmgr.request_notified = errorcode;
1244 /* LCOV_EXCL_START */
1246 _cb_block_expired(void *data EINA_UNUSED,
1247 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1251 /* LCOV_EXCL_STOP */
1253 static efl_util_error_e
1254 _efl_util_input_convert_input_generator_error(int ret)
1258 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1259 return EFL_UTIL_ERROR_NONE;
1260 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1261 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1262 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1263 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1264 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1265 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1267 return EFL_UTIL_ERROR_NONE;
1271 API efl_util_inputgen_h
1272 efl_util_input_initialize_generator(unsigned int dev_type)
1274 int ret = EFL_UTIL_ERROR_NONE;
1275 efl_util_inputgen_h inputgen_h = NULL;
1276 unsigned int clas = 0x0;
1279 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1280 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1281 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1283 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1287 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1290 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1294 inputgen_h->init_type |= dev_type;
1297 if (ret == (int)EINA_FALSE)
1299 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1303 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1304 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1305 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1306 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1307 if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1308 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1310 while (!_eflutil.wl.devmgr.devicemgr)
1311 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1313 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
1315 while (_eflutil.wl.devmgr.request_notified == -1)
1316 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1318 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1319 _eflutil.wl.devmgr.request_notified = -1;
1321 set_last_result(ret);
1322 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1337 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1339 int ret = EFL_UTIL_ERROR_NONE;
1340 unsigned int clas = 0x0;
1341 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1343 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1344 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1345 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1346 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1347 if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1348 clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1353 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1355 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas);
1357 while (_eflutil.wl.devmgr.request_notified == -1)
1358 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1360 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1361 _eflutil.wl.devmgr.request_notified = -1;
1367 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1369 int ret = EFL_UTIL_ERROR_NONE;
1371 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1372 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1373 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1374 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1376 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1378 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1380 while (_eflutil.wl.devmgr.request_notified == -1)
1381 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1383 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1384 _eflutil.wl.devmgr.request_notified = -1;
1390 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1391 efl_util_input_touch_type_e touch_type, int x, int y)
1394 enum tizen_input_device_manager_pointer_event_type type;
1396 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1397 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1398 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1399 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1401 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1405 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1406 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1408 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1409 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1411 case EFL_UTIL_INPUT_TOUCH_END:
1412 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1415 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1418 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1420 while (_eflutil.wl.devmgr.request_notified == -1)
1421 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1423 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1424 _eflutil.wl.devmgr.request_notified = -1;
1430 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)
1433 enum tizen_input_device_manager_pointer_event_type type;
1435 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1436 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1437 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1438 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1440 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1442 switch(pointer_type)
1444 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1445 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1447 case EFL_UTIL_INPUT_POINTER_MOVE:
1448 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1450 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1451 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1454 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1457 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1459 while (_eflutil.wl.devmgr.request_notified == -1)
1460 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1462 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1463 _eflutil.wl.devmgr.request_notified = -1;
1469 struct _efl_util_screenshot_h
1474 Eina_Bool shot_done;
1479 Eina_Bool auto_rotation;
1482 /* scrrenshot handle */
1483 static efl_util_screenshot_h g_screenshot;
1484 static Eina_Bool shot_mutex_init;
1485 static pthread_mutex_t shot_lock;
1488 _screenshot_mutex_init(void)
1490 if (shot_mutex_init)
1493 if (pthread_mutex_init(&shot_lock, NULL))
1495 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1496 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1499 shot_mutex_init = EINA_TRUE;
1505 _screenshot_mutex_destory(void)
1507 if (!shot_mutex_init)
1510 if (pthread_mutex_destroy(&shot_lock))
1512 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1513 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1516 shot_mutex_init = EINA_FALSE;
1522 _screenshot_mutex_lock(void)
1524 if (!_screenshot_mutex_init())
1527 pthread_mutex_lock(&shot_lock);
1531 _screenshot_mutex_unlock(void)
1533 pthread_mutex_unlock(&shot_lock);
1536 API efl_util_screenshot_h
1537 efl_util_screenshot_initialize(int width, int height)
1539 efl_util_screenshot_h screenshot = NULL;
1540 struct wl_display *display_wrapper = NULL;
1541 struct wl_registry *reg = NULL;
1544 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1545 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1547 _screenshot_mutex_lock();
1549 if (!_eflutil.wl.shot.screenshooter)
1552 if (ret == (int)EINA_FALSE)
1554 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1555 _screenshot_mutex_unlock();
1558 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1560 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1561 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
1563 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1564 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_init);
1566 wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
1568 reg = wl_display_get_registry(display_wrapper);
1569 wl_proxy_wrapper_destroy(display_wrapper);
1570 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1572 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1574 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1575 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1576 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1577 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1579 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1580 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1583 if (_eflutil.wl.shot.noti == 0)
1585 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1591 if (g_screenshot->width != width || g_screenshot->height != height)
1593 g_screenshot->width = width;
1594 g_screenshot->height = height;
1597 _screenshot_mutex_unlock();
1599 return g_screenshot;
1602 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1603 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1605 screenshot->width = width;
1606 screenshot->height = height;
1607 screenshot->auto_rotation = EINA_TRUE;
1609 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1610 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1612 g_screenshot = screenshot;
1613 set_last_result(EFL_UTIL_ERROR_NONE);
1615 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1617 _screenshot_mutex_unlock();
1619 return g_screenshot;
1622 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1625 /* LCOV_EXCL_START */
1626 if (display_wrapper)
1627 wl_proxy_wrapper_destroy(display_wrapper);
1628 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1630 /* LCOV_EXCL_STOP */
1633 efl_util_screenshot_deinitialize(screenshot);
1634 _screenshot_mutex_unlock();
1635 if (display_wrapper)
1636 wl_proxy_wrapper_destroy(display_wrapper);
1637 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1642 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1644 _screenshot_mutex_lock();
1648 _screenshot_mutex_unlock();
1649 _screenshot_mutex_destory();
1650 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1654 g_screenshot = NULL;
1656 if (_eflutil.wl.shot.queue)
1658 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1659 _eflutil.wl.shot.queue = NULL;
1662 if (_eflutil.wl.shot.screenshooter)
1664 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1665 _eflutil.wl.shot.screenshooter = NULL;
1667 if (_eflutil.wl.shot.tz_screenshooter)
1669 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1670 _eflutil.wl.shot.tz_screenshooter = NULL;
1673 _screenshot_mutex_unlock();
1674 _screenshot_mutex_destory();
1676 return EFL_UTIL_ERROR_NONE;
1681 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1683 tbm_surface_h t_surface = NULL;
1684 struct wl_buffer *buffer = NULL;
1685 Efl_Util_Wl_Output_Info *output;
1688 _screenshot_mutex_lock();
1690 if (!screenshot || (screenshot != g_screenshot))
1692 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1693 _screenshot_mutex_unlock();
1697 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1700 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1704 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1707 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1711 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1714 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1718 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1720 screenshot->shot_done = EINA_FALSE;
1721 while (!screenshot->shot_done && ret != -1)
1722 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1726 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1730 wl_buffer_destroy(buffer);
1732 /* reset shot_done for next screenshot */
1733 screenshot->shot_done = EINA_FALSE;
1735 set_last_result(EFL_UTIL_ERROR_NONE);
1737 _screenshot_mutex_unlock();
1743 tbm_surface_destroy(t_surface);
1745 wl_buffer_destroy(buffer);
1747 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1749 _screenshot_mutex_unlock();
1755 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1757 if (!screenshot || (screenshot != g_screenshot))
1758 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1760 if (!(set == 0 || set == 1))
1761 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1764 g_screenshot->auto_rotation = EINA_TRUE;
1766 g_screenshot->auto_rotation = EINA_FALSE;
1768 tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1770 return EFL_UTIL_ERROR_NONE;
1774 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1776 if (!screenshot || (screenshot != g_screenshot) || !set)
1777 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1779 *set = g_screenshot->auto_rotation;
1781 return EFL_UTIL_ERROR_NONE;