3
* Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
7
* Permission is hereby granted, free of charge, to any person obtaining
8
* a copy of this software and associated documentation files (the
9
* "Software"), to deal in the Software without restriction, including
10
* without limitation on the rights to use, copy, modify, merge,
11
* publish, distribute, sublicense, and/or sell copies of the Software,
12
* and to permit persons to whom the Software is furnished to do so,
13
* subject to the following conditions:
15
* The above copyright notice and this permission notice (including the
16
* next paragraph) shall be included in all copies or substantial
17
* portions of the Software.
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
23
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
* Rickard E. (Rik) Faith <faith@redhat.com>
38
#include <X11/extensions/dmxext.h>
40
static void indent(int level)
43
for (i = 0; i < level; i++) printf(" ");
46
static void print_window_id(const char *displayName, Display *display,
47
Window window, int level, int child)
51
if (!XFetchName(display, window, &name)) name = NULL;
53
if (child) printf("(%d) ", child);
54
printf("%s window 0x%08lx: %s%s\n",
56
(long unsigned)window,
58
(window == DefaultRootWindow(display))
59
? " (DMX root window)" : "");
60
if (name) XFree(name);
63
static void print_info(Display *display, Window window, int level, int child)
65
DMXWindowAttributes winfo[128];
69
if (!DMXGetWindowAttributes(display, window, &count, 128, winfo)) {
70
printf("Could not get window information for 0x%08lx\n",
71
(long unsigned)window);
75
print_window_id("DMX", display, window, level, child);
76
for (i = 0; i < count; i++) {
77
DMXScreenAttributes sinfo;
80
/* This could also be cached -- the information doesn't change. */
81
if (!DMXGetScreenAttributes(display, winfo[i].screen, &sinfo)) {
82
printf("Could not get screen information for screen %d\n", i);
85
if (!(backend = XOpenDisplay(sinfo.displayName))) {
86
printf("Cannot open backend display %s\n", sinfo.displayName);
89
XCloseDisplay(backend);
92
printf("%s window 0x%08lx: %dx%d%+d%+d",
94
(long unsigned)winfo[i].window,
95
winfo[i].pos.width, winfo[i].pos.height,
96
winfo[i].pos.x, winfo[i].pos.y);
97
if (!winfo[i].vis.width
98
&& !winfo[i].vis.height
100
&& !winfo[i].vis.y) printf(" not visible\n");
101
else if (winfo[i].vis.width == winfo[i].pos.width
102
&& winfo[i].vis.height == winfo[i].pos.height) {
103
printf( " %+d%+d\n", winfo[i].vis.x, winfo[i].vis.y);
105
printf( " %dx%d%+d%+d\n",
106
winfo[i].vis.width, winfo[i].vis.height,
107
winfo[i].vis.x, winfo[i].vis.y);
112
static void print_tree(Display *display, Window window, int level, int child)
119
print_info(display, window, level, child);
121
if (!XQueryTree(display, window, &root, &parent, &list, &count)) {
122
printf("Cannot query window tree for 0x%08lx\n",
123
(long unsigned)window);
129
printf("%d child%s:\n", count, count > 1 ? "ren" : "");
130
for (i = 0; i < count; i++) {
131
print_tree(display, list[i], level+1, i+1);
136
static const char *core(DMXInputAttributes *iinfo)
138
if (iinfo->isCore) return "core";
139
else if (iinfo->sendsCore) return "extension (sends core)";
140
else return "extension";
143
int main(int argc, char **argv)
145
Display *display = NULL;
149
int major_version, minor_version, patch_version;
150
DMXScreenAttributes sinfo;
151
DMXInputAttributes iinfo;
155
if (argc == 2 || argc == 3) {
156
if (!(display = XOpenDisplay(argv[1]))) {
157
printf("Cannot open display %s\n", argv[1]);
160
if (argc == 3) window = strtol(argv[2], NULL, 0);
162
printf("Usage: %s display [windowid]\n", argv[0]);
166
if (!display && !(display = XOpenDisplay(NULL))) {
167
printf("Cannot open default display\n");
171
if (!DMXQueryExtension(display, &event_base, &error_base)) {
172
printf("DMX extension not present\n");
175
printf("DMX extension present: event_base = %d, error_base = %d\n",
176
event_base, error_base);
178
if (!DMXQueryVersion(display,
179
&major_version, &minor_version, &patch_version)) {
180
printf("Could not get extension version\n");
183
printf("Extension version: %d.%d patch %d\n",
184
major_version, minor_version, patch_version);
186
if (!DMXGetScreenCount(display, &count)) {
187
printf("Could not get screen count\n");
190
printf("Screen count = %d\n", count);
192
for (i = 0; i < count; i++) {
193
if (!DMXGetScreenAttributes(display, i, &sinfo)) {
194
printf("Could not get screen information for %d\n", i);
197
printf("%d: %s %ux%u+%d+%d %d @%dx%d (root: %dx%d%+d%+d)\n",
198
i, sinfo.displayName,
199
sinfo.screenWindowWidth, sinfo.screenWindowHeight,
200
sinfo.screenWindowXoffset, sinfo.screenWindowYoffset,
202
sinfo.rootWindowXorigin, sinfo.rootWindowYorigin,
203
sinfo.rootWindowWidth, sinfo.rootWindowHeight,
204
sinfo.rootWindowXoffset, sinfo.rootWindowYoffset);
207
if (major_version == 1 && minor_version >= 1) {
208
if (!DMXGetInputCount(display, &count)) {
209
printf("Could not get input count\n");
212
printf("Input count = %d\n", count);
213
for (i = 0; i < count; i++) {
214
if (!DMXGetInputAttributes(display, i, &iinfo)) {
215
printf("Could not get input information for id %d\n", i);
218
switch (iinfo.inputType) {
219
case DMXLocalInputType:
220
printf(" %2d local %-20.20s %s\n", i, "", core(&iinfo));
222
case DMXConsoleInputType:
223
printf(" %2d console %-20.20s %s\n",
224
i, iinfo.name, core(&iinfo));
226
case DMXBackendInputType:
227
printf(" %2d backend %-20.20s id=%2d screen=%2d %s\n",
228
i, iinfo.name, iinfo.physicalId, iinfo.physicalScreen,
235
if (window) print_info(display, window, 0, 0);
236
else print_tree(display, DefaultRootWindow(display), 0, 0);
238
XCloseDisplay(display);