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)
204 Atom atom_active_win;
205 Atom atom_win_rotate_angle;
207 root_win = XDefaultRootWindow(dpy);
209 atom_active_win = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
210 ret = __utilx_ss_get_window_property(dpy, root_win, atom_active_win,
212 (unsigned int *)&active_win, 1);
214 /*printf("[SYSPOPUP] Active win : %x, Window %x\n", active_win, win);*/
216 /*active_win = get_active_win(dpy, root_win, atom_active_win);*/
220 atom_win_rotate_angle =
221 XInternAtom(dpy, "_E_ILLUME_ROTATE_ROOT_ANGLE", False);
222 ret = __utilx_ss_get_window_property(dpy, root_win,
223 atom_win_rotate_angle, XA_CARDINAL,
224 (unsigned int *)&rotation, 1);
226 /*printf("[SYSPOPUP] Rotation %d\n", rotation);*/
234 int X_syspopup_process_keydown(int id, const char *keyname)
240 if (strcmp(keyname, KEY_END) == 0) {
241 d = XOpenDisplay(NULL);
242 sp = _syspopup_find_by_id(id);
244 _D("find key down - %s", sp->name);
245 if (sp->endkey_act == SYSPOPUP_KEYEND_TERM) {
246 if (sp->def_term_fn != NULL)
247 sp->def_term_fn(sp->dupped_bundle,
249 win = (Window) sp->internal_data;
252 } else if (sp->endkey_act == SYSPOPUP_KEYEND_HIDE) {
253 if (sp->def_term_fn != NULL)
254 sp->def_term_fn(sp->dupped_bundle,
256 win = (Window) sp->internal_data;
257 XUnmapWindow(d, win);
261 _E("no find key down");
270 #ifdef ROTATE_USING_X_CLIENT
271 int X_syspopup_process_rotate(int id)
277 sp = _syspopup_find_by_id(id);
282 win = (Window) sp->internal_data;
284 d = XOpenDisplay(NULL);
285 sp->rotate_cb(d, win, sp);
291 static void __efl_rotation_set(Evas_Object* win, Ecore_X_Window xwin)
293 ecore_x_icccm_name_class_set(xwin, WIN_PROP_NAME, WIN_PROP_NAME);
294 if (elm_win_wm_rotation_supported_get(win)) {
295 int rots[4] = { 0, 90, 180, 270 };
296 elm_win_wm_rotation_available_rotations_set(win, &rots, 4);
298 _E("win rotation no supported");
303 int X_make_syspopup(bundle *b, Display *dpy, Window xwin, void *win,
304 int (*rotate_func) (Display*, Window, syspopup*),
305 syspopup_handler *handler, void *user_data)
308 syspopup_info_t *info;
309 const char *popup_name = _syspopup_get_name_from_bundle(b);
310 XWindowAttributes attr;
311 int is_unviewable = 0;
313 if (popup_name == NULL || handler == NULL)
316 info = _syspopup_info_get(popup_name);
320 if (_syspopup_init(__X_syspopup_term_handler,
321 __X_syspopup_timeout_handler) < 0){
322 _syspopup_info_free(info);
326 XGetWindowAttributes(dpy, xwin, &attr);
328 if (attr.map_state == IsViewable) {
329 XUnmapWindow(dpy, xwin);
333 sp = (syspopup *) malloc(sizeof(syspopup));
335 _syspopup_info_free(info);
339 sp->name = strdup(info->name);
340 sp->def_term_fn = handler->def_term_fn;
341 sp->def_timeout_fn = handler->def_timeout_fn;
342 sp->user_data = user_data;
343 sp->internal_data = (void *)xwin;
344 sp->win = (void *)win;
345 sp->rotate_cb = rotate_func;
347 sp->dupped_bundle = bundle_dup(b);
348 _syspopup_add_new(sp);
350 _syspopup_set_term_type(sp, info);
351 _syspopup_set_endkey_type(sp, info);
353 _syspopup_reset_timeout(sp, info);
355 __X_syspopup_change_xwin_type(dpy, xwin);
356 utilx_set_system_notification_level(dpy, xwin, info->prio);
358 if (info->focus == 1) {
359 __X_syspopup_disable_focus (dpy, xwin);
362 #ifdef ROTATE_USING_X_CLIENT
363 rotate_func(dpy, xwin, sp);
365 __efl_rotation_set((Evas_Object* )win,(Ecore_X_Window)xwin);
368 if (is_unviewable == 1) {
369 XMapWindow(dpy, xwin);
372 _syspopup_info_free(info);
378 * @brief This API reset created the system popup's properties
380 * This API reset created the system popup's properties based on
381 * system popup information DB after extracting popup name from
382 * given bundle system popup properties to be reset : timeout,
383 * default action type, ....
385 * @param[in] b bundle received by app_reset handler
386 * (included system popup name)
387 * @return 0 if success, negative value(<0) if fail
388 * @retval 0 - success
389 * @retval -1 - generic error
391 int X_syspopup_reset(bundle *b)
393 const char *popup_name;
394 syspopup_info_t *info;
397 popup_name = _syspopup_get_name_from_bundle(b);
398 if (popup_name == NULL)
401 sp = _syspopup_find(popup_name);
408 info = _syspopup_info_get(popup_name);
411 _syspopup_reset_timeout(sp, info);
413 if (sp->dupped_bundle)
414 free(sp->dupped_bundle);
415 sp->dupped_bundle = bundle_dup(b);
418 d = XOpenDisplay(NULL);
419 win = (Window) sp->internal_data;
421 _E("X open is null");
424 utilx_set_system_notification_level(d, win, info->prio);
426 if (info->focus == 1) {
427 __X_syspopup_disable_focus (d, win);
430 #ifdef ROTATE_USING_X_CLIENT
431 int (*rotate_func) (Display *, Window, syspopup *);
432 rotate_func = sp->rotate_cb;
433 rotate_func(d, win, sp);
435 __efl_rotation_set((Evas_Object *)sp->win, (Ecore_X_Window)win);
438 /*XMapRaised(d,win);*/
442 _syspopup_info_free(info);
447 API int syspopup_has_popup(bundle *b)
449 const char *popup_name;
450 popup_name = _syspopup_get_name_from_bundle(b);
451 if (popup_name == NULL)
454 if (_syspopup_find(popup_name) != NULL)
460 API int syspopup_reset_timeout(bundle *b, unsigned int time)
462 const char *popup_name;
463 syspopup_info_t *info;
467 popup_name = _syspopup_get_name_from_bundle(b);
468 if (popup_name == NULL) {
469 _E("popup_name is null");
473 sp = _syspopup_find(popup_name);
475 _E("find syspopup error");
478 info = _syspopup_info_get(popup_name);
480 _E("get syspopup info error");
483 info->timeout = time;
484 ret = _syspopup_reset_timeout(sp, info);
485 _syspopup_info_free(info);