home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xdaliclk.zip / vroot.h < prev    next >
C/C++ Source or Header  |  1992-06-11  |  5KB  |  124 lines

  1. /*****************************************************************************/
  2. /**                   Copyright 1991 by Andreas Stolcke                     **/
  3. /**               Copyright 1990 by Solbourne Computer Inc.                 **/
  4. /**                          Longmont, Colorado                             **/
  5. /**                                                                         **/
  6. /**                           All Rights Reserved                           **/
  7. /**                                                                         **/
  8. /**    Permission to use, copy, modify, and distribute this software and    **/
  9. /**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  10. /**    granted, provided that the above copyright notice appear  in  all    **/
  11. /**    copies and that both  that  copyright  notice  and  this  permis-    **/
  12. /**    sion  notice appear in supporting  documentation,  and  that  the    **/
  13. /**    name of Solbourne not be used in advertising                         **/
  14. /**    in publicity pertaining to distribution of the  software  without    **/
  15. /**    specific, written prior permission.                                  **/
  16. /**                                                                         **/
  17. /**    ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/
  18. /**    WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF    **/
  19. /**    MERCHANTABILITY  AND  FITNESS,  IN  NO  EVENT SHALL ANDREAS STOLCKE  **/
  20. /**    OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL    **/
  21. /**    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA   **/
  22. /**    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER    **/
  23. /**    TORTIOUS ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE    **/
  24. /**    OR PERFORMANCE OF THIS SOFTWARE.                                     **/
  25. /*****************************************************************************/
  26. /*
  27.  * vroot.h -- Virtual Root Window handling header file
  28.  *
  29.  * This header file redefines the X11 macros RootWindow and DefaultRootWindow,
  30.  * making them look for a virtual root window as provided by certain `virtual'
  31.  * window managers like swm and tvtwm. If none is found, the ordinary root
  32.  * window is returned, thus retaining backward compatibility with standard
  33.  * window managers.
  34.  * The function implementing the virtual root lookup remembers the result of
  35.  * its last invocation to avoid overhead in the case of repeated calls
  36.  * on the same display and screen arguments. 
  37.  * The lookup code itself is taken from Tom LaStrange's ssetroot program.
  38.  *
  39.  * Most simple root window changing X programs can be converted to using
  40.  * virtual roots by just including
  41.  *
  42.  * #include <X11/vroot.h>
  43.  *
  44.  * after all the X11 header files.  It has been tested on such popular
  45.  * X clients as xphoon, xfroot, xloadimage, and xaqua.
  46.  * It also works with the core clients xprop, xwininfo, xwd, and editres
  47.  * (and is necessary to get those clients working under tvtwm).
  48.  * It does NOT work with xsetroot; get the xsetroot replacement included in
  49.  * the tvtwm distribution instead.
  50.  *
  51.  * Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90
  52.  * - replaced all NULL's with properly cast 0's, 5/6/91
  53.  * - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91
  54.  * - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91
  55.  */
  56.  
  57. #ifndef _VROOT_H_
  58. #define _VROOT_H_
  59.  
  60. #if !defined(lint) && !defined(SABER)
  61. static char vroot_rcsid[] = "$Id: vroot.h,v 1.4 1991/09/30 19:23:16 stolcke Exp stolcke $";
  62. #endif
  63.  
  64. #include <X11/X.h>
  65. #include <X11/Xatom.h>
  66. #include <X11/Xlib.h>
  67.  
  68. static Window
  69. VirtualRootWindowOfScreen(screen)
  70.     Screen *screen;
  71. {
  72.     static Screen *save_screen = (Screen *)0;
  73.     static Window root = (Window)0;
  74.  
  75.     if (screen != save_screen) {
  76.         Display *dpy = DisplayOfScreen(screen);
  77.         Atom __SWM_VROOT = None;
  78.         int i;
  79.         Window rootReturn, parentReturn, *children;
  80.         unsigned int numChildren;
  81.  
  82.         root = RootWindowOfScreen(screen);
  83.  
  84.         /* go look for a virtual root */
  85.         __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
  86.         if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
  87.                  &children, &numChildren)) {
  88.             for (i = 0; i < numChildren; i++) {
  89.                 Atom actual_type;
  90.                 int actual_format;
  91.                 unsigned long nitems, bytesafter;
  92.                 Window *newRoot = (Window *)0;
  93.  
  94.                 if (XGetWindowProperty(dpy, children[i],
  95.                     __SWM_VROOT, 0, 1, False, XA_WINDOW,
  96.                     &actual_type, &actual_format,
  97.                     &nitems, &bytesafter,
  98.                     (unsigned char **) &newRoot) == Success
  99.                     && newRoot) {
  100.                     root = *newRoot;
  101.                     break;
  102.                 }
  103.             }
  104.             if (children)
  105.                 XFree((char *)children);
  106.         }
  107.  
  108.         save_screen = screen;
  109.     }
  110.  
  111.     return root;
  112. }
  113.  
  114. #undef RootWindowOfScreen
  115. #define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
  116.  
  117. #undef RootWindow
  118. #define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
  119.  
  120. #undef DefaultRootWindow
  121. #define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
  122.  
  123. #endif /* _VROOT_H_ */
  124.