Annotation of researchv9/X11/src/X.V11R1/clients/xwininfo/xwininfo.c, revision 1.1.1.1

1.1       root        1: /* Copyright 1987, Massachusetts Institute of Technology */
                      2: 
                      3: /*
                      4:  * xwininfo.c  - MIT Project Athena, X Window system window
                      5:  *               information utility.
                      6:  *
                      7:  *     This program will report all relavent information
                      8:  *     about a specific window.
                      9:  *
                     10:  *  Author:    Mark Lillibridge, MIT Project Athena
                     11:  *             16-Jun-87
                     12:  */
                     13: 
                     14: #include <X11/Xlib.h>
                     15: #include <X11/Xutil.h>
                     16: #include <stdio.h>
                     17: #include <strings.h>
                     18: 
                     19: /* Include routines to handle parsing defaults */
                     20: #include "dsimple.h"
                     21: 
                     22: #define TRUE 1
                     23: #define FALSE 0
                     24: 
                     25: #define FAILURE 0
                     26: 
                     27: Window window;
                     28: static char *window_id_format = " 0x%x";
                     29: 
                     30: /*
                     31:  * Report the syntax for calling xwininfo:
                     32:  */
                     33: usage()
                     34: {
                     35:     fprintf(stderr, "\n");
                     36:     fprintf(stderr, "Usage: %s [-help] %s [-int] ",
                     37:            program_name, SELECT_USAGE);
                     38:     fprintf(stderr, "[host:vs] [-tree] [-stats] [-bits] [-events] [-size] [-wm]\n\n");
                     39:     exit(0);
                     40: }
                     41: 
                     42: 
                     43: main(argc, argv)
                     44:      int argc;
                     45:      char **argv;
                     46: {
                     47:   register int i;
                     48:   int tree, stats, bits, events, wm, size  = 0;
                     49: 
                     50:   INIT_NAME;
                     51: 
                     52:   /* Open display, handle command line arguments */
                     53:   Setup_Display_And_Screen(&argc, argv);
                     54: 
                     55:   /* Get window selected on command line, if any */
                     56:   window = Select_Window_Args(&argc, argv);
                     57: 
                     58:   /* Handle our command line arguments */
                     59:   for (i = 1; i < argc; i++) {
                     60:     if (!strcmp(argv[i], "-help"))
                     61:       usage();
                     62:     if (!strcmp(argv[i], "-int")) {
                     63:       window_id_format = " %d";
                     64:       continue;
                     65:     }
                     66:     if (!strcmp(argv[i], "-tree")) {
                     67:       tree = 1;
                     68:       continue;
                     69:     }
                     70:     if (!strcmp(argv[i], "-stats")) {
                     71:       stats = 1;
                     72:       continue;
                     73:     }
                     74:     if (!strcmp(argv[i], "-bits")) {
                     75:       bits = 1;
                     76:       continue;
                     77:     }
                     78:     if (!strcmp(argv[i], "-events")) {
                     79:       events = 1;
                     80:       continue;
                     81:     }
                     82:     if (!strcmp(argv[i], "-wm")) {
                     83:       wm = 1;
                     84:       continue;
                     85:     }
                     86:     if (!strcmp(argv[i], "-size")) {
                     87:       size = 1;
                     88:       continue;
                     89:     }
                     90:     usage();
                     91:   }
                     92: 
                     93:   /* If no window selected on command line, let user pick one the hard way */
                     94:   if (!window) {
                     95:          printf("\nxwininfo ==> Please select the window you wish\n");
                     96:          printf("         ==> information on by clicking the\n");
                     97:          printf("         ==> mouse in that window.\n");
                     98:          window = Select_Window(dpy);
                     99:   }
                    100: 
                    101:   /*
                    102:    * Do the actual displaying as per parameters
                    103:    */
                    104:   if (!(tree || bits || events || wm || size))
                    105:     stats = 1;
                    106: 
                    107:   printf("\nxwininfo ==> Window id:");
                    108:   Display_Window_Id(window);
                    109:   if (tree)
                    110:     Display_Tree_Info(window);
                    111:   if (stats)
                    112:     Display_Stats_Info(window);
                    113:   if (bits)
                    114:     Display_Bits_Info(window);
                    115:   if (events)
                    116:     Display_Events_Info(window);
                    117:   if (wm)
                    118:     Display_WM_Info(window);
                    119:   if (size)
                    120:     Display_Size_Hints(window);
                    121:   printf("\n");
                    122: }
                    123: 
                    124: 
                    125: /*
                    126:  * Lookup: lookup a code in a table.
                    127:  */
                    128: typedef struct {
                    129:        long code;
                    130:        char *name;
                    131: } binding;
                    132: 
                    133: static char _lookup_buffer[100];
                    134: 
                    135: char *Lookup(code, table)
                    136: long code;
                    137: binding *table;
                    138: {
                    139:        char *name;
                    140: 
                    141:        sprintf(_lookup_buffer, "unknown (code = %ld. = 0x%lx)", code, code);
                    142:        name = _lookup_buffer;
                    143: 
                    144:        while (table->name) {
                    145:                if (table->code == code) {
                    146:                        name = table->name;
                    147:                        break;
                    148:                }
                    149:                table++;
                    150:        }
                    151: 
                    152:        return(name);
                    153: }
                    154: 
                    155: 
                    156: /*
                    157:  * Routine to display a window id in dec/hex with name if window has one
                    158:  */
                    159: 
                    160: Display_Window_Id(window)
                    161:      Window window;
                    162: {
                    163:   char *win_name;
                    164: 
                    165:   printf(window_id_format, window);         /* print id # in hex/dec */
                    166:   if (!window) {
                    167:          printf(" (none)\n");
                    168:          return;
                    169:   }
                    170:   if (!XFetchName(dpy, window, &win_name)) { /* Get window name if any */
                    171:          printf(" (has no name)\n");
                    172:          return;
                    173:   }
                    174:   if (win_name) {
                    175:     printf(" (%s)\n", win_name);
                    176:     free(win_name);
                    177:   } else if (window == RootWindow(dpy, screen))
                    178:     printf(" (the root window)\n");
                    179:   else
                    180:     printf(" (has no name)\n");
                    181: }
                    182: 
                    183: 
                    184: /*
                    185:  * Display Stats on window
                    186:  */
                    187: static binding _window_classes[] = {
                    188:        { InputOutput, "InputOutput" },
                    189:        { InputOnly, "InputOnly" },
                    190:         { 0, 0 } };
                    191: 
                    192: static binding _map_states[] = {
                    193:        { IsUnmapped, "IsUnMapped" },
                    194:        { IsUnviewable, "IsUnviewable" },
                    195:        { IsViewable, "IsViewable" },
                    196:        { 0, 0 } };
                    197: 
                    198: Display_Stats_Info(window)
                    199:      Window window;
                    200: {
                    201:   XWindowAttributes win_attributes;
                    202: 
                    203:   if (!XGetWindowAttributes(dpy, window, &win_attributes))
                    204:     Fatal_Error("Can't get window attributes.");
                    205: 
                    206:   printf("\n         ==> Upper left X: %d\n", win_attributes.x);
                    207:   printf("         ==> Upper left Y: %d\n", win_attributes.y);
                    208:   printf("         ==> Width: %d\n", win_attributes.width);
                    209:   printf("         ==> Height: %d\n", win_attributes.height);
                    210:   printf("         ==> Depth: %d\n", win_attributes.depth);
                    211:   printf("         ==> Border width: %d\n", win_attributes.border_width);
                    212:   printf("         ==> Window class: %s\n", Lookup(win_attributes.class,
                    213:                                                   _window_classes));
                    214:   printf("         ==> Window Map State: %s\n",
                    215:         Lookup(win_attributes.map_state, _map_states));
                    216: }
                    217: 
                    218: 
                    219: /*
                    220:  * Display bits info:
                    221:  */
                    222: static binding _gravities[] = {
                    223:        { UnmapGravity, "UnMapGravity" },      /* WARNING: both of these have*/
                    224:        { ForgetGravity, "ForgetGravity" },    /* the same value - see code */
                    225:        { NorthWestGravity, "NorthWestGravity" },
                    226:        { NorthGravity, "NorthGravity" },
                    227:        { NorthEastGravity, "NorthEastGravity" },
                    228:        { WestGravity, "WestGravity" },
                    229:        { CenterGravity, "CenterGravity" },
                    230:        { EastGravity, "EastGravity" },
                    231:        { SouthWestGravity, "SouthWestGravity" },
                    232:        { SouthGravity, "SouthGravity" },
                    233:        { SouthEastGravity, "SouthEastGravity" },
                    234:        { StaticGravity, "StaticGravity" },
                    235:        { 0, 0 } };
                    236: 
                    237: static binding _backing_store_hint[] = {
                    238:        { NotUseful, "NotUseful" },
                    239:        { WhenMapped, "WhenMapped" },
                    240:        { Always, "Always" },
                    241:        { 0, 0 } };
                    242: 
                    243: static binding _bool[] = {
                    244:        { 0, "No" },
                    245:        { 1, "Yes" },
                    246:        { 0, 0 } };
                    247: 
                    248: Display_Bits_Info(window)
                    249:      Window window;
                    250: {
                    251:   XWindowAttributes win_attributes;
                    252: 
                    253:   if (!XGetWindowAttributes(dpy, window, &win_attributes))
                    254:     Fatal_Error("Can't get window attributes.");
                    255: 
                    256:   printf("\n         ==> Bit gravity: %s\n",
                    257:         Lookup(win_attributes.bit_gravity, _gravities+1));
                    258:   printf("         ==> Window gravity: %s\n",
                    259:         Lookup(win_attributes.win_gravity, _gravities));
                    260:   printf("         ==> Backing-store hint: %s\n",
                    261:         Lookup(win_attributes.backing_store, _backing_store_hint));
                    262:   printf("         ==> Backing-planes to be preserved: 0x%x\n",
                    263:         win_attributes.backing_planes);
                    264:   printf("         ==> Backing pixel: %d\n", win_attributes.backing_pixel);
                    265:   printf("         ==> Save-under?: %s\n",
                    266:         Lookup(win_attributes.save_under, _bool));
                    267: }
                    268: 
                    269: 
                    270: /*
                    271:  * Routine to display all events in an event mask
                    272:  */
                    273: static binding _event_mask_names[] = {
                    274:        { KeyPressMask, "KeyPress" },
                    275:        { KeyReleaseMask, "KeyRelease" },
                    276:        { ButtonPressMask, "ButtonPress" },
                    277:        { ButtonReleaseMask, "ButtonRelease" },
                    278:        { EnterWindowMask, "EnterWindow" },
                    279:        { LeaveWindowMask, "LeaveWindow" },
                    280:        { PointerMotionMask, "PointerMotion" },
                    281:        { PointerMotionHintMask, "PointerMotionHint" },
                    282:        { Button1MotionMask, "Button1Motion" },
                    283:        { Button2MotionMask, "Button2Motion" },
                    284:        { Button3MotionMask, "Button3Motion" },
                    285:        { Button4MotionMask, "Button4Motion" },
                    286:        { Button5MotionMask, "Button5Motion" },
                    287:        { ButtonMotionMask, "ButtonMotion" },
                    288:        { KeymapStateMask, "KeymapState" },
                    289:        { ExposureMask, "Exposure" },
                    290:        { VisibilityChangeMask, "VisibilityChange" },
                    291:        { StructureNotifyMask, "StructureNotify" },
                    292:        { ResizeRedirectMask, "ResizeRedirect" },
                    293:        { SubstructureNotifyMask, "SubstructureNotify" },
                    294:        { SubstructureRedirectMask, "SubstructureRedirect" },
                    295:        { FocusChangeMask, "FocusChange" },
                    296:        { PropertyChangeMask, "PropertyChange" },
                    297:        { ColormapChangeMask, "ColormapChange" },
                    298:        { OwnerGrabButtonMask, "OwnerGrabButton" },
                    299:        { 0, 0 } };
                    300: 
                    301: Display_Event_Mask(mask)
                    302:      long mask;
                    303: {
                    304:   long bit, bit_mask;
                    305: 
                    306:   for (bit=0, bit_mask=1; bit<sizeof(long)*8; bit++, bit_mask <<= 1)
                    307:     if (mask & bit_mask)
                    308:       printf("             ==> %s\n",
                    309:             Lookup(bit_mask, _event_mask_names));
                    310: }
                    311: 
                    312: 
                    313: /*
                    314:  * Display info on events
                    315:  */
                    316: Display_Events_Info(window)
                    317:      Window window;
                    318: {
                    319:   XWindowAttributes win_attributes;
                    320: 
                    321:   if (!XGetWindowAttributes(dpy, window, &win_attributes))
                    322:     Fatal_Error("Can't get window attributes.");
                    323: 
                    324:   printf("\n         ==> Someone wants these events:\n");
                    325:   Display_Event_Mask(win_attributes.all_event_masks);
                    326: 
                    327:   printf("         ==> Do not prograte these events:\n");
                    328:   Display_Event_Mask(win_attributes.do_not_propagate_mask);
                    329: 
                    330:   printf("         ==> Overide redirection?: %s\n",
                    331:         Lookup(win_attributes.override_redirect, _bool));
                    332: }
                    333: 
                    334: 
                    335:   /* left out visual stuff */
                    336:   /* left out colormap */
                    337:   /* left out map_installed */
                    338: 
                    339: 
                    340: /*
                    341:  * Display root, parent, and children window id's of window
                    342:  */
                    343: Display_Tree_Info(window)
                    344:      Window window;
                    345: {
                    346:   int i;
                    347:   Window root_win, parent_win;
                    348:   int num_children;
                    349:   Window *child_list;
                    350:   
                    351:   if (!XQueryTree(dpy, window, &root_win, &parent_win, &child_list,
                    352:                  &num_children))
                    353:     Fatal_Error("Can't query window tree.");
                    354: 
                    355:   printf("\n         ==> Root window id:");
                    356:   Display_Window_Id(root_win);
                    357:   printf("         ==> Parent window id:");
                    358:   Display_Window_Id(parent_win);
                    359: 
                    360:   printf("         ==> Number of children: %d\n", num_children);
                    361: 
                    362:   for (i = num_children - 1; i >= 0; i--) {
                    363:     printf("             ==> Child window id:"); 
                    364:     Display_Window_Id(child_list[i]);
                    365:   }
                    366: 
                    367:   free(child_list);
                    368: }
                    369: 
                    370: 
                    371: /*
                    372:  * Display a set of size hints
                    373:  */
                    374: Display_Hints(hints)
                    375:      XSizeHints hints;
                    376: {
                    377:        long flags;
                    378: 
                    379:        flags = hints.flags;
                    380:        
                    381:        if (flags & USPosition)
                    382:          printf("             ==> User supplied location: %d, %d\n",
                    383:                 hints.x, hints.y);
                    384: 
                    385:        if (flags & PPosition)
                    386:          printf("             ==> Program supplied location: %d, %d\n",
                    387:                 hints.x, hints.y);
                    388: 
                    389:        if (flags & USSize)
                    390:          printf("             ==> User supplied size: %d by %d\n",
                    391:                 hints.width, hints.height);
                    392: 
                    393:        if (flags & PSize)
                    394:          printf("             ==> Program supplied size: %d by %d\n",
                    395:                 hints.width, hints.height);
                    396: 
                    397:        if (flags & PMinSize)
                    398:          printf("             ==> Program supplied minimum size: %d by %d\n",
                    399:                 hints.min_width, hints.min_height);
                    400: 
                    401:        if (flags & PMaxSize)
                    402:          printf("             ==> Program supplied maximum size: %d by %d\n",
                    403:                 hints.max_width, hints.max_height);
                    404: 
                    405:        if (flags & PResizeInc) {
                    406:          printf("             ==> Program supplied x resize increment: %d\n",
                    407:                 hints.width_inc);
                    408:          printf("             ==> Program supplied y resize increment: %d\n",
                    409:                 hints.height_inc);
                    410:         }
                    411: 
                    412:        if (flags & PAspect) {
                    413:          printf("             ==> Program supplied min aspect ratio: %d/%d\n",
                    414:                 hints.min_aspect.x, hints.min_aspect.y);
                    415:          printf("             ==> Program supplied max aspect ratio: %d/%d\n",
                    416:                 hints.max_aspect.x, hints.max_aspect.y);
                    417:         }
                    418: }
                    419: 
                    420: 
                    421: /*
                    422:  * Display Size Hints info
                    423:  */
                    424: Display_Size_Hints(window)
                    425:      Window window;
                    426: {
                    427:        XSizeHints hints;
                    428: 
                    429:        if (!XGetNormalHints(dpy, window, &hints))
                    430:          printf("\n         ==> No normal window size hints defined\n");
                    431:        else {
                    432:                printf("\n         ==> Normal window size hints:\n\n");
                    433:                Display_Hints(hints);
                    434:        }
                    435: 
                    436:        if (!XGetZoomHints(dpy, window, &hints))
                    437:          printf("\n         ==> No zoom window size hints defined\n");
                    438:        else {
                    439:                printf("\n         ==> Zoom window size hints:\n\n");
                    440:                Display_Hints(hints);
                    441:        }
                    442: }
                    443: 
                    444: 
                    445: /*
                    446:  * Display Window Manager Info
                    447:  */
                    448: static binding _state_hints[] = {
                    449:        { DontCareState, "Don't Care State" },
                    450:        { NormalState, "Normal State" },
                    451:        { ZoomState, "Zoomed State" },
                    452:        { IconicState, "Iconic State" },
                    453:        { InactiveState, "Inactive State" },
                    454:        { 0, 0 } };
                    455: 
                    456: Display_WM_Info(window)
                    457:      Window window;
                    458: {
                    459:         XWMHints *wmhints;
                    460:        long flags;
                    461: 
                    462:        wmhints = XGetWMHints(dpy, window);
                    463:        if (!wmhints) {
                    464:                printf("\n         ==> No window manager hints defined\n");
                    465:                return;
                    466:        }
                    467:        flags = wmhints->flags;
                    468: 
                    469:        printf("\n         ==> Window manager hints:\n\n");
                    470: 
                    471:        if (flags & InputHint)
                    472:          printf("             ==> Application accepts input?  %s\n",
                    473:                 Lookup(wmhints->input, _bool));
                    474: 
                    475:        if (flags & IconWindowHint) {
                    476:                printf("             ==> Icon window id:");
                    477:                Display_Window_Id(wmhints->icon_window);
                    478:        }
                    479: 
                    480:        if (flags & IconPositionHint)
                    481:          printf("             ==> Initial icon position: %d, %d\n",
                    482:                 wmhints->icon_x, wmhints->icon_y);
                    483: 
                    484:        if (flags & StateHint)
                    485:          printf("             ==> Initial state is %s\n",
                    486:                 Lookup(wmhints->initial_state, _state_hints));
                    487: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.