1 /* xscreensaver, Copyright (c) 1997, 2001 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
12 /* If the server's root window contains a SERVER_OVERLAY_VISUALS property,
13 then that identifies the visuals which correspond to the video hardware's
14 overlay planes. Windows created in these kinds of visuals have the
15 property that one or more particular pixel values is transparent.
19 SGI: - Supported on all systems since IRIX 4.0.
20 - Their version of the Motif toolkit renders menus into the overlay
21 visual, so that they don't cause exposure events on occluded
23 - 2 bit overlay plane with Indigo Entry graphics (e.g., Indy).
24 - 8 bit overlay on O2 with Indigo 24 graphics or better (e.g., O2).
26 HP: - Supported on workstations with CRX24 and CRX48Z graphics hardware.
27 - 8 bit or 24 bit overlay plane.
28 - The default visual is the overlay visual, with a transparent pixel.
29 That way, all Xlib programs draw into the overlay plane, and no
30 Xlib program causes exposures on occluded OpenGL windows.
32 IBM: - Supported on some graphics hardware (which?)
34 DEC: - Supported on some graphics hardware (which?)
36 SUN: - Some systems apparently implement it VERRRRRRY SLOWLY, so drawing
37 into the overlay plane is a performance killer (about as bad as
38 using the SHAPE extension.)
41 On my Indy, there are two transparent visuals, one of which is at layer 1,
42 and one of which is at layer 2. This is apparently the ordering in which
43 they are overlayed (1 being topmost.) The other difference between them
44 is that the topmost one only has 2 planes, while the next one has 8.
46 This code selects the topmost one, regardless of depth. Maybe that's not
47 the right thing. Well, in XScreenSaver, we only need to allocate two
48 colors from it (it's only used to display the stderr output, so that the
49 text can overlay the graphics without being obliterated by it.)
51 Documentation, such as it is, on SERVER_OVERLAY_VISUALS found on the web:
53 http://www.hp.com/xwindow/sharedInfo/Whitepapers/Visuals/server_overlay_visuals.html
54 http://www.xig.com/Pages/Ed-Overlays.html
60 #include <X11/Xutil.h>
61 #include <X11/Xproto.h>
69 CARD32 transparency; /* 0: none; 1: pixel; 2: mask
70 ("mask" means "any pixel with these bits set
71 is a transparent pixel")
73 CARD32 value; /* the transparent pixel or mask */
74 CARD32 layer; /* -1: underlay; 0: normal; 1: popup; 2: overlay */
78 get_overlay_prop (Screen *screen, struct overlay_data **data_ret)
83 unsigned long nitems, bytes_after;
84 struct overlay_data *data = 0;
85 Display *dpy = DisplayOfScreen(screen);
86 Window window = RootWindowOfScreen(screen);
87 Atom XA_SERVER_OVERLAY_VISUALS =
88 XInternAtom (dpy, "SERVER_OVERLAY_VISUALS", False);
91 result = XGetWindowProperty (dpy, window, XA_SERVER_OVERLAY_VISUALS,
92 0, (65536 / sizeof (long)), False,
93 XA_SERVER_OVERLAY_VISUALS,
94 &actual_type, &actual_format,
95 &nitems, &bytes_after,
96 (unsigned char **) &data);
97 if (result != Success ||
98 actual_type != XA_SERVER_OVERLAY_VISUALS ||
99 actual_format != 32 ||
102 if (data) XFree(data);
108 return nitems / (sizeof(*data) / sizeof(CARD32));
114 get_overlay_visual (Screen *screen, unsigned long *transparent_pixel_ret)
116 struct overlay_data *data = 0;
117 int n_visuals = get_overlay_prop (screen, &data);
120 unsigned long pixel = 0;
121 unsigned int layer = 0;
125 for (i = 0; i < n_visuals; i++)
127 /* Only accept ones that have a transparent pixel or mask. */
128 if (data[i].transparency == 1 ||
129 data[i].transparency == 2)
131 XVisualInfo vi_in, *vi_out;
133 vi_in.visualid = data[i].visual_id;
134 vi_out = XGetVisualInfo (DisplayOfScreen(screen), VisualIDMask,
138 /* Prefer the one at the topmost layer; after that, prefer
139 the one with the greatest depth (most colors.) */
140 if (layer < data[i].layer ||
141 (layer == data[i].layer &&
142 depth < vi_out[0].depth))
144 visual = vi_out[0].visual;
145 depth = vi_out[0].depth;
146 layer = data[i].layer;
147 pixel = data[i].value;
153 if (data) XFree(data);
154 if (visual && transparent_pixel_ret)
155 *transparent_pixel_ret = pixel;