home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / ClientWin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-09  |  2.2 KB  |  79 lines

  1. /* $XConsortium: ClientWin.c,v 1.3 89/12/10 10:26:35 rws Exp $ */
  2.  
  3. /* 
  4.  * Copyright 1989 by the Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided 
  8.  * that the above copyright notice appear in all copies and that both that 
  9.  * copyright notice and this permission notice appear in supporting 
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific, 
  12.  * written prior permission. M.I.T. makes no representations about the 
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  */
  17.  
  18. #include <X11/Xlib.h>
  19. #include <X11/Xatom.h>
  20.  
  21. static Window TryChildren();
  22.  
  23. /* Find a window with WM_STATE, else return win itself, as per ICCCM */
  24.  
  25. Window XmuClientWindow (dpy, win)
  26.     Display *dpy;
  27.     Window win;
  28. {
  29.     Atom WM_STATE;
  30.     Atom type = None;
  31.     int format;
  32.     unsigned long nitems, after;
  33.     unsigned char *data;
  34.     Window inf;
  35.  
  36.     WM_STATE = XInternAtom(dpy, "WM_STATE", True);
  37.     if (!WM_STATE)
  38.     return win;
  39.     XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType,
  40.                &type, &format, &nitems, &after, &data);
  41.     if (type)
  42.     return win;
  43.     inf = TryChildren(dpy, win, WM_STATE);
  44.     if (!inf)
  45.     inf = win;
  46.     return inf;
  47. }
  48.  
  49. static
  50. Window TryChildren (dpy, win, WM_STATE)
  51.     Display *dpy;
  52.     Window win;
  53.     Atom WM_STATE;
  54. {
  55.     Window root, parent;
  56.     Window *children;
  57.     unsigned int nchildren;
  58.     unsigned int i;
  59.     Atom type = None;
  60.     int format;
  61.     unsigned long nitems, after;
  62.     unsigned char *data;
  63.     Window inf = 0;
  64.  
  65.     if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren))
  66.     return 0;
  67.     for (i = 0; !inf && (i < nchildren); i++) {
  68.     XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False,
  69.                AnyPropertyType, &type, &format, &nitems,
  70.                &after, &data);
  71.     if (type)
  72.         inf = children[i];
  73.     }
  74.     for (i = 0; !inf && (i < nchildren); i++)
  75.     inf = TryChildren(dpy, children[i], WM_STATE);
  76.     if (children) XFree((char *)children);
  77.     return inf;
  78. }
  79.