Back to index

tetex-bin  3.0
xserver-info.c
Go to the documentation of this file.
00001 /* Xserver debugging functions, lifted from X11 R6.6's xdpyinfo.c.
00002    Original copyright follows:
00003 */
00004 
00005 /*
00006 Copyright 1988, 1998  The Open Group
00007 
00008 Permission to use, copy, modify, distribute, and sell this software and its
00009 documentation for any purpose is hereby granted without fee, provided that
00010 the above copyright notice appear in all copies and that both that
00011 copyright notice and this permission notice appear in supporting
00012 documentation.
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 
00024 Except as contained in this notice, the name of The Open Group shall not be
00025 used in advertising or otherwise to promote the sale, use or other dealings
00026 in this Software without prior written authorization from The Open Group.
00027  *
00028  * Author:  Jim Fulton, MIT X Consortium
00029  */
00030 
00031 #include "xdvi.h"
00032 #include "xserver-info.h"
00033 
00034 #ifdef XSERVER_INFO
00035 
00036 static void
00037 print_display_info (dpy)
00038     Display *dpy;
00039 {
00040     char dummybuf[40];
00041     char *cp;
00042     int minkeycode, maxkeycode;
00043     int i, n;
00044     /*     long req_size; */
00045     XPixmapFormatValues *pmf;
00046     Window focuswin;
00047     int focusrevert;
00048 
00049     printf("name of display:    %s\n", DisplayString (dpy));
00050     printf("version number:    %d.%d\n",
00051           ProtocolVersion (dpy), ProtocolRevision (dpy));
00052     printf("vendor string:    %s\n", ServerVendor (dpy));
00053     printf("vendor release number:    %d\n", VendorRelease (dpy));
00054     /* apparently AIX 3 does not have XExtendedMaxRequestSize.
00055        We don't really need it either.
00056     */
00057     /*     req_size = XExtendedMaxRequestSize (dpy); */
00058     /*     if (!req_size) req_size = XMaxRequestSize (dpy); */
00059     /*     printf("maximum request size:  %ld bytes\n", req_size * 4); */
00060     /*     printf("motion buffer size:  %lu\n", XDisplayMotionBufferSize (dpy)); */
00061 
00062     switch (BitmapBitOrder (dpy)) {
00063     case LSBFirst:    cp = "LSBFirst"; break;
00064     case MSBFirst:    cp = "MSBFirst"; break;
00065     default:    
00066        sprintf(dummybuf, "unknown order %d", BitmapBitOrder (dpy));
00067        cp = dummybuf;
00068        break;
00069     }
00070     printf("bitmap unit: %d, bit order: %d (%s), padding: %d\n",
00071           BitmapUnit (dpy), BitmapBitOrder(dpy), cp, BitmapPad (dpy));
00072 
00073     switch (ImageByteOrder (dpy)) {
00074     case LSBFirst:    cp = "LSBFirst"; break;
00075     case MSBFirst:    cp = "MSBFirst"; break;
00076     default:    
00077        sprintf(dummybuf, "unknown order %d", ImageByteOrder (dpy));
00078        cp = dummybuf;
00079        break;
00080     }
00081     printf("image byte order: %d (%s)\n", ImageByteOrder(dpy), cp);
00082 
00083     pmf = XListPixmapFormats (dpy, &n);
00084     printf("number of supported pixmap formats:    %d\n", n);
00085     if (pmf) {
00086        printf("supported pixmap formats:\n");
00087        for (i = 0; i < n; i++) {
00088            printf("    depth %d, bits_per_pixel %d, scanline_pad %d\n",
00089                  pmf[i].depth, pmf[i].bits_per_pixel, pmf[i].scanline_pad);
00090        }
00091        XFree ((char *) pmf);
00092     }
00093 
00094 
00095     /*
00096      * when we get interfaces to the PixmapFormat stuff, insert code here
00097      */
00098 
00099     XDisplayKeycodes (dpy, &minkeycode, &maxkeycode);
00100     printf("keycode range:    minimum %d, maximum %d\n",
00101           minkeycode, maxkeycode);
00102 
00103     XGetInputFocus (dpy, &focuswin, &focusrevert);
00104     printf("focus:  ");
00105     switch (focuswin) {
00106     case PointerRoot:
00107        printf("PointerRoot\n");
00108        break;
00109     case None:
00110        printf("None\n");
00111        break;
00112     default:
00113        printf("window 0x%lx, revert to ", focuswin);
00114        switch (focusrevert) {
00115        case RevertToParent:
00116            printf("Parent\n");
00117            break;
00118        case RevertToNone:
00119            printf("None\n");
00120            break;
00121        case RevertToPointerRoot:
00122            printf("PointerRoot\n");
00123            break;
00124        default:                    /* should not happen */
00125            printf("%d\n", focusrevert);
00126            break;
00127        }
00128        break;
00129     }
00130 
00131     /*      print_extension_info (dpy); */
00132 
00133     printf("default screen number:    %d\n", DefaultScreen (dpy));
00134     printf("number of screens:    %d\n", ScreenCount (dpy));
00135 }
00136 
00137 static void
00138 print_visual_info (vip)
00139     XVisualInfo *vip;
00140 {
00141     char errorbuf[40];                    /* for sprintfing into */
00142     char *class = NULL;                   /* for printing */
00143 
00144     switch (vip->class) {
00145     case StaticGray:    class = "StaticGray"; break;
00146     case GrayScale:    class = "GrayScale"; break;
00147     case StaticColor:    class = "StaticColor"; break;
00148     case PseudoColor:    class = "PseudoColor"; break;
00149     case TrueColor:    class = "TrueColor"; break;
00150     case DirectColor:    class = "DirectColor"; break;
00151     default:    
00152        sprintf(errorbuf, "unknown class %d", vip->class);
00153        class = errorbuf;
00154        break;
00155     }
00156 
00157     printf("  visual:\n");
00158     printf("    visual id:    0x%lx\n", vip->visualid);
00159     printf("    class:    %s\n", class);
00160     printf("    depth:    %d plane%s\n", vip->depth, 
00161           vip->depth == 1 ? "" : "s");
00162     if (vip->class == TrueColor || vip->class == DirectColor)
00163        printf("    available colormap entries:    %d per subfield\n",
00164               vip->colormap_size);
00165     else
00166        printf("    available colormap entries:    %d\n",
00167               vip->colormap_size);
00168     printf("    red, green, blue masks:    0x%lx, 0x%lx, 0x%lx\n",
00169           vip->red_mask, vip->green_mask, vip->blue_mask);
00170     printf("    significant bits in color specification:    %d bits\n",
00171           vip->bits_per_rgb);
00172 }
00173 
00174 static void
00175 print_screen_info (dpy, scr)
00176     Display *dpy;
00177     int scr;
00178 {
00179     Screen *s = ScreenOfDisplay (dpy, scr);  /* opaque structure */
00180     XVisualInfo viproto;           /* fill in for getting info */
00181     XVisualInfo *vip;                     /* retured info */
00182     int nvi;                       /* number of elements returned */
00183     int i;                         /* temp variable: iterator */
00184     /*      char eventbuf[80]; */                /* want 79 chars per line + nul */
00185     static char *yes = "YES", *no = "NO", *when = "WHEN MAPPED";
00186     double xres, yres;
00187     int ndepths = 0, *depths = NULL;
00188     unsigned int width, height;
00189 
00190 
00191     /*
00192      * there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
00193      *
00194      *     dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
00195      *         = N pixels / (M inch / 25.4)
00196      *         = N * 25.4 pixels / M inch
00197      */
00198 
00199     xres = ((((double) DisplayWidth(dpy,scr)) * 25.4) / 
00200            ((double) DisplayWidthMM(dpy,scr)));
00201     yres = ((((double) DisplayHeight(dpy,scr)) * 25.4) / 
00202            ((double) DisplayHeightMM(dpy,scr)));
00203 
00204     printf("\n");
00205     printf("screen #%d:\n", scr);
00206     printf("  dimensions:    %dx%d pixels (%dx%d millimeters)\n",
00207           DisplayWidth (dpy, scr), DisplayHeight (dpy, scr),
00208           DisplayWidthMM(dpy, scr), DisplayHeightMM (dpy, scr));
00209     printf("  resolution:    %dx%d dots per inch\n", 
00210           (int) (xres + 0.5), (int) (yres + 0.5));
00211     depths = XListDepths (dpy, scr, &ndepths);
00212     if (!depths) ndepths = 0;
00213     printf("  depths (%d):    ", ndepths);
00214     for (i = 0; i < ndepths; i++) {
00215        printf("%d", depths[i]);
00216        if (i < ndepths - 1) { 
00217            putchar (',');
00218            putchar (' ');
00219        }
00220     }
00221     putchar ('\n');
00222     if (depths) XFree ((char *) depths);
00223     printf("  root window id:    0x%lx\n", RootWindow (dpy, scr));
00224     printf("  depth of root window:    %d plane%s\n",
00225           DisplayPlanes (dpy, scr),
00226           DisplayPlanes (dpy, scr) == 1 ? "" : "s");
00227     printf("  number of colormaps:    minimum %d, maximum %d\n",
00228           MinCmapsOfScreen(s), MaxCmapsOfScreen(s));
00229     printf("  default colormap:    0x%lx\n", DefaultColormap (dpy, scr));
00230     printf("  default number of colormap cells:    %d\n",
00231           DisplayCells (dpy, scr));
00232     printf("  preallocated pixels:    black %lu, white %lu\n",
00233           BlackPixel (dpy, scr), WhitePixel (dpy, scr));
00234     printf("  options:    backing-store %s, save-unders %s\n",
00235           (DoesBackingStore (s) == NotUseful) ? no :
00236           ((DoesBackingStore (s) == Always) ? yes : when),
00237           DoesSaveUnders (s) ? yes : no);
00238     XQueryBestSize (dpy, CursorShape, RootWindow (dpy, scr), 65535, 65535,
00239                   &width, &height);
00240     if (width == 65535 && height == 65535)
00241        printf("  largest cursor:    unlimited\n");
00242     else
00243        printf("  largest cursor:    %dx%d\n", width, height);
00244     printf("  current input event mask:    0x%lx\n", EventMaskOfScreen (s));
00245     /*      (void) print_event_mask (eventbuf, 79, 4, EventMaskOfScreen (s)); */
00246                     
00247 
00248     nvi = 0;
00249     viproto.screen = scr;
00250     vip = XGetVisualInfo (dpy, VisualScreenMask, &viproto, &nvi);
00251     printf("  number of visuals:    %d\n", nvi);
00252     printf("  default visual id:  0x%lx\n", 
00253           XVisualIDFromVisual (DefaultVisual (dpy, scr)));
00254     for (i = 0; i < nvi; i++) {
00255        print_visual_info (vip+i);
00256     }
00257     if (vip) XFree ((char *) vip);
00258 }
00259 
00260 
00261 /*
00262   public function: when DBG_ALL is enabled, dump info on Xserver
00263   to stdout.
00264 */
00265 void
00266 print_xserver_info(void)
00267 {
00268     int i;
00269     if (globals.debug & DBG_PK) {
00270        puts("========== Xserver properties info begin ==========\n");
00271        print_display_info(DISP);
00272        for (i = 0; i < ScreenCount(DISP); i++) {
00273            print_screen_info(DISP, i);
00274        }
00275        puts("========== Xserver properties info end ==========\n");
00276     }
00277 }
00278 
00279 
00280 #else
00281 /* silence `empty compilation unit' warnings */
00282 static void bar(void); static void foo() { bar(); } static void bar(void) { foo(); }
00283 #endif /* XSERVER_INFO */