dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

vroot.h
Go to the documentation of this file.
1 /*****************************************************************************/
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 #include <X11/X.h>
61 #include <X11/Xatom.h>
62 #include <X11/Xlib.h>
63 
64 static Window
66  Screen *screen;
67 {
68  static Screen *save_screen = (Screen *)0;
69  static Window root = (Window)0;
70 
71  if (screen != save_screen) {
72  Display *dpy = DisplayOfScreen(screen);
73  Atom __SWM_VROOT = None;
74  int i;
75  Window rootReturn, parentReturn, *children;
76  unsigned int numChildren;
77 
78  root = RootWindowOfScreen(screen);
79 
80  /* go look for a virtual root */
81  __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
82  if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
83  &children, &numChildren)) {
84  for (i = 0; i < numChildren; i++) {
85  Atom actual_type;
86  int actual_format;
87  unsigned long nitems, bytesafter;
88  Window *newRoot = (Window *)0;
89 
90  if (XGetWindowProperty(dpy, children[i],
91  __SWM_VROOT, 0, 1, False, XA_WINDOW,
92  &actual_type, &actual_format,
93  &nitems, &bytesafter,
94  (unsigned char **) &newRoot) == Success
95  && newRoot) {
96  root = *newRoot;
97  break;
98  }
99  }
100  if (children)
101  XFree((char *)children);
102  }
103 
104  save_screen = screen;
105  }
106 
107  return root;
108 }
109 
110 #undef RootWindowOfScreen
111 #define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
112 
113 #undef RootWindow
114 #define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
115 
116 #undef DefaultRootWindow
117 #define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
118 
119 #endif /* _VROOT_H_ */
RootWindowOfScreen
#define RootWindowOfScreen(s)
Definition: vroot.h:111
root
static Window root
Definition: vroot.h:69
VirtualRootWindowOfScreen
static Window VirtualRootWindowOfScreen(screen) Screen *screen
dpy
Display * dpy
Definition: webspy.c:37