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)
762 if (ecore_wl_window_shell_surface_get(wlwin) ||
763 ecore_wl_window_xdg_surface_get(wlwin))
765 while (lv_info->wait_for_done)
768 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
773 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
774 return EFL_UTIL_ERROR_INVALID_PARAMETER;
778 switch (lv_info->level)
780 case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break;
781 case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break;
782 case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break;
783 case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break;
784 case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
785 case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break;
786 case TIZEN_POLICY_LEVEL_HIGH: *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH; break;
787 case TIZEN_POLICY_LEVEL_TOP: *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP; break;
788 default: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
789 return EFL_UTIL_ERROR_INVALID_PARAMETER;
791 return EFL_UTIL_ERROR_NONE;
794 *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
796 return EFL_UTIL_ERROR_NONE;
798 #endif /* end of WAYLAND */
799 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
803 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
804 efl_util_notification_window_level_error_cb callback,
807 Eina_Bool ret = EINA_FALSE;
809 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
810 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
812 ret = _cb_info_add(window,
813 (Efl_Util_Cb)callback,
816 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
819 if (!_eflutil.cb_handler[CBH_NOTI_LEV].atom)
820 _eflutil.cb_handler[CBH_NOTI_LEV].atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
821 #endif /* end of X11 */
823 return EFL_UTIL_ERROR_NONE;
827 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
829 Eina_Bool ret = EINA_FALSE;
831 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
833 ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
834 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
836 return EFL_UTIL_ERROR_NONE;
840 efl_util_set_window_opaque_state(Evas_Object *window,
845 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
846 EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
847 EFL_UTIL_ERROR_INVALID_PARAMETER);
851 Utilx_Opaque_State state;
855 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
857 xwin = elm_win_xwindow_get(window);
858 EINA_SAFETY_ON_FALSE_RETURN_VAL(xwin > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
861 state = UTILX_OPAQUE_STATE_ON;
863 state = UTILX_OPAQUE_STATE_OFF;
865 ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
870 return EFL_UTIL_ERROR_INVALID_PARAMETER;
872 return EFL_UTIL_ERROR_NONE;
873 #endif /* end of X11 */
876 Ecore_Wl_Window *wlwin;
877 struct wl_surface *surface;
879 if (!_eflutil.wl.policy.proto)
884 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
886 while (!_eflutil.wl.policy.proto && ret != -1)
887 ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
889 EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
892 wlwin = elm_win_wl_window_get(window);
894 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
896 surface = ecore_wl_window_surface_get(wlwin);
898 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
900 tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
902 return EFL_UTIL_ERROR_NONE;
903 #endif /* end of WAYLAND */
907 efl_util_set_window_screen_mode(Evas_Object *window,
908 efl_util_screen_mode_e mode)
910 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
911 EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
912 (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
913 EFL_UTIL_ERROR_INVALID_PARAMETER);
920 e = evas_object_evas_get(window);
921 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
923 ee = ecore_evas_ecore_evas_get(e);
924 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
926 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
927 if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
930 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
932 ecore_evas_aux_hint_val_set(ee, id, "1");
934 else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
937 ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
939 ecore_evas_aux_hint_val_set(ee, id, "0");
942 return EFL_UTIL_ERROR_INVALID_PARAMETER;
944 return EFL_UTIL_ERROR_NONE;
945 #endif /* end of X11 */
948 Ecore_Wl_Window *wlwin;
949 struct wl_surface *surface;
950 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
954 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
956 wlwin = elm_win_wl_window_get(window);
959 while (!_eflutil.wl.policy.proto)
960 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
962 surface = ecore_wl_window_surface_get(wlwin);
963 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
964 EFL_UTIL_ERROR_INVALID_PARAMETER);
966 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
969 scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
970 EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
972 scr_mode_info->surface = surface;
973 scr_mode_info->mode = (unsigned int)mode;
974 scr_mode_info->wait_for_done = EINA_TRUE;
976 eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
982 scr_mode_info->mode = (unsigned int)mode;
983 scr_mode_info->wait_for_done = EINA_TRUE;
986 tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
987 surface, (unsigned int)mode);
989 return EFL_UTIL_ERROR_NONE;
992 return EFL_UTIL_ERROR_INVALID_PARAMETER;
993 #endif /* end of WAYLAND */
997 efl_util_get_window_screen_mode(Evas_Object *window,
998 efl_util_screen_mode_e *mode)
1000 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1001 EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1009 e = evas_object_evas_get(window);
1010 EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
1012 ee = ecore_evas_ecore_evas_get(e);
1013 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
1015 id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
1016 EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
1018 str = ecore_evas_aux_hint_val_get(ee, id);
1019 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
1021 if (strncmp(str, "1", strlen("1")) == 0)
1022 *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
1024 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1026 return EFL_UTIL_ERROR_NONE;
1027 #endif /* end of X11 */
1030 Ecore_Wl_Window *wlwin;
1031 struct wl_surface *surface;
1032 Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1036 EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1038 wlwin = elm_win_wl_window_get(window);
1041 while (!_eflutil.wl.policy.proto)
1042 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1044 surface = ecore_wl_window_surface_get(wlwin);
1045 EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1046 EFL_UTIL_ERROR_INVALID_PARAMETER);
1048 scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1051 if (scr_mode_info->wait_for_done)
1053 while (scr_mode_info->wait_for_done)
1056 wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1060 switch (scr_mode_info->mode)
1062 case TIZEN_POLICY_MODE_DEFAULT: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT; break;
1063 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1064 default: *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1065 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1067 return EFL_UTIL_ERROR_NONE;
1071 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1072 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1076 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1077 #endif /* end of WAYLAND */
1081 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1082 efl_util_window_screen_mode_error_cb callback,
1085 Eina_Bool ret = EINA_FALSE;
1087 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1088 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1090 ret = _cb_info_add(window,
1091 (Efl_Util_Cb)callback,
1094 if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1097 if (!_eflutil.cb_handler[CBH_SCR_MODE].atom)
1098 _eflutil.cb_handler[CBH_SCR_MODE].atom = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
1099 #endif /* end of X11 */
1101 return EFL_UTIL_ERROR_NONE;
1105 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1107 Eina_Bool ret = EINA_FALSE;
1109 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1111 ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1112 if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1114 return EFL_UTIL_ERROR_NONE;
1118 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
1120 return EFL_UTIL_ERROR_NONE;
1124 efl_util_input_deinitialize_generator(void)
1130 efl_util_input_generate_key(const char *key_name,
1133 return EFL_UTIL_ERROR_NONE;
1137 efl_util_input_generate_touch(int idx,
1138 efl_util_input_touch_type_e touch_type,
1142 return EFL_UTIL_ERROR_NONE;
1145 struct _efl_util_screenshot_h
1151 Ecore_X_Display *dpy;
1152 int internal_display;
1167 int eventBase, errorBase;
1168 int dri2Major, dri2Minor;
1169 char *driver_name, *device_name;
1176 Eina_Bool shot_done;
1182 /* scrrenshot handle */
1183 static efl_util_screenshot_h g_screenshot;
1186 #define FOURCC(a,b,c,d) (((unsigned)d&0xff)<<24 | ((unsigned)c&0xff)<<16 | ((unsigned)b&0xff)<<8 | ((unsigned)a&0xff))
1187 #define FOURCC_RGB32 FOURCC('R','G','B','4')
1188 #define TIMEOUT_CAPTURE 3
1190 /* x error handling */
1191 static Bool g_efl_util_x_error_caught;
1194 _efl_util_screenshot_x_error_handle(Display *dpy, XErrorEvent *ev)
1196 if (!g_screenshot || (dpy != g_screenshot->dpy))
1199 g_efl_util_x_error_caught = True;
1205 _efl_util_screenshot_get_port(Display *dpy, unsigned int id, Window win)
1207 unsigned int ver, rev, req_base, evt_base, err_base;
1208 unsigned int adaptors;
1209 XvAdaptorInfo *ai = NULL;
1210 XvImageFormatValues *fo = NULL;
1214 if (XvQueryExtension(dpy, &ver, &rev, &req_base, &evt_base, &err_base) != Success)
1216 fprintf(stderr, "[screenshot] fail: no XV extension. \n");
1220 if (XvQueryAdaptors(dpy, win, &adaptors, &ai) != Success)
1222 fprintf(stderr, "[screenshot] fail: query adaptors. \n");
1226 EINA_SAFETY_ON_NULL_RETURN_VAL(ai, -1);
1228 for (i = 0; i < adaptors; i++)
1230 int support_format = False;
1232 if (!(ai[i].type & XvInputMask) ||
1233 !(ai[i].type & XvStillMask))
1238 fo = XvListImageFormats(dpy, p, &formats);
1239 for (j = 0; j < formats; j++)
1240 if (fo[j].id == (int)id)
1241 support_format = True;
1246 if (!support_format)
1249 for (; p < ai[i].base_id + ai[i].num_ports; p++)
1251 if (XvGrabPort(dpy, p, 0) == Success)
1253 XvFreeAdaptorInfo(ai);
1259 XvFreeAdaptorInfo(ai);
1266 static int _efl_util_screenshot_get_best_size(Display *dpy, int port, int width, int height, unsigned int *best_width, unsigned int *best_height)
1268 XErrorHandler old_handler = NULL;
1270 Atom atom_capture = XInternAtom(dpy, "_USER_WM_PORT_ATTRIBUTE_CAPTURE", False);
1272 g_efl_util_x_error_caught = False;
1273 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1275 XvSetPortAttribute(dpy, port, atom_capture, 1);
1278 g_efl_util_x_error_caught = False;
1279 XSetErrorHandler(old_handler);
1281 XvQueryBestSize(dpy, port, 0, 0, 0, width, height, best_width, best_height);
1282 if (best_width <= 0 || best_height <= 0)
1289 API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height)
1292 efl_util_screenshot_h screenshot = NULL;
1294 int damage_err_base = 0;
1295 unsigned int best_width = 0;
1296 unsigned int best_height = 0;
1298 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1299 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1301 if (g_screenshot != NULL)
1303 if (g_screenshot->width != width || g_screenshot->height != height)
1305 // TODO: recreate pixmap and update information
1306 if (!_efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height))
1308 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1312 g_screenshot->width = width;
1313 g_screenshot->height = height;
1316 return g_screenshot;
1319 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1320 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1323 screenshot->dpy = ecore_x_display_get();
1324 if (!screenshot->dpy)
1326 screenshot->dpy = XOpenDisplay(0);
1327 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_init);
1329 /* for XCloseDisplay at denitialization */
1330 screenshot->internal_display = 1;
1334 screenshot->screen = DefaultScreen(screenshot->dpy);
1336 /* set root window */
1337 screenshot->root = DefaultRootWindow(screenshot->dpy);
1339 /* initialize capture adaptor */
1340 screenshot->port = _efl_util_screenshot_get_port(screenshot->dpy, FOURCC_RGB32, screenshot->root);
1341 EINA_SAFETY_ON_FALSE_GOTO(screenshot->port > 0, fail_init);
1343 /* get the best size */
1344 _efl_util_screenshot_get_best_size(screenshot->dpy, screenshot->port, width, height, &best_width, &best_height);
1345 EINA_SAFETY_ON_FALSE_GOTO(best_width > 0, fail_init);
1346 EINA_SAFETY_ON_FALSE_GOTO(best_height > 0, fail_init);
1348 /* set the width and the height */
1349 screenshot->width = best_width;
1350 screenshot->height = best_height;
1352 /* create a pixmap */
1353 depth = DefaultDepth(screenshot->dpy, screenshot->screen);
1354 screenshot->pixmap = XCreatePixmap(screenshot->dpy, screenshot->root, screenshot->width, screenshot->height, depth);
1355 EINA_SAFETY_ON_FALSE_GOTO(screenshot->pixmap > 0, fail_init);
1357 screenshot->gc = XCreateGC(screenshot->dpy, screenshot->pixmap, 0, 0);
1358 EINA_SAFETY_ON_NULL_GOTO(screenshot->gc, fail_init);
1360 XSetForeground(screenshot->dpy, screenshot->gc, 0xFF000000);
1361 XFillRectangle(screenshot->dpy, screenshot->pixmap, screenshot->gc, 0, 0, width, height);
1363 /* initialize damage */
1364 if (!XDamageQueryExtension(screenshot->dpy, &screenshot->damage_base, &damage_err_base))
1367 screenshot->damage = XDamageCreate(screenshot->dpy, screenshot->pixmap, XDamageReportNonEmpty);
1368 EINA_SAFETY_ON_FALSE_GOTO(screenshot->damage > 0, fail_init);
1370 /* initialize dri3 and dri2 */
1371 if (!DRI2QueryExtension(screenshot->dpy, &screenshot->eventBase, &screenshot->errorBase))
1373 fprintf(stderr, "[screenshot] fail: DRI2QueryExtention\n");
1377 if (!DRI2QueryVersion(screenshot->dpy, &screenshot->dri2Major, &screenshot->dri2Minor))
1379 fprintf(stderr, "[screenshot] fail: DRI2QueryVersion\n");
1383 if (!DRI2Connect(screenshot->dpy, screenshot->root, &screenshot->driver_name, &screenshot->device_name))
1385 fprintf(stderr, "[screenshot] fail: DRI2Connect\n");
1389 screenshot->drm_fd = open(screenshot->device_name, O_RDWR);
1390 EINA_SAFETY_ON_FALSE_GOTO(screenshot->drm_fd >= 0, fail_init);
1392 if (drmGetMagic(screenshot->drm_fd, &screenshot->magic))
1394 fprintf(stderr, "[screenshot] fail: drmGetMagic\n");
1398 if (!DRI2Authenticate(screenshot->dpy, screenshot->root, screenshot->magic))
1400 fprintf(stderr, "[screenshot] fail: DRI2Authenticate\n");
1404 if (!drmAuthMagic(screenshot->drm_fd, screenshot->magic))
1406 fprintf(stderr, "[screenshot] fail: drmAuthMagic\n");
1410 DRI2CreateDrawable(screenshot->dpy, screenshot->pixmap);
1413 screenshot->bufmgr = tbm_bufmgr_init(screenshot->drm_fd);
1414 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1416 XFlush(screenshot->dpy);
1418 g_screenshot = screenshot;
1419 set_last_result(EFL_UTIL_ERROR_NONE);
1421 return g_screenshot;
1425 efl_util_screenshot_h screenshot = NULL;
1427 if (!_eflutil.wl.shot.screenshooter)
1431 while (!_eflutil.wl.shot.screenshooter && ret != -1)
1432 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1433 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1435 _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1436 EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1439 EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1440 EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1444 if (g_screenshot->width != width || g_screenshot->height != height)
1446 g_screenshot->width = width;
1447 g_screenshot->height = height;
1450 return g_screenshot;
1453 screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1454 EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1456 screenshot->width = width;
1457 screenshot->height = height;
1459 screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1460 EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1462 g_screenshot = screenshot;
1463 set_last_result(EFL_UTIL_ERROR_NONE);
1465 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1467 return g_screenshot;
1471 efl_util_screenshot_deinitialize(screenshot);
1472 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1476 efl_util_screenshot_deinitialize(screenshot);
1477 set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1481 efl_util_screenshot_deinitialize(screenshot);
1482 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1486 API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1490 return EFL_UTIL_ERROR_INVALID_PARAMETER;
1493 if (screenshot->bufmgr)
1494 tbm_bufmgr_deinit(screenshot->bufmgr);
1496 DRI2DestroyDrawable(screenshot->dpy, screenshot->pixmap);
1499 if (screenshot->drm_fd)
1500 close(screenshot->drm_fd);
1501 if (screenshot->driver_name)
1502 free(screenshot->driver_name);
1503 if (screenshot->device_name)
1504 free(screenshot->device_name);
1507 if (screenshot->port > 0 && screenshot->pixmap > 0)
1508 XvStopVideo(screenshot->dpy, screenshot->port, screenshot->pixmap);
1511 if (screenshot->damage)
1512 XDamageDestroy(screenshot->dpy, screenshot->damage);
1516 XFreeGC(screenshot->dpy, screenshot->gc);
1519 if (screenshot->pixmap > 0)
1520 XFreePixmap(screenshot->dpy, screenshot->pixmap);
1523 if (screenshot->port > 0)
1524 XvUngrabPort(screenshot->dpy, screenshot->port, 0);
1526 XSync(screenshot->dpy, False);
1529 if (screenshot->internal_display ==1 && screenshot->dpy)
1530 XCloseDisplay(screenshot->dpy);
1533 g_screenshot = NULL;
1535 return EFL_UTIL_ERROR_NONE;
1539 return EFL_UTIL_ERROR_NONE;
1542 g_screenshot = NULL;
1544 if (_eflutil.wl.shot.screenshooter)
1545 screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL);
1547 return EFL_UTIL_ERROR_NONE;
1552 API tbm_surface_h efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1556 XErrorHandler old_handler = NULL;
1557 unsigned int attachment = DRI2BufferFrontLeft;
1559 DRI2Buffer *bufs = NULL;
1561 tbm_surface_h t_surface = NULL;
1564 tbm_surface_info_s surf_info;
1567 if (screenshot != g_screenshot)
1569 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1573 /* for flush other pending requests and pending events */
1574 XSync(screenshot->dpy, 0);
1576 g_efl_util_x_error_caught = False;
1577 old_handler = XSetErrorHandler(_efl_util_screenshot_x_error_handle);
1580 XvPutStill(screenshot->dpy, screenshot->port, screenshot->pixmap, screenshot->gc,
1581 0, 0, screenshot->width, screenshot->height,
1582 0, 0, screenshot->width, screenshot->height);
1584 XSync(screenshot->dpy, 0);
1586 if (g_efl_util_x_error_caught)
1588 g_efl_util_x_error_caught = False;
1589 XSetErrorHandler(old_handler);
1593 g_efl_util_x_error_caught = False;
1594 XSetErrorHandler(old_handler);
1596 if (XPending(screenshot->dpy))
1597 XNextEvent(screenshot->dpy, &ev);
1600 int fd = ConnectionNumber(screenshot->dpy);
1609 tv.tv_sec = TIMEOUT_CAPTURE;
1611 ret = select(fd + 1, &mask, 0, 0, &tv);
1613 fprintf(stderr, "[screenshot] fail: select.\n");
1615 fprintf(stderr, "[screenshot] fail: timeout(%d sec)!\n", TIMEOUT_CAPTURE);
1616 else if (XPending(screenshot->dpy))
1617 XNextEvent(screenshot->dpy, &ev);
1619 fprintf(stderr, "[screenshot] fail: not passed a event!\n");
1622 /* check if the capture is done by xserver and pixmap has got the captured image */
1623 if (ev.type == (screenshot->damage_base + XDamageNotify))
1625 XDamageNotifyEvent *damage_ev = (XDamageNotifyEvent *)&ev;
1626 if (damage_ev->drawable == screenshot->pixmap)
1628 /* Get DRI2 FrontLeft buffer of the pixmap */
1629 bufs = DRI2GetBuffers(screenshot->dpy, screenshot->pixmap, &buf_width, &buf_height, &attachment, 1, &nbufs);
1632 fprintf(stderr, "[screenshot] fail: DRI2GetBuffers\n");
1636 t_bo = tbm_bo_import(screenshot->bufmgr, bufs[0].name);
1639 fprintf(stderr, "[screenshot] fail: import tbm_bo!\n");
1643 surf_info.width = buf_width;
1644 surf_info.height = buf_height;
1645 surf_info.format = TBM_FORMAT_XRGB8888;
1647 surf_info.size = bufs->pitch * surf_info.height;
1648 surf_info.num_planes = 1;
1649 for (i = 0; i < surf_info.num_planes; i++)
1651 surf_info.planes[i].size = bufs->pitch * surf_info.height;
1652 surf_info.planes[i].stride = bufs->pitch;
1653 surf_info.planes[i].offset = 0;
1655 t_surface = tbm_surface_internal_create_with_bos(&surf_info, &t_bo, 1);
1658 fprintf(stderr, "[screenshot] fail: get tbm_surface!\n");
1665 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1667 set_last_result(EFL_UTIL_ERROR_NONE);
1672 XDamageSubtract(screenshot->dpy, screenshot->damage, None, None );
1682 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1688 tbm_surface_h t_surface = NULL;
1689 struct wl_buffer *buffer = NULL;
1690 Efl_Util_Wl_Output_Info *output;
1693 if (screenshot != g_screenshot)
1695 set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1699 output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1702 fprintf(stderr, "[screenshot] fail: no output for screenshot\n");
1706 t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1709 fprintf(stderr, "[screenshot] fail: tbm_surface_create\n");
1713 buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1716 fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n");
1720 screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1722 screenshot->shot_done = EINA_FALSE;
1723 while (!screenshot->shot_done && ret != -1)
1724 ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1728 fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n");
1732 wl_buffer_destroy(buffer);
1734 /* reset shot_done for next screenshot */
1735 screenshot->shot_done = EINA_FALSE;
1741 tbm_surface_destroy(t_surface);
1743 wl_buffer_destroy(buffer);
1745 set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);