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 utilx_grab_key(dpy, xwin, KEY_END, TOP_POSITION_GRAB);
360 if (info->focus == 1) {
361 __X_syspopup_disable_focus (dpy, xwin);
364 #ifdef ROTATE_USING_X_CLIENT
365 rotate_func(dpy, xwin, sp);
367 __efl_rotation_set((Evas_Object* )win,(Ecore_X_Window)xwin);
370 if (is_unviewable == 1) {
371 XMapWindow(dpy, xwin);
374 _syspopup_info_free(info);
380 * @brief This API reset created the system popup's properties
382 * This API reset created the system popup's properties based on
383 * system popup information DB after extracting popup name from
384 * given bundle system popup properties to be reset : timeout,
385 * default action type, ....
387 * @param[in] b bundle received by app_reset handler
388 * (included system popup name)
389 * @return 0 if success, negative value(<0) if fail
390 * @retval 0 - success
391 * @retval -1 - generic error
393 int X_syspopup_reset(bundle *b)
395 const char *popup_name;
396 syspopup_info_t *info;
399 popup_name = _syspopup_get_name_from_bundle(b);
400 if (popup_name == NULL)
403 sp = _syspopup_find(popup_name);
410 info = _syspopup_info_get(popup_name);
413 _syspopup_reset_timeout(sp, info);
415 if (sp->dupped_bundle)
416 free(sp->dupped_bundle);
417 sp->dupped_bundle = bundle_dup(b);
419 d = XOpenDisplay(NULL);
420 win = (Window) sp->internal_data;
421 utilx_set_system_notification_level(d, win, info->prio);
423 if (info->focus == 1) {
424 __X_syspopup_disable_focus (d, win);
427 #ifdef ROTATE_USING_X_CLIENT
428 int (*rotate_func) (Display *, Window, syspopup *);
429 rotate_func = sp->rotate_cb;
430 rotate_func(d, win, sp);
432 __efl_rotation_set((Evas_Object *)sp->win, (Ecore_X_Window)win);
435 /*XMapRaised(d,win);*/
438 _syspopup_info_free(info);
443 API int syspopup_has_popup(bundle *b)
445 const char *popup_name;
446 popup_name = _syspopup_get_name_from_bundle(b);
447 if (popup_name == NULL)
450 if (_syspopup_find(popup_name) != NULL)
456 API int syspopup_reset_timeout(bundle *b, unsigned int time)
458 const char *popup_name;
459 syspopup_info_t *info;
463 popup_name = _syspopup_get_name_from_bundle(b);
464 if (popup_name == NULL) {
465 _E("popup_name is null");
469 sp = _syspopup_find(popup_name);
471 _E("find syspopup error");
474 info = _syspopup_info_get(popup_name);
476 _E("get syspopup info error");
479 info->timeout = time;
480 ret = _syspopup_reset_timeout(sp, info);
481 _syspopup_info_free(info);