2 * Copyright (c) 2011 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.
18 #define LOG_TAG "TIZEN_N_EFL_UTIL"
25 #include <Elementary.h>
32 typedef struct _notification_error_cb_info
35 efl_util_notification_window_level_error_cb err_cb;
37 } notification_error_cb_info;
39 Eina_List *_g_notification_error_cb_info_list;
40 static Ecore_Event_Handler* _noti_level_access_result_handler = NULL;
41 static int _noti_handler_count = 0;
42 static unsigned int _noti_level_access_result_atom = 0;
44 static Eina_Bool _efl_util_client_message(void *data, int type, void *event);
45 static notification_error_cb_info *_notification_error_cb_info_find(Evas_Object *window);
46 static notification_error_cb_info *_notification_error_cb_info_find_by_xwin(unsigned int xwin);
47 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data);
48 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window);
51 int efl_util_set_notification_window_level (Evas_Object* window, efl_util_notification_level_e level)
53 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
54 EINA_SAFETY_ON_FALSE_RETURN_VAL(level >= EFL_UTIL_NOTIFICATION_LEVEL_1 &&
55 level <= EFL_UTIL_NOTIFICATION_LEVEL_3,
56 EFL_UTIL_ERROR_INVALID_PARAMETER);
59 Ecore_X_Window xwin = elm_win_xwindow_get(window);
62 Ecore_X_Window_Type window_type;
63 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
65 // success to get window type
66 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
68 // given EFL window's type is not notification type.
69 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
73 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
75 utilx_set_system_notification_level(ecore_x_display_get(), xwin,
77 return EFL_UTIL_ERROR_NONE;
81 #if ECORE_WAYLAND_FOUND
82 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
85 printf("not implemented for wayland yet\n");
86 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
90 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
95 int efl_util_get_notification_window_level (Evas_Object* window, efl_util_notification_level_e* level)
98 EINA_SAFETY_ON_NULL_RETURN_VAL(window,
99 EFL_UTIL_ERROR_INVALID_PARAMETER);
100 EINA_SAFETY_ON_NULL_RETURN_VAL(level,
101 EFL_UTIL_ERROR_INVALID_PARAMETER);
104 Ecore_X_Window_Type window_type;
105 Utilx_Notification_Level utilx_level;
106 Ecore_X_Window xwin = elm_win_xwindow_get(window);
109 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
111 // success to get window type
112 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
114 // given EFL window's type is not notification type.
115 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
118 utilx_level = utilx_get_system_notification_level (ecore_x_display_get(), xwin);
120 if(utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
122 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
124 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
126 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
128 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
130 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
134 return EFL_UTIL_ERROR_INVALID_PARAMETER;
140 // fail to get window type
141 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
144 return EFL_UTIL_ERROR_NONE;
148 #if ECORE_WAYLAND_FOUND
149 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
152 printf("not implemented for wayland yet\n");
153 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
156 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
159 int efl_util_set_notification_window_level_error_cb(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
161 Eina_Bool ret = EINA_FALSE;
163 EINA_SAFETY_ON_NULL_RETURN_VAL(window,
164 EFL_UTIL_ERROR_INVALID_PARAMETER);
165 EINA_SAFETY_ON_NULL_RETURN_VAL(callback,
166 EFL_UTIL_ERROR_INVALID_PARAMETER);
168 ret = _efl_util_notification_info_add(window, callback, user_data);
172 if (!_noti_level_access_result_atom)
173 _noti_level_access_result_atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
175 if (!_noti_level_access_result_handler)
176 _noti_level_access_result_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _efl_util_client_message, NULL);
177 _noti_handler_count++;
179 return EFL_UTIL_ERROR_NONE;
182 #if ECORE_WAYLAND_FOUND
183 printf("not implemented for wayland yet\n");
184 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
188 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
191 int efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
193 Eina_Bool ret = EINA_FALSE;
195 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
197 ret = _efl_util_notification_info_del(window);
200 _noti_handler_count--;
201 if (_noti_handler_count == 0)
203 if (_noti_level_access_result_handler)
205 ecore_event_handler_del(_noti_level_access_result_handler);
206 _noti_level_access_result_handler = NULL;
209 return EFL_UTIL_ERROR_NONE;
212 return EFL_UTIL_ERROR_INVALID_PARAMETER;
215 int efl_util_grab_key (Evas_Object *obj, const char* key, int grab_mode)
217 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0);
220 Ecore_X_Window x_win;
221 Ecore_X_Display *x_disp;
223 x_win = elm_win_xwindow_get(obj);
226 x_disp = ecore_x_display_get();
227 return utilx_grab_key(x_disp, x_win, key, grab_mode);
232 #if ECORE_WAYLAND_FOUND
233 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
236 printf("not implemented for wayland yet\n");
244 int efl_util_ungrab_key (Evas_Object *obj, const char* key)
246 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0);
249 Ecore_X_Window x_win;
250 Ecore_X_Display *x_disp;
252 x_win = elm_win_xwindow_get(obj);
255 x_disp = ecore_x_display_get();
256 return utilx_ungrab_key (x_disp, x_win, key);
260 #if ECORE_WAYLAND_FOUND
261 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
264 printf("not implemented for wayland yet\n");
272 void efl_util_set_system_notification_level (Evas_Object *obj, Efl_Util_Notification_Level level)
274 EINA_SAFETY_ON_NULL_RETURN(obj);
275 EINA_SAFETY_ON_FALSE_RETURN(level >= EFL_UTIL_NOTIFICATION_LEVEL_LOW &&
276 level <= EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN);
279 Ecore_X_Window x_win;
280 Ecore_X_Display *x_disp;
282 x_win = elm_win_xwindow_get(obj);
285 x_disp = ecore_x_display_get();
286 utilx_set_system_notification_level(x_disp, x_win, level);
291 #if ECORE_WAYLAND_FOUND
292 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
295 printf("not implemented for wayland yet\n");
300 Efl_Util_Notification_Level efl_util_get_system_notification_level (Evas_Object *obj)
302 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN);
305 Ecore_X_Window x_win;
306 Ecore_X_Display *x_disp;
308 x_win = elm_win_xwindow_get(obj);
311 x_disp = ecore_x_display_get();
312 return utilx_get_system_notification_level(x_disp, x_win);
317 #if ECORE_WAYLAND_FOUND
318 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
321 printf("not implemented for wayland yet\n");
322 return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
326 return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
329 void efl_util_netwm_window_type_set(Evas_Object *obj, Efl_Util_Window_Type type)
331 EINA_SAFETY_ON_NULL_RETURN(obj);
332 EINA_SAFETY_ON_FALSE_RETURN(type == EFL_UTIL_WINDOW_TYPE_NORMAL ||
333 type == EFL_UTIL_WINDOW_TYPE_NOTIFICATION);
336 Ecore_X_Window x_win;
338 x_win = elm_win_xwindow_get(obj);
341 ecore_x_netwm_window_type_set(x_win, type);
347 #if ECORE_WAYLAND_FOUND
348 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
350 printf("not implemented for wayland yet\n");
354 void efl_util_set_window_effect_style(Evas_Object *win, Efl_Util_Effect_Type type, Efl_Util_Effect_Style style)
357 EINA_SAFETY_ON_NULL_RETURN(win);
360 Ecore_X_Window x_win;
361 Ecore_X_Display *x_disp;
363 x_win = elm_win_xwindow_get(win);
366 x_disp = ecore_x_display_get();
367 utilx_set_window_effect_style(x_disp, x_win, type, style);
372 #if ECORE_WAYLAND_FOUND
373 Ecore_Wl_Window wl_win = elm_win_wl_window_get(win);
375 printf("not implemented for wayland yet\n");
379 int efl_util_set_window_opaque_state (Evas_Object *win, Efl_Util_Opaque_State state)
381 EINA_SAFETY_ON_NULL_RETURN_VAL(win, 0);
384 Ecore_X_Window x_win;
385 Ecore_X_Display *x_disp;
387 x_win = elm_win_xwindow_get(win);
390 x_disp = ecore_x_display_get();
391 return utilx_set_window_opaque_state(x_disp, x_win, state);
395 #if ECORE_WAYLAND_FOUND
396 Ecore_Wl_Window wl_win = elm_win_wl_window_get(win);
398 printf("not implemented for wayland yet\n");
404 static Eina_Bool _efl_util_client_message(void *data, int type, void *event)
407 Ecore_X_Event_Client_Message *ev;
410 if (!ev) return ECORE_CALLBACK_PASS_ON;
412 if (ev->message_type == _noti_level_access_result_atom)
417 notification_error_cb_info *cb_info = NULL;
418 cb_info = _notification_error_cb_info_find_by_xwin(xwin);
421 int access = ev->data.l[1];
422 if (access == 0) // permission denied
426 cb_info->err_cb(cb_info->window, EFL_UTIL_ERROR_PERMISSION_DENIED, cb_info->user_data);
433 return ECORE_CALLBACK_PASS_ON;
436 static notification_error_cb_info *_notification_error_cb_info_find_by_xwin(unsigned int xwin)
439 notification_error_cb_info* temp;
440 unsigned int temp_xwin;
442 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
446 temp_xwin = elm_win_xwindow_get(temp->window);
447 if (xwin == temp_xwin)
457 static notification_error_cb_info *_notification_error_cb_info_find(Evas_Object *window)
460 notification_error_cb_info* temp;
462 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
464 if (temp->window == window)
473 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
475 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
479 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);
484 _err_info = (notification_error_cb_info*)calloc(1, sizeof(notification_error_cb_info));
489 _err_info->window = window;
490 _err_info->err_cb = callback;
491 _err_info->user_data = user_data;
493 _g_notification_error_cb_info_list = eina_list_append(_g_notification_error_cb_info_list, _err_info);
498 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window)
500 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
506 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);