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"
30 #include <X11/Xatom.h>
31 #include <X11/Xutil.h>
35 static int __utilx_ss_get_window_property(Display *dpy, Window win, Atom atom,
36 Atom type, unsigned int *val,
39 unsigned char *prop_ret;
41 unsigned long bytes_after;
42 unsigned long num_ret;
48 if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
49 type, &type_ret, &format_ret, &num_ret,
50 &bytes_after, &prop_ret) != Success)
53 if (type_ret != type || format_ret != 32)
55 else if (num_ret == 0 || !prop_ret)
60 for (i = 0; i < len; i++) {
61 val[i] = ((unsigned long *)prop_ret)[i];
74 static Window get_active_win(Display *dpy, Window win, Atom property)
76 Window active_win = None;
79 unsigned long nitems, bytes_after;
80 unsigned char *prop_return = NULL;
82 if(Success == XGetWindowProperty(dpy, win, property, 0L, sizeof(Window),
83 False, XA_WINDOW, &actual_type,
84 &actual_format, &nitems, &bytes_after,
85 &prop_return) && prop_return) {
86 active_win = *(Window *)prop_return;
94 static void __X_syspopup_term_handler(void *data)
102 _D("enter syspopup term handler");
104 d = XOpenDisplay(NULL);
105 tmp = _syspopup_get_head();
108 _D("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,
119 /*XDestroyWindow(d, win);*/
120 /* TODO :modify for multi popup */
123 win = (Window) tmp->internal_data;
125 if (tmp->def_term_fn != NULL)
126 tmp->def_term_fn(tmp->dupped_bundle,
128 XUnmapWindow(d, win);
131 _D("term action IGNORED - %s", tmp->name);
137 /*TODO : if there is no popup window, kill client*/
141 static gboolean __X_syspopup_timeout_handler(void *user_data)
150 d = XOpenDisplay(NULL);
152 sp = _syspopup_find_by_id(id);
154 _D("find timeout - %s", sp->name);
155 if (sp->def_timeout_fn != NULL)
156 sp->def_timeout_fn(sp->dupped_bundle, sp->user_data);
157 win = (Window) sp->internal_data;
160 _E("no find timeout");
170 static int __X_syspopup_change_xwin_type(Display *dpy, Window win)
173 Atom win_type_utility_atom;
175 win_type_atom = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
176 win_type_utility_atom =
177 XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
178 XChangeProperty(dpy, win, win_type_atom, XA_ATOM, 32, PropModeReplace,
179 (unsigned char *)&win_type_utility_atom, 1);
186 static int __X_syspopup_disable_focus(Display *dpy, Window win)
190 hints = XAllocWMHints();
191 if (!hints) return -1;
193 hints->flags = InputHint | StateHint;
195 hints->initial_state = NormalState;
197 XSetWMHints(dpy, win, hints);
205 int X_syspopup_rotation_get(Display *dpy, Window win)
214 Atom atom_active_win;
215 Atom atom_win_rotate_angle;
217 root_win = XDefaultRootWindow(dpy);
219 atom_active_win = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
220 ret = __utilx_ss_get_window_property(dpy, root_win, atom_active_win,
222 (unsigned int *)&active_win, 1);
224 /*printf("[SYSPOPUP] Active win : %x, Window %x\n", active_win, win);*/
226 /*active_win = get_active_win(dpy, root_win, atom_active_win);*/
230 atom_win_rotate_angle =
231 XInternAtom(dpy, "_E_ILLUME_ROTATE_ROOT_ANGLE", False);
232 ret = __utilx_ss_get_window_property(dpy, root_win,
233 atom_win_rotate_angle, XA_CARDINAL,
234 (unsigned int *)&rotation, 1);
236 /*printf("[SYSPOPUP] Rotation %d\n", rotation);*/
245 int X_syspopup_process_keydown(int id, const char *keyname)
252 if (strcmp(keyname, KEY_END) == 0) {
253 d = XOpenDisplay(NULL);
254 sp = _syspopup_find_by_id(id);
256 _D("find key down - %s", sp->name);
257 if (sp->endkey_act == SYSPOPUP_KEYEND_TERM) {
258 if (sp->def_term_fn != NULL)
259 sp->def_term_fn(sp->dupped_bundle,
261 win = (Window) sp->internal_data;
264 } else if (sp->endkey_act == SYSPOPUP_KEYEND_HIDE) {
265 if (sp->def_term_fn != NULL)
266 sp->def_term_fn(sp->dupped_bundle,
268 win = (Window) sp->internal_data;
269 XUnmapWindow(d, win);
273 _E("no find key down");
283 #ifdef ROTATE_USING_X_CLIENT
284 int X_syspopup_process_rotate(int id)
291 sp = _syspopup_find_by_id(id);
296 win = (Window) sp->internal_data;
298 d = XOpenDisplay(NULL);
299 sp->rotate_cb(d, win, sp);
308 int X_make_syspopup(bundle *b, Display *dpy, Window xwin, void *win,
309 int (*rotate_func) (Display*, Window, syspopup*),
310 syspopup_handler *handler, void *user_data)
313 syspopup_info_t *info;
314 const char *popup_name = _syspopup_get_name_from_bundle(b);
315 XWindowAttributes attr;
316 int is_unviewable = 0;
318 if (popup_name == NULL || handler == NULL)
321 info = _syspopup_info_get(popup_name);
325 if (_syspopup_init(__X_syspopup_term_handler,
326 __X_syspopup_timeout_handler) < 0){
327 _syspopup_info_free(info);
331 XGetWindowAttributes(dpy, xwin, &attr);
333 if (attr.map_state == IsViewable) {
334 XUnmapWindow(dpy, xwin);
338 sp = (syspopup *) malloc(sizeof(syspopup));
340 _syspopup_info_free(info);
344 sp->name = strdup(info->name);
345 sp->def_term_fn = handler->def_term_fn;
346 sp->def_timeout_fn = handler->def_timeout_fn;
347 sp->user_data = user_data;
348 sp->internal_data = (void *)xwin;
349 sp->win = (void *)win;
350 sp->rotate_cb = rotate_func;
352 sp->dupped_bundle = bundle_dup(b);
353 _syspopup_add_new(sp);
355 _syspopup_set_term_type(sp, info);
356 _syspopup_set_endkey_type(sp, info);
358 _syspopup_reset_timeout(sp, info);
360 __X_syspopup_change_xwin_type(dpy, xwin);
361 utilx_set_system_notification_level(dpy, xwin, info->prio);
363 utilx_grab_key(dpy, xwin, KEY_END, TOP_POSITION_GRAB);
365 if (info->focus == 1) {
366 __X_syspopup_disable_focus (dpy, xwin);
369 rotate_func(dpy, xwin, sp);
371 if (is_unviewable == 1) {
372 XMapWindow(dpy, xwin);
375 _syspopup_info_free(info);
382 * @brief This API reset created the system popup's properties
384 * This API reset created the system popup's properties based on
385 * system popup information DB after extracting popup name from
386 * given bundle system popup properties to be reset : timeout,
387 * default action type, ....
389 * @param[in] b bundle received by app_reset handler
390 * (included system popup name)
391 * @return 0 if success, negative value(<0) if fail
392 * @retval 0 - success
393 * @retval -1 - generic error
395 int X_syspopup_reset(bundle *b)
398 const char *popup_name;
399 syspopup_info_t *info;
401 int (*rotate_func) (Display *, Window, syspopup *);
403 popup_name = _syspopup_get_name_from_bundle(b);
404 if (popup_name == NULL)
407 sp = _syspopup_find(popup_name);
414 info = _syspopup_info_get(popup_name);
417 _syspopup_reset_timeout(sp, info);
419 if (sp->dupped_bundle)
420 free(sp->dupped_bundle);
421 sp->dupped_bundle = bundle_dup(b);
423 d = XOpenDisplay(NULL);
424 win = (Window) sp->internal_data;
425 utilx_set_system_notification_level(d, win, info->prio);
427 if (info->focus == 1) {
428 __X_syspopup_disable_focus (d, win);
430 rotate_func = sp->rotate_cb;
431 rotate_func(d, win, sp);
434 /*XMapRaised(d,win);*/
437 _syspopup_info_free(info);
444 API int syspopup_has_popup(bundle *b)
446 const char *popup_name;
447 popup_name = _syspopup_get_name_from_bundle(b);
448 if (popup_name == NULL)
451 if (_syspopup_find(popup_name) != NULL)
457 API int syspopup_reset_timeout(bundle *b, unsigned int time)
459 const char *popup_name;
460 syspopup_info_t *info;
464 popup_name = _syspopup_get_name_from_bundle(b);
465 if (popup_name == NULL) {
466 _E("popup_name is null");
470 sp = _syspopup_find(popup_name);
472 _E("find syspopup error");
475 info = _syspopup_info_get(popup_name);
477 _E("get syspopup info error");
480 info->timeout = time;
481 ret = _syspopup_reset_timeout(sp, info);
482 _syspopup_info_free(info);