home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / xv221src / unsupt / vms / pseudo_r.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  2.7 KB  |  129 lines

  1. /*
  2.     pseudo_root - Return the Window ID of the Pseudo Root
  3.  
  4.     NOTE: This routine is required for DECwindows
  5.     because the true root window is hidden behind
  6.     a pseudo-root window created by the window manager.
  7.  
  8.     Calling Sequence:
  9.         root_win = pseudo_root(display, screen);
  10.     where:
  11.         display must already be opened and
  12.         screen is usually DefaultScreen(display).
  13.  
  14. */
  15.  
  16. #include <X11/Xlib.h>
  17.  
  18. #define    NULL    0L
  19.  
  20. static void chase_root();
  21.  
  22. static int done;
  23. static Window last_win;
  24. static int root_x, root_y, root_width, root_height;
  25. static int root_bw, root_depth;
  26.  
  27.  
  28. Window pseudo_root(dpy, screen)
  29. Display *dpy;
  30. int screen;
  31. {
  32.     Window root, win;
  33.  
  34.     /* Start at the real root */
  35.     root = RootWindow(dpy, screen);
  36.  
  37.     /* Get the geometry of the root */
  38.     if (XGetGeometry(dpy, root, &win, &root_x, &root_y, 
  39.             &root_width, &root_height,
  40.             &root_bw, &root_depth))
  41.     {
  42.     /* Set up for the tree walk */
  43.     done = False;
  44.     last_win = root;
  45.  
  46.     /* Run down the tree to find the pseudo root */
  47.     chase_root(dpy, root);
  48.     return last_win;
  49.     }
  50.     else
  51.     /* Classic case of "this should never happen" */
  52.     return root;
  53.  
  54. } /*** End pseudo_root() ***/
  55.  
  56.  
  57. /*
  58.     chase_root - Internal to this module
  59.  
  60.     This is a recursive routine for descending the window tree.
  61.  
  62.     It looks for the first window which does NOT overlay the root,
  63.     then returns with the ID of the last window it saw in the
  64.     global variable last_win.
  65.  
  66.     NOTE: The parameters of the root window must be set up before
  67.     calling chase_root().
  68. */
  69.  
  70. static void chase_root (dpy, w)
  71. Display *dpy;
  72. Window w;
  73. {
  74.     Window root, parent;
  75.     unsigned int nchildren;
  76.     Window *children = NULL;
  77.     Status status;
  78.     int n;
  79.     int x, y, rx, ry;
  80.     unsigned int width, height, bw, depth;
  81.  
  82.     /* Insurance */
  83.     if (done)
  84.     return;
  85.  
  86.     if (XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &bw, &depth))
  87.     {
  88.     /*
  89.         If this window does not exactly overlay the root
  90.         then we have gone one too far, i.e., we have finished.
  91.     */
  92.     if ( (x != root_x) ||
  93.          (y != root_y) ||
  94.          (width  != root_width) ||
  95.          (height != root_height) )
  96.     {
  97.         done = True;
  98.         return;
  99.     }
  100.  
  101.     /* Otherwise, remember where we got up to and continue */
  102.     else
  103.         last_win = w;
  104.     }
  105.  
  106.     else
  107.     /* We are in trouble if this happens!!! */
  108.     return;
  109.  
  110.     if (!XQueryTree (dpy, w, &root, &parent, &children, &nchildren))
  111.     /* Likewise, we hope we never get here!!! */
  112.     return;
  113.  
  114.     for (n = 0; n < nchildren; n++)
  115.     {
  116.     chase_root (dpy, children[n]);
  117.     if (done)
  118.         break;
  119.     }
  120. #ifdef VMS
  121.     if (children) XFree ((char *) children);
  122. #else
  123.     if (children) free ((char *) children);
  124. #endif
  125.     return;
  126.  
  127. } /*** End chase_root() ***/
  128.  
  129.