You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
6.1KB

  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.
  10. //
  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.
  13. //
  14. // Copyright 1998-2010 by Bill Spitzak and others.
  15. //
  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.
  20. //
  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.
  25. //
  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.
  30. //
  31. // Please report all bugs and problems on the following page:
  32. //
  33. // http://www.fltk.org/str.php
  34. //
  35. #if defined(WIN32) || defined(__APPLE__)
  36. #include <FL/Fl.H>
  37. #include <FL/fl_message.H>
  38. int main(int, char**) {
  39. fl_alert("Currently, this program works only under X.");
  40. return 1;
  41. }
  42. #else
  43. #include <config.h>
  44. #ifndef Fl_H
  45. #include <X11/Xlib.h>
  46. #include <X11/Xutil.h>
  47. #include <X11/Xatom.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. Display *fl_display;
  51. int fl_screen;
  52. const char *dname;
  53. void fl_open_display() {
  54. fl_display = XOpenDisplay(dname);
  55. if (!fl_display) {
  56. fprintf(stderr,"Can't open display: %s\n",XDisplayName(dname));
  57. exit(1);
  58. }
  59. fl_screen = DefaultScreen(fl_display);
  60. }
  61. #endif
  62. const char *ClassNames[] = {
  63. "StaticGray ",
  64. "GrayScale ",
  65. "StaticColor",
  66. "PseudoColor",
  67. "TrueColor ",
  68. "DirectColor"
  69. };
  70. // SERVER_OVERLAY_VISUALS property element:
  71. typedef struct _OverlayInfo {
  72. long overlay_visual;
  73. long transparent_type;
  74. long value;
  75. long layer;
  76. } OverlayInfo;
  77. #if HAVE_MULTIBUF
  78. #include <X11/extensions/multibuf.h>
  79. #endif
  80. #if HAVE_XDBE
  81. #include <X11/extensions/Xdbe.h>
  82. #endif
  83. static void print_mask(XVisualInfo* p) {
  84. int n = 0;
  85. int what = 0;
  86. int print_anything = 0;
  87. char buf[20];
  88. char *q = buf;
  89. *q = 0;
  90. int b; unsigned int m; for (b=32,m=0x80000000; ; b--,m>>=1) {
  91. int new_what = 0;
  92. if (p->red_mask&m) new_what = 'r';
  93. else if (p->green_mask&m) new_what = 'g';
  94. else if (p->blue_mask&m) new_what = 'b';
  95. else new_what = '?';
  96. if (new_what != what) {
  97. if (what && (what != '?' || print_anything)) {
  98. q += sprintf(q,"%d%c", n, what);
  99. print_anything = 1;
  100. }
  101. what = new_what;
  102. n = 1;
  103. } else {
  104. n++;
  105. }
  106. if (!b) break;
  107. }
  108. printf("%7s", buf);
  109. }
  110. void list_visuals() {
  111. fl_open_display();
  112. XVisualInfo vTemplate;
  113. int num;
  114. XVisualInfo *visualList = XGetVisualInfo(fl_display,0,&vTemplate,&num);
  115. XPixmapFormatValues *pfvlist;
  116. static int numpfv;
  117. pfvlist = XListPixmapFormats(fl_display, &numpfv);
  118. OverlayInfo *overlayInfo = 0;
  119. int numoverlayinfo = 0;
  120. Atom overlayVisualsAtom = XInternAtom(fl_display,"SERVER_OVERLAY_VISUALS",1);
  121. if (overlayVisualsAtom) {
  122. unsigned long sizeData, bytesLeft;
  123. Atom actualType;
  124. int actualFormat;
  125. if (!XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
  126. overlayVisualsAtom, 0L, 10000L, False,
  127. overlayVisualsAtom, &actualType, &actualFormat,
  128. &sizeData, &bytesLeft,
  129. (unsigned char **) &overlayInfo))
  130. numoverlayinfo = int(sizeData/4);
  131. }
  132. #if HAVE_MULTIBUF
  133. int event_base, error_base;
  134. XmbufBufferInfo *mbuf, *sbuf;
  135. int nmbuf = 0, nsbuf = 0;
  136. if (XmbufQueryExtension(fl_display,&event_base, &error_base)) {
  137. XmbufGetScreenInfo(fl_display,RootWindow(fl_display,fl_screen),
  138. &nmbuf, &mbuf, &nsbuf, &sbuf);
  139. }
  140. #endif
  141. #if HAVE_XDBE
  142. int event_base, error_base;
  143. int numdouble = 0;
  144. XdbeVisualInfo *dbe = 0;
  145. if (XdbeQueryExtension(fl_display, &event_base, &error_base)) {
  146. Drawable root = RootWindow(fl_display,fl_screen);
  147. int numscreens = 1;
  148. XdbeScreenVisualInfo *a = XdbeGetVisualInfo(fl_display,&root,&numscreens);
  149. if (!a) printf("error getting double buffer visuals\n");
  150. else {
  151. dbe = a->visinfo;
  152. numdouble = a->count;
  153. }
  154. }
  155. #endif
  156. for (int i=0; i<num; i++) {
  157. XVisualInfo *p = visualList+i;
  158. XPixmapFormatValues *pfv;
  159. for (pfv = pfvlist; ; pfv++) {
  160. if (pfv >= pfvlist+numpfv) {pfv = 0; break;} // should not happen!
  161. if (pfv->depth == p->depth) break;
  162. }
  163. int j = pfv ? pfv->bits_per_pixel : 0;
  164. printf(" %2ld: %s %2d/%d", p->visualid, ClassNames[p->c_class],
  165. p->depth, j);
  166. if (j < 10) putchar(' ');
  167. print_mask(p);
  168. for (j=0; j<numoverlayinfo; j++) {
  169. OverlayInfo *o = &overlayInfo[j];
  170. if (o->overlay_visual == long(p->visualid)) {
  171. printf(" overlay(");
  172. if (o->transparent_type==1) printf("transparent pixel %ld, ",o->value);
  173. else if (o->transparent_type==2) printf("transparent mask %ld, ",o->value);
  174. else printf("opaque, ");
  175. printf("layer %ld)", o->layer);
  176. }
  177. }
  178. #if HAVE_MULTIBUF
  179. for (j=0; j<nmbuf; j++) {
  180. XmbufBufferInfo *m = &mbuf[j];
  181. if (m->visualid == p->visualid)
  182. printf(" multibuffer(%d)", m->max_buffers);
  183. }
  184. for (j=0; j<nsbuf; j++) {
  185. XmbufBufferInfo *m = &sbuf[j];
  186. if (m->visualid == p->visualid)
  187. printf(" stereo multibuffer(%d)", m->max_buffers);
  188. }
  189. #endif
  190. #if HAVE_XDBE
  191. for (j = 0; j < numdouble; j++) if (dbe[j].visual == p->visualid)
  192. printf(" doublebuf(perflevel %d)",dbe[j].perflevel);
  193. #endif
  194. if (p->visualid==XVisualIDFromVisual(DefaultVisual(fl_display,fl_screen)))
  195. printf(" (default visual)");
  196. putchar('\n');
  197. }
  198. }
  199. #endif
  200. #ifndef Fl_H
  201. int main(int argc, char **argv) {
  202. if (argc == 1);
  203. else if (argc == 2 && argv[1][0]!='-') dname = argv[1];
  204. else {fprintf(stderr,"usage: %s <display>\n",argv[0]); exit(1);}
  205. list_visuals();
  206. return 0;
  207. }
  208. #endif
  209. //
  210. // End of "$Id: list_visuals.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".
  211. //