kscreensaver_vroot.h
00001 /*****************************************************************************/ 00025 /*****************************************************************************/ 00026 /* 00027 * vroot.h -- Virtual Root Window handling header file 00028 * 00029 * This header file redefines the X11 macros RootWindow and DefaultRootWindow, 00030 * making them look for a virtual root window as provided by certain `virtual' 00031 * window managers like swm and tvtwm. If none is found, the ordinary root 00032 * window is returned, thus retaining backward compatibility with standard 00033 * window managers. 00034 * The function implementing the virtual root lookup remembers the result of 00035 * its last invocation to avoid overhead in the case of repeated calls 00036 * on the same display and screen arguments. 00037 * The lookup code itself is taken from Tom LaStrange's ssetroot program. 00038 * 00039 * Most simple root window changing X programs can be converted to using 00040 * virtual roots by just including 00041 * 00042 * #include <X11/vroot.h> 00043 * 00044 * after all the X11 header files. It has been tested on such popular 00045 * X clients as xphoon, xfroot, xloadimage, and xaqua. 00046 * It also works with the core clients xprop, xwininfo, xwd, and editres 00047 * (and is necessary to get those clients working under tvtwm). 00048 * It does NOT work with xsetroot; get the xsetroot replacement included in 00049 * the tvtwm distribution instead. 00050 * 00051 * Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90 00052 * - replaced all NULL's with properly cast 0's, 5/6/91 00053 * - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91 00054 * - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91 00055 */ 00056 00057 #ifndef _VROOT_H_ 00058 #define _VROOT_H_ 00059 00060 #if !defined(lint) && !defined(SABER) 00061 static const char vroot_rcsid[] = "#Id: vroot.h,v 1.4 1991/09/30 19:23:16 stolcke Exp stolcke #"; 00062 #endif 00063 00064 #include <qwidget.h> 00065 #ifdef Q_WS_X11 00066 #include <X11/X.h> 00067 #include <X11/Xatom.h> 00068 #include <X11/Xlib.h> 00069 00070 static Window 00071 #if defined(__STDC__) || defined(__cplusplus) /* ANSIfication added by jwz, to avoid superfluous warnings. */ 00072 VirtualRootWindowOfScreen(Screen *screen) 00073 #else /* !__STDC__ */ 00074 VirtualRootWindowOfScreen(screen) Screen *screen; 00075 #endif /* !__STDC__ */ 00076 { 00077 static Screen *save_screen = (Screen *)0; 00078 static Window root = (Window)0; 00079 00080 if (screen != save_screen) { 00081 Display *dpy = DisplayOfScreen(screen); 00082 Atom __SWM_VROOT = None; 00083 uint i; 00084 Window rootReturn, parentReturn, *children; 00085 unsigned int numChildren; 00086 00087 root = RootWindowOfScreen(screen); 00088 00089 /* go look for a virtual root */ 00090 __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False); 00091 if (XQueryTree(dpy, root, &rootReturn, &parentReturn, 00092 &children, &numChildren)) { 00093 for (i = 0; i < numChildren; i++) { 00094 Atom actual_type; 00095 int actual_format; 00096 unsigned long nitems, bytesafter; 00097 unsigned char *newRoot = 0; 00098 00099 if (XGetWindowProperty(dpy, children[i], 00100 __SWM_VROOT, 0, 1, False, XA_WINDOW, 00101 &actual_type, &actual_format, 00102 &nitems, &bytesafter, 00103 &newRoot) == Success 00104 && newRoot) 00105 { 00106 void *tmpRoot = (void *) newRoot; 00107 root = *(Window*) tmpRoot; 00108 XFree( (char*) newRoot ); 00109 break; 00110 } 00111 } 00112 if (children) 00113 XFree((char *)children); 00114 } 00115 00116 save_screen = screen; 00117 } 00118 00119 return root; 00120 } 00121 00122 #undef RootWindowOfScreen 00123 #define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s) 00124 00125 #undef RootWindow 00126 #define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen)) 00127 00128 #undef DefaultRootWindow 00129 #define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy)) 00130 #endif 00131 00132 #endif /* _VROOT_H_ */