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"
24 #include <Elementary.h>
31 typedef struct _notification_error_cb_info
34 efl_util_notification_window_level_error_cb err_cb;
36 } notification_error_cb_info;
38 Eina_List *_g_notification_error_cb_info_list;
39 static Ecore_Event_Handler* _noti_level_access_result_handler = NULL;
40 static int _noti_handler_count = 0;
42 static notification_error_cb_info *_notification_error_cb_info_find(Evas_Object *window);
43 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data);
44 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window);
47 static unsigned int _noti_level_access_result_atom = 0;
49 static Eina_Bool _efl_util_client_message(void *data, int type, void *event);
50 static notification_error_cb_info *_notification_error_cb_info_find_by_xwin(unsigned int xwin);
55 efl_util_set_notification_window_level(Evas_Object *window, efl_util_notification_level_e level)
57 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
58 EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_1) &&
59 (level <= EFL_UTIL_NOTIFICATION_LEVEL_3),
60 EFL_UTIL_ERROR_INVALID_PARAMETER);
63 Ecore_X_Window xwin = elm_win_xwindow_get(window);
66 Ecore_X_Window_Type window_type;
67 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
69 // success to get window type
70 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
72 // given EFL window's type is not notification type.
73 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
77 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
79 utilx_set_system_notification_level(ecore_x_display_get(), xwin,
81 return EFL_UTIL_ERROR_NONE;
85 #if ECORE_WAYLAND_FOUND
86 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
89 printf("not implemented for wayland yet\n");
90 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
94 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
98 efl_util_get_notification_window_level(Evas_Object *window, efl_util_notification_level_e *level)
101 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
102 EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
105 Ecore_X_Window_Type window_type;
106 Utilx_Notification_Level utilx_level;
107 Ecore_X_Window xwin = elm_win_xwindow_get(window);
110 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
112 // success to get window type
113 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
115 // given EFL window's type is not notification type.
116 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
119 utilx_level = utilx_get_system_notification_level (ecore_x_display_get(), xwin);
121 if(utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
123 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
125 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
127 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
129 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
131 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
135 return EFL_UTIL_ERROR_INVALID_PARAMETER;
141 // fail to get window type
142 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
145 return EFL_UTIL_ERROR_NONE;
149 #if ECORE_WAYLAND_FOUND
150 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
153 printf("not implemented for wayland yet\n");
154 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
157 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
161 efl_util_set_notification_window_level_error_cb(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
163 Eina_Bool ret = EINA_FALSE;
165 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
166 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, 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;
192 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
194 Eina_Bool ret = EINA_FALSE;
196 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
198 ret = _efl_util_notification_info_del(window);
201 _noti_handler_count--;
202 if (_noti_handler_count == 0)
204 if (_noti_level_access_result_handler)
206 ecore_event_handler_del(_noti_level_access_result_handler);
207 _noti_level_access_result_handler = NULL;
210 return EFL_UTIL_ERROR_NONE;
213 return EFL_UTIL_ERROR_INVALID_PARAMETER;
218 _efl_util_client_message(void *data, int type, void *event)
220 Ecore_X_Event_Client_Message *ev;
223 if (!ev) return ECORE_CALLBACK_PASS_ON;
225 if (ev->message_type == _noti_level_access_result_atom)
230 notification_error_cb_info *cb_info = NULL;
231 cb_info = _notification_error_cb_info_find_by_xwin(xwin);
234 int access = ev->data.l[1];
235 if (access == 0) // permission denied
239 cb_info->err_cb(cb_info->window, EFL_UTIL_ERROR_PERMISSION_DENIED, cb_info->user_data);
245 return ECORE_CALLBACK_PASS_ON;
248 static notification_error_cb_info *
249 _notification_error_cb_info_find_by_xwin(unsigned int xwin)
252 notification_error_cb_info* temp;
253 unsigned int temp_xwin;
255 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
259 temp_xwin = elm_win_xwindow_get(temp->window);
260 if (xwin == temp_xwin)
271 static notification_error_cb_info *
272 _notification_error_cb_info_find(Evas_Object *window)
275 notification_error_cb_info* temp;
277 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
279 if (temp->window == window)
289 _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
291 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
295 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);
300 _err_info = (notification_error_cb_info*)calloc(1, sizeof(notification_error_cb_info));
305 _err_info->window = window;
306 _err_info->err_cb = callback;
307 _err_info->user_data = user_data;
309 _g_notification_error_cb_info_list = eina_list_append(_g_notification_error_cb_info_list, _err_info);
315 _efl_util_notification_info_del(Evas_Object *window)
317 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
323 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);