2
// "$Id: list_visuals.cxx,v 1.1 2002/01/30 23:51:19 edgomez Exp $"
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-2000 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 to "fltk-bugs@fltk.org".
36
#include <FL/fl_message.H>
38
/*int main(int, char**) {
39
fl_alert("Currently, this program works only under X.");
50
#include <X11/Xutil.h>
51
#include <X11/Xatom.h>
58
void fl_open_display() {
59
fl_display = XOpenDisplay(dname);
61
fprintf(stderr,"Can't open display: %s\n",XDisplayName(dname));
64
fl_screen = DefaultScreen(fl_display);
69
const char *ClassNames[] = {
78
// SERVER_OVERLAY_VISUALS property element:
79
typedef struct _OverlayInfo {
81
long transparent_type;
87
#include <X11/extensions/multibuf.h>
91
#include <X11/extensions/Xdbe.h>
94
static void print_mask(XVisualInfo* p) {
97
int print_anything = 0;
101
int b; unsigned int m; for (b=32,m=0x80000000; ; b--,m>>=1) {
103
if (p->red_mask&m) new_what = 'r';
104
else if (p->green_mask&m) new_what = 'g';
105
else if (p->blue_mask&m) new_what = 'b';
107
if (new_what != what) {
108
if (what && (what != '?' || print_anything)) {
109
q += sprintf(q,"%d%c", n, what);
122
void list_visuals() {
124
XVisualInfo vTemplate;
126
XVisualInfo *visualList = XGetVisualInfo(fl_display,0,&vTemplate,&num);
128
XPixmapFormatValues *pfvlist;
130
pfvlist = XListPixmapFormats(fl_display, &numpfv);
132
OverlayInfo *overlayInfo = 0;
133
int numoverlayinfo = 0;
134
Atom overlayVisualsAtom = XInternAtom(fl_display,"SERVER_OVERLAY_VISUALS",1);
135
if (overlayVisualsAtom) {
136
unsigned long sizeData, bytesLeft;
139
if (!XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
140
overlayVisualsAtom, 0L, 10000L, False,
141
overlayVisualsAtom, &actualType, &actualFormat,
142
&sizeData, &bytesLeft,
143
(unsigned char **) &overlayInfo))
144
numoverlayinfo = int(sizeData/4);
148
int event_base, error_base;
149
XmbufBufferInfo *mbuf, *sbuf;
150
int nmbuf = 0, nsbuf = 0;
151
if (XmbufQueryExtension(fl_display,&event_base, &error_base)) {
152
XmbufGetScreenInfo(fl_display,RootWindow(fl_display,fl_screen),
153
&nmbuf, &mbuf, &nsbuf, &sbuf);
158
int event_base, error_base;
160
XdbeVisualInfo *dbe = 0;
161
if (XdbeQueryExtension(fl_display, &event_base, &error_base)) {
162
Drawable root = RootWindow(fl_display,fl_screen);
164
XdbeScreenVisualInfo *a = XdbeGetVisualInfo(fl_display,&root,&numscreens);
165
if (!a) printf("error getting double buffer visuals\n");
168
numdouble = a->count;
173
for (int i=0; i<num; i++) {
174
XVisualInfo *p = visualList+i;
176
XPixmapFormatValues *pfv;
177
for (pfv = pfvlist; ; pfv++) {
178
if (pfv >= pfvlist+numpfv) {pfv = 0; break;} // should not happen!
179
if (pfv->depth == p->depth) break;
182
int j = pfv ? pfv->bits_per_pixel : 0;
183
printf(" %2ld: %s %2d/%d", p->visualid, ClassNames[p->c_class],
185
if (j < 10) putchar(' ');
189
for (j=0; j<numoverlayinfo; j++) {
190
OverlayInfo *o = &overlayInfo[j];
191
if (o->overlay_visual == long(p->visualid)) {
193
if (o->transparent_type==1) printf("transparent pixel %ld, ",o->value);
194
else if (o->transparent_type==2) printf("transparent mask %ld, ",o->value);
195
else printf("opaque, ");
196
printf("layer %ld)", o->layer);
201
for (j=0; j<nmbuf; j++) {
202
XmbufBufferInfo *m = &mbuf[j];
203
if (m->visualid == p->visualid)
204
printf(" multibuffer(%d)", m->max_buffers);
206
for (j=0; j<nsbuf; j++) {
207
XmbufBufferInfo *m = &sbuf[j];
208
if (m->visualid == p->visualid)
209
printf(" stereo multibuffer(%d)", m->max_buffers);
214
for (j = 0; j < numdouble; j++) if (dbe[j].visual == p->visualid)
215
printf(" doublebuf(perflevel %d)",dbe[j].perflevel);
218
if (p->visualid==XVisualIDFromVisual(DefaultVisual(fl_display,fl_screen)))
219
printf(" (default visual)");
228
/*int main(int argc, char **argv) {
230
else if (argc == 2 && argv[1][0]!='-') dname = argv[1];
231
else {fprintf(stderr,"usage: %s <display>\n",argv[0]); exit(1);}
238
// End of "$Id: list_visuals.cxx,v 1.1 2002/01/30 23:51:19 edgomez Exp $".