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 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0);
224 Ecore_X_Window x_win;
225 Ecore_X_Display *x_disp;
227 x_win = elm_win_xwindow_get(obj);
230 x_disp = ecore_x_display_get();
231 return utilx_grab_key(x_disp, x_win, key, grab_mode);
236 #if ECORE_WAYLAND_FOUND
237 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
240 printf("not implemented for wayland yet\n");
248 int efl_util_ungrab_key (Evas_Object *obj, const char* key)
250 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0);
253 Ecore_X_Window x_win;
254 Ecore_X_Display *x_disp;
256 x_win = elm_win_xwindow_get(obj);
259 x_disp = ecore_x_display_get();
260 return utilx_ungrab_key (x_disp, x_win, key);
264 #if ECORE_WAYLAND_FOUND
265 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
268 printf("not implemented for wayland yet\n");
276 void efl_util_set_system_notification_level (Evas_Object *obj, Efl_Util_Notification_Level level)
278 EINA_SAFETY_ON_NULL_RETURN(obj);
279 EINA_SAFETY_ON_FALSE_RETURN(level >= EFL_UTIL_NOTIFICATION_LEVEL_LOW &&
280 level <= EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN);
283 Ecore_X_Window x_win;
284 Ecore_X_Display *x_disp;
286 x_win = elm_win_xwindow_get(obj);
289 x_disp = ecore_x_display_get();
290 utilx_set_system_notification_level(x_disp, x_win, level);
295 #if ECORE_WAYLAND_FOUND
296 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
299 printf("not implemented for wayland yet\n");
304 Efl_Util_Notification_Level efl_util_get_system_notification_level (Evas_Object *obj)
306 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN);
309 Ecore_X_Window x_win;
310 Ecore_X_Display *x_disp;
312 x_win = elm_win_xwindow_get(obj);
315 x_disp = ecore_x_display_get();
316 return utilx_get_system_notification_level(x_disp, x_win);
321 #if ECORE_WAYLAND_FOUND
322 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
325 printf("not implemented for wayland yet\n");
326 return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
330 return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
333 void efl_util_netwm_window_type_set(Evas_Object *obj, Efl_Util_Window_Type type)
335 EINA_SAFETY_ON_NULL_RETURN(obj);
336 EINA_SAFETY_ON_FALSE_RETURN(type == EFL_UTIL_WINDOW_TYPE_NORMAL ||
337 type == EFL_UTIL_WINDOW_TYPE_NOTIFICATION);
340 Ecore_X_Window x_win;
342 x_win = elm_win_xwindow_get(obj);
345 ecore_x_netwm_window_type_set(x_win, type);
351 #if ECORE_WAYLAND_FOUND
352 Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
354 printf("not implemented for wayland yet\n");
358 void efl_util_set_window_effect_style(Evas_Object *win, Efl_Util_Effect_Type type, Efl_Util_Effect_Style style)
361 EINA_SAFETY_ON_NULL_RETURN(win);
364 Ecore_X_Window x_win;
365 Ecore_X_Display *x_disp;
367 x_win = elm_win_xwindow_get(win);
370 x_disp = ecore_x_display_get();
371 utilx_set_window_effect_style(x_disp, x_win, type, style);
376 #if ECORE_WAYLAND_FOUND
377 Ecore_Wl_Window wl_win = elm_win_wl_window_get(win);
379 printf("not implemented for wayland yet\n");
383 int efl_util_set_window_opaque_state (Evas_Object *win, Efl_Util_Opaque_State state)
385 EINA_SAFETY_ON_NULL_RETURN_VAL(win, 0);
388 Ecore_X_Window x_win;
389 Ecore_X_Display *x_disp;
391 x_win = elm_win_xwindow_get(win);
394 x_disp = ecore_x_display_get();
395 return utilx_set_window_opaque_state(x_disp, x_win, state);
399 #if ECORE_WAYLAND_FOUND
400 Ecore_Wl_Window wl_win = elm_win_wl_window_get(win);
402 printf("not implemented for wayland yet\n");
409 static Eina_Bool _efl_util_client_message(void *data, int type, void *event)
411 Ecore_X_Event_Client_Message *ev;
414 if (!ev) return ECORE_CALLBACK_PASS_ON;
416 if (ev->message_type == _noti_level_access_result_atom)
421 notification_error_cb_info *cb_info = NULL;
422 cb_info = _notification_error_cb_info_find_by_xwin(xwin);
425 int access = ev->data.l[1];
426 if (access == 0) // permission denied
430 cb_info->err_cb(cb_info->window, EFL_UTIL_ERROR_PERMISSION_DENIED, cb_info->user_data);
436 return ECORE_CALLBACK_PASS_ON;
439 static notification_error_cb_info *_notification_error_cb_info_find_by_xwin(unsigned int xwin)
442 notification_error_cb_info* temp;
443 unsigned int temp_xwin;
445 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
449 temp_xwin = elm_win_xwindow_get(temp->window);
450 if (xwin == temp_xwin)
461 static notification_error_cb_info *_notification_error_cb_info_find(Evas_Object *window)
464 notification_error_cb_info* temp;
466 EINA_LIST_FOREACH(_g_notification_error_cb_info_list, l, temp)
468 if (temp->window == window)
477 static Eina_Bool _efl_util_notification_info_add(Evas_Object *window, efl_util_notification_window_level_error_cb callback, void *user_data)
479 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
483 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);
488 _err_info = (notification_error_cb_info*)calloc(1, sizeof(notification_error_cb_info));
493 _err_info->window = window;
494 _err_info->err_cb = callback;
495 _err_info->user_data = user_data;
497 _g_notification_error_cb_info_list = eina_list_append(_g_notification_error_cb_info_list, _err_info);
502 static Eina_Bool _efl_util_notification_info_del(Evas_Object *window)
504 notification_error_cb_info* _err_info = _notification_error_cb_info_find(window);
510 _g_notification_error_cb_info_list = eina_list_remove(_g_notification_error_cb_info_list, _err_info);