1: #include <X/mit-copyright.h>
   2: 
   3: /* Copyright 1985, Massachusetts Institute of Technology */
   4: 
   5: /*
   6:  * xwininfo.c	- MIT Project Athena, X Window system window
   7:  *		  information utility.
   8:  *
   9:  *	This program will report all relavent information
  10:  *	about a specific window.
  11:  *
  12:  *  Author:	Tony Della Fera, DEC
  13:  *		27-Nov-84
  14:  */
  15: #ifndef lint
  16: static char *rcsid_xhost_c = "$Header: xwininfo.c,v 10.5 86/02/01 16:08:18 tony Rel $";
  17: #endif
  18: 
  19: #include <X/Xlib.h>
  20: #include <stdio.h>
  21: #include "../cursors/target.cursor"
  22: #include "../cursors/target_mask.cursor"
  23: #include <strings.h>
  24: 
  25: typedef enum _bool {FALSE, TRUE} Bool;
  26: 
  27: #define MAX(a, b) (a) > (b) ? (a) : (b)
  28: #define MIN(a, b) (a) < (b) ? (a) : (b)
  29: #define ABS(a) (a) < 0 ? -(a) : (a)
  30: 
  31: #define FAILURE 0
  32: 
  33: char *index();
  34: 
  35: extern int errno;
  36: 
  37: main(argc, argv)
  38:     int argc;
  39:     char **argv;
  40: {
  41:     int mse_x, mse_y;
  42:     int rel_mse_x, rel_mse_y;
  43:     int w0, h0, w_inc, h_inc;
  44:     int lr_rel_x, lr_rel_y;
  45:     int root_w, root_h;
  46:     int num_children;
  47:     int status;
  48:     char display[256];
  49:     char *strind = NULL;
  50:     char *win_name = NULL;
  51:     char *id = NULL;
  52:     char *win_fmt = " 0x%x\n";
  53:     Bool children = FALSE;
  54:     Bool root_switch = FALSE;
  55:     register int i;
  56: 
  57:     Window target_win;
  58:     Window temp_win;
  59:     Window parent_win;
  60:     Window *child_list;
  61:     WindowInfo win_info;
  62:     Cursor cursor;
  63:     XButtonPressedEvent event;
  64: 
  65:     display[0] = '\0';
  66: 
  67:     for (i = 1; i < argc; i++) {
  68:     strind = index(argv[i], ':');
  69:     if (strind != NULL) {
  70:         (void) strncpy(display, argv[i], sizeof(display));
  71:         continue;
  72:     }
  73:     strind = index (argv [i], '-');
  74:     if (strind == NULL) Syntax(argv[0]);
  75:     if (strncmp(argv [i], "-children", 9) == 0) {
  76:         children = TRUE;
  77:         continue;
  78:     }
  79:     if (strncmp(argv [i], "-help", 5) == 0) {
  80:         Syntax(argv[0]);
  81:     }
  82:     if (strncmp(argv [i], "-id", 3) == 0) {
  83:         if (++i >= argc) Syntax(argv[0]);
  84:         id = argv[i];
  85:         continue;
  86:     }
  87:     if (strncmp(argv [i], "-int", 4) == 0) {
  88:         win_fmt = " %d\n";
  89:         continue;
  90:     }
  91:     if (strncmp(argv [i], "-root", 5) == 0) {
  92:         root_switch = TRUE;
  93:         continue;
  94:     }
  95:     Syntax(argv[0]);
  96:     }
  97: 
  98:     if (XOpenDisplay(display) == NULL) Error("Couldn't Open display.");
  99: 
 100:     /*
 101:      * Store the target cursor incase we need it.
 102:      */
 103:     cursor = XCreateCursor(
 104:         target_width, target_height,
 105:         target_bits, target_mask_bits,
 106:     8, 8,
 107:     BlackPixel, WhitePixel,
 108:     GXcopy
 109:     );
 110:     if (cursor == FAILURE) {
 111:     Error("Error occured while trying to store target cursor.");
 112:     }
 113: 
 114:     /*
 115:      * Depending on the state of the root and id switches, get the
 116:      * target window from the user.
 117:      */
 118:     if (root_switch) {
 119:     /*
 120: 	 * The root window selected on the command line.
 121: 	 */
 122:     target_win = RootWindow;
 123:     }
 124:     else {
 125:     if (id != NULL) {
 126:         /*
 127: 	     * A window id was provided on the command line.
 128: 	     */
 129:         (void) sscanf(id, "0x%x", &target_win);
 130:         if (target_win == 0) {
 131:         /*
 132: 		 * Then the target was entered in decimal.
 133: 		 */
 134:         (void) sscanf(id, "%d", &target_win);
 135:         if (target_win == 0) {
 136:             Error("Invalid window id format.");
 137:         }
 138:         }
 139:     }
 140:     else {
 141:         /*
 142: 	     * No selection was provided on the command line.
 143: 	     * Allow the user to select a window with the mouse.
 144: 	     */
 145:         status = XGrabMouse(RootWindow, cursor, ButtonPressed);
 146:         if (status == FAILURE) Error("Can't grab the mouse.");
 147: 
 148:         printf("\n");
 149:         printf("xwininfo ==> Please select the window you wish\n");
 150:         printf("         ==> information on by clicking the\n");
 151:         printf("         ==> mouse in that window.\n");
 152: 
 153:         XNextEvent(&event);
 154:         target_win = event.subwindow;
 155: 
 156:         XUngrabMouse();
 157: 
 158:         if (target_win == 0) {
 159:         /*
 160: 		 * The user must have indicated the root window.
 161: 		 */
 162:         target_win = RootWindow;
 163:         }
 164:     }
 165:     }
 166: 
 167:     status = XQueryMouse(RootWindow, &mse_x, &mse_y, &temp_win);
 168:     if (status == FAILURE) Error("Can't query mouse on Root Window.");
 169:     if (target_win == RootWindow){
 170:     rel_mse_x = mse_x;
 171:     rel_mse_y = mse_y;
 172:     }
 173:     else {
 174:     status = XQueryMouse(target_win, &rel_mse_x, &rel_mse_y, &temp_win);
 175:     if (status == FAILURE) Error("Can't query mouse on target window.");
 176:     }
 177: 
 178:     status = XQueryWindow(RootWindow, &win_info);
 179:     if (status == FAILURE) Error("Couldn't query root window.");
 180:     root_w = win_info.width;
 181:     root_h = win_info.height;
 182: 
 183:     status = XQueryWindow(target_win, &win_info);
 184:     if (status == FAILURE) Error("Couldn't query target window.");
 185:     lr_rel_x = root_w - (win_info.x + win_info.width +
 186:     (win_info.bdrwidth << 1));
 187:     lr_rel_y = root_h - (win_info.y + win_info.height +
 188:     (win_info.bdrwidth << 1));
 189: 
 190:     status = XFetchName(target_win, &win_name);
 191:     if (status == FAILURE) Error("Can't fetch window name.");
 192: 
 193:     status = XQueryTree(target_win, &parent_win, &num_children, &child_list);
 194:     if (status == FAILURE) Error("Can't query window tree.");
 195: 
 196:     (void) XGetResizeHint(target_win, &w0, &h0, &w_inc, &h_inc);
 197: 
 198:     printf("\nxwininfo ==> Window name: '%s'\n", win_name);
 199:     printf("         ==> Window id:");
 200:     printf(win_fmt, target_win);
 201:     printf("         ==> Parent window id:");
 202:     printf(win_fmt, parent_win);
 203:     printf("         ==> Number of children: %d\n", num_children);
 204:     if (children) {
 205:         for (i = num_children - 1; i >= 0; i--) {
 206:             printf("             ==> Child window id:");
 207:         printf(win_fmt, child_list[i]);
 208:         }
 209:     }
 210:     printf("         ==> Associated window id:");
 211:     printf(win_fmt, win_info.assoc_wind);
 212:     printf("         ==> Window type: ");
 213:     switch (win_info.type) {
 214:         case IsTransparent:
 215:             printf("IsTransparent\n");
 216:             break;
 217:         case IsOpaque:
 218:             printf("IsOpaque\n");
 219:             break;
 220:         case IsIcon:
 221:             printf("IsIcon\n");
 222:             break;
 223:         default:
 224:             printf("Unknown %d?\n", win_info.type);
 225:             break;
 226:     }
 227:     printf("         ==> Window state: ");
 228:     switch (win_info.mapped) {
 229:         case IsMapped:
 230:             printf("IsMapped\n");
 231:             break;
 232:         case IsUnmapped:
 233:             printf("IsUnmapped\n");
 234:             break;
 235:         case IsInvisible:
 236:             printf("IsInvisible\n");
 237:             break;
 238:         default:
 239:             printf("Unknown %d?\n", win_info.mapped);
 240:             break;
 241:     }
 242:     printf("         ==> Upper left X: %d\n", win_info.x);
 243:     printf("         ==> Upper left Y: %d\n", win_info.y);
 244:     printf("         ==> Width: %d\n", win_info.width);
 245:     printf("         ==> Height: %d\n", win_info.height);
 246:     printf("         ==> Border width: %d\n", win_info.bdrwidth);
 247:     printf("         ==> Geometry specification:\n");
 248:     printf("             ==> Upper left  =%dx%d+%d+%d\n",
 249:     win_info.width, win_info.height, win_info.x, win_info.y);
 250:     printf("             ==> Lower right =%dx%d-%d-%d\n",
 251:     win_info.width, win_info.height, lr_rel_x, lr_rel_y);
 252:     printf("         ==> Resize base width: %d\n", w0);
 253:     printf("         ==> Resize base height: %d\n", h0);
 254:     printf("         ==> Resize width increment: %d\n", w_inc);
 255:     printf("         ==> Resize height increment: %d\n", h_inc);
 256:     printf("         ==> Root absolute mouse X Position: %d\n", mse_x);
 257:     printf("         ==> Root absolute mouse Y Position: %d\n", mse_y);
 258:     printf("         ==> Target relative mouse X Position: %d\n", rel_mse_x);
 259:     printf("         ==> Target relative mouse Y Position: %d\n", rel_mse_y);
 260:     printf("\n");
 261: 
 262:     exit(0);
 263: }
 264: 
 265: 
 266: /*
 267:  * Report the syntax for calling xwininfo.
 268:  */
 269: Syntax(call)
 270:     char *call;
 271: {
 272:     fprintf(stderr, "\n");
 273:     fprintf(stderr, "Usage: %s [-children] [-help] [-id <id>] [-int] ", call);
 274:     fprintf(stderr, "[-root] [[host]:vs]\n\n");
 275:     exit(0);
 276: }
 277: 
 278: 
 279: /*
 280:  * Error - Fatal xwininfo error.
 281:  */
 282: Error(string)
 283:     char *string;   /* Error description string. */
 284: {
 285:     fprintf(stderr, "\nxwininfo: %s", string);
 286:     fprintf(stderr, "\n\n");
 287: 
 288:     if (errno != 0) {
 289:         perror("xwininfo");
 290:         fprintf(stderr, "\n");
 291:     }
 292: 
 293:     exit(1);
 294: }

Defined functions

Error defined in line 282; used 10 times
Syntax defined in line 269; used 4 times
main defined in line 37; never used

Defined variables

rcsid_xhost_c defined in line 16; never used

Defined enum's

_bool defined in line 25; never used

Defined typedef's

Bool defined in line 25; used 2 times

Defined macros

ABS defined in line 29; never used
FAILURE defined in line 31; used 8 times
MAX defined in line 27; never used
MIN defined in line 28; never used
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1588
Valid CSS Valid XHTML 1.0 Strict