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>
36 #include <X11/extensions/Xvlib.h>
37 #include <X11/extensions/Xvproto.h>
38 #include <X11/extensions/Xdamage.h>
42 #endif /* end of X11 */
45 #include <Ecore_Wayland.h>
46 #include <wayland-client.h>
47 #include <wayland-tbm-client.h>
48 #include <tizen-extension-client-protocol.h>
49 #include <screenshooter-client-protocol.h>
50 #endif /* end of WAYLAND */
52 /* callback handler index */
53 #define CBH_NOTI_LEV 0
54 #define CBH_SCR_MODE 1
57 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
59 typedef struct _Efl_Util_Callback_Info
64 } Efl_Util_Callback_Info;
67 typedef struct _Efl_Util_Wl_Surface_Lv_Info
70 void *surface; /* wl_surface */
72 Eina_Bool wait_for_done;
74 } Efl_Util_Wl_Surface_Lv_Info;
76 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
78 void *surface; /* wl_surface */
80 Eina_Bool wait_for_done;
82 } Efl_Util_Wl_Surface_Scr_Mode_Info;
84 typedef struct _Efl_Util_Wl_Output_Info
86 struct wl_output *output;
87 int offset_x, offset_y, width, height;
88 } Efl_Util_Wl_Output_Info;
91 typedef struct _Efl_Util_Data
94 /* x11 related stuffs */
98 Ecore_Event_Handler *handler; /* x11 client message handler */
101 #endif /* end of X11 */
104 /* wayland related stuffs */
108 struct wl_display *dpy;
109 struct wl_event_queue *queue;
113 struct tizen_policy *proto;
114 Eina_Hash *hash_noti_lv;
115 Eina_Hash *hash_scr_mode;
119 struct screenshooter *screenshooter;
120 struct wayland_tbm_client *tbm_client;
121 Eina_List *output_list;
124 #endif /* end of WAYLAND */
128 Eina_List *info_list; /* list of callback info */
129 unsigned int atom; /* x11 atom */
130 } cb_handler[CBH_MAX];
133 static Efl_Util_Data _eflutil =
141 #endif /* end of X11 */
146 { NULL, NULL, NULL }, /* tizen_policy protocol */
147 { NULL, NULL, NULL } /* screenshooter protocol */
149 #endif /* end of WAYLAND */
151 { NULL, 0 }, /* handler for notification level */
152 { NULL, 0 } /* handler for screen mode */
156 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
157 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
158 static Eina_List *_cb_info_list_get(int idx);
159 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
161 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin, int idx);
162 static Eina_Bool _cb_x11_client_msg(void *data, int type, void *event);
163 static Eina_Bool _x11_init(void);
164 #endif /* end of X11 */
166 static Eina_Bool _wl_init(void);
167 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
168 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
169 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
170 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
171 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);
172 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);
173 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
174 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 const struct wl_registry_listener _wl_reg_listener =
179 _cb_wl_reg_global_remove
182 struct tizen_policy_listener _wl_tz_policy_listener =
184 _cb_wl_tz_policy_conformant,
185 _cb_wl_tz_policy_conformant_area,
186 _cb_wl_tz_policy_notification_done,
187 _cb_wl_tz_policy_transient_for_done,
188 _cb_wl_tz_policy_scr_mode_done
190 #endif /* end of WAYLAND */
193 _cb_info_add(Evas_Object *win,
198 Efl_Util_Callback_Info *info;
200 info = _cb_info_find_by_win(win, idx);
203 _eflutil.cb_handler[idx].info_list
204 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
209 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
210 if (!info) return EINA_FALSE;
216 _eflutil.cb_handler[idx].info_list
217 = eina_list_append(_eflutil.cb_handler[idx].info_list,
221 if (!_eflutil.x11.handler)
222 _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
225 #endif /* end of X11 */
231 _cb_info_del_by_win(Evas_Object *win,
234 Efl_Util_Callback_Info *info;
236 info = _cb_info_find_by_win(win, idx);
237 if (!info) return EINA_FALSE;
239 _eflutil.cb_handler[idx].info_list
240 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
245 unsigned int count = eina_list_count(_eflutil.cb_handler[idx].info_list);
246 if ((count == 0) && (_eflutil.x11.handler))
248 ecore_event_handler_del(_eflutil.x11.handler);
249 _eflutil.x11.handler = NULL;
257 _cb_info_list_get(int idx)
259 return _eflutil.cb_handler[idx].info_list;
262 static Efl_Util_Callback_Info *
263 _cb_info_find_by_win(Evas_Object *win,
267 Efl_Util_Callback_Info *info;
269 l = _cb_info_list_get(idx);
270 EINA_LIST_FOREACH(l, ll, info)
272 if (info->win == win) return info;
279 static Efl_Util_Callback_Info *
280 _cb_info_find_by_xwin(unsigned int xwin,
284 Efl_Util_Callback_Info *info;
287 l = _cb_info_list_get(idx);
288 EINA_LIST_FOREACH(l, ll, info)
290 xwin2 = elm_win_xwindow_get(info->win);
291 if (xwin == xwin2) return info;
298 _cb_x11_client_msg(void *data,
302 Ecore_X_Event_Client_Message *ev;
304 Efl_Util_Callback_Info *info;
307 if (!ev) return ECORE_CALLBACK_PASS_ON;
310 if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
312 if (ev->message_type == _eflutil.cb_handler[CBH_NOTI_LEV].atom)
314 info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
316 /* permission denied */
317 if ((ev->data.l[1] == 0) &&
322 EFL_UTIL_ERROR_PERMISSION_DENIED,
326 else if (ev->message_type == _eflutil.cb_handler[CBH_SCR_MODE].atom)
328 info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
330 /* permission denied */
331 if ((ev->data.l[1] == 0) &&
336 EFL_UTIL_ERROR_PERMISSION_DENIED,
340 return ECORE_CALLBACK_PASS_ON;
346 if (_eflutil.x11.init) return EINA_TRUE;
348 _eflutil.x11.dpy = ecore_x_display_get();
349 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE);
351 _eflutil.x11.init = EINA_TRUE;
355 #endif /* end of X11 */
361 struct wl_registry *reg = NULL;
363 if (_eflutil.wl.init) return EINA_TRUE;
367 _eflutil.wl.dpy = ecore_wl_display_get();
368 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
370 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
371 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
373 reg = wl_display_get_registry(_eflutil.wl.dpy);
374 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
376 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
377 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
379 _eflutil.wl.init = EINA_TRUE;
383 if (_eflutil.wl.queue)
385 wl_event_queue_destroy(_eflutil.wl.queue);
386 _eflutil.wl.queue = NULL;
390 wl_registry_destroy(reg);
396 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
397 int physical_width, int physical_height, int subpixel,
398 const char *make, const char *model, int transform)
400 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
401 if (wl_output == output->output)
403 output->offset_x = x;
404 output->offset_y = y;
409 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
410 int width, int height, int refresh)
412 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
413 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
415 output->width = width;
416 output->height = height;
421 _cb_wl_output_done(void *data, struct wl_output *wl_output)
426 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
430 static const struct wl_output_listener output_listener =
432 _cb_wl_output_geometry,
439 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
441 Eina_Bool *shot_done = (Eina_Bool*)data;
443 *shot_done = EINA_TRUE;
446 static const struct screenshooter_listener screenshooter_listener =
448 _cb_wl_screenshot_done
452 _cb_wl_reg_global(void *data,
453 struct wl_registry *reg,
455 const char *interface,
456 unsigned int version)
458 if (!strcmp(interface, "tizen_policy"))
460 struct tizen_policy *proto;
461 proto = wl_registry_bind(reg,
463 &tizen_policy_interface,
467 tizen_policy_add_listener(proto,
468 &_wl_tz_policy_listener,
471 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
472 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
473 _eflutil.wl.policy.proto = proto;
475 else if (strcmp(interface, "wl_output") == 0)
477 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
478 EINA_SAFETY_ON_NULL_RETURN(output);
480 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
482 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
483 wl_output_add_listener(output->output, &output_listener, output);
485 else if (strcmp(interface, "screenshooter") == 0)
487 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
488 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
493 _cb_wl_reg_global_remove(void *data,
494 struct wl_registry *reg,
497 _eflutil.wl.policy.proto = NULL;
498 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
499 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
502 static Efl_Util_Callback_Info *
503 _cb_info_find_by_wlsurf(void *wlsurf,
507 Efl_Util_Callback_Info *info;
508 Ecore_Wl_Window *wlwin2 = NULL;
509 void *wlsurf2 = NULL;
511 l = _cb_info_list_get(idx);
512 EINA_LIST_FOREACH(l, ll, info)
514 wlwin2 = elm_win_wl_window_get(info->win);
515 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
516 if (wlsurf== wlsurf2) return info;
523 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
524 struct wl_surface *surface, uint32_t is_conformant)
529 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
530 struct wl_surface *surface, uint32_t conformant_part,
531 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,
565 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
570 _cb_wl_tz_policy_scr_mode_done(void *data,
571 struct tizen_policy *tizen_policy,
572 struct wl_surface *surface,
577 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
578 Efl_Util_Callback_Info *cb_info;
580 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
583 scr_mode_info->mode = mode;
584 scr_mode_info->wait_for_done = EINA_FALSE;
585 scr_mode_info->state = state;
588 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
590 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
591 if (!cb_info) return;
592 if (!cb_info->cb) return;
594 cb_info->cb(cb_info->win,
595 EFL_UTIL_ERROR_PERMISSION_DENIED,
600 _cb_window_show(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
602 Efl_Util_Wl_Surface_Lv_Info *lv_info;
603 Ecore_Wl_Window *wlwin;
604 struct wl_surface *surface;
607 if (EINA_UNLIKELY(!lv_info))
610 wlwin = elm_win_wl_window_get(lv_info->window);
611 if (EINA_UNLIKELY(!wlwin))
614 surface = ecore_wl_window_surface_get(wlwin);
615 if (EINA_UNLIKELY(!surface))
618 eina_hash_free_cb_set(_eflutil.wl.policy.hash_noti_lv, NULL);
619 eina_hash_del_by_key(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface);
621 lv_info->surface = surface;
622 eina_hash_add(_eflutil.wl.policy.hash_noti_lv, &surface, lv_info);
623 eina_hash_free_cb_set(_eflutil.wl.policy.hash_noti_lv, free);
625 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
626 surface, (int)lv_info->level);
630 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
632 Efl_Util_Wl_Surface_Lv_Info *lv_info;
635 if (EINA_UNLIKELY(!lv_info))
638 eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
640 #endif /* end of WAYLAND */
643 efl_util_set_notification_window_level(Evas_Object *window,
644 efl_util_notification_level_e level)
648 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
649 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
650 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
651 EFL_UTIL_ERROR_INVALID_PARAMETER);
654 Ecore_X_Window_Type window_type;
658 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
660 xwin = elm_win_xwindow_get(window);
663 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
665 // success to get window type
666 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
668 // given EFL window's type is not notification type.
669 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
673 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
675 utilx_set_system_notification_level(_eflutil.x11.dpy,
678 return EFL_UTIL_ERROR_NONE;
681 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
682 #endif /* end of X11 */
686 Ecore_Wl_Window *wlwin;
687 struct wl_surface *surface;
688 Efl_Util_Wl_Surface_Lv_Info *lv_info;
689 Ecore_Wl_Window_Type wl_type;
692 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
694 wlwin = elm_win_wl_window_get(window);
695 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
697 type = elm_win_type_get(window);
698 if (type != ELM_WIN_NOTIFICATION)
700 wl_type = ecore_wl_window_type_get(wlwin);
701 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
702 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
705 while (!_eflutil.wl.policy.proto)
706 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
708 surface = ecore_wl_window_surface_get(wlwin);
709 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
710 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
712 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
715 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
716 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
718 lv_info->window = window;
719 lv_info->surface = surface;
720 lv_info->level = (int)level;
721 lv_info->wait_for_done = EINA_TRUE;
722 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
723 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
727 evas_object_event_callback_add(window, EVAS_CALLBACK_SHOW,
728 _cb_window_show, lv_info);
729 evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
730 _cb_window_del, lv_info);
734 lv_info->level = (int)level;
735 lv_info->wait_for_done = EINA_TRUE;
736 lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
740 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
741 surface, (int)level);
743 if (lv_info->wait_for_done)
746 while (lv_info->wait_for_done && (count < 3))
749 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
753 if (lv_info->wait_for_done)
755 return EFL_UTIL_ERROR_INVALID_PARAMETER;
759 if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
761 return EFL_UTIL_ERROR_PERMISSION_DENIED;
766 return EFL_UTIL_ERROR_NONE;
767 #endif /* end of WAYLAND */
771 efl_util_get_notification_window_level(Evas_Object *window,
772 efl_util_notification_level_e *level)
776 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
777 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
780 Ecore_X_Window_Type window_type;
781 Utilx_Notification_Level utilx_level;
785 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
787 xwin = elm_win_xwindow_get(window);
790 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
792 // success to get window type
793 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
795 // given EFL window's type is not notification type.
796 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
799 utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin);
800 if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
801 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
802 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
803 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
804 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
805 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
807 return EFL_UTIL_ERROR_INVALID_PARAMETER;
810 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
812 return EFL_UTIL_ERROR_NONE;
815 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
816 #endif /* end of X11 */
820 Ecore_Wl_Window *wlwin;
821 struct wl_surface *surface;
822 Efl_Util_Wl_Surface_Lv_Info *lv_info;
823 Ecore_Wl_Window_Type wl_type;
826 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
828 wlwin = elm_win_wl_window_get(window);
829 EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
831 type = elm_win_type_get(window);
832 if (type != ELM_WIN_NOTIFICATION)
834 wl_type = ecore_wl_window_type_get(wlwin);
835 EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION),
836 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
839 while (!_eflutil.wl.policy.proto)
840 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
842 surface = ecore_wl_window_surface_get(wlwin);
843 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
844 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
846 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
849 if (lv_info->wait_for_done)
852 while ((lv_info->wait_for_done) && (count < 3))
855 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
859 if (lv_info->wait_for_done)
861 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
862 return EFL_UTIL_ERROR_INVALID_PARAMETER;
866 switch (lv_info->level)
868 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
869 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
870 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
871 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
872 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
873 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
874 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
875 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
876 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
877 return EFL_UTIL_ERROR_INVALID_PARAMETER;
879 return EFL_UTIL_ERROR_NONE;
882 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
884 return EFL_UTIL_ERROR_NONE;
885 #endif /* end of WAYLAND */
889 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
890 efl_util_notification_window_level_error_cb callback,
893 Eina_Bool ret = EINA_FALSE;
895 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
896 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
898 ret = _cb_info_add(window,
899 (Efl_Util_Cb)callback,
902 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
905 if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom)
906 _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
907 #endif /* end of X11 */
909 return EFL_UTIL_ERROR_NONE;
913 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
915 Eina_Bool ret = EINA_FALSE;
917 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
919 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
920 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
922 return EFL_UTIL_ERROR_NONE;
926 efl_util_set_window_opaque_state(Evas_Object *window,
931 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
932 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
933 EFL_UTIL_ERROR_INVALID_PARAMETER);
937 Utilx_Opaque_State state;
941 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
943 xwin = elm_win_xwindow_get(window);
944 EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
947 state = UTILX_OPAQUE_STATE_ON;
949 state = UTILX_OPAQUE_STATE_OFF;
951 ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
956 return EFL_UTIL_ERROR_INVALID_PARAMETER;
958 return EFL_UTIL_ERROR_NONE;
959 #endif /* end of X11 */
962 Ecore_Wl_Window *wlwin;
963 struct wl_surface *surface;
965 if (!_eflutil.wl.policy.proto)
970 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
972 while (!_eflutil.wl.policy.proto && ret != -1)
973 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
975 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
978 wlwin = elm_win_wl_window_get(window);
980 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
982 surface = ecore_wl_window_surface_get(wlwin);
984 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
986 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
988 return EFL_UTIL_ERROR_NONE;
989 #endif /* end of WAYLAND */
993 efl_util_set_window_screen_mode(Evas_Object *window,
994 efl_util_screen_mode_e mode)
996 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
997 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
998 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
999 EFL_UTIL_ERROR_INVALID_PARAMETER);
1006 e = evas_object_evas_get(window);
1007 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
1009 ee = ecore_evas_ecore_evas_get(e);
1010 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
1012 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1013 if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
1016 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
1018 ecore_evas_aux_hint_val_set(ee, id, "1");
1020 else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
1023 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
1025 ecore_evas_aux_hint_val_set(ee, id, "0");
1028 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1030 return EFL_UTIL_ERROR_NONE;
1031 #endif /* end of X11 */
1034 Ecore_Wl_Window *wlwin;
1035 struct wl_surface *surface;
1036 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1040 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1042 wlwin = elm_win_wl_window_get(window);
1045 while (!_eflutil.wl.policy.proto)
1046 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1048 surface = ecore_wl_window_surface_get(wlwin);
1049 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1050 EFL_UTIL_ERROR_INVALID_PARAMETER);
1052 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1055 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
1056 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1058 scr_mode_info->surface = surface;
1059 scr_mode_info->mode = (unsigned int)mode;
1060 scr_mode_info->wait_for_done = EINA_TRUE;
1061 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1063 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
1069 scr_mode_info->mode = (unsigned int)mode;
1070 scr_mode_info->wait_for_done = EINA_TRUE;
1071 scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1074 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
1075 surface, (unsigned int)mode);
1076 if (scr_mode_info->wait_for_done)
1079 while (scr_mode_info->wait_for_done && (count < 3))
1082 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1086 if (scr_mode_info->wait_for_done)
1088 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1092 if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1094 return EFL_UTIL_ERROR_PERMISSION_DENIED;
1099 return EFL_UTIL_ERROR_NONE;
1102 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1103 #endif /* end of WAYLAND */
1107 efl_util_get_window_screen_mode(Evas_Object *window,
1108 efl_util_screen_mode_e *mode)
1110 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1111 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1119 e = evas_object_evas_get(window);
1120 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
1122 ee = ecore_evas_ecore_evas_get(e);
1123 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
1125 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1126 EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
1128 str = ecore_evas_aux_hint_val_get(ee, id);
1129 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
1131 if (strncmp(str, "1", strlen("1")) == 0)
1132 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1134 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1136 return EFL_UTIL_ERROR_NONE;
1137 #endif /* end of X11 */
1140 Ecore_Wl_Window *wlwin;
1141 struct wl_surface *surface;
1142 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1146 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1148 wlwin = elm_win_wl_window_get(window);
1151 while (!_eflutil.wl.policy.proto)
1152 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1154 surface = ecore_wl_window_surface_get(wlwin);
1155 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1156 EFL_UTIL_ERROR_INVALID_PARAMETER);
1158 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1161 if (scr_mode_info->wait_for_done)
1163 while (scr_mode_info->wait_for_done)
1166 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1170 switch (scr_mode_info->mode)
1172 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1173 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1174 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1175 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1177 return EFL_UTIL_ERROR_NONE;
1181 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1182 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1186 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1187 #endif /* end of WAYLAND */
1191 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1192 efl_util_window_screen_mode_error_cb callback,
1195 Eina_Bool ret = EINA_FALSE;
1197 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1198 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1200 ret = _cb_info_add(window,
1201 (Efl_Util_Cb)callback,
1204 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1207 if (!_eflutil.cb_handler[CBH_SCR_MODE].atom)
1208 _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
1209 #endif /* end of X11 */
1211 return EFL_UTIL_ERROR_NONE;
1215 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1217 Eina_Bool ret = EINA_FALSE;
1219 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1221 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1222 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1224 return EFL_UTIL_ERROR_NONE;
1228 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1230 return EFL_UTIL_ERROR_NONE;
1234 efl_util_input_deinitialize_generator(void)
1240 efl_util_input_generate_key(const char *key_name,
1243 return EFL_UTIL_ERROR_NONE;
1247 efl_util_input_generate_touch(int idx,
1248 efl_util_input_touch_type_e touch_type,
1252 return EFL_UTIL_ERROR_NONE;
1255 struct _efl_util_screenshot_h
1261 Ecore_X_Display *dpy;
1262 int internal_display;
1277 int eventBase, errorBase;
1278 int dri2Major, dri2Minor;
1279 char *driver_name, *device_name;
1286 Eina_Bool shot_done;
1292 /* scrrenshot handle */
1293 static efl_util_screenshot_h g_screenshot;
1296 #define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff))
1297 #define FOURCC_RGB32 FOURCC('R','G','B','4')
1298 #define TIMEOUT_CAPTURE 3
1300 /* x error handling */
1301 static Bool g_efl_util_x_error_caught;
1304 _efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev)
1306 if (!g_screenshot || (dpy != g_screenshot->dpy))
1309 g_efl_util_x_error_caught = True;
1315 _efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win)
1317 unsigned int ver, rev, req_base, evt_base, err_base;
1318 unsigned int adaptors;
1319 XvAdaptorInfo *ai = NULL;
1320 XvImageFormatValues *fo = NULL;
1324 if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success)
1326 fprintf(stderr, "[screenshot] fail: no XV extension. \n");
1330 if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success)
1332 fprintf(stderr, "[screenshot] fail: query adaptors. \n");
1336 EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1);
1338 for (i = 0; i < adaptors; i++)
1340 int support_format = False;
1342 if (!(ai[i].type & XvInputMask) ||
1343 !(ai[i].type & XvStillMask))
1348 fo = XvListImageFormats(dpy, p, &formats);
1349 for (j = 0; j < formats; j++)
1350 if (fo[j].id == (int)id)
1351 support_format = True;
1356 if (!support_format)
1359 for (; p < ai[i].base_id + ai[i].num_ports; p++)
1361 if (XvGrabPort(dpy, p, 0) == Success)
1363 XvFreeAdaptorInfo(ai);
1369 XvFreeAdaptorInfo(ai);
1376 static int _efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height)
1378 XErrorHandler old_handler = NULL;
1380 Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
1382 g_efl_util_x_error_caught = False;
1383 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1385 XvSetPortAttribute(dpy, port, atom_capture, 1);
1388 g_efl_util_x_error_caught = False;
1389 XSetErrorHandler(old_handler);
1391 XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height);
1392 if (best_width <= 0 || best_height <= 0)
1399 API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height)
1402 efl_util_screenshot_h screenshot = NULL;
1404 int damage_err_base = 0;
1405 unsigned int best_width = 0;
1406 unsigned int best_height = 0;
1408 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1409 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1411 if (g_screenshot != NULL)
1413 if (g_screenshot->width != width || g_screenshot->height != height)
1415 // TODO: recreate pixmap and update information
1416 if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height))
1418 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1422 g_screenshot->width = width;
1423 g_screenshot->height = height;
1426 return g_screenshot;
1429 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1430 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1433 screenshot->dpy = ecore_x_display_get();
1434 if (!screenshot->dpy)
1436 screenshot->dpy = XOpenDisplay(0);
1437 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init);
1439 /* for XCloseDisplay at denitialization */
1440 screenshot->internal_display = 1;
1444 screenshot->screen = DefaultScreen(screenshot->dpy);
1446 /* set root window */
1447 screenshot->root = DefaultRootWindow(screenshot->dpy);
1449 /* initialize capture adaptor */
1450 screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root);
1451 EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init);
1453 /* get the best size */
1454 _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height);
1455 EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init);
1456 EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init);
1458 /* set the width and the height */
1459 screenshot->width = best_width;
1460 screenshot->height = best_height;
1462 /* create a pixmap */
1463 depth = DefaultDepth(screenshot->dpy, screenshot->screen);
1464 screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth);
1465 EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init);
1467 screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0);
1468 EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init);
1470 XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000);
1471 XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height);
1473 /* initialize damage */
1474 if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base))
1477 screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty);
1478 EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init);
1480 /* initialize dri3 and dri2 */
1481 if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase))
1483 fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n");
1487 if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor))
1489 fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n");
1493 if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name))
1495 fprintf(stderr, "[screenshot] fail: DRI2Connect\n");
1499 screenshot->drm_fd = open(screenshot->device_name, O_RDWR);
1500 EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init);
1502 if (drmGetMagic(screenshot->drm_fd, &screenshot->magic))
1504 fprintf(stderr, "[screenshot] fail: drmGetMagic\n");
1508 if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic))
1510 fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n");
1514 if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic))
1516 fprintf(stderr, "[screenshot] fail: drmAuthMagic\n");
1520 DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap);
1523 screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd);
1524 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1526 XFlush(screenshot->dpy);
1528 g_screenshot = screenshot;
1529 set_last_result(EFL_UTIL_ERROR_NONE);
1531 return g_screenshot;
1535 efl_util_screenshot_h screenshot = NULL;
1537 if (!_eflutil.wl.shot.screenshooter)
1541 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1542 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1543 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1545 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1546 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1549 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1550 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1554 if (g_screenshot->width != width || g_screenshot->height != height)
1556 g_screenshot->width = width;
1557 g_screenshot->height = height;
1560 return g_screenshot;
1563 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1564 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1566 screenshot->width = width;
1567 screenshot->height = height;
1569 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1570 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1572 g_screenshot = screenshot;
1573 set_last_result(EFL_UTIL_ERROR_NONE);
1575 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1577 return g_screenshot;
1581 efl_util_screenshot_deinitialize(screenshot);
1582 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1586 efl_util_screenshot_deinitialize(screenshot);
1587 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1591 efl_util_screenshot_deinitialize(screenshot);
1592 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1596 API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1600 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1603 if (screenshot->bufmgr)
1604 tbm_bufmgr_deinit(screenshot->bufmgr);
1606 DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap);
1609 if (screenshot->drm_fd)
1610 close(screenshot->drm_fd);
1611 if (screenshot->driver_name)
1612 free(screenshot->driver_name);
1613 if (screenshot->device_name)
1614 free(screenshot->device_name);
1617 if (screenshot->port > 0 && screenshot->pixmap > 0)
1618 XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap);
1621 if (screenshot->damage)
1622 XDamageDestroy(screenshot->dpy, screenshot->damage);
1626 XFreeGC(screenshot->dpy, screenshot->gc);
1629 if (screenshot->pixmap > 0)
1630 XFreePixmap(screenshot->dpy, screenshot->pixmap);
1633 if (screenshot->port > 0)
1634 XvUngrabPort(screenshot->dpy, screenshot->port, 0);
1636 XSync(screenshot->dpy, False);
1639 if (screenshot->internal_display ==1 && screenshot->dpy)
1640 XCloseDisplay(screenshot->dpy);
1643 g_screenshot = NULL;
1645 return EFL_UTIL_ERROR_NONE;
1649 return EFL_UTIL_ERROR_NONE;
1652 g_screenshot = NULL;
1654 if (_eflutil.wl.shot.screenshooter)
1655 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1657 return EFL_UTIL_ERROR_NONE;
1662 API tbm_surface_h efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1666 XErrorHandler old_handler = NULL;
1667 unsigned int attachment = DRI2BufferFrontLeft;
1669 DRI2Buffer *bufs = NULL;
1671 tbm_surface_h t_surface = NULL;
1674 tbm_surface_info_s surf_info;
1677 if (screenshot != g_screenshot)
1679 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1683 /* for flush other pending requests and pending events */
1684 XSync(screenshot->dpy, 0);
1686 g_efl_util_x_error_caught = False;
1687 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1690 XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc,
1691 0, 0, screenshot->width, screenshot->height,
1692 0, 0, screenshot->width, screenshot->height);
1694 XSync(screenshot->dpy, 0);
1696 if (g_efl_util_x_error_caught)
1698 g_efl_util_x_error_caught = False;
1699 XSetErrorHandler(old_handler);
1703 g_efl_util_x_error_caught = False;
1704 XSetErrorHandler(old_handler);
1706 if (XPending(screenshot->dpy))
1707 XNextEvent(screenshot->dpy, &ev);
1710 int fd = ConnectionNumber(screenshot->dpy);
1719 tv.tv_sec = TIMEOUT_CAPTURE;
1721 ret = select(fd + 1, &mask, 0, 0, &tv);
1723 fprintf(stderr, "[screenshot] fail: select.\n");
1725 fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE);
1726 else if (XPending(screenshot->dpy))
1727 XNextEvent(screenshot->dpy, &ev);
1729 fprintf(stderr, "[screenshot] fail: not passed a event!\n");
1732 /* check if the capture is done by xserver and pixmap has got the captured image */
1733 if (ev.type == (screenshot->damage_base + XDamageNotify))
1735 XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
1736 if (damage_ev->drawable == screenshot->pixmap)
1738 /* Get DRI2 FrontLeft buffer of the pixmap */
1739 bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs);
1742 fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n");
1746 t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name);
1749 fprintf(stderr, "[screenshot] fail: import tbm_bo!\n");
1753 surf_info.width = buf_width;
1754 surf_info.height = buf_height;
1755 surf_info.format = TBM_FORMAT_XRGB8888;
1757 surf_info.size = bufs->pitch * surf_info.height;
1758 surf_info.num_planes = 1;
1759 for (i = 0; i < surf_info.num_planes; i++)
1761 surf_info.planes[i].size = bufs->pitch * surf_info.height;
1762 surf_info.planes[i].stride = bufs->pitch;
1763 surf_info.planes[i].offset = 0;
1765 t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1);
1768 fprintf(stderr, "[screenshot] fail: get tbm_surface!\n");
1775 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1777 set_last_result(EFL_UTIL_ERROR_NONE);
1782 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1792 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1798 tbm_surface_h t_surface = NULL;
1799 struct wl_buffer *buffer = NULL;
1800 Efl_Util_Wl_Output_Info *output;
1803 if (screenshot != g_screenshot)
1805 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1809 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1812 fprintf(stderr, "[screenshot] fail: no output for screenshot\n");
1816 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1819 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n");
1823 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1826 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n");
1830 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1832 screenshot->shot_done = EINA_FALSE;
1833 while (!screenshot->shot_done && ret != -1)
1834 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1838 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n");
1842 wl_buffer_destroy(buffer);
1844 /* reset shot_done for next screenshot */
1845 screenshot->shot_done = EINA_FALSE;
1851 tbm_surface_destroy(t_surface);
1853 wl_buffer_destroy(buffer);
1855 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);