2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://www.tizenopensource.org/license
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.
25 #include <X11/Xatom.h>
27 #include <X11/Xutil.h>
28 #include <X11/extensions/Xcomposite.h>
29 #include <X11/extensions/XShm.h>
31 #include "app-selector.h"
32 #include "app-selector-util.h"
35 static pid_t __get_win_pid(Display *d, Window win);
36 static int __tm_get_win_with_pid(Display *d, Window * win, pid_t pid);
37 static Window __find_top_win(Window win);
40 static pid_t __get_win_pid(Display *d, Window win)
49 unsigned long bytes_after;
50 unsigned char *prop_ret;
55 a_pid = XInternAtom(d, "_NET_WM_PID", True);
59 ret = XGetWindowProperty(d, win, a_pid, 0, 1, False, XA_CARDINAL,
60 &a_type, &format, &nitems, &bytes_after,
63 if (ret != 0 || prop_ret == NULL)
66 pid = *(unsigned long *)prop_ret;
72 static int __tm_get_win_with_pid(Display *d, Window * win, pid_t pid)
77 Window root, parent, *child;
79 p = __get_win_pid(d, *win);
83 ret = XQueryTree(d, *win, &root, &parent, &child, &n);
88 for (i = 0; i < n; i++) {
89 found = __tm_get_win_with_pid(d, &child[i], pid);
103 static Window __find_top_win(Window win)
105 Window root, parent, *childw, return_win;
107 if (!XQueryTree(ecore_x_display_get(),
108 win, &root, &parent, &childw, &nchild)) {
109 /* DBG_PRT("XQueryTree failed.\n");*/
112 if (parent == root) {
113 /* DBG_PRT("toplevel window: 0x%x \n", (unsigned int)win);*/
118 /* DBG_PRT("window: 0x%x \n",(unsigned int)win);*/
120 return __find_top_win(parent);
124 int set_transient(Ecore_X_Display *display, Ecore_X_Window win,
125 Ecore_X_Window prev_win)
129 ret = XSetTransientForHint(display, win, prev_win);