1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// Visual list utility for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
// List all the visuals on the screen, and dumps anything interesting
|
|
|
|
// about them to stdout.
|
|
|
|
//
|
2021-04-19 15:07:21 +03:00
|
|
|
// Does not use FLTK under X11.
|
1998-10-06 22:21:25 +04:00
|
|
|
//
|
|
|
|
// This file may be #included in another program to make a function to
|
|
|
|
// call to list the visuals. Fl.H must be included first to indicate this.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2021-12-19 00:42:30 +03:00
|
|
|
// Copyright 1998-2021 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-04-19 15:07:21 +03:00
|
|
|
#ifndef Fl_H
|
|
|
|
# define NEED_MAIN 1 // when not included by another FLTK program
|
|
|
|
#endif
|
1998-10-06 23:18:34 +04:00
|
|
|
|
2021-12-19 00:42:30 +03:00
|
|
|
#include <FL/platform.H> // for FLTK_USE_X11
|
1998-10-06 23:18:34 +04:00
|
|
|
|
2021-12-19 00:42:30 +03:00
|
|
|
#ifdef FLTK_USE_X11
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2010-12-15 15:11:16 +03:00
|
|
|
#include <config.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2016-01-31 07:33:54 +03:00
|
|
|
#define HAVE_MULTIBUF 0
|
|
|
|
|
2021-04-19 15:07:21 +03:00
|
|
|
#ifdef NEED_MAIN
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
Display *fl_display;
|
|
|
|
int fl_screen;
|
|
|
|
const char *dname;
|
|
|
|
void fl_open_display() {
|
|
|
|
fl_display = XOpenDisplay(dname);
|
|
|
|
if (!fl_display) {
|
|
|
|
fprintf(stderr,"Can't open display: %s\n",XDisplayName(dname));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fl_screen = DefaultScreen(fl_display);
|
|
|
|
}
|
|
|
|
|
2021-04-19 15:07:21 +03:00
|
|
|
#endif // NEED_MAIN
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
const char *ClassNames[] = {
|
|
|
|
"StaticGray ",
|
|
|
|
"GrayScale ",
|
|
|
|
"StaticColor",
|
|
|
|
"PseudoColor",
|
|
|
|
"TrueColor ",
|
|
|
|
"DirectColor"
|
|
|
|
};
|
|
|
|
|
|
|
|
// SERVER_OVERLAY_VISUALS property element:
|
|
|
|
typedef struct _OverlayInfo {
|
|
|
|
long overlay_visual;
|
|
|
|
long transparent_type;
|
|
|
|
long value;
|
|
|
|
long layer;
|
|
|
|
} OverlayInfo;
|
|
|
|
|
|
|
|
#if HAVE_MULTIBUF
|
|
|
|
#include <X11/extensions/multibuf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void print_mask(XVisualInfo* p) {
|
|
|
|
int n = 0;
|
|
|
|
int what = 0;
|
|
|
|
int print_anything = 0;
|
|
|
|
char buf[20];
|
|
|
|
char *q = buf;
|
|
|
|
*q = 0;
|
|
|
|
int b; unsigned int m; for (b=32,m=0x80000000; ; b--,m>>=1) {
|
|
|
|
int new_what = 0;
|
|
|
|
if (p->red_mask&m) new_what = 'r';
|
|
|
|
else if (p->green_mask&m) new_what = 'g';
|
|
|
|
else if (p->blue_mask&m) new_what = 'b';
|
|
|
|
else new_what = '?';
|
|
|
|
if (new_what != what) {
|
|
|
|
if (what && (what != '?' || print_anything)) {
|
2022-09-26 17:12:18 +03:00
|
|
|
q += snprintf(q, sizeof(buf) - (q-buf), "%d%c", n, what);
|
2020-07-01 19:03:10 +03:00
|
|
|
print_anything = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
what = new_what;
|
|
|
|
n = 1;
|
|
|
|
} else {
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (!b) break;
|
|
|
|
}
|
|
|
|
printf("%7s", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_visuals() {
|
|
|
|
fl_open_display();
|
|
|
|
XVisualInfo vTemplate;
|
|
|
|
int num;
|
|
|
|
XVisualInfo *visualList = XGetVisualInfo(fl_display,0,&vTemplate,&num);
|
|
|
|
|
|
|
|
XPixmapFormatValues *pfvlist;
|
|
|
|
static int numpfv;
|
|
|
|
pfvlist = XListPixmapFormats(fl_display, &numpfv);
|
|
|
|
|
|
|
|
OverlayInfo *overlayInfo = 0;
|
|
|
|
int numoverlayinfo = 0;
|
|
|
|
Atom overlayVisualsAtom = XInternAtom(fl_display,"SERVER_OVERLAY_VISUALS",1);
|
|
|
|
if (overlayVisualsAtom) {
|
|
|
|
unsigned long sizeData, bytesLeft;
|
|
|
|
Atom actualType;
|
|
|
|
int actualFormat;
|
|
|
|
if (!XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
|
2020-07-01 19:03:10 +03:00
|
|
|
overlayVisualsAtom, 0L, 10000L, False,
|
|
|
|
overlayVisualsAtom, &actualType, &actualFormat,
|
|
|
|
&sizeData, &bytesLeft,
|
|
|
|
(unsigned char **) &overlayInfo))
|
1998-10-06 22:21:25 +04:00
|
|
|
numoverlayinfo = int(sizeData/4);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_MULTIBUF
|
|
|
|
int event_base, error_base;
|
|
|
|
XmbufBufferInfo *mbuf, *sbuf;
|
|
|
|
int nmbuf = 0, nsbuf = 0;
|
|
|
|
if (XmbufQueryExtension(fl_display,&event_base, &error_base)) {
|
|
|
|
XmbufGetScreenInfo(fl_display,RootWindow(fl_display,fl_screen),
|
2020-07-01 19:03:10 +03:00
|
|
|
&nmbuf, &mbuf, &nsbuf, &sbuf);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int i=0; i<num; i++) {
|
|
|
|
XVisualInfo *p = visualList+i;
|
|
|
|
|
|
|
|
XPixmapFormatValues *pfv;
|
|
|
|
for (pfv = pfvlist; ; pfv++) {
|
|
|
|
if (pfv >= pfvlist+numpfv) {pfv = 0; break;} // should not happen!
|
|
|
|
if (pfv->depth == p->depth) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int j = pfv ? pfv->bits_per_pixel : 0;
|
|
|
|
printf(" %2ld: %s %2d/%d", p->visualid, ClassNames[p->c_class],
|
2020-07-01 19:03:10 +03:00
|
|
|
p->depth, j);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (j < 10) putchar(' ');
|
|
|
|
|
|
|
|
print_mask(p);
|
|
|
|
|
|
|
|
for (j=0; j<numoverlayinfo; j++) {
|
|
|
|
OverlayInfo *o = &overlayInfo[j];
|
|
|
|
if (o->overlay_visual == long(p->visualid)) {
|
2020-07-01 19:03:10 +03:00
|
|
|
printf(" overlay(");
|
|
|
|
if (o->transparent_type==1) printf("transparent pixel %ld, ",o->value);
|
|
|
|
else if (o->transparent_type==2) printf("transparent mask %ld, ",o->value);
|
|
|
|
else printf("opaque, ");
|
|
|
|
printf("layer %ld)", o->layer);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_MULTIBUF
|
|
|
|
for (j=0; j<nmbuf; j++) {
|
|
|
|
XmbufBufferInfo *m = &mbuf[j];
|
|
|
|
if (m->visualid == p->visualid)
|
2020-07-01 19:03:10 +03:00
|
|
|
printf(" multibuffer(%d)", m->max_buffers);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
for (j=0; j<nsbuf; j++) {
|
|
|
|
XmbufBufferInfo *m = &sbuf[j];
|
|
|
|
if (m->visualid == p->visualid)
|
2020-07-01 19:03:10 +03:00
|
|
|
printf(" stereo multibuffer(%d)", m->max_buffers);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (p->visualid==XVisualIDFromVisual(DefaultVisual(fl_display,fl_screen)))
|
|
|
|
printf(" (default visual)");
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2013-09-20 07:36:02 +04:00
|
|
|
if ( overlayInfo ) { XFree(overlayInfo); overlayInfo = 0; }
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-19 00:42:30 +03:00
|
|
|
#endif // FLTK_USE_X11
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-04-19 15:07:21 +03:00
|
|
|
#ifdef NEED_MAIN
|
|
|
|
|
2021-12-19 00:42:30 +03:00
|
|
|
# ifndef FLTK_USE_X11
|
2021-04-19 15:07:21 +03:00
|
|
|
# include <FL/fl_ask.H>
|
|
|
|
# endif
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2021-12-19 00:42:30 +03:00
|
|
|
# ifdef FLTK_USE_X11
|
1998-10-06 22:21:25 +04:00
|
|
|
if (argc == 1);
|
|
|
|
else if (argc == 2 && argv[1][0]!='-') dname = argv[1];
|
|
|
|
else {fprintf(stderr,"usage: %s <display>\n",argv[0]); exit(1);}
|
|
|
|
list_visuals();
|
|
|
|
return 0;
|
2021-04-19 15:07:21 +03:00
|
|
|
# else
|
|
|
|
fl_alert("Currently, this program works only under X.");
|
|
|
|
return 1;
|
2021-12-19 00:42:30 +03:00
|
|
|
# endif // FLTK_USE_X11
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2021-04-19 15:07:21 +03:00
|
|
|
|
|
|
|
#endif // NEED_MAIN
|