4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include "syspopup_core.h"
26 #include "syspopup_api.h"
27 #include "simple_util.h"
28 #include <X11/Xatom.h>
29 #include <X11/Xutil.h>
31 #define WIN_PROP_NAME "SYSTEM_POPUP"
33 static int __utilx_ss_get_window_property(Display *dpy, Window win, Atom atom,
34 Atom type, unsigned int *val,
37 unsigned char *prop_ret;
39 unsigned long bytes_after;
40 unsigned long num_ret;
46 if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
47 type, &type_ret, &format_ret, &num_ret,
48 &bytes_after, &prop_ret) != Success)
51 if (type_ret != type || format_ret != 32)
53 else if (num_ret == 0 || !prop_ret)
58 for (i = 0; i < len; i++) {
59 val[i] = ((unsigned long *)prop_ret)[i];
71 static Window get_active_win(Display *dpy, Window win, Atom property)
73 Window active_win = None;
76 unsigned long nitems, bytes_after;
77 unsigned char *prop_return = NULL;
79 if(Success == XGetWindowProperty(dpy, win, property, 0L, sizeof(Window),
80 False, XA_WINDOW, &actual_type,
81 &actual_format, &nitems, &bytes_after,
82 &prop_return) && prop_return) {
83 active_win = *(Window *)prop_return;
91 static void __X_syspopup_term_handler(void *data)
98 _I("enter syspopup term handler");
100 d = XOpenDisplay(NULL);
102 _E("XOpenDisplay return null");
105 tmp = _syspopup_get_head();
108 _I("term action %d - %s", tmp->term_act, tmp->name);
111 switch (tmp->term_act) {
113 win = (Window) tmp->internal_data;
115 if (tmp->def_term_fn != NULL)
116 tmp->def_term_fn(tmp->dupped_bundle, tmp->user_data);
118 if(d) XKillClient(d, win);
121 win = (Window) tmp->internal_data;
123 if (tmp->def_term_fn != NULL)
124 tmp->def_term_fn(tmp->dupped_bundle, tmp->user_data);
126 if(d) XUnmapWindow(d, win);
129 _I("term action IGNORED - %s", tmp->name);
134 if(d) XCloseDisplay(d);
137 static gboolean __X_syspopup_timeout_handler(void *user_data)
146 d = XOpenDisplay(NULL);
148 sp = _syspopup_find_by_id(id);
150 _D("find timeout - %s", sp->name);
151 if (sp->def_timeout_fn != NULL)
152 sp->def_timeout_fn(sp->dupped_bundle, sp->user_data);
153 win = (Window) sp->internal_data;
156 _E("no find timeout");
164 static int __X_syspopup_change_xwin_type(Display *dpy, Window win)
167 Atom win_type_utility_atom;
169 win_type_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
170 win_type_utility_atom =
171 XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
172 XChangeProperty(dpy, win, win_type_atom, XA_ATOM, 32, PropModeReplace,
173 (unsigned char *)&win_type_utility_atom, 1);
178 static int __X_syspopup_disable_focus(Display *dpy, Window win)
182 hints = XAllocWMHints();
183 if (!hints) return -1;
185 hints->flags = InputHint | StateHint;
187 hints->initial_state = NormalState;
189 XSetWMHints(dpy, win, hints);
195 int X_syspopup_rotation_get(Display *dpy, Window win)
202 Atom atom_active_win;
203 Atom atom_win_rotate_angle;
205 root_win = XDefaultRootWindow(dpy);
207 atom_active_win = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
208 ret = __utilx_ss_get_window_property(dpy, root_win, atom_active_win,
210 (unsigned int *)&active_win, 1);
212 /*printf("[SYSPOPUP] Active win : %x, Window %x\n", active_win, win);*/
214 /*active_win = get_active_win(dpy, root_win, atom_active_win);*/
218 atom_win_rotate_angle =
219 XInternAtom(dpy, "_E_ILLUME_ROTATE_ROOT_ANGLE", False);
220 ret = __utilx_ss_get_window_property(dpy, root_win,
221 atom_win_rotate_angle, XA_CARDINAL,
222 (unsigned int *)&rotation, 1);
224 /*printf("[SYSPOPUP] Rotation %d\n", rotation);*/
232 int X_syspopup_process_keydown(int id, const char *keyname)
238 if (strcmp(keyname, KEY_END) == 0) {
239 d = XOpenDisplay(NULL);
240 sp = _syspopup_find_by_id(id);
242 _D("find key down - %s", sp->name);
243 if (sp->endkey_act == SYSPOPUP_KEYEND_TERM) {
244 if (sp->def_term_fn != NULL)
245 sp->def_term_fn(sp->dupped_bundle,
247 win = (Window) sp->internal_data;
250 } else if (sp->endkey_act == SYSPOPUP_KEYEND_HIDE) {
251 if (sp->def_term_fn != NULL)
252 sp->def_term_fn(sp->dupped_bundle,
254 win = (Window) sp->internal_data;
255 XUnmapWindow(d, win);
259 _E("no find key down");
268 #ifdef ROTATE_USING_X_CLIENT
269 int X_syspopup_process_rotate(int id)
275 sp = _syspopup_find_by_id(id);
280 win = (Window) sp->internal_data;
282 d = XOpenDisplay(NULL);
283 sp->rotate_cb(d, win, sp);
289 static void __efl_rotation_set(Evas_Object* win, Ecore_X_Window xwin)
291 ecore_x_icccm_name_class_set(xwin, WIN_PROP_NAME, WIN_PROP_NAME);
292 if (elm_win_wm_rotation_supported_get(win)) {
293 int rots[4] = { 0, 90, 180, 270 };
294 elm_win_wm_rotation_available_rotations_set(win, (const int*)(&rots), 4);
296 _E("win rotation no supported");
301 int X_make_syspopup(bundle *b, Display *dpy, Window xwin, void *win,
302 int (*rotate_func) (Display*, Window, syspopup*),
303 syspopup_handler *handler, void *user_data)
306 syspopup_info_t *info;
307 const char *popup_name = _syspopup_get_name_from_bundle(b);
308 XWindowAttributes attr;
309 int is_unviewable = 0;
311 if (popup_name == NULL || handler == NULL)
314 info = _syspopup_info_get(popup_name);
318 if (_syspopup_init(__X_syspopup_term_handler,
319 __X_syspopup_timeout_handler) < 0){
320 _syspopup_info_free(info);
324 XGetWindowAttributes(dpy, xwin, &attr);
326 if (attr.map_state == IsViewable) {
327 XUnmapWindow(dpy, xwin);
331 sp = (syspopup *) malloc(sizeof(syspopup));
333 _syspopup_info_free(info);
337 sp->name = strdup(info->name);
338 sp->def_term_fn = handler->def_term_fn;
339 sp->def_timeout_fn = handler->def_timeout_fn;
340 sp->user_data = user_data;
341 sp->internal_data = (void *)xwin;
342 sp->win = (void *)win;
343 sp->rotate_cb = rotate_func;
345 sp->dupped_bundle = bundle_dup(b);
346 _syspopup_add_new(sp);
348 _syspopup_set_term_type(sp, info);
349 _syspopup_set_endkey_type(sp, info);
351 _syspopup_reset_timeout(sp, info);
353 __X_syspopup_change_xwin_type(dpy, xwin);
354 utilx_set_system_notification_level(dpy, xwin, info->prio);
356 if (info->focus == 1) {
357 __X_syspopup_disable_focus (dpy, xwin);
360 #ifdef ROTATE_USING_X_CLIENT
361 rotate_func(dpy, xwin, sp);
363 __efl_rotation_set((Evas_Object* )win,(Ecore_X_Window)xwin);
366 if (is_unviewable == 1) {
367 XMapWindow(dpy, xwin);
370 _syspopup_info_free(info);
376 * @brief This API reset created the system popup's properties
378 * This API reset created the system popup's properties based on
379 * system popup information DB after extracting popup name from
380 * given bundle system popup properties to be reset : timeout,
381 * default action type, ....
383 * @param[in] b bundle received by app_reset handler
384 * (included system popup name)
385 * @return 0 if success, negative value(<0) if fail
386 * @retval 0 - success
387 * @retval -1 - generic error
389 int X_syspopup_reset(bundle *b)
391 const char *popup_name;
392 syspopup_info_t *info;
395 popup_name = _syspopup_get_name_from_bundle(b);
396 if (popup_name == NULL)
399 sp = _syspopup_find(popup_name);
406 info = _syspopup_info_get(popup_name);
409 _syspopup_reset_timeout(sp, info);
411 if (sp->dupped_bundle)
412 free(sp->dupped_bundle);
413 sp->dupped_bundle = bundle_dup(b);
416 d = XOpenDisplay(NULL);
417 win = (Window) sp->internal_data;
419 _E("X open is null");
422 utilx_set_system_notification_level(d, win, info->prio);
424 if (info->focus == 1) {
425 __X_syspopup_disable_focus (d, win);
428 #ifdef ROTATE_USING_X_CLIENT
429 int (*rotate_func) (Display *, Window, syspopup *);
430 rotate_func = sp->rotate_cb;
431 rotate_func(d, win, sp);
433 __efl_rotation_set((Evas_Object *)sp->win, (Ecore_X_Window)win);
436 /*XMapRaised(d,win);*/
440 _syspopup_info_free(info);
445 API int syspopup_has_popup(bundle *b)
447 const char *popup_name;
448 popup_name = _syspopup_get_name_from_bundle(b);
449 if (popup_name == NULL)
452 if (_syspopup_find(popup_name) != NULL)
458 API int syspopup_reset_timeout(bundle *b, unsigned int time)
460 const char *popup_name;
461 syspopup_info_t *info;
465 popup_name = _syspopup_get_name_from_bundle(b);
466 if (popup_name == NULL) {
467 _E("popup_name is null");
471 sp = _syspopup_find(popup_name);
473 _E("find syspopup error");
476 info = _syspopup_info_get(popup_name);
478 _E("get syspopup info error");
481 info->timeout = time;
482 ret = _syspopup_reset_timeout(sp, info);
483 _syspopup_info_free(info);