1 //
2 // "$Id: fl_overlay_visual.cxx 5190 2006-06-09 16:16:34Z mike $"
3 //
4 // X overlay support for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27
28 // Return an overlay visual, if any. Also allocate a colormap and
29 // record the depth for fl_color() to use.
30 // Another disgusting X interface, based on code extracted and
31 // purified with great difficulty from XLayerUtil.cxx:
32
33 #include <config.h>
34 #if HAVE_OVERLAY
35 #include <FL/Fl.H>
36 #include <FL/x.H>
37
38 // SERVER_OVERLAY_VISUALS property element:
39 struct OverlayInfo {
40 long overlay_visual;
41 long transparent_type;
42 long value;
43 long layer;
44 };
45
46 extern Colormap fl_overlay_colormap;
47 extern XVisualInfo* fl_overlay_visual;
48 extern ulong fl_transparent_pixel;
49
fl_find_overlay_visual()50 XVisualInfo *fl_find_overlay_visual() {
51 static char beenhere;
52 if (beenhere) return fl_overlay_visual;
53 beenhere = 1;
54
55 fl_open_display();
56 Atom overlayVisualsAtom =
57 XInternAtom(fl_display,"SERVER_OVERLAY_VISUALS",1);
58 if (!overlayVisualsAtom) return 0;
59 OverlayInfo *overlayInfo;
60 ulong sizeData, bytesLeft;
61 Atom actualType;
62 int actualFormat;
63 if (XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
64 overlayVisualsAtom, 0L, 10000L, False,
65 overlayVisualsAtom, &actualType, &actualFormat,
66 &sizeData, &bytesLeft,
67 (unsigned char **) &overlayInfo)) return 0;
68
69 if (actualType == overlayVisualsAtom && actualFormat == 32) {
70 int n = int(sizeData/4);
71 XVisualInfo* v = 0;
72 // find the greatest depth that has a transparent pixel:
73 for (int i = 0; i < n; i++) {
74 if (overlayInfo[i].transparent_type != 1) continue;
75 if (overlayInfo[i].layer <= 0) continue;
76 XVisualInfo templt;
77 templt.visualid = overlayInfo[i].overlay_visual;
78 int num;
79 XVisualInfo *v1=XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
80 if (v1->screen == fl_screen && v1->c_class == PseudoColor
81 && (!v || v1->depth > v->depth && v1->depth <= 8)) {
82 if (v) XFree((char*)v);
83 v = v1;
84 fl_transparent_pixel = overlayInfo[i].value;
85 } else {
86 XFree((char*)v1);
87 }
88 }
89 if (v) {
90 fl_overlay_visual = v;
91 fl_overlay_colormap =
92 XCreateColormap(fl_display, RootWindow(fl_display, fl_screen),
93 v->visual, AllocNone);
94 }
95 }
96 XFree((char*)overlayInfo);
97 //printf("overlay visual %ld selected\n", fl_overlay_visual->visualid);
98 return fl_overlay_visual;
99 }
100
101 #endif
102
103 //
104 // End of "$Id: fl_overlay_visual.cxx 5190 2006-06-09 16:16:34Z mike $".
105 //
106