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
69 void *surface; /* wl_surface */
71 Eina_Bool wait_for_done;
72 } Efl_Util_Wl_Surface_Lv_Info;
74 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
76 void *surface; /* wl_surface */
78 Eina_Bool wait_for_done;
79 } Efl_Util_Wl_Surface_Scr_Mode_Info;
81 typedef struct _Efl_Util_Wl_Output_Info
83 struct wl_output *output;
84 int offset_x, offset_y, width, height;
85 } Efl_Util_Wl_Output_Info;
88 typedef struct _Efl_Util_Data
91 /* x11 related stuffs */
95 Ecore_Event_Handler *handler; /* x11 client message handler */
98 #endif /* end of X11 */
101 /* wayland related stuffs */
105 struct wl_display *dpy;
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 screenshooter *screenshooter;
117 struct wayland_tbm_client *tbm_client;
118 Eina_List *output_list;
121 #endif /* end of WAYLAND */
125 Eina_List *info_list; /* list of callback info */
126 unsigned int atom; /* x11 atom */
127 } cb_handler[CBH_MAX];
130 static Efl_Util_Data _eflutil =
138 #endif /* end of X11 */
143 { NULL, NULL, NULL }, /* tizen_policy protocol */
144 { NULL, NULL, NULL } /* screenshooter protocol */
146 #endif /* end of WAYLAND */
148 { NULL, 0 }, /* handler for notification level */
149 { NULL, 0 } /* handler for screen mode */
153 static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
154 static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx);
155 static Eina_List *_cb_info_list_get(int idx);
156 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
158 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin, int idx);
159 static Eina_Bool _cb_x11_client_msg(void *data, int type, void *event);
160 static Eina_Bool _x11_init(void);
161 #endif /* end of X11 */
163 static Eina_Bool _wl_init(void);
164 static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
165 static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
166 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
167 static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
168 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);
169 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);
170 static void _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
171 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);
173 static const struct wl_registry_listener _wl_reg_listener =
176 _cb_wl_reg_global_remove
179 struct tizen_policy_listener _wl_tz_policy_listener =
181 _cb_wl_tz_policy_conformant,
182 _cb_wl_tz_policy_conformant_area,
183 _cb_wl_tz_policy_notification_done,
184 _cb_wl_tz_policy_transient_for_done,
185 _cb_wl_tz_policy_scr_mode_done
187 #endif /* end of WAYLAND */
190 _cb_info_add(Evas_Object *win,
195 Efl_Util_Callback_Info *info;
197 info = _cb_info_find_by_win(win, idx);
200 _eflutil.cb_handler[idx].info_list
201 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
206 info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
207 if (!info) return EINA_FALSE;
213 _eflutil.cb_handler[idx].info_list
214 = eina_list_append(_eflutil.cb_handler[idx].info_list,
218 if (!_eflutil.x11.handler)
219 _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
222 #endif /* end of X11 */
228 _cb_info_del_by_win(Evas_Object *win,
231 Efl_Util_Callback_Info *info;
233 info = _cb_info_find_by_win(win, idx);
234 if (!info) return EINA_FALSE;
236 _eflutil.cb_handler[idx].info_list
237 = eina_list_remove(_eflutil.cb_handler[idx].info_list,
242 unsigned int count = eina_list_count(_eflutil.cb_handler[idx].info_list);
243 if ((count == 0) && (_eflutil.x11.handler))
245 ecore_event_handler_del(_eflutil.x11.handler);
246 _eflutil.x11.handler = NULL;
254 _cb_info_list_get(int idx)
256 return _eflutil.cb_handler[idx].info_list;
259 static Efl_Util_Callback_Info *
260 _cb_info_find_by_win(Evas_Object *win,
264 Efl_Util_Callback_Info *info;
266 l = _cb_info_list_get(idx);
267 EINA_LIST_FOREACH(l, ll, info)
269 if (info->win == win) return info;
276 static Efl_Util_Callback_Info *
277 _cb_info_find_by_xwin(unsigned int xwin,
281 Efl_Util_Callback_Info *info;
284 l = _cb_info_list_get(idx);
285 EINA_LIST_FOREACH(l, ll, info)
287 xwin2 = elm_win_xwindow_get(info->win);
288 if (xwin == xwin2) return info;
295 _cb_x11_client_msg(void *data,
299 Ecore_X_Event_Client_Message *ev;
301 Efl_Util_Callback_Info *info;
304 if (!ev) return ECORE_CALLBACK_PASS_ON;
307 if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
309 if (ev->message_type == _eflutil.cb_handler[CBH_NOTI_LEV].atom)
311 info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
313 /* permission denied */
314 if ((ev->data.l[1] == 0) &&
319 EFL_UTIL_ERROR_PERMISSION_DENIED,
323 else if (ev->message_type == _eflutil.cb_handler[CBH_SCR_MODE].atom)
325 info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
327 /* permission denied */
328 if ((ev->data.l[1] == 0) &&
333 EFL_UTIL_ERROR_PERMISSION_DENIED,
337 return ECORE_CALLBACK_PASS_ON;
343 if (_eflutil.x11.init) return EINA_TRUE;
345 _eflutil.x11.dpy = ecore_x_display_get();
346 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE);
348 _eflutil.x11.init = EINA_TRUE;
352 #endif /* end of X11 */
358 struct wl_registry *reg = NULL;
360 if (_eflutil.wl.init) return EINA_TRUE;
364 _eflutil.wl.dpy = ecore_wl_display_get();
365 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
367 _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
368 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
370 reg = wl_display_get_registry(_eflutil.wl.dpy);
371 EINA_SAFETY_ON_NULL_GOTO(reg, fail);
373 wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue);
374 wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
376 _eflutil.wl.init = EINA_TRUE;
380 if (_eflutil.wl.queue)
382 wl_event_queue_destroy(_eflutil.wl.queue);
383 _eflutil.wl.queue = NULL;
387 wl_registry_destroy(reg);
393 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
394 int physical_width, int physical_height, int subpixel,
395 const char *make, const char *model, int transform)
397 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
398 if (wl_output == output->output)
400 output->offset_x = x;
401 output->offset_y = y;
406 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
407 int width, int height, int refresh)
409 Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
410 if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
412 output->width = width;
413 output->height = height;
418 _cb_wl_output_done(void *data, struct wl_output *wl_output)
423 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
427 static const struct wl_output_listener output_listener =
429 _cb_wl_output_geometry,
436 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
438 Eina_Bool *shot_done = (Eina_Bool*)data;
440 *shot_done = EINA_TRUE;
443 static const struct screenshooter_listener screenshooter_listener =
445 _cb_wl_screenshot_done
449 _cb_wl_reg_global(void *data,
450 struct wl_registry *reg,
452 const char *interface,
453 unsigned int version)
455 if (!strcmp(interface, "tizen_policy"))
457 struct tizen_policy *proto;
458 proto = wl_registry_bind(reg,
460 &tizen_policy_interface,
464 tizen_policy_add_listener(proto,
465 &_wl_tz_policy_listener,
468 _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
469 _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
470 _eflutil.wl.policy.proto = proto;
472 else if (strcmp(interface, "wl_output") == 0)
474 Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
475 EINA_SAFETY_ON_NULL_RETURN(output);
477 _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
479 output->output = wl_registry_bind(reg, name, &wl_output_interface, version);
480 wl_output_add_listener(output->output, &output_listener, output);
482 else if (strcmp(interface, "screenshooter") == 0)
484 _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
485 screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
490 _cb_wl_reg_global_remove(void *data,
491 struct wl_registry *reg,
494 _eflutil.wl.policy.proto = NULL;
495 eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
496 eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
499 static Efl_Util_Callback_Info *
500 _cb_info_find_by_wlsurf(void *wlsurf,
504 Efl_Util_Callback_Info *info;
505 Ecore_Wl_Window *wlwin2 = NULL;
506 void *wlsurf2 = NULL;
508 l = _cb_info_list_get(idx);
509 EINA_LIST_FOREACH(l, ll, info)
511 wlwin2 = elm_win_wl_window_get(info->win);
512 wlsurf2 = ecore_wl_window_surface_get(wlwin2);
513 if (wlsurf== wlsurf2) return info;
520 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
521 struct wl_surface *surface, uint32_t is_conformant)
526 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
527 struct wl_surface *surface, uint32_t conformant_part,
528 uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
533 _cb_wl_tz_policy_notification_done(void *data,
534 struct tizen_policy *tizen_policy,
535 struct wl_surface *surface,
539 Efl_Util_Wl_Surface_Lv_Info *lv_info;
540 Efl_Util_Callback_Info *cb_info;
542 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
545 lv_info->level = level;
546 lv_info->wait_for_done = EINA_FALSE;
549 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
551 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
552 if (!cb_info) return;
553 if (!cb_info->cb) return;
555 cb_info->cb(cb_info->win,
556 EFL_UTIL_ERROR_PERMISSION_DENIED,
561 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
566 _cb_wl_tz_policy_scr_mode_done(void *data,
567 struct tizen_policy *tizen_policy,
568 struct wl_surface *surface,
573 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
574 Efl_Util_Callback_Info *cb_info;
576 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
579 scr_mode_info->mode = mode;
580 scr_mode_info->wait_for_done = EINA_FALSE;
583 if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
585 cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
586 if (!cb_info) return;
587 if (!cb_info->cb) return;
589 cb_info->cb(cb_info->win,
590 EFL_UTIL_ERROR_PERMISSION_DENIED,
593 #endif /* end of WAYLAND */
596 efl_util_set_notification_window_level(Evas_Object *window,
597 efl_util_notification_level_e level)
601 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
602 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_1) &&
603 (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
604 EFL_UTIL_ERROR_INVALID_PARAMETER);
607 Ecore_X_Window_Type window_type;
611 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
613 xwin = elm_win_xwindow_get(window);
616 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
618 // success to get window type
619 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
621 // given EFL window's type is not notification type.
622 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
626 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
628 utilx_set_system_notification_level(_eflutil.x11.dpy,
631 return EFL_UTIL_ERROR_NONE;
633 #endif /* end of X11 */
637 Ecore_Wl_Window *wlwin;
638 struct wl_surface *surface;
639 Efl_Util_Wl_Surface_Lv_Info *lv_info;
642 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
644 type = elm_win_type_get(window);
645 EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
646 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
648 wlwin = elm_win_wl_window_get(window);
651 while (!_eflutil.wl.policy.proto)
652 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
654 surface = ecore_wl_window_surface_get(wlwin);
655 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
656 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
658 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
661 lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
662 EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
664 lv_info->surface = surface;
665 lv_info->level = (int)level;
666 lv_info->wait_for_done = EINA_TRUE;
668 eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
674 lv_info->level = (int)level;
675 lv_info->wait_for_done = EINA_TRUE;
678 tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
679 surface, (int)level);
681 return EFL_UTIL_ERROR_NONE;
683 #endif /* end of WAYLAND */
685 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
689 efl_util_get_notification_window_level(Evas_Object *window,
690 efl_util_notification_level_e *level)
694 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
695 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
698 Ecore_X_Window_Type window_type;
699 Utilx_Notification_Level utilx_level;
703 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
705 xwin = elm_win_xwindow_get(window);
708 if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
710 // success to get window type
711 if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
713 // given EFL window's type is not notification type.
714 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
717 utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin);
718 if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
719 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
720 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
721 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
722 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
723 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
725 return EFL_UTIL_ERROR_INVALID_PARAMETER;
728 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
730 return EFL_UTIL_ERROR_NONE;
732 #endif /* end of X11 */
736 Ecore_Wl_Window *wlwin;
737 struct wl_surface *surface;
738 Efl_Util_Wl_Surface_Lv_Info *lv_info;
741 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
743 type = elm_win_type_get(window);
744 EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
745 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
747 wlwin = elm_win_wl_window_get(window);
750 while (!_eflutil.wl.policy.proto)
751 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
753 surface = ecore_wl_window_surface_get(wlwin);
754 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
755 EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
757 lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
760 if (lv_info->wait_for_done)
763 while ((lv_info->wait_for_done) && (count < 3))
766 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
770 if (lv_info->wait_for_done)
772 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
773 return EFL_UTIL_ERROR_INVALID_PARAMETER;
777 switch (lv_info->level)
779 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
780 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
781 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
782 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
783 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
784 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
785 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
786 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
787 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
788 return EFL_UTIL_ERROR_INVALID_PARAMETER;
790 return EFL_UTIL_ERROR_NONE;
793 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
795 return EFL_UTIL_ERROR_NONE;
797 #endif /* end of WAYLAND */
798 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
802 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
803 efl_util_notification_window_level_error_cb callback,
806 Eina_Bool ret = EINA_FALSE;
808 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
809 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
811 ret = _cb_info_add(window,
812 (Efl_Util_Cb)callback,
815 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
818 if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom)
819 _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
820 #endif /* end of X11 */
822 return EFL_UTIL_ERROR_NONE;
826 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
828 Eina_Bool ret = EINA_FALSE;
830 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
832 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
833 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
835 return EFL_UTIL_ERROR_NONE;
839 efl_util_set_window_opaque_state(Evas_Object *window,
844 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
845 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
846 EFL_UTIL_ERROR_INVALID_PARAMETER);
850 Utilx_Opaque_State state;
854 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
856 xwin = elm_win_xwindow_get(window);
857 EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
860 state = UTILX_OPAQUE_STATE_ON;
862 state = UTILX_OPAQUE_STATE_OFF;
864 ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
869 return EFL_UTIL_ERROR_INVALID_PARAMETER;
871 return EFL_UTIL_ERROR_NONE;
872 #endif /* end of X11 */
875 Ecore_Wl_Window *wlwin;
876 struct wl_surface *surface;
878 if (!_eflutil.wl.policy.proto)
883 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
885 while (!_eflutil.wl.policy.proto && ret != -1)
886 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
888 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
891 wlwin = elm_win_wl_window_get(window);
893 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
895 surface = ecore_wl_window_surface_get(wlwin);
897 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
899 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
901 return EFL_UTIL_ERROR_NONE;
902 #endif /* end of WAYLAND */
906 efl_util_set_window_screen_mode(Evas_Object *window,
907 efl_util_screen_mode_e mode)
909 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
910 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
911 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
912 EFL_UTIL_ERROR_INVALID_PARAMETER);
919 e = evas_object_evas_get(window);
920 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
922 ee = ecore_evas_ecore_evas_get(e);
923 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
925 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
926 if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
929 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
931 ecore_evas_aux_hint_val_set(ee, id, "1");
933 else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
936 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
938 ecore_evas_aux_hint_val_set(ee, id, "0");
941 return EFL_UTIL_ERROR_INVALID_PARAMETER;
943 return EFL_UTIL_ERROR_NONE;
944 #endif /* end of X11 */
947 Ecore_Wl_Window *wlwin;
948 struct wl_surface *surface;
949 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
953 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
955 wlwin = elm_win_wl_window_get(window);
958 while (!_eflutil.wl.policy.proto)
959 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
961 surface = ecore_wl_window_surface_get(wlwin);
962 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
963 EFL_UTIL_ERROR_INVALID_PARAMETER);
965 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
968 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
969 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
971 scr_mode_info->surface = surface;
972 scr_mode_info->mode = (unsigned int)mode;
973 scr_mode_info->wait_for_done = EINA_TRUE;
975 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
981 scr_mode_info->mode = (unsigned int)mode;
982 scr_mode_info->wait_for_done = EINA_TRUE;
985 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
986 surface, (unsigned int)mode);
988 return EFL_UTIL_ERROR_NONE;
991 return EFL_UTIL_ERROR_INVALID_PARAMETER;
992 #endif /* end of WAYLAND */
996 efl_util_get_window_screen_mode(Evas_Object *window,
997 efl_util_screen_mode_e *mode)
999 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1000 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1008 e = evas_object_evas_get(window);
1009 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
1011 ee = ecore_evas_ecore_evas_get(e);
1012 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
1014 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1015 EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
1017 str = ecore_evas_aux_hint_val_get(ee, id);
1018 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
1020 if (strncmp(str, "1", strlen("1")) == 0)
1021 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1023 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1025 return EFL_UTIL_ERROR_NONE;
1026 #endif /* end of X11 */
1029 Ecore_Wl_Window *wlwin;
1030 struct wl_surface *surface;
1031 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1035 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1037 wlwin = elm_win_wl_window_get(window);
1040 while (!_eflutil.wl.policy.proto)
1041 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1043 surface = ecore_wl_window_surface_get(wlwin);
1044 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1045 EFL_UTIL_ERROR_INVALID_PARAMETER);
1047 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1050 if (scr_mode_info->wait_for_done)
1052 while (scr_mode_info->wait_for_done)
1055 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1059 switch (scr_mode_info->mode)
1061 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1062 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1063 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1064 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1066 return EFL_UTIL_ERROR_NONE;
1070 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1071 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1075 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1076 #endif /* end of WAYLAND */
1080 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1081 efl_util_window_screen_mode_error_cb callback,
1084 Eina_Bool ret = EINA_FALSE;
1086 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1087 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1089 ret = _cb_info_add(window,
1090 (Efl_Util_Cb)callback,
1093 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1096 if (!_eflutil.cb_handler[CBH_SCR_MODE].atom)
1097 _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
1098 #endif /* end of X11 */
1100 return EFL_UTIL_ERROR_NONE;
1104 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1106 Eina_Bool ret = EINA_FALSE;
1108 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1110 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1111 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1113 return EFL_UTIL_ERROR_NONE;
1117 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1119 return EFL_UTIL_ERROR_NONE;
1123 efl_util_input_deinitialize_generator(void)
1129 efl_util_input_generate_key(const char *key_name,
1132 return EFL_UTIL_ERROR_NONE;
1136 efl_util_input_generate_touch(int idx,
1137 efl_util_input_touch_type_e touch_type,
1141 return EFL_UTIL_ERROR_NONE;
1144 struct _efl_util_screenshot_h
1150 Ecore_X_Display *dpy;
1151 int internal_display;
1166 int eventBase, errorBase;
1167 int dri2Major, dri2Minor;
1168 char *driver_name, *device_name;
1175 Eina_Bool shot_done;
1181 /* scrrenshot handle */
1182 static efl_util_screenshot_h g_screenshot;
1185 #define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff))
1186 #define FOURCC_RGB32 FOURCC('R','G','B','4')
1187 #define TIMEOUT_CAPTURE 3
1189 /* x error handling */
1190 static Bool g_efl_util_x_error_caught;
1193 _efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev)
1195 if (!g_screenshot || (dpy != g_screenshot->dpy))
1198 g_efl_util_x_error_caught = True;
1204 _efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win)
1206 unsigned int ver, rev, req_base, evt_base, err_base;
1207 unsigned int adaptors;
1208 XvAdaptorInfo *ai = NULL;
1209 XvImageFormatValues *fo = NULL;
1213 if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success)
1215 fprintf(stderr, "[screenshot] fail: no XV extension. \n");
1219 if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success)
1221 fprintf(stderr, "[screenshot] fail: query adaptors. \n");
1225 EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1);
1227 for (i = 0; i < adaptors; i++)
1229 int support_format = False;
1231 if (!(ai[i].type & XvInputMask) ||
1232 !(ai[i].type & XvStillMask))
1237 fo = XvListImageFormats(dpy, p, &formats);
1238 for (j = 0; j < formats; j++)
1239 if (fo[j].id == (int)id)
1240 support_format = True;
1245 if (!support_format)
1248 for (; p < ai[i].base_id + ai[i].num_ports; p++)
1250 if (XvGrabPort(dpy, p, 0) == Success)
1252 XvFreeAdaptorInfo(ai);
1258 XvFreeAdaptorInfo(ai);
1265 static int _efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height)
1267 XErrorHandler old_handler = NULL;
1269 Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
1271 g_efl_util_x_error_caught = False;
1272 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1274 XvSetPortAttribute(dpy, port, atom_capture, 1);
1277 g_efl_util_x_error_caught = False;
1278 XSetErrorHandler(old_handler);
1280 XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height);
1281 if (best_width <= 0 || best_height <= 0)
1288 API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height)
1291 efl_util_screenshot_h screenshot = NULL;
1293 int damage_err_base = 0;
1294 unsigned int best_width = 0;
1295 unsigned int best_height = 0;
1297 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1298 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1300 if (g_screenshot != NULL)
1302 if (g_screenshot->width != width || g_screenshot->height != height)
1304 // TODO: recreate pixmap and update information
1305 if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height))
1307 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1311 g_screenshot->width = width;
1312 g_screenshot->height = height;
1315 return g_screenshot;
1318 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1319 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1322 screenshot->dpy = ecore_x_display_get();
1323 if (!screenshot->dpy)
1325 screenshot->dpy = XOpenDisplay(0);
1326 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init);
1328 /* for XCloseDisplay at denitialization */
1329 screenshot->internal_display = 1;
1333 screenshot->screen = DefaultScreen(screenshot->dpy);
1335 /* set root window */
1336 screenshot->root = DefaultRootWindow(screenshot->dpy);
1338 /* initialize capture adaptor */
1339 screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root);
1340 EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init);
1342 /* get the best size */
1343 _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height);
1344 EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init);
1345 EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init);
1347 /* set the width and the height */
1348 screenshot->width = best_width;
1349 screenshot->height = best_height;
1351 /* create a pixmap */
1352 depth = DefaultDepth(screenshot->dpy, screenshot->screen);
1353 screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth);
1354 EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init);
1356 screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0);
1357 EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init);
1359 XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000);
1360 XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height);
1362 /* initialize damage */
1363 if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base))
1366 screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty);
1367 EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init);
1369 /* initialize dri3 and dri2 */
1370 if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase))
1372 fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n");
1376 if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor))
1378 fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n");
1382 if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name))
1384 fprintf(stderr, "[screenshot] fail: DRI2Connect\n");
1388 screenshot->drm_fd = open(screenshot->device_name, O_RDWR);
1389 EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init);
1391 if (drmGetMagic(screenshot->drm_fd, &screenshot->magic))
1393 fprintf(stderr, "[screenshot] fail: drmGetMagic\n");
1397 if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic))
1399 fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n");
1403 if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic))
1405 fprintf(stderr, "[screenshot] fail: drmAuthMagic\n");
1409 DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap);
1412 screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd);
1413 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1415 XFlush(screenshot->dpy);
1417 g_screenshot = screenshot;
1418 set_last_result(EFL_UTIL_ERROR_NONE);
1420 return g_screenshot;
1424 efl_util_screenshot_h screenshot = NULL;
1426 if (!_eflutil.wl.shot.screenshooter)
1430 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1431 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1432 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1434 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1435 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1438 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1439 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1443 if (g_screenshot->width != width || g_screenshot->height != height)
1445 g_screenshot->width = width;
1446 g_screenshot->height = height;
1449 return g_screenshot;
1452 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1453 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1455 screenshot->width = width;
1456 screenshot->height = height;
1458 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1459 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1461 g_screenshot = screenshot;
1462 set_last_result(EFL_UTIL_ERROR_NONE);
1464 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1466 return g_screenshot;
1470 efl_util_screenshot_deinitialize(screenshot);
1471 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1475 efl_util_screenshot_deinitialize(screenshot);
1476 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1480 efl_util_screenshot_deinitialize(screenshot);
1481 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1485 API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1489 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1492 if (screenshot->bufmgr)
1493 tbm_bufmgr_deinit(screenshot->bufmgr);
1495 DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap);
1498 if (screenshot->drm_fd)
1499 close(screenshot->drm_fd);
1500 if (screenshot->driver_name)
1501 free(screenshot->driver_name);
1502 if (screenshot->device_name)
1503 free(screenshot->device_name);
1506 if (screenshot->port > 0 && screenshot->pixmap > 0)
1507 XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap);
1510 if (screenshot->damage)
1511 XDamageDestroy(screenshot->dpy, screenshot->damage);
1515 XFreeGC(screenshot->dpy, screenshot->gc);
1518 if (screenshot->pixmap > 0)
1519 XFreePixmap(screenshot->dpy, screenshot->pixmap);
1522 if (screenshot->port > 0)
1523 XvUngrabPort(screenshot->dpy, screenshot->port, 0);
1525 XSync(screenshot->dpy, False);
1528 if (screenshot->internal_display ==1 && screenshot->dpy)
1529 XCloseDisplay(screenshot->dpy);
1532 g_screenshot = NULL;
1534 return EFL_UTIL_ERROR_NONE;
1538 return EFL_UTIL_ERROR_NONE;
1541 g_screenshot = NULL;
1543 if (_eflutil.wl.shot.screenshooter)
1544 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1546 return EFL_UTIL_ERROR_NONE;
1551 API tbm_surface_h efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1555 XErrorHandler old_handler = NULL;
1556 unsigned int attachment = DRI2BufferFrontLeft;
1558 DRI2Buffer *bufs = NULL;
1560 tbm_surface_h t_surface = NULL;
1563 tbm_surface_info_s surf_info;
1566 if (screenshot != g_screenshot)
1568 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1572 /* for flush other pending requests and pending events */
1573 XSync(screenshot->dpy, 0);
1575 g_efl_util_x_error_caught = False;
1576 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1579 XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc,
1580 0, 0, screenshot->width, screenshot->height,
1581 0, 0, screenshot->width, screenshot->height);
1583 XSync(screenshot->dpy, 0);
1585 if (g_efl_util_x_error_caught)
1587 g_efl_util_x_error_caught = False;
1588 XSetErrorHandler(old_handler);
1592 g_efl_util_x_error_caught = False;
1593 XSetErrorHandler(old_handler);
1595 if (XPending(screenshot->dpy))
1596 XNextEvent(screenshot->dpy, &ev);
1599 int fd = ConnectionNumber(screenshot->dpy);
1608 tv.tv_sec = TIMEOUT_CAPTURE;
1610 ret = select(fd + 1, &mask, 0, 0, &tv);
1612 fprintf(stderr, "[screenshot] fail: select.\n");
1614 fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE);
1615 else if (XPending(screenshot->dpy))
1616 XNextEvent(screenshot->dpy, &ev);
1618 fprintf(stderr, "[screenshot] fail: not passed a event!\n");
1621 /* check if the capture is done by xserver and pixmap has got the captured image */
1622 if (ev.type == (screenshot->damage_base + XDamageNotify))
1624 XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
1625 if (damage_ev->drawable == screenshot->pixmap)
1627 /* Get DRI2 FrontLeft buffer of the pixmap */
1628 bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs);
1631 fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n");
1635 t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name);
1638 fprintf(stderr, "[screenshot] fail: import tbm_bo!\n");
1642 surf_info.width = buf_width;
1643 surf_info.height = buf_height;
1644 surf_info.format = TBM_FORMAT_XRGB8888;
1646 surf_info.size = bufs->pitch * surf_info.height;
1647 surf_info.num_planes = 1;
1648 for (i = 0; i < surf_info.num_planes; i++)
1650 surf_info.planes[i].size = bufs->pitch * surf_info.height;
1651 surf_info.planes[i].stride = bufs->pitch;
1652 surf_info.planes[i].offset = 0;
1654 t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1);
1657 fprintf(stderr, "[screenshot] fail: get tbm_surface!\n");
1664 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1666 set_last_result(EFL_UTIL_ERROR_NONE);
1671 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1681 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1687 tbm_surface_h t_surface = NULL;
1688 struct wl_buffer *buffer = NULL;
1689 Efl_Util_Wl_Output_Info *output;
1692 if (screenshot != g_screenshot)
1694 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1698 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1701 fprintf(stderr, "[screenshot] fail: no output for screenshot\n");
1705 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1708 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n");
1712 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1715 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n");
1719 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1721 screenshot->shot_done = EINA_FALSE;
1722 while (!screenshot->shot_done && ret != -1)
1723 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1727 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n");
1731 wl_buffer_destroy(buffer);
1733 /* reset shot_done for next screenshot */
1734 screenshot->shot_done = EINA_FALSE;
1740 tbm_surface_destroy(t_surface);
1742 wl_buffer_destroy(buffer);
1744 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);