ClientWin.c

Go to the documentation of this file.
00001 /* $Xorg: ClientWin.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */
00002 
00003 /* 
00004  
00005 Copyright 1989, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/ClientWin.c,v 1.7 2001/12/14 19:55:34 dawes Exp $ */
00029 
00030 #include <X11/Xlib.h>
00031 #include <X11/Xatom.h>
00032 
00033 #include <X11/Xmu/WinUtil.h>
00034 
00035 /*
00036  * Prototypes
00037  */
00038 static Window TryChildren(Display*, Window, Atom);
00039 
00040 /* Find a window with WM_STATE, else return win itself, as per ICCCM */
00041 
00042 Window
00043 XmuClientWindow(Display *dpy, Window win)
00044 {
00045     Atom WM_STATE;
00046     Atom type = None;
00047     int format;
00048     unsigned long nitems, after;
00049     unsigned char *data = NULL;
00050     Window inf;
00051 
00052     WM_STATE = XInternAtom(dpy, "WM_STATE", True);
00053     if (!WM_STATE)
00054         return win;
00055     XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType,
00056                        &type, &format, &nitems, &after, &data);
00057     if (data)
00058         XFree(data);
00059     if (type)
00060         return win;
00061     inf = TryChildren(dpy, win, WM_STATE);
00062     if (!inf)
00063         inf = win;
00064     return inf;
00065 }
00066 
00067 static Window
00068 TryChildren(Display *dpy, Window win, Atom WM_STATE)
00069 {
00070     Window root, parent;
00071     Window *children;
00072     unsigned int nchildren;
00073     unsigned int i;
00074     Atom type = None;
00075     int format;
00076     unsigned long nitems, after;
00077     unsigned char *data;
00078     Window inf = 0;
00079 
00080     if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren))
00081         return 0;
00082     for (i = 0; !inf && (i < nchildren); i++) {
00083         data = NULL;
00084         XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False,
00085                            AnyPropertyType, &type, &format, &nitems,
00086                            &after, &data);
00087         if (data)
00088             XFree(data);
00089         if (type)
00090             inf = children[i];
00091     }
00092     for (i = 0; !inf && (i < nchildren); i++)
00093         inf = TryChildren(dpy, children[i], WM_STATE);
00094     if (children)
00095         XFree(children);
00096     return inf;
00097 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1