1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* $XFree86$ */
/*
* Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
*
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation on the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Authors:
* Rickard E. (Rik) Faith <faith@redhat.com>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/extensions/dmxext.h>
static void indent(int level)
{
int i;
for (i = 0; i < level; i++) printf(" ");
}
static void print_window_id(const char *displayName, Display *display,
Window window, int level, int child)
{
char *name;
if (!XFetchName(display, window, &name)) name = NULL;
indent(level);
if (child) printf("(%d) ", child);
printf("%s window 0x%08lx: %s%s\n",
displayName,
(long unsigned)window,
name ? name : "",
(window == DefaultRootWindow(display))
? " (DMX root window)" : "");
if (name) XFree(name);
}
static void print_info(Display *display, Window window, int level, int child)
{
DMXWindowAttributes winfo[128];
int count;
int i;
if (!DMXGetWindowAttributes(display, window, &count, 128, winfo)) {
printf("Could not get window information for 0x%08lx\n",
(long unsigned)window);
exit(-2);
}
printf("\n");
print_window_id("DMX", display, window, level, child);
for (i = 0; i < count; i++) {
DMXScreenAttributes sinfo;
Display *backend;
/* This could also be cached -- the information doesn't change. */
if (!DMXGetScreenAttributes(display, winfo[i].screen, &sinfo)) {
printf("Could not get screen information for screen %d\n", i);
exit(-2);
}
if (!(backend = XOpenDisplay(sinfo.displayName))) {
printf("Cannot open backend display %s\n", sinfo.displayName);
exit(-2);
}
XCloseDisplay(backend);
indent(level+1);
printf("%s window 0x%08lx: %dx%d%+d%+d",
sinfo.displayName,
(long unsigned)winfo[i].window,
winfo[i].pos.width, winfo[i].pos.height,
winfo[i].pos.x, winfo[i].pos.y);
if (!winfo[i].vis.width
&& !winfo[i].vis.height
&& !winfo[i].vis.x
&& !winfo[i].vis.y) printf(" not visible\n");
else if (winfo[i].vis.width == winfo[i].pos.width
&& winfo[i].vis.height == winfo[i].pos.height) {
printf( " %+d%+d\n", winfo[i].vis.x, winfo[i].vis.y);
} else {
printf( " %dx%d%+d%+d\n",
winfo[i].vis.width, winfo[i].vis.height,
winfo[i].vis.x, winfo[i].vis.y);
}
}
}
static void print_tree(Display *display, Window window, int level, int child)
{
Window root, parent;
Window *list;
unsigned int count;
unsigned int i;
print_info(display, window, level, child);
if (!XQueryTree(display, window, &root, &parent, &list, &count)) {
printf("Cannot query window tree for 0x%08lx\n",
(long unsigned)window);
exit(-3);
}
if (count) {
indent(level+1);
printf("%d child%s:\n", count, count > 1 ? "ren" : "");
for (i = 0; i < count; i++) {
print_tree(display, list[i], level+1, i+1);
}
}
}
static const char *core(DMXInputAttributes *iinfo)
{
if (iinfo->isCore) return "core";
else if (iinfo->sendsCore) return "extension (sends core)";
else return "extension";
}
int main(int argc, char **argv)
{
Display *display = NULL;
Window window = 0;
int event_base;
int error_base;
int major_version, minor_version, patch_version;
DMXScreenAttributes sinfo;
DMXInputAttributes iinfo;
int count;
int i;
if (argc == 2 || argc == 3) {
if (!(display = XOpenDisplay(argv[1]))) {
printf("Cannot open display %s\n", argv[1]);
return -1;
}
if (argc == 3) window = strtol(argv[2], NULL, 0);
} else {
printf("Usage: %s display [windowid]\n", argv[0]);
return -1;
}
if (!display && !(display = XOpenDisplay(NULL))) {
printf("Cannot open default display\n");
return -1;
}
if (!DMXQueryExtension(display, &event_base, &error_base)) {
printf("DMX extension not present\n");
return -1;
}
printf("DMX extension present: event_base = %d, error_base = %d\n",
event_base, error_base);
if (!DMXQueryVersion(display,
&major_version, &minor_version, &patch_version)) {
printf("Could not get extension version\n");
return -1;
}
printf("Extension version: %d.%d patch %d\n",
major_version, minor_version, patch_version);
if (!DMXGetScreenCount(display, &count)) {
printf("Could not get screen count\n");
return -1;
}
printf("Screen count = %d\n", count);
for (i = 0; i < count; i++) {
if (!DMXGetScreenAttributes(display, i, &sinfo)) {
printf("Could not get screen information for %d\n", i);
return -1;
}
printf("%d: %s %ux%u+%d+%d %d @%dx%d (root: %dx%d%+d%+d)\n",
i, sinfo.displayName,
sinfo.screenWindowWidth, sinfo.screenWindowHeight,
sinfo.screenWindowXoffset, sinfo.screenWindowYoffset,
sinfo.logicalScreen,
sinfo.rootWindowXorigin, sinfo.rootWindowYorigin,
sinfo.rootWindowWidth, sinfo.rootWindowHeight,
sinfo.rootWindowXoffset, sinfo.rootWindowYoffset);
}
if (major_version == 1 && minor_version >= 1) {
if (!DMXGetInputCount(display, &count)) {
printf("Could not get input count\n");
return -1;
}
printf("Input count = %d\n", count);
for (i = 0; i < count; i++) {
if (!DMXGetInputAttributes(display, i, &iinfo)) {
printf("Could not get input information for id %d\n", i);
return -1;
}
switch (iinfo.inputType) {
case DMXLocalInputType:
printf(" %2d local %-20.20s %s\n", i, "", core(&iinfo));
break;
case DMXConsoleInputType:
printf(" %2d console %-20.20s %s\n",
i, iinfo.name, core(&iinfo));
break;
case DMXBackendInputType:
printf(" %2d backend %-20.20s id=%2d screen=%2d %s\n",
i, iinfo.name, iinfo.physicalId, iinfo.physicalScreen,
core(&iinfo));
break;
}
}
}
if (window) print_info(display, window, 0, 0);
else print_tree(display, DefaultRootWindow(display), 0, 0);
XCloseDisplay(display);
return 0;
}
|