~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/dmx/examples/xdmx.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86$ */
 
2
/*
 
3
 * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina.
 
4
 *
 
5
 * All Rights Reserved.
 
6
 *
 
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:
 
14
 *
 
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.
 
18
 *
 
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
 
26
 * SOFTWARE.
 
27
 */
 
28
 
 
29
/*
 
30
 * Authors:
 
31
 *   Rickard E. (Rik) Faith <faith@redhat.com>
 
32
 *
 
33
 */
 
34
 
 
35
#include <stdio.h>
 
36
#include <stdlib.h>
 
37
#include <X11/Xlib.h>
 
38
#include <X11/extensions/dmxext.h>
 
39
 
 
40
static void indent(int level)
 
41
{
 
42
    int i;
 
43
    for (i = 0; i < level; i++) printf("    ");
 
44
}
 
45
 
 
46
static void print_window_id(const char *displayName, Display *display,
 
47
                            Window window, int level, int child)
 
48
{
 
49
    char                 *name;
 
50
    
 
51
    if (!XFetchName(display, window, &name)) name = NULL;
 
52
    indent(level);
 
53
    if (child) printf("(%d) ", child);
 
54
    printf("%s window 0x%08lx: %s%s\n",
 
55
           displayName,
 
56
           (long unsigned)window,
 
57
           name ? name : "",
 
58
           (window == DefaultRootWindow(display))
 
59
           ? " (DMX root window)" : "");
 
60
    if (name) XFree(name);
 
61
}
 
62
 
 
63
static void print_info(Display *display, Window window, int level, int child)
 
64
{
 
65
    DMXWindowAttributes winfo[128];
 
66
    int                 count;
 
67
    int                 i;
 
68
    
 
69
    if (!DMXGetWindowAttributes(display, window, &count, 128, winfo)) {
 
70
        printf("Could not get window information for 0x%08lx\n",
 
71
               (long unsigned)window);
 
72
        exit(-2);
 
73
    }
 
74
    printf("\n");
 
75
    print_window_id("DMX", display, window, level, child);
 
76
    for (i = 0; i < count; i++) {
 
77
        DMXScreenAttributes  sinfo;
 
78
        Display              *backend;
 
79
 
 
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);
 
83
            exit(-2);
 
84
        }
 
85
        if (!(backend = XOpenDisplay(sinfo.displayName))) {
 
86
            printf("Cannot open backend display %s\n", sinfo.displayName);
 
87
            exit(-2);
 
88
        }
 
89
        XCloseDisplay(backend);
 
90
        
 
91
        indent(level+1);
 
92
        printf("%s window 0x%08lx: %dx%d%+d%+d",
 
93
               sinfo.displayName,
 
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
 
99
            && !winfo[i].vis.x
 
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);
 
104
        } else {
 
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);
 
108
        }
 
109
    }
 
110
}
 
111
 
 
112
static void print_tree(Display *display, Window window, int level, int child)
 
113
{
 
114
    Window       root, parent;
 
115
    Window       *list;
 
116
    unsigned int count;
 
117
    unsigned int i;
 
118
 
 
119
    print_info(display, window, level, child);
 
120
    
 
121
    if (!XQueryTree(display, window, &root, &parent, &list, &count)) {
 
122
        printf("Cannot query window tree for 0x%08lx\n",
 
123
               (long unsigned)window);
 
124
        exit(-3);
 
125
    }
 
126
 
 
127
    if (count) {
 
128
        indent(level+1);
 
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);
 
132
        }
 
133
    }
 
134
}
 
135
 
 
136
static const char *core(DMXInputAttributes *iinfo)
 
137
{
 
138
    if (iinfo->isCore)         return "core";
 
139
    else if (iinfo->sendsCore) return "extension (sends core)";
 
140
    else                       return "extension";
 
141
}
 
142
 
 
143
int main(int argc, char **argv)
 
144
{
 
145
    Display              *display = NULL;
 
146
    Window               window   = 0;
 
147
    int                  event_base;
 
148
    int                  error_base;
 
149
    int                  major_version, minor_version, patch_version;
 
150
    DMXScreenAttributes  sinfo;
 
151
    DMXInputAttributes   iinfo;
 
152
    int                  count;
 
153
    int                  i;
 
154
 
 
155
    if (argc == 2 || argc == 3) {
 
156
        if (!(display = XOpenDisplay(argv[1]))) {
 
157
            printf("Cannot open display %s\n", argv[1]);
 
158
            return -1;
 
159
        }
 
160
        if (argc == 3) window = strtol(argv[2], NULL, 0);
 
161
    } else {
 
162
        printf("Usage: %s display [windowid]\n", argv[0]);
 
163
        return -1;
 
164
    }
 
165
 
 
166
    if (!display && !(display = XOpenDisplay(NULL))) {
 
167
        printf("Cannot open default display\n");
 
168
        return -1;
 
169
    }
 
170
 
 
171
    if (!DMXQueryExtension(display, &event_base, &error_base)) {
 
172
        printf("DMX extension not present\n");
 
173
        return -1;
 
174
    }
 
175
    printf("DMX extension present: event_base = %d, error_base = %d\n",
 
176
           event_base, error_base);
 
177
 
 
178
    if (!DMXQueryVersion(display,
 
179
                         &major_version, &minor_version, &patch_version)) {
 
180
        printf("Could not get extension version\n");
 
181
        return -1;
 
182
    }
 
183
    printf("Extension version: %d.%d patch %d\n",
 
184
           major_version, minor_version, patch_version);
 
185
 
 
186
    if (!DMXGetScreenCount(display, &count)) {
 
187
        printf("Could not get screen count\n");
 
188
        return -1;
 
189
    }
 
190
    printf("Screen count = %d\n", count);
 
191
 
 
192
    for (i = 0; i < count; i++) {
 
193
        if (!DMXGetScreenAttributes(display, i, &sinfo)) {
 
194
            printf("Could not get screen information for %d\n", i);
 
195
            return -1;
 
196
        }
 
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,
 
201
               sinfo.logicalScreen,
 
202
               sinfo.rootWindowXorigin, sinfo.rootWindowYorigin,
 
203
               sinfo.rootWindowWidth, sinfo.rootWindowHeight,
 
204
               sinfo.rootWindowXoffset, sinfo.rootWindowYoffset);
 
205
    }
 
206
 
 
207
    if (major_version == 1 && minor_version >= 1) {
 
208
        if (!DMXGetInputCount(display, &count)) {
 
209
            printf("Could not get input count\n");
 
210
            return -1;
 
211
        }
 
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);
 
216
                return -1;
 
217
            }
 
218
            switch (iinfo.inputType) {
 
219
            case DMXLocalInputType:
 
220
                printf("  %2d local   %-20.20s %s\n", i, "", core(&iinfo));
 
221
                break;
 
222
            case DMXConsoleInputType:
 
223
                printf("  %2d console %-20.20s %s\n",
 
224
                       i, iinfo.name, core(&iinfo));
 
225
                break;
 
226
            case DMXBackendInputType:
 
227
                printf("  %2d backend %-20.20s id=%2d screen=%2d %s\n",
 
228
                       i, iinfo.name, iinfo.physicalId, iinfo.physicalScreen,
 
229
                       core(&iinfo));
 
230
                break;
 
231
            }
 
232
        }
 
233
    }
 
234
 
 
235
    if (window) print_info(display, window, 0, 0);
 
236
    else        print_tree(display, DefaultRootWindow(display), 0, 0);
 
237
    
 
238
    XCloseDisplay(display);
 
239
    return 0;
 
240
}