Use cairo to draw everything.
[ntk.git] / test / list_visuals.cxx
bloba219e4b03f656dc1820d819616ba0e5ccd23e04d
1 //
2 // "$Id: list_visuals.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
3 //
4 // Visual list utility for the Fast Light Tool Kit (FLTK).
5 //
6 // List all the visuals on the screen, and dumps anything interesting
7 // about them to stdout.
8 //
9 // Does not use FLTK.
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
29 // USA.
31 // Please report all bugs and problems on the following page:
33 // http://www.fltk.org/str.php
36 #if defined(WIN32) || defined(__APPLE__)
37 #include <FL/Fl.H>
38 #include <FL/fl_message.H>
40 int main(int, char**) {
41 fl_alert("Currently, this program works only under X.");
42 return 1;
45 #else
47 #include <config.h>
49 #ifndef Fl_H
51 #include <X11/Xlib.h>
52 #include <X11/Xutil.h>
53 #include <X11/Xatom.h>
54 #include <stdio.h>
55 #include <stdlib.h>
57 Display *fl_display;
58 int fl_screen;
59 const char *dname;
60 void fl_open_display() {
61 fl_display = XOpenDisplay(dname);
62 if (!fl_display) {
63 fprintf(stderr,"Can't open display: %s\n",XDisplayName(dname));
64 exit(1);
66 fl_screen = DefaultScreen(fl_display);
69 #endif
71 const char *ClassNames[] = {
72 "StaticGray ",
73 "GrayScale ",
74 "StaticColor",
75 "PseudoColor",
76 "TrueColor ",
77 "DirectColor"
80 // SERVER_OVERLAY_VISUALS property element:
81 typedef struct _OverlayInfo {
82 long overlay_visual;
83 long transparent_type;
84 long value;
85 long layer;
86 } OverlayInfo;
88 #if HAVE_MULTIBUF
89 #include <X11/extensions/multibuf.h>
90 #endif
92 #if HAVE_XDBE
93 #include <X11/extensions/Xdbe.h>
94 #endif
96 static void print_mask(XVisualInfo* p) {
97 int n = 0;
98 int what = 0;
99 int print_anything = 0;
100 char buf[20];
101 char *q = buf;
102 *q = 0;
103 int b; unsigned int m; for (b=32,m=0x80000000; ; b--,m>>=1) {
104 int new_what = 0;
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';
108 else new_what = '?';
109 if (new_what != what) {
110 if (what && (what != '?' || print_anything)) {
111 q += sprintf(q,"%d%c", n, what);
112 print_anything = 1;
114 what = new_what;
115 n = 1;
116 } else {
117 n++;
119 if (!b) break;
121 printf("%7s", buf);
124 void list_visuals() {
125 fl_open_display();
126 XVisualInfo vTemplate;
127 int num;
128 XVisualInfo *visualList = XGetVisualInfo(fl_display,0,&vTemplate,&num);
130 XPixmapFormatValues *pfvlist;
131 static int numpfv;
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;
139 Atom actualType;
140 int actualFormat;
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);
149 #if HAVE_MULTIBUF
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);
157 #endif
159 #if HAVE_XDBE
160 int event_base, error_base;
161 int numdouble = 0;
162 XdbeVisualInfo *dbe = 0;
163 if (XdbeQueryExtension(fl_display, &event_base, &error_base)) {
164 Drawable root = RootWindow(fl_display,fl_screen);
165 int numscreens = 1;
166 XdbeScreenVisualInfo *a = XdbeGetVisualInfo(fl_display,&root,&numscreens);
167 if (!a) printf("error getting double buffer visuals\n");
168 else {
169 dbe = a->visinfo;
170 numdouble = a->count;
173 #endif
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],
186 p->depth, j);
187 if (j < 10) putchar(' ');
189 print_mask(p);
191 for (j=0; j<numoverlayinfo; j++) {
192 OverlayInfo *o = &overlayInfo[j];
193 if (o->overlay_visual == long(p->visualid)) {
194 printf(" overlay(");
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);
202 #if HAVE_MULTIBUF
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);
213 #endif
215 #if HAVE_XDBE
216 for (j = 0; j < numdouble; j++) if (dbe[j].visual == p->visualid)
217 printf(" doublebuf(perflevel %d)",dbe[j].perflevel);
218 #endif
220 if (p->visualid==XVisualIDFromVisual(DefaultVisual(fl_display,fl_screen)))
221 printf(" (default visual)");
223 putchar('\n');
227 #endif
229 #ifndef Fl_H
230 int main(int argc, char **argv) {
231 if (argc == 1);
232 else if (argc == 2 && argv[1][0]!='-') dname = argv[1];
233 else {fprintf(stderr,"usage: %s <display>\n",argv[0]); exit(1);}
234 list_visuals();
235 return 0;
237 #endif
240 // End of "$Id: list_visuals.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".