| 1 |
/* $XConsortium: ClientWin.c,v 1.4 94/04/17 20:15:50 rws Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
|
| 5 |
Copyright (c) 1989 X Consortium |
| 6 |
|
| 7 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 |
of this software and associated documentation files (the "Software"), to deal |
| 9 |
in the Software without restriction, including without limitation the rights |
| 10 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 |
copies of the Software, and to permit persons to whom the Software is |
| 12 |
furnished to do so, subject to the following conditions: |
| 13 |
|
| 14 |
The above copyright notice and this permission notice shall be included in |
| 15 |
all copies or substantial portions of the Software. |
| 16 |
|
| 17 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 |
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
|
| 24 |
Except as contained in this notice, the name of the X Consortium shall not be |
| 25 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 26 |
in this Software without prior written authorization from the X Consortium. |
| 27 |
|
| 28 |
*/ |
| 29 |
|
| 30 |
#include <X11/Xlib.h> |
| 31 |
#include <X11/Xatom.h> |
| 32 |
|
| 33 |
static Window TryChildren(); |
| 34 |
|
| 35 |
/* Find a window with WM_STATE, else return win itself, as per ICCCM */ |
| 36 |
|
| 37 |
Window XmuClientWindow (dpy, win) |
| 38 |
Display *dpy; |
| 39 |
Window win; |
| 40 |
{ |
| 41 |
#ifdef WIN32 |
| 42 |
return None; |
| 43 |
#else |
| 44 |
Atom WM_STATE; |
| 45 |
Atom type = None; |
| 46 |
int format; |
| 47 |
unsigned long nitems, after; |
| 48 |
unsigned char *data; |
| 49 |
Window inf; |
| 50 |
|
| 51 |
WM_STATE = XInternAtom(dpy, "WM_STATE", True); |
| 52 |
if (!WM_STATE) |
| 53 |
return win; |
| 54 |
XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType, |
| 55 |
&type, &format, &nitems, &after, &data); |
| 56 |
if (type) |
| 57 |
return win; |
| 58 |
inf = TryChildren(dpy, win, WM_STATE); |
| 59 |
if (!inf) |
| 60 |
inf = win; |
| 61 |
return inf; |
| 62 |
#endif |
| 63 |
} |
| 64 |
|
| 65 |
static |
| 66 |
Window TryChildren (dpy, win, WM_STATE) |
| 67 |
Display *dpy; |
| 68 |
Window win; |
| 69 |
Atom WM_STATE; |
| 70 |
{ |
| 71 |
#ifdef WIN32 |
| 72 |
return None; |
| 73 |
#else |
| 74 |
Window root, parent; |
| 75 |
Window *children; |
| 76 |
unsigned int nchildren; |
| 77 |
unsigned int i; |
| 78 |
Atom type = None; |
| 79 |
int format; |
| 80 |
unsigned long nitems, after; |
| 81 |
unsigned char *data; |
| 82 |
Window inf = 0; |
| 83 |
|
| 84 |
if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren)) |
| 85 |
return 0; |
| 86 |
for (i = 0; !inf && (i < nchildren); i++) { |
| 87 |
XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False, |
| 88 |
AnyPropertyType, &type, &format, &nitems, |
| 89 |
&after, &data); |
| 90 |
if (type) |
| 91 |
inf = children[i]; |
| 92 |
} |
| 93 |
for (i = 0; !inf && (i < nchildren); i++) |
| 94 |
inf = TryChildren(dpy, children[i], WM_STATE); |
| 95 |
if (children) XFree((char *)children); |
| 96 |
return inf; |
| 97 |
#endif |
| 98 |
} |