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);
54 int efl_util_set_notification_window_level (Evas_Object* window, efl_util_notification_level_e level)
56 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
57 EINA_SAFETY_ON_FALSE_RETURN_VAL(level >= EFL_UTIL_NOTIFICATION_LEVEL_1 &&
58 level <= EFL_UTIL_NOTIFICATION_LEVEL_3,
59 EFL_UTIL_ERROR_INVALID_PARAMETER);
62 Ecore_X_Window xwin = elm_win_xwindow_get(window);
65 Ecore_X_Window_Type window_type;
66 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
68 // success to get window type
69 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
71 // given EFL window's type is not notification type.
72 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
76 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
78 utilx_set_system_notification_level(ecore_x_display_get(), xwin,
80 return EFL_UTIL_ERROR_NONE;
84 #if ECORE_WAYLAND_FOUND
85 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
88 printf("not implemented for wayland yet\n");
89 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
93 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
98 int efl_util_get_notification_window_level (Evas_Object* window, efl_util_notification_level_e* level)
101 EINA_SAFETY_ON_NULL_RETURN_VAL(window,
102 EFL_UTIL_ERROR_INVALID_PARAMETER);
103 EINA_SAFETY_ON_NULL_RETURN_VAL(level,
104 EFL_UTIL_ERROR_INVALID_PARAMETER);
107 Ecore_X_Window_Type window_type;
108 Utilx_Notification_Level utilx_level;
109 Ecore_X_Window xwin = elm_win_xwindow_get(window);
112 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
114 // success to get window type
115 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
117 // given EFL window's type is not notification type.
118 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
121 utilx_level = utilx_get_system_notification_level (ecore_x_display_get(), xwin);
123 if(utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
125 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
127 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
129 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
131 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
133 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
137 return EFL_UTIL_ERROR_INVALID_PARAMETER;
143 // fail to get window type
144 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
147 return EFL_UTIL_ERROR_NONE;
151 #if ECORE_WAYLAND_FOUND
152 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
155 printf("not implemented for wayland yet\n");
156 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
159 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
162 int efl_util_set_notification_window_level_error_cb(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
164 Eina_Bool ret = EINA_FALSE;
166 EINA_SAFETY_ON_NULL_RETURN_VAL(window,
167 EFL_UTIL_ERROR_INVALID_PARAMETER);
168 EINA_SAFETY_ON_NULL_RETURN_VAL(callback,
169 EFL_UTIL_ERROR_INVALID_PARAMETER);
171 ret = _efl_util_notification_info_add(window, callback, user_data);
175 if (!_noti_level_access_result_atom)
176 _noti_level_access_result_atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
178 if (!_noti_level_access_result_handler)
179 _noti_level_access_result_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _efl_util_client_message, NULL);
180 _noti_handler_count++;
182 return EFL_UTIL_ERROR_NONE;
185 #if ECORE_WAYLAND_FOUND
186 printf("not implemented for wayland yet\n");
187 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
191 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
194 int efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
196 Eina_Bool ret = EINA_FALSE;
198 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
200 ret = _efl_util_notification_info_del(window);
203 _noti_handler_count--;
204 if (_noti_handler_count == 0)
206 if (_noti_level_access_result_handler)
208 ecore_event_handler_del(_noti_level_access_result_handler);
209 _noti_level_access_result_handler = NULL;
212 return EFL_UTIL_ERROR_NONE;
215 return EFL_UTIL_ERROR_INVALID_PARAMETER;
219 static Eina_Bool _efl_util_client_message(void *data, int type, void *event)
221 Ecore_X_Event_Client_Message *ev;
224 if (!ev) return ECORE_CALLBACK_PASS_ON;
226 if (ev->message_type == _noti_level_access_result_atom)
231 notification_error_cb_info *cb_info = NULL;
232 cb_info = _notification_error_cb_info_find_by_xwin(xwin);
235 int access = ev->data.l[1];
236 if (access == 0) // permission denied
240 cb_info->err_cb(cb_info->window, EFL_UTIL_ERROR_PERMISSION_DENIED, cb_info->user_data);
246 return ECORE_CALLBACK_PASS_ON;
249 static notification_error_cb_info *_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 *_notification_error_cb_info_find(Evas_Object *window)
274 notification_error_cb_info* temp;
276 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
278 if (temp->window == window)
287 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
289 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
293 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);
298 _err_info = (notification_error_cb_info*)calloc(1, sizeof(notification_error_cb_info));
303 _err_info->window = window;
304 _err_info->err_cb = callback;
305 _err_info->user_data = user_data;
307 _g_notification_error_cb_info_list = eina_list_append(_g_notification_error_cb_info_list, _err_info);
312 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window)
314 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
320 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);