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 */
103 struct wl_display *dpy;
104 struct wl_registry *reg;
106 struct wl_event_queue *queue;
110 struct tizen_policy *proto;
111 Eina_Hash *hash_noti_lv;
112 Eina_Hash *hash_scr_mode;
116 struct wl_event_queue *queue;
117 struct screenshooter *screenshooter;
118 struct tizen_screenshooter *tz_screenshooter;
119 struct wayland_tbm_client *tbm_client;
120 Eina_List *output_list;
125 struct tizen_input_device_manager *devicemgr;
126 int request_notified;
127 Eina_List *device_list;
131 struct tizen_display_policy *proto;
132 Eina_Hash *hash_brightness;
138 Eina_List *info_list; /* list of callback info */
139 unsigned int atom; /* x11 atom */
140 } cb_handler[CBH_MAX];
143 static Efl_Util_Data _eflutil =
149 { NULL, NULL, NULL }, /* tizen_policy protocol */
150 { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
151 { NULL, -1 } /* tizen_input_device_manager protocol */
154 { NULL, 0 }, /* handler for notification level */
155 { NULL, 0 } /* handler for screen mode */
159 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
160 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
161 static Eina_List *_cb_info_list_get(int idx);
162 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
163 static Eina_Bool _wl_init(void);
164 static void _wl_shutdown(void);
166 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
167 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
168 static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
169 static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
170 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
171 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
172 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);
173 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);
174 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
175 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);
176 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);
177 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);
178 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
179 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);
181 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);
183 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);
184 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);
185 static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
186 static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
188 static const struct wl_registry_listener _wl_reg_listener =
191 _cb_wl_reg_global_remove
194 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
196 _cb_wl_reg_screenshooter_global,
197 _cb_wl_reg_screenshooter_global_remove
200 struct tizen_policy_listener _wl_tz_policy_listener =
202 _cb_wl_tz_policy_conformant,
203 _cb_wl_tz_policy_conformant_area,
204 _cb_wl_tz_policy_notification_done,
205 _cb_wl_tz_policy_transient_for_done,
206 _cb_wl_tz_policy_scr_mode_done,
207 _cb_wl_tz_policy_iconify_state_changed,
208 _cb_wl_tz_policy_supported_aux_hints,
209 _cb_wl_tz_policy_allowed_aux_hint,
210 _cb_wl_tz_policy_aux_message,
213 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
221 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
223 _cb_wl_tz_display_policy_brightness_done,
227 _cb_info_add(Evas_Object *win,
232 Efl_Util_Callback_Info *info;
234 info = _cb_info_find_by_win(win, idx);
237 _eflutil.cb_handler[idx].info_list
238 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
243 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
244 if (!info) return EINA_FALSE;
250 _eflutil.cb_handler[idx].info_list
251 = eina_list_append(_eflutil.cb_handler[idx].info_list,
258 _cb_info_del_by_win(Evas_Object *win,
261 Efl_Util_Callback_Info *info;
263 info = _cb_info_find_by_win(win, idx);
264 if (!info) return EINA_FALSE;
266 _eflutil.cb_handler[idx].info_list
267 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
275 _cb_info_list_get(int idx)
277 return _eflutil.cb_handler[idx].info_list;
280 static Efl_Util_Callback_Info *
281 _cb_info_find_by_win(Evas_Object *win,
285 Efl_Util_Callback_Info *info;
287 l = _cb_info_list_get(idx);
288 EINA_LIST_FOREACH(l, ll, info)
290 if (info->win == win) return info;
299 _eflutil.wl.ref_count++;
301 if (_eflutil.wl.init) return EINA_TRUE;
305 _eflutil.wl.dpy = ecore_wl_display_get();
306 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
308 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
309 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
311 _eflutil.wl.reg = wl_display_get_registry(_eflutil.wl.dpy);
312 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.reg, fail);
314 wl_proxy_set_queue((struct wl_proxy*)_eflutil.wl.reg, _eflutil.wl.queue);
315 wl_registry_add_listener(_eflutil.wl.reg, &_wl_reg_listener, NULL);
317 _eflutil.wl.init = EINA_TRUE;
321 if (_eflutil.wl.queue)
323 wl_event_queue_destroy(_eflutil.wl.queue);
324 _eflutil.wl.queue = NULL;
329 wl_registry_destroy(_eflutil.wl.reg);
330 _eflutil.wl.reg = NULL;
333 _eflutil.wl.dpy = NULL;
343 struct tizen_input_device *data;
344 Efl_Util_Wl_Output_Info *output;
346 if (!_eflutil.wl.init) return;
348 _eflutil.wl.ref_count--;
349 if (_eflutil.wl.ref_count > 0)
353 if (_eflutil.wl.policy.proto)
354 tizen_policy_destroy(_eflutil.wl.policy.proto);
355 _eflutil.wl.policy.proto = NULL;
357 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
358 _eflutil.wl.policy.hash_noti_lv = NULL;
359 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
360 _eflutil.wl.policy.hash_scr_mode = NULL;
363 if (_eflutil.wl.shot.output_list)
365 EINA_LIST_FREE(_eflutil.wl.shot.output_list, output)
367 wl_output_destroy(output->output);
371 _eflutil.wl.shot.output_list = NULL;
374 if (_eflutil.wl.shot.screenshooter)
375 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
376 _eflutil.wl.shot.screenshooter = NULL;
378 // tizen_input_device_manager
379 EINA_LIST_FOREACH_SAFE(_eflutil.wl.devmgr.device_list, l, ll, data)
381 tizen_input_device_release(data);
382 _eflutil.wl.devmgr.device_list = eina_list_remove_list(_eflutil.wl.devmgr.device_list, l);
384 if (_eflutil.wl.devmgr.devicemgr)
385 tizen_input_device_manager_destroy(_eflutil.wl.devmgr.devicemgr);
386 _eflutil.wl.devmgr.devicemgr = NULL;
388 // tizen_display_policy
389 if (_eflutil.wl.display_policy.proto)
390 tizen_display_policy_destroy(_eflutil.wl.display_policy.proto);
391 _eflutil.wl.display_policy.proto = NULL;
393 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
394 _eflutil.wl.display_policy.hash_brightness = NULL;
398 wl_proxy_set_queue((struct wl_proxy*)_eflutil.wl.reg, NULL);
399 wl_registry_destroy(_eflutil.wl.reg);
400 _eflutil.wl.reg = NULL;
403 if (_eflutil.wl.queue)
405 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
406 wl_event_queue_destroy(_eflutil.wl.queue);
407 _eflutil.wl.queue = NULL;
410 _eflutil.wl.dpy = NULL;
411 _eflutil.wl.init = EINA_FALSE;
417 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
418 int physical_width, int physical_height, int subpixel,
419 const char *make, const char *model, int transform)
421 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
422 if (wl_output == output->output)
424 output->offset_x = x;
425 output->offset_y = y;
430 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
431 int width, int height, int refresh)
433 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
434 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
436 output->width = width;
437 output->height = height;
442 _cb_wl_output_done(void *data, struct wl_output *wl_output)
447 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
451 static const struct wl_output_listener output_listener =
453 _cb_wl_output_geometry,
460 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
462 Eina_Bool *shot_done = (Eina_Bool*)data;
464 *shot_done = EINA_TRUE;
467 static const struct screenshooter_listener screenshooter_listener =
469 _cb_wl_screenshot_done
473 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
478 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
480 _eflutil.wl.shot.noti = noti;
483 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
485 _cb_tz_screenshot_format,
486 _cb_tz_screenshot_noti
490 _cb_wl_reg_global(void *data,
491 struct wl_registry *reg,
493 const char *interface,
494 unsigned int version)
496 if (!strcmp(interface, "tizen_policy"))
498 struct tizen_policy *proto;
499 proto = wl_registry_bind(reg,
501 &tizen_policy_interface,
505 tizen_policy_add_listener(proto,
506 &_wl_tz_policy_listener,
509 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
510 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
511 _eflutil.wl.policy.proto = proto;
513 else if (strcmp(interface, "wl_output") == 0)
515 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
516 EINA_SAFETY_ON_NULL_RETURN(output);
518 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
520 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
521 wl_output_add_listener(output->output, &output_listener, output);
523 else if (strcmp(interface, "tizen_input_device_manager") == 0)
525 _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version);
526 tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
528 else if (!strcmp(interface, "tizen_display_policy"))
530 _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version);
531 if (!_eflutil.wl.display_policy.proto) return;
533 tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
534 &_wl_tz_display_policy_listener,
537 _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
541 /* LCOV_EXCL_START */
543 _cb_wl_reg_global_remove(void *data,
544 struct wl_registry *reg,
548 struct tizen_input_device *ddata;
549 Efl_Util_Wl_Output_Info *output;
552 if (_eflutil.wl.policy.proto)
553 tizen_policy_destroy(_eflutil.wl.policy.proto);
554 _eflutil.wl.policy.proto = NULL;
556 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
557 _eflutil.wl.policy.hash_noti_lv = NULL;
558 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
559 _eflutil.wl.policy.hash_scr_mode = NULL;
562 if (_eflutil.wl.shot.output_list)
564 EINA_LIST_FREE(_eflutil.wl.shot.output_list, output)
566 wl_output_destroy(output->output);
570 _eflutil.wl.shot.output_list = NULL;
573 if (_eflutil.wl.shot.screenshooter)
574 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
575 _eflutil.wl.shot.screenshooter = NULL;
577 // tizen_input_device_manager
578 EINA_LIST_FOREACH_SAFE(_eflutil.wl.devmgr.device_list, l, ll, ddata)
580 tizen_input_device_release(ddata);
581 _eflutil.wl.devmgr.device_list = eina_list_remove_list(_eflutil.wl.devmgr.device_list, l);
583 if (_eflutil.wl.devmgr.devicemgr)
584 tizen_input_device_manager_destroy(_eflutil.wl.devmgr.devicemgr);
585 _eflutil.wl.devmgr.devicemgr = NULL;
587 // tizen_display_policy
588 if (_eflutil.wl.display_policy.proto)
589 tizen_display_policy_destroy(_eflutil.wl.display_policy.proto);
590 _eflutil.wl.display_policy.proto = NULL;
592 eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
593 _eflutil.wl.display_policy.hash_brightness = NULL;
598 _cb_wl_reg_screenshooter_global(void *data,
599 struct wl_registry *reg,
601 const char *interface,
602 unsigned int version)
604 if (strcmp(interface, "screenshooter") == 0)
606 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
607 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
609 else if (strcmp(interface, "tizen_screenshooter") == 0)
611 _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
612 tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
614 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
618 /* LCOV_EXCL_START */
620 _cb_wl_reg_screenshooter_global_remove(void *data,
621 struct wl_registry *reg,
626 static Efl_Util_Callback_Info *
627 _cb_info_find_by_wlsurf(void *wlsurf,
631 Efl_Util_Callback_Info *info;
632 Ecore_Wl_Window *wlwin2 = NULL;
633 void *wlsurf2 = NULL;
635 l = _cb_info_list_get(idx);
636 EINA_LIST_FOREACH(l, ll, info)
638 wlwin2 = elm_win_wl_window_get(info->win);
639 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
640 if (wlsurf== wlsurf2) return info;
647 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
648 struct wl_surface *surface, uint32_t is_conformant)
653 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
654 struct wl_surface *surface, uint32_t conformant_part,
655 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
661 _cb_wl_tz_policy_notification_done(void *data,
662 struct tizen_policy *tizen_policy,
663 struct wl_surface *surface,
667 Efl_Util_Wl_Surface_Lv_Info *lv_info;
668 Efl_Util_Callback_Info *cb_info;
670 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
673 lv_info->level = level;
674 lv_info->wait_for_done = EINA_FALSE;
675 lv_info->state = state;
678 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
680 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
681 if (!cb_info) return;
682 if (!cb_info->cb) return;
684 cb_info->cb(cb_info->win,
685 EFL_UTIL_ERROR_PERMISSION_DENIED,
689 /* LCOV_EXCL_START */
691 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
697 _cb_wl_tz_policy_scr_mode_done(void *data,
698 struct tizen_policy *tizen_policy,
699 struct wl_surface *surface,
704 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
705 Efl_Util_Callback_Info *cb_info;
707 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
710 scr_mode_info->mode = mode;
711 scr_mode_info->wait_for_done = EINA_FALSE;
712 scr_mode_info->state = state;
715 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
717 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
718 if (!cb_info) return;
719 if (!cb_info->cb) return;
721 cb_info->cb(cb_info->win,
722 EFL_UTIL_ERROR_PERMISSION_DENIED,
726 /* LCOV_EXCL_START */
727 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)
731 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)
735 static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
739 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)
745 _cb_wl_tz_display_policy_brightness_done(void *data,
746 struct tizen_display_policy *tizen_display_policy,
747 struct wl_surface *surface,
751 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
753 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
756 brightness_info->brightness = brightness;
757 brightness_info->wait_for_done = EINA_FALSE;
758 brightness_info->state = state;
763 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
765 Efl_Util_Wl_Surface_Lv_Info *lv_info;
768 if (EINA_UNLIKELY(!lv_info))
771 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
773 eina_hash_population(_eflutil.wl.policy.hash_noti_lv);
775 if (eina_hash_population(_eflutil.wl.policy.hash_noti_lv) == 0)
782 _init_tizen_policy_proto(void)
786 if (!_eflutil.wl.policy.proto)
789 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EINA_FALSE);
792 while (!_eflutil.wl.policy.proto && ret != -1)
793 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
795 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EINA_FALSE);
802 efl_util_set_notification_window_level(Evas_Object *window,
803 efl_util_notification_level_e level)
807 Ecore_Wl_Window *wlwin;
808 struct wl_surface *surface;
809 Efl_Util_Wl_Surface_Lv_Info *lv_info;
810 Ecore_Wl_Window_Type wl_type;
812 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
813 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
814 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
815 EFL_UTIL_ERROR_INVALID_PARAMETER);
817 if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
819 dlog_print(DLOG_WARN, LOG_TAG,
820 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
822 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
824 dlog_print(DLOG_WARN, LOG_TAG,
825 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
827 else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
829 dlog_print(DLOG_WARN, LOG_TAG,
830 "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
833 wlwin = elm_win_wl_window_get(window);
834 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
836 type = elm_win_type_get(window);
837 if (type != ELM_WIN_NOTIFICATION)
839 wl_type = ecore_wl_window_type_get(wlwin);
840 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
841 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
844 ret = _init_tizen_policy_proto();
845 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
847 surface = ecore_wl_window_surface_get(wlwin);
848 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
849 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
851 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
854 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
855 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
857 lv_info->surface = surface;
858 lv_info->level = (int)level;
859 lv_info->wait_for_done = EINA_TRUE;
860 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
861 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
865 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
866 _cb_window_del, lv_info);
870 lv_info->level = (int)level;
871 lv_info->wait_for_done = EINA_TRUE;
872 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
876 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
877 surface, (int)level);
879 if (lv_info->wait_for_done)
882 while (lv_info->wait_for_done && (count < 3))
885 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
889 if (lv_info->wait_for_done)
891 return EFL_UTIL_ERROR_INVALID_PARAMETER;
895 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
897 return EFL_UTIL_ERROR_PERMISSION_DENIED;
902 return EFL_UTIL_ERROR_NONE;
906 efl_util_get_notification_window_level(Evas_Object *window,
907 efl_util_notification_level_e *level)
911 Ecore_Wl_Window *wlwin;
912 struct wl_surface *surface;
913 Efl_Util_Wl_Surface_Lv_Info *lv_info;
914 Ecore_Wl_Window_Type wl_type;
916 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
917 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
919 wlwin = elm_win_wl_window_get(window);
920 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
922 type = elm_win_type_get(window);
923 if (type != ELM_WIN_NOTIFICATION)
925 wl_type = ecore_wl_window_type_get(wlwin);
926 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
927 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
930 surface = ecore_wl_window_surface_get(wlwin);
931 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
932 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
934 ret = _init_tizen_policy_proto();
935 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
937 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
940 if (lv_info->wait_for_done)
943 while ((lv_info->wait_for_done) && (count < 3))
946 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
950 if (lv_info->wait_for_done)
952 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
953 return EFL_UTIL_ERROR_INVALID_PARAMETER;
957 switch (lv_info->level)
959 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
960 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
961 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
962 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
963 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
964 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
965 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
966 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
967 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
968 return EFL_UTIL_ERROR_INVALID_PARAMETER;
970 return EFL_UTIL_ERROR_NONE;
973 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
975 return EFL_UTIL_ERROR_NONE;
979 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
980 efl_util_notification_window_level_error_cb callback,
983 dlog_print(DLOG_WARN, LOG_TAG,
984 "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.");
986 Eina_Bool ret = EINA_FALSE;
988 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
989 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
991 ret = _cb_info_add(window,
992 (Efl_Util_Cb)callback,
995 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
997 return EFL_UTIL_ERROR_NONE;
1001 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
1003 dlog_print(DLOG_WARN, LOG_TAG,
1004 "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.");
1006 Eina_Bool ret = EINA_FALSE;
1008 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1010 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
1011 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1013 return EFL_UTIL_ERROR_NONE;
1017 efl_util_set_window_opaque_state(Evas_Object *window,
1021 Ecore_Wl_Window *wlwin;
1022 struct wl_surface *surface;
1024 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1025 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
1026 EFL_UTIL_ERROR_INVALID_PARAMETER);
1028 wlwin = elm_win_wl_window_get(window);
1030 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
1032 surface = ecore_wl_window_surface_get(wlwin);
1034 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
1036 ret = _init_tizen_policy_proto();
1037 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
1039 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
1041 return EFL_UTIL_ERROR_NONE;
1045 efl_util_set_window_screen_mode(Evas_Object *window,
1046 efl_util_screen_mode_e mode)
1048 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1049 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
1050 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
1051 EFL_UTIL_ERROR_INVALID_PARAMETER);
1053 Ecore_Wl_Window *wlwin;
1054 struct wl_surface *surface;
1055 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1058 wlwin = elm_win_wl_window_get(window);
1059 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_INVALID_PARAMETER);
1061 surface = ecore_wl_window_surface_get(wlwin);
1062 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER);
1064 ret = _init_tizen_policy_proto();
1065 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
1067 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1070 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
1071 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1073 scr_mode_info->surface = surface;
1074 scr_mode_info->mode = (unsigned int)mode;
1075 scr_mode_info->wait_for_done = EINA_TRUE;
1076 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1078 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
1084 scr_mode_info->mode = (unsigned int)mode;
1085 scr_mode_info->wait_for_done = EINA_TRUE;
1086 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1089 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
1090 surface, (unsigned int)mode);
1091 if (scr_mode_info->wait_for_done)
1094 while (scr_mode_info->wait_for_done && (count < 3))
1097 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1101 if (scr_mode_info->wait_for_done)
1103 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1107 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1109 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1114 return EFL_UTIL_ERROR_NONE;
1118 efl_util_get_window_screen_mode(Evas_Object *window,
1119 efl_util_screen_mode_e *mode)
1121 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1122 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1124 Ecore_Wl_Window *wlwin;
1125 struct wl_surface *surface;
1126 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1129 wlwin = elm_win_wl_window_get(window);
1130 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_INVALID_PARAMETER);
1132 surface = ecore_wl_window_surface_get(wlwin);
1133 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER);
1135 ret = _init_tizen_policy_proto();
1136 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
1138 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1141 if (scr_mode_info->wait_for_done)
1143 while (scr_mode_info->wait_for_done)
1146 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1150 switch (scr_mode_info->mode)
1152 case TIZEN_POLICY_MODE_DEFAULT:
1153 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1156 case TIZEN_POLICY_MODE_ALWAYS_ON:
1157 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1161 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1162 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1165 return EFL_UTIL_ERROR_NONE;
1169 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1170 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1174 #ifndef TIZEN_WEARABLE
1176 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1177 efl_util_window_screen_mode_error_cb callback,
1180 dlog_print(DLOG_WARN, LOG_TAG,
1181 "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.");
1183 Eina_Bool ret = EINA_FALSE;
1185 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1186 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1188 ret = _cb_info_add(window,
1189 (Efl_Util_Cb)callback,
1192 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1194 return EFL_UTIL_ERROR_NONE;
1198 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1200 dlog_print(DLOG_WARN, LOG_TAG,
1201 "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.");
1203 Eina_Bool ret = EINA_FALSE;
1205 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1207 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1208 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1210 return EFL_UTIL_ERROR_NONE;
1215 _init_tizen_display_policy_proto(void)
1219 if (!_eflutil.wl.display_policy.proto)
1222 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EINA_FALSE);
1225 while (!_eflutil.wl.display_policy.proto && ret != -1)
1226 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1228 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.display_policy.proto, EINA_FALSE);
1235 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1237 Ecore_Wl_Window *wlwin;
1238 struct wl_surface *surface;
1239 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1242 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1243 EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1245 wlwin = elm_win_wl_window_get(window);
1246 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_INVALID_PARAMETER);
1248 surface = ecore_wl_window_surface_get(wlwin);
1249 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER);
1251 ret = _init_tizen_display_policy_proto();
1252 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
1254 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1255 if (!brightness_info)
1257 brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1258 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1260 brightness_info->surface = surface;
1261 brightness_info->brightness = brightness;
1262 brightness_info->wait_for_done = EINA_TRUE;
1263 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1265 eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1271 brightness_info->brightness = brightness;
1272 brightness_info->wait_for_done = EINA_TRUE;
1273 brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1276 tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1277 surface, brightness);
1278 if (brightness_info->wait_for_done)
1281 while (brightness_info->wait_for_done && (count < 3))
1284 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1288 if (brightness_info->wait_for_done)
1290 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1294 if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1296 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1301 return EFL_UTIL_ERROR_NONE;
1305 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1307 Ecore_Wl_Window *wlwin;
1308 struct wl_surface *surface;
1309 Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1312 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1313 EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1315 wlwin = elm_win_wl_window_get(window);
1316 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_INVALID_PARAMETER);
1318 surface = ecore_wl_window_surface_get(wlwin);
1319 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER);
1321 ret = _init_tizen_display_policy_proto();
1322 EINA_SAFETY_ON_FALSE_RETURN_VAL(ret, EFL_UTIL_ERROR_NOT_SUPPORTED);
1324 brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1325 if (brightness_info)
1327 if (brightness_info->wait_for_done)
1329 while (brightness_info->wait_for_done)
1332 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1335 *brightness = brightness_info->brightness;
1340 return EFL_UTIL_ERROR_NONE;
1344 struct _efl_util_inputgen_h
1346 unsigned int init_type;
1350 _cb_device_add(void *data EINA_UNUSED,
1351 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1352 uint32_t serial EINA_UNUSED,
1353 const char *identifier EINA_UNUSED,
1354 struct tizen_input_device *device,
1355 struct wl_seat *seat EINA_UNUSED)
1358 struct tizen_input_device *ddata;
1360 EINA_LIST_FOREACH(_eflutil.wl.devmgr.device_list, l, ddata)
1362 if (device == ddata) return;
1365 _eflutil.wl.devmgr.device_list = eina_list_append(_eflutil.wl.devmgr.device_list, device);
1368 /* LCOV_EXCL_START */
1370 _cb_device_remove(void *data EINA_UNUSED,
1371 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1372 uint32_t serial EINA_UNUSED,
1373 const char *identifier EINA_UNUSED,
1374 struct tizen_input_device *device,
1375 struct wl_seat *seat EINA_UNUSED)
1378 struct tizen_input_device *ddata;
1380 EINA_LIST_FOREACH_SAFE(_eflutil.wl.devmgr.device_list, l, ll, ddata)
1382 if (device == ddata)
1384 _eflutil.wl.devmgr.device_list = eina_list_remove_list(_eflutil.wl.devmgr.device_list, l);
1388 /* LCOV_EXCL_STOP */
1391 _cb_error(void *data EINA_UNUSED,
1392 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1395 _eflutil.wl.devmgr.request_notified = errorcode;
1398 /* LCOV_EXCL_START */
1400 _cb_block_expired(void *data EINA_UNUSED,
1401 struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1405 /* LCOV_EXCL_STOP */
1407 static efl_util_error_e
1408 _efl_util_input_convert_input_generator_error(int ret)
1412 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1413 return EFL_UTIL_ERROR_NONE;
1414 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1415 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1416 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1417 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1418 case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1419 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1421 return EFL_UTIL_ERROR_NONE;
1425 API efl_util_inputgen_h
1426 efl_util_input_initialize_generator(unsigned int dev_type)
1428 int ret = EFL_UTIL_ERROR_NONE;
1429 efl_util_inputgen_h inputgen_h = NULL;
1432 dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1433 | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1434 | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1436 set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1440 inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1443 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1447 inputgen_h->init_type |= dev_type;
1450 if (ret == (int)EINA_FALSE)
1452 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1456 while (!_eflutil.wl.devmgr.devicemgr)
1457 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1459 tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr);
1461 while (_eflutil.wl.devmgr.request_notified == -1)
1462 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1464 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1465 _eflutil.wl.devmgr.request_notified = -1;
1467 set_last_result(ret);
1468 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1483 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1485 int ret = EFL_UTIL_ERROR_NONE;
1486 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1491 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1493 tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr);
1495 while (_eflutil.wl.devmgr.request_notified == -1)
1496 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1498 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1499 _eflutil.wl.devmgr.request_notified = -1;
1507 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1509 int ret = EFL_UTIL_ERROR_NONE;
1511 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1512 EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1513 EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1514 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1516 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1518 tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1520 while (_eflutil.wl.devmgr.request_notified == -1)
1521 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1523 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1524 _eflutil.wl.devmgr.request_notified = -1;
1530 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1531 efl_util_input_touch_type_e touch_type, int x, int y)
1534 enum tizen_input_device_manager_pointer_event_type type;
1536 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1537 EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1538 EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1539 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1541 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1545 case EFL_UTIL_INPUT_TOUCH_BEGIN:
1546 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1548 case EFL_UTIL_INPUT_TOUCH_UPDATE:
1549 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1551 case EFL_UTIL_INPUT_TOUCH_END:
1552 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1555 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1558 tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1560 while (_eflutil.wl.devmgr.request_notified == -1)
1561 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1563 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1564 _eflutil.wl.devmgr.request_notified = -1;
1570 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)
1573 enum tizen_input_device_manager_pointer_event_type type;
1575 EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1576 EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1577 EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1578 EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1580 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1582 switch(pointer_type)
1584 case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1585 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1587 case EFL_UTIL_INPUT_POINTER_MOVE:
1588 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1590 case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1591 type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1594 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1597 tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1599 while (_eflutil.wl.devmgr.request_notified == -1)
1600 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1602 ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1603 _eflutil.wl.devmgr.request_notified = -1;
1609 struct _efl_util_screenshot_h
1614 Eina_Bool shot_done;
1619 Eina_Bool auto_rotation;
1622 /* scrrenshot handle */
1623 static efl_util_screenshot_h g_screenshot;
1624 static Eina_Bool shot_mutex_init;
1625 static pthread_mutex_t shot_lock;
1628 _screenshot_mutex_init(void)
1630 if (shot_mutex_init)
1633 if (pthread_mutex_init(&shot_lock, NULL))
1635 fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1636 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1639 shot_mutex_init = EINA_TRUE;
1645 _screenshot_mutex_destory(void)
1647 if (!shot_mutex_init)
1650 if (pthread_mutex_destroy(&shot_lock))
1652 fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1653 return EINA_FALSE; /*LCOV_EXCL_LINE*/
1656 shot_mutex_init = EINA_FALSE;
1662 _screenshot_mutex_lock(void)
1664 if (!_screenshot_mutex_init())
1667 pthread_mutex_lock(&shot_lock);
1671 _screenshot_mutex_unlock(void)
1673 pthread_mutex_unlock(&shot_lock);
1676 API efl_util_screenshot_h
1677 efl_util_screenshot_initialize(int width, int height)
1679 efl_util_screenshot_h screenshot = NULL;
1680 struct wl_display *display_wrapper = NULL;
1681 struct wl_registry *reg = NULL;
1684 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1685 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1687 _screenshot_mutex_lock();
1689 if (!_eflutil.wl.shot.screenshooter)
1692 if (ret == (int)EINA_FALSE)
1694 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1695 _screenshot_mutex_unlock();
1698 wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1700 display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1701 EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
1703 _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1704 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_init);
1706 reg = wl_display_get_registry(display_wrapper);
1707 EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1709 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.shot.queue);
1711 wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1713 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1714 EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1715 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1716 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1718 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1719 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1722 if (_eflutil.wl.shot.noti == 0)
1724 fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1730 if (g_screenshot->width != width || g_screenshot->height != height)
1732 g_screenshot->width = width;
1733 g_screenshot->height = height;
1736 _screenshot_mutex_unlock();
1738 return g_screenshot;
1741 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1742 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1744 screenshot->width = width;
1745 screenshot->height = height;
1746 screenshot->auto_rotation = EINA_TRUE;
1748 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1749 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1751 g_screenshot = screenshot;
1752 set_last_result(EFL_UTIL_ERROR_NONE);
1754 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1756 _screenshot_mutex_unlock();
1758 return g_screenshot;
1761 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1764 /* LCOV_EXCL_START */
1765 if (display_wrapper)
1766 wl_proxy_wrapper_destroy(display_wrapper);
1767 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1769 /* LCOV_EXCL_STOP */
1772 efl_util_screenshot_deinitialize(screenshot);
1773 _screenshot_mutex_unlock();
1774 if (display_wrapper)
1775 wl_proxy_wrapper_destroy(display_wrapper);
1776 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1781 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1783 _screenshot_mutex_lock();
1787 _screenshot_mutex_unlock();
1788 _screenshot_mutex_destory();
1789 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1793 g_screenshot = NULL;
1795 if (_eflutil.wl.shot.queue)
1797 wl_event_queue_destroy(_eflutil.wl.shot.queue);
1798 _eflutil.wl.shot.queue = NULL;
1801 if (_eflutil.wl.shot.screenshooter)
1803 screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1804 _eflutil.wl.shot.screenshooter = NULL;
1806 if (_eflutil.wl.shot.tz_screenshooter)
1808 tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1809 _eflutil.wl.shot.tz_screenshooter = NULL;
1812 _screenshot_mutex_unlock();
1813 _screenshot_mutex_destory();
1817 return EFL_UTIL_ERROR_NONE;
1822 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1824 tbm_surface_h t_surface = NULL;
1825 struct wl_buffer *buffer = NULL;
1826 Efl_Util_Wl_Output_Info *output;
1829 _screenshot_mutex_lock();
1831 if (!screenshot || (screenshot != g_screenshot))
1833 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1834 _screenshot_mutex_unlock();
1838 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1841 fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1845 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1848 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1852 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1855 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1859 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1861 screenshot->shot_done = EINA_FALSE;
1862 while (!screenshot->shot_done && ret != -1)
1863 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1867 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1871 wl_buffer_destroy(buffer);
1873 /* reset shot_done for next screenshot */
1874 screenshot->shot_done = EINA_FALSE;
1876 set_last_result(EFL_UTIL_ERROR_NONE);
1878 _screenshot_mutex_unlock();
1884 tbm_surface_destroy(t_surface);
1886 wl_buffer_destroy(buffer);
1888 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1890 _screenshot_mutex_unlock();
1896 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1898 if (!screenshot || (screenshot != g_screenshot))
1899 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1901 if (!(set == 0 || set == 1))
1902 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1905 g_screenshot->auto_rotation = EINA_TRUE;
1907 g_screenshot->auto_rotation = EINA_FALSE;
1909 tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1911 return EFL_UTIL_ERROR_NONE;
1915 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1917 if (!screenshot || (screenshot != g_screenshot) || !set)
1918 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1920 *set = g_screenshot->auto_rotation;
1922 return EFL_UTIL_ERROR_NONE;