2 // "$Id: list_visuals.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
4 // Visual list utility for the Fast Light Tool Kit (FLTK).
6 // List all the visuals on the screen, and dumps anything interesting
7 // about them to stdout.
11 // This file may be #included in another program to make a function to
12 // call to list the visuals. Fl.H must be included first to indicate this.
14 // Copyright 1998-2010 by Bill Spitzak and others.
16 // This library is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU Library General Public
18 // License as published by the Free Software Foundation; either
19 // version 2 of the License, or (at your option) any later version.
21 // This library is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 // Library General Public License for more details.
26 // You should have received a copy of the GNU Library General Public
27 // License along with this library; if not, write to the Free Software
28 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 // Please report all bugs and problems on the following page:
33 // http://www.fltk.org/str.php
36 #if defined(WIN32) || defined(__APPLE__)
38 #include <FL/fl_message.H>
40 int main(int, char**) {
41 fl_alert("Currently, this program works only under X.");
52 #include <X11/Xutil.h>
53 #include <X11/Xatom.h>
60 void fl_open_display() {
61 fl_display
= XOpenDisplay(dname
);
63 fprintf(stderr
,"Can't open display: %s\n",XDisplayName(dname
));
66 fl_screen
= DefaultScreen(fl_display
);
71 const char *ClassNames
[] = {
80 // SERVER_OVERLAY_VISUALS property element:
81 typedef struct _OverlayInfo
{
83 long transparent_type
;
89 #include <X11/extensions/multibuf.h>
93 #include <X11/extensions/Xdbe.h>
96 static void print_mask(XVisualInfo
* p
) {
99 int print_anything
= 0;
103 int b
; unsigned int m
; for (b
=32,m
=0x80000000; ; b
--,m
>>=1) {
105 if (p
->red_mask
&m
) new_what
= 'r';
106 else if (p
->green_mask
&m
) new_what
= 'g';
107 else if (p
->blue_mask
&m
) new_what
= 'b';
109 if (new_what
!= what
) {
110 if (what
&& (what
!= '?' || print_anything
)) {
111 q
+= sprintf(q
,"%d%c", n
, what
);
124 void list_visuals() {
126 XVisualInfo vTemplate
;
128 XVisualInfo
*visualList
= XGetVisualInfo(fl_display
,0,&vTemplate
,&num
);
130 XPixmapFormatValues
*pfvlist
;
132 pfvlist
= XListPixmapFormats(fl_display
, &numpfv
);
134 OverlayInfo
*overlayInfo
= 0;
135 int numoverlayinfo
= 0;
136 Atom overlayVisualsAtom
= XInternAtom(fl_display
,"SERVER_OVERLAY_VISUALS",1);
137 if (overlayVisualsAtom
) {
138 unsigned long sizeData
, bytesLeft
;
141 if (!XGetWindowProperty(fl_display
, RootWindow(fl_display
, fl_screen
),
142 overlayVisualsAtom
, 0L, 10000L, False
,
143 overlayVisualsAtom
, &actualType
, &actualFormat
,
144 &sizeData
, &bytesLeft
,
145 (unsigned char **) &overlayInfo
))
146 numoverlayinfo
= int(sizeData
/4);
150 int event_base
, error_base
;
151 XmbufBufferInfo
*mbuf
, *sbuf
;
152 int nmbuf
= 0, nsbuf
= 0;
153 if (XmbufQueryExtension(fl_display
,&event_base
, &error_base
)) {
154 XmbufGetScreenInfo(fl_display
,RootWindow(fl_display
,fl_screen
),
155 &nmbuf
, &mbuf
, &nsbuf
, &sbuf
);
160 int event_base
, error_base
;
162 XdbeVisualInfo
*dbe
= 0;
163 if (XdbeQueryExtension(fl_display
, &event_base
, &error_base
)) {
164 Drawable root
= RootWindow(fl_display
,fl_screen
);
166 XdbeScreenVisualInfo
*a
= XdbeGetVisualInfo(fl_display
,&root
,&numscreens
);
167 if (!a
) printf("error getting double buffer visuals\n");
170 numdouble
= a
->count
;
175 for (int i
=0; i
<num
; i
++) {
176 XVisualInfo
*p
= visualList
+i
;
178 XPixmapFormatValues
*pfv
;
179 for (pfv
= pfvlist
; ; pfv
++) {
180 if (pfv
>= pfvlist
+numpfv
) {pfv
= 0; break;} // should not happen!
181 if (pfv
->depth
== p
->depth
) break;
184 int j
= pfv
? pfv
->bits_per_pixel
: 0;
185 printf(" %2ld: %s %2d/%d", p
->visualid
, ClassNames
[p
->c_class
],
187 if (j
< 10) putchar(' ');
191 for (j
=0; j
<numoverlayinfo
; j
++) {
192 OverlayInfo
*o
= &overlayInfo
[j
];
193 if (o
->overlay_visual
== long(p
->visualid
)) {
195 if (o
->transparent_type
==1) printf("transparent pixel %ld, ",o
->value
);
196 else if (o
->transparent_type
==2) printf("transparent mask %ld, ",o
->value
);
197 else printf("opaque, ");
198 printf("layer %ld)", o
->layer
);
203 for (j
=0; j
<nmbuf
; j
++) {
204 XmbufBufferInfo
*m
= &mbuf
[j
];
205 if (m
->visualid
== p
->visualid
)
206 printf(" multibuffer(%d)", m
->max_buffers
);
208 for (j
=0; j
<nsbuf
; j
++) {
209 XmbufBufferInfo
*m
= &sbuf
[j
];
210 if (m
->visualid
== p
->visualid
)
211 printf(" stereo multibuffer(%d)", m
->max_buffers
);
216 for (j
= 0; j
< numdouble
; j
++) if (dbe
[j
].visual
== p
->visualid
)
217 printf(" doublebuf(perflevel %d)",dbe
[j
].perflevel
);
220 if (p
->visualid
==XVisualIDFromVisual(DefaultVisual(fl_display
,fl_screen
)))
221 printf(" (default visual)");
230 int main(int argc
, char **argv
) {
232 else if (argc
== 2 && argv
[1][0]!='-') dname
= argv
[1];
233 else {fprintf(stderr
,"usage: %s <display>\n",argv
[0]); exit(1);}
240 // End of "$Id: list_visuals.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".