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;
43 static notification_error_cb_info *_notification_error_cb_info_find(Evas_Object *window);
44 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data);
45 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window);
48 static unsigned int _noti_level_access_result_atom = 0;
50 static Eina_Bool _efl_util_client_message(void *data, int type, void *event);
51 static notification_error_cb_info *_notification_error_cb_info_find_by_xwin(unsigned int xwin);
55 int 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;
99 int efl_util_get_notification_window_level (Evas_Object* window, efl_util_notification_level_e* level)
102 EINA_SAFETY_ON_NULL_RETURN_VAL(window,
103 EFL_UTIL_ERROR_INVALID_PARAMETER);
104 EINA_SAFETY_ON_NULL_RETURN_VAL(level,
105 EFL_UTIL_ERROR_INVALID_PARAMETER);
108 Ecore_X_Window_Type window_type;
109 Utilx_Notification_Level utilx_level;
110 Ecore_X_Window xwin = elm_win_xwindow_get(window);
113 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
115 // success to get window type
116 if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
118 // given EFL window's type is not notification type.
119 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
122 utilx_level = utilx_get_system_notification_level (ecore_x_display_get(), xwin);
124 if(utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
126 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
128 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
130 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
132 else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
134 *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
138 return EFL_UTIL_ERROR_INVALID_PARAMETER;
144 // fail to get window type
145 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
148 return EFL_UTIL_ERROR_NONE;
152 #if ECORE_WAYLAND_FOUND
153 Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
156 printf("not implemented for wayland yet\n");
157 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
160 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
163 int efl_util_set_notification_window_level_error_cb(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
165 Eina_Bool ret = EINA_FALSE;
167 EINA_SAFETY_ON_NULL_RETURN_VAL(window,
168 EFL_UTIL_ERROR_INVALID_PARAMETER);
169 EINA_SAFETY_ON_NULL_RETURN_VAL(callback,
170 EFL_UTIL_ERROR_INVALID_PARAMETER);
172 ret = _efl_util_notification_info_add(window, callback, user_data);
176 if (!_noti_level_access_result_atom)
177 _noti_level_access_result_atom = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
179 if (!_noti_level_access_result_handler)
180 _noti_level_access_result_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _efl_util_client_message, NULL);
181 _noti_handler_count++;
183 return EFL_UTIL_ERROR_NONE;
186 #if ECORE_WAYLAND_FOUND
187 printf("not implemented for wayland yet\n");
188 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
192 return EFL_UTIL_ERROR_OUT_OF_MEMORY;
195 int efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
197 Eina_Bool ret = EINA_FALSE;
199 EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
201 ret = _efl_util_notification_info_del(window);
204 _noti_handler_count--;
205 if (_noti_handler_count == 0)
207 if (_noti_level_access_result_handler)
209 ecore_event_handler_del(_noti_level_access_result_handler);
210 _noti_level_access_result_handler = NULL;
213 return EFL_UTIL_ERROR_NONE;
216 return EFL_UTIL_ERROR_INVALID_PARAMETER;
219 int efl_util_grab_key (Evas_Object *obj, const char* key, int grab_mode)
221 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
226 int efl_util_ungrab_key (Evas_Object *obj, const char* key)
228 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
233 void efl_util_set_system_notification_level (Evas_Object *obj, Efl_Util_Notification_Level level)
235 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
238 Efl_Util_Notification_Level efl_util_get_system_notification_level (Evas_Object *obj)
240 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
241 return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
244 void efl_util_netwm_window_type_set(Evas_Object *obj, Efl_Util_Window_Type type)
246 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
249 void efl_util_set_window_effect_style(Evas_Object *win, Efl_Util_Effect_Type type, Efl_Util_Effect_Style style)
251 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
254 int efl_util_set_window_opaque_state (Evas_Object *win, Efl_Util_Opaque_State state)
256 fprintf (stderr, "%s deprecated\n", __FUNCTION__);
261 static Eina_Bool _efl_util_client_message(void *data, int type, void *event)
263 Ecore_X_Event_Client_Message *ev;
266 if (!ev) return ECORE_CALLBACK_PASS_ON;
268 if (ev->message_type == _noti_level_access_result_atom)
273 notification_error_cb_info *cb_info = NULL;
274 cb_info = _notification_error_cb_info_find_by_xwin(xwin);
277 int access = ev->data.l[1];
278 if (access == 0) // permission denied
282 cb_info->err_cb(cb_info->window, EFL_UTIL_ERROR_PERMISSION_DENIED, cb_info->user_data);
288 return ECORE_CALLBACK_PASS_ON;
291 static notification_error_cb_info *_notification_error_cb_info_find_by_xwin(unsigned int xwin)
294 notification_error_cb_info* temp;
295 unsigned int temp_xwin;
297 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
301 temp_xwin = elm_win_xwindow_get(temp->window);
302 if (xwin == temp_xwin)
313 static notification_error_cb_info *_notification_error_cb_info_find(Evas_Object *window)
316 notification_error_cb_info* temp;
318 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
320 if (temp->window == window)
329 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
331 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
335 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);
340 _err_info = (notification_error_cb_info*)calloc(1, sizeof(notification_error_cb_info));
345 _err_info->window = window;
346 _err_info->err_cb = callback;
347 _err_info->user_data = user_data;
349 _g_notification_error_cb_info_list = eina_list_append(_g_notification_error_cb_info_list, _err_info);
354 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window)
356 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
362 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);