|
|
1.1 root 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.6 86/11/19 19:59:23 jg 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) {
99: fprintf(stderr, "%s: Can't open display '%s'\n",
100: argv[0], XDisplayName(display));
101: exit(1);
102: }
103:
104: /*
105: * Store the target cursor incase we need it.
106: */
107: cursor = XCreateCursor(
108: target_width, target_height,
109: target_bits, target_mask_bits,
110: 8, 8,
111: BlackPixel, WhitePixel,
112: GXcopy
113: );
114: if (cursor == FAILURE) {
115: Error("Error occured while trying to store target cursor.");
116: }
117:
118: /*
119: * Depending on the state of the root and id switches, get the
120: * target window from the user.
121: */
122: if (root_switch) {
123: /*
124: * The root window selected on the command line.
125: */
126: target_win = RootWindow;
127: }
128: else {
129: if (id != NULL) {
130: /*
131: * A window id was provided on the command line.
132: */
133: (void) sscanf(id, "0x%x", &target_win);
134: if (target_win == 0) {
135: /*
136: * Then the target was entered in decimal.
137: */
138: (void) sscanf(id, "%d", &target_win);
139: if (target_win == 0) {
140: Error("Invalid window id format.");
141: }
142: }
143: }
144: else {
145: /*
146: * No selection was provided on the command line.
147: * Allow the user to select a window with the mouse.
148: */
149: status = XGrabMouse(RootWindow, cursor, ButtonPressed);
150: if (status == FAILURE) Error("Can't grab the mouse.");
151:
152: printf("\n");
153: printf("xwininfo ==> Please select the window you wish\n");
154: printf(" ==> information on by clicking the\n");
155: printf(" ==> mouse in that window.\n");
156:
157: XNextEvent(&event);
158: target_win = event.subwindow;
159:
160: XUngrabMouse();
161:
162: if (target_win == 0) {
163: /*
164: * The user must have indicated the root window.
165: */
166: target_win = RootWindow;
167: }
168: }
169: }
170:
171: status = XQueryMouse(RootWindow, &mse_x, &mse_y, &temp_win);
172: if (status == FAILURE) Error("Can't query mouse on Root Window.");
173: if (target_win == RootWindow){
174: rel_mse_x = mse_x;
175: rel_mse_y = mse_y;
176: }
177: else {
178: status = XQueryMouse(target_win, &rel_mse_x, &rel_mse_y, &temp_win);
179: if (status == FAILURE) Error("Can't query mouse on target window.");
180: }
181:
182: status = XQueryWindow(RootWindow, &win_info);
183: if (status == FAILURE) Error("Couldn't query root window.");
184: root_w = win_info.width;
185: root_h = win_info.height;
186:
187: status = XQueryWindow(target_win, &win_info);
188: if (status == FAILURE) Error("Couldn't query target window.");
189: lr_rel_x = root_w - (win_info.x + win_info.width +
190: (win_info.bdrwidth << 1));
191: lr_rel_y = root_h - (win_info.y + win_info.height +
192: (win_info.bdrwidth << 1));
193:
194: status = XFetchName(target_win, &win_name);
195: if (status == FAILURE) Error("Can't fetch window name.");
196:
197: status = XQueryTree(target_win, &parent_win, &num_children, &child_list);
198: if (status == FAILURE) Error("Can't query window tree.");
199:
200: (void) XGetResizeHint(target_win, &w0, &h0, &w_inc, &h_inc);
201:
202: printf("\nxwininfo ==> Window name: '%s'\n", win_name);
203: printf(" ==> Window id:");
204: printf(win_fmt, target_win);
205: printf(" ==> Parent window id:");
206: printf(win_fmt, parent_win);
207: printf(" ==> Number of children: %d\n", num_children);
208: if (children) {
209: for (i = num_children - 1; i >= 0; i--) {
210: printf(" ==> Child window id:");
211: printf(win_fmt, child_list[i]);
212: }
213: }
214: printf(" ==> Associated window id:");
215: printf(win_fmt, win_info.assoc_wind);
216: printf(" ==> Window type: ");
217: switch (win_info.type) {
218: case IsTransparent:
219: printf("IsTransparent\n");
220: break;
221: case IsOpaque:
222: printf("IsOpaque\n");
223: break;
224: case IsIcon:
225: printf("IsIcon\n");
226: break;
227: default:
228: printf("Unknown %d?\n", win_info.type);
229: break;
230: }
231: printf(" ==> Window state: ");
232: switch (win_info.mapped) {
233: case IsMapped:
234: printf("IsMapped\n");
235: break;
236: case IsUnmapped:
237: printf("IsUnmapped\n");
238: break;
239: case IsInvisible:
240: printf("IsInvisible\n");
241: break;
242: default:
243: printf("Unknown %d?\n", win_info.mapped);
244: break;
245: }
246: printf(" ==> Upper left X: %d\n", win_info.x);
247: printf(" ==> Upper left Y: %d\n", win_info.y);
248: printf(" ==> Width: %d\n", win_info.width);
249: printf(" ==> Height: %d\n", win_info.height);
250: printf(" ==> Border width: %d\n", win_info.bdrwidth);
251: printf(" ==> Geometry specification:\n");
252: printf(" ==> Upper left =%dx%d+%d+%d\n",
253: win_info.width, win_info.height, win_info.x, win_info.y);
254: printf(" ==> Lower right =%dx%d-%d-%d\n",
255: win_info.width, win_info.height, lr_rel_x, lr_rel_y);
256: printf(" ==> Resize base width: %d\n", w0);
257: printf(" ==> Resize base height: %d\n", h0);
258: printf(" ==> Resize width increment: %d\n", w_inc);
259: printf(" ==> Resize height increment: %d\n", h_inc);
260: printf(" ==> Root absolute mouse X Position: %d\n", mse_x);
261: printf(" ==> Root absolute mouse Y Position: %d\n", mse_y);
262: printf(" ==> Target relative mouse X Position: %d\n", rel_mse_x);
263: printf(" ==> Target relative mouse Y Position: %d\n", rel_mse_y);
264: printf("\n");
265:
266: exit(0);
267: }
268:
269:
270: /*
271: * Report the syntax for calling xwininfo.
272: */
273: Syntax(call)
274: char *call;
275: {
276: fprintf(stderr, "\n");
277: fprintf(stderr, "Usage: %s [-children] [-help] [-id <id>] [-int] ", call);
278: fprintf(stderr, "[-root] [[host]:vs]\n\n");
279: exit(0);
280: }
281:
282:
283: /*
284: * Error - Fatal xwininfo error.
285: */
286: Error(string)
287: char *string; /* Error description string. */
288: {
289: fprintf(stderr, "\nxwininfo: %s", string);
290: fprintf(stderr, "\n\n");
291:
292: if (errno != 0) {
293: perror("xwininfo");
294: fprintf(stderr, "\n");
295: }
296:
297: exit(1);
298: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.