d3408bc0b5dd783041351178ad8026c558daa218
[platform/core/api/efl-util.git] / src / efl_util.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16
17
18 #define LOG_TAG "TIZEN_N_EFL_UTIL"
19
20 #include <efl_util.h>
21 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <Elementary.h>
26
27 #if ECORE_X_FOUND
28 #include <Ecore_X.h>
29 #include <utilX.h>
30 #endif
31
32 int efl_util_set_notification_window_level (Evas_Object* window, efl_util_notification_level_e level)
33 {
34         EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
35         EINA_SAFETY_ON_FALSE_RETURN_VAL(level >= EFL_UTIL_NOTIFICATION_LEVEL_1 &&
36                                         level <= EFL_UTIL_NOTIFICATION_LEVEL_2,
37                                         EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
38
39 #if ECORE_X_FOUND
40         Ecore_X_Window xwin = elm_win_xwindow_get(window);
41         if (xwin)
42         {
43                 Ecore_X_Window_Type window_type;
44                 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
45                 {
46                         // success to get window type
47                         if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
48                         {
49                                 // given EFL window's type is not notification type.
50                                 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
51                         }
52                 }
53                 else
54                         return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
55
56                 utilx_set_system_notification_level(ecore_x_display_get(), xwin,
57                                                     level);
58                 return EFL_UTIL_ERROR_NONE;
59         }
60 #endif
61
62 #if ECORE_WAYLAND_FOUND
63         Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
64         if (wl_win)
65         {
66                 printf("not implemented for wayland yet\n");
67                 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
68         }
69 #endif
70
71        return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
72 }
73
74
75
76 int efl_util_get_notification_window_level (Evas_Object* window, efl_util_notification_level_e* level)
77 {
78         
79         EINA_SAFETY_ON_NULL_RETURN_VAL(window,
80                                        EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
81
82 #if ECORE_X_FOUND
83         Ecore_X_Window_Type window_type;
84         Utilx_Notification_Level utilx_level;
85         Ecore_X_Window xwin = elm_win_xwindow_get(window);
86         if (xwin)
87         {
88                 if(ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
89                 {
90                         // success to get window type
91                         if(window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
92                         {
93                                 // given EFL window's type is not notification type.
94                                 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
95                         }
96                 
97                         utilx_level = utilx_get_system_notification_level (ecore_x_display_get(), xwin);
98
99                         if(utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
100                         {
101                                 *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
102                         }
103                         else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
104                         {
105                                 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
106                         }
107                         else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
108                         {
109                                 *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
110                         }
111                         else
112                         {
113                                 return EFL_UTIL_ERROR_INVALID_PARAMETER;
114                         }
115                 
116                 }
117                 else
118                 {
119                         // fail to get window type
120                         return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
121                 }
122         
123                 return EFL_UTIL_ERROR_NONE;
124         }
125 #endif
126
127 #if ECORE_WAYLAND_FOUND
128         Ecore_Wl_Window wl_win = elm_win_wl_window_get(window);
129         if (wl_win)
130         {
131                 printf("not implemented for wayland yet\n");
132                 return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
133         }
134 #endif
135         return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
136 }
137
138 int efl_util_grab_key (Evas_Object *obj, const char* key, int grab_mode)
139 {
140         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0);
141
142 #if ECORE_X_FOUND
143         Ecore_X_Window x_win;
144         Ecore_X_Display *x_disp;
145
146         x_win = elm_win_xwindow_get(obj);
147         if (x_win)
148         {
149                 x_disp = ecore_x_display_get();
150                 return utilx_grab_key(x_disp, x_win, key, grab_mode);
151         }
152
153 #endif
154
155 #if ECORE_WAYLAND_FOUND
156         Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
157         if (wl_win)
158         {
159                 printf("not implemented for wayland yet\n");
160                 return 0;
161         }
162 #endif
163
164         return 0;
165 }
166
167 int efl_util_ungrab_key (Evas_Object *obj, const char* key)
168 {
169         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0);
170
171 #if ECORE_X_FOUND
172         Ecore_X_Window x_win;
173         Ecore_X_Display *x_disp;
174
175         x_win = elm_win_xwindow_get(obj);
176         if (x_win)
177         {
178                 x_disp = ecore_x_display_get();
179                 return utilx_ungrab_key (x_disp, x_win, key);
180         }
181 #endif
182
183 #if ECORE_WAYLAND_FOUND
184         Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
185         if (wl_win)
186         {
187                 printf("not implemented for wayland yet\n");
188                 return 0;
189         }
190 #endif
191
192         return 0;
193 }
194
195 void efl_util_set_system_notification_level (Evas_Object *obj, Efl_Util_Notification_Level level)
196 {
197         EINA_SAFETY_ON_NULL_RETURN(obj);
198         EINA_SAFETY_ON_FALSE_RETURN(level >= EFL_UTIL_NOTIFICATION_LEVEL_LOW &&
199                                     level <= EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN);
200
201 #if ECORE_X_FOUND
202         Ecore_X_Window x_win;
203         Ecore_X_Display *x_disp;
204
205         x_win = elm_win_xwindow_get(obj);
206         if (x_win)
207         {
208                 x_disp = ecore_x_display_get();
209                 utilx_set_system_notification_level(x_disp, x_win, level);
210                 return;
211         }
212 #endif
213
214 #if ECORE_WAYLAND_FOUND
215         Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
216         if (wl_win)
217         {
218                 printf("not implemented for wayland yet\n");
219         }
220 #endif
221 }
222
223 Efl_Util_Notification_Level efl_util_get_system_notification_level (Evas_Object *obj)
224 {
225         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN);
226
227 #if ECORE_X_FOUND
228         Ecore_X_Window x_win;
229         Ecore_X_Display *x_disp;
230
231         x_win = elm_win_xwindow_get(obj);
232         if (x_win)
233         {
234                 x_disp = ecore_x_display_get();
235                 return utilx_get_system_notification_level(x_disp, x_win);
236         }
237
238 #endif
239
240 #if ECORE_WAYLAND_FOUND
241         Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
242         if (wl_win)
243         {
244                 printf("not implemented for wayland yet\n");
245                 return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
246         }
247 #endif
248
249         return EFL_UTIL_NOTIFICATION_LEVEL_UNKNOWN;
250 }
251
252 void efl_util_netwm_window_type_set(Evas_Object *obj, Efl_Util_Window_Type type)
253 {
254         EINA_SAFETY_ON_NULL_RETURN(obj);
255         EINA_SAFETY_ON_FALSE_RETURN(type == EFL_UTIL_WINDOW_TYPE_NORMAL ||
256                                     type == EFL_UTIL_WINDOW_TYPE_NOTIFICATION);
257
258 #if ECORE_X_FOUND
259         Ecore_X_Window x_win;
260
261         x_win = elm_win_xwindow_get(obj);
262         if (x_win)
263         {
264                 ecore_x_netwm_window_type_set(x_win, type);
265                 return;
266         }
267
268 #endif
269
270 #if ECORE_WAYLAND_FOUND
271         Ecore_Wl_Window wl_win = elm_win_wl_window_get(obj);
272         if (wl_win)
273                 printf("not implemented for wayland yet\n");
274 #endif
275 }
276
277 void efl_util_set_window_effect_style(Evas_Object *win, Efl_Util_Effect_Type type, Efl_Util_Effect_Style style)
278 {
279
280         EINA_SAFETY_ON_NULL_RETURN(win);
281
282 #if ECORE_X_FOUND
283         Ecore_X_Window x_win;
284         Ecore_X_Display *x_disp;
285
286         x_win = elm_win_xwindow_get(win);
287         if (x_win)
288         {
289                 x_disp = ecore_x_display_get();
290                 utilx_set_window_effect_style(x_disp, x_win, type, style);
291                 return;
292         }
293 #endif
294
295 #if ECORE_WAYLAND_FOUND
296         Ecore_Wl_Window wl_win = elm_win_wl_window_get(win);
297         if (wl_win)
298                 printf("not implemented for wayland yet\n");
299 #endif
300 }
301
302 int efl_util_set_window_opaque_state (Evas_Object *win, Efl_Util_Opaque_State state)
303 {
304    EINA_SAFETY_ON_NULL_RETURN_VAL(win, 0);
305
306 #if ECORE_X_FOUND
307         Ecore_X_Window x_win;
308         Ecore_X_Display *x_disp;
309
310         x_win = elm_win_xwindow_get(win);
311         if (x_win)
312         {
313                 x_disp = ecore_x_display_get();
314                 return utilx_set_window_opaque_state(x_disp, x_win, state);
315         }
316 #endif
317
318 #if ECORE_WAYLAND_FOUND
319         Ecore_Wl_Window wl_win = elm_win_wl_window_get(win);
320         if (wl_win)
321                 printf("not implemented for wayland yet\n");
322 #endif
323
324         return 0;
325 }