Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 2003 Red Hat Inc., Durham, North Carolina. | |
3 | * | |
4 | * All Rights Reserved. | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining | |
7 | * a copy of this software and associated documentation files (the | |
8 | * "Software"), to deal in the Software without restriction, including | |
9 | * without limitation on the rights to use, copy, modify, merge, | |
10 | * publish, distribute, sublicense, and/or sell copies of the Software, | |
11 | * and to permit persons to whom the Software is furnished to do so, | |
12 | * subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice (including the | |
15 | * next paragraph) shall be included in all copies or substantial | |
16 | * portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
21 | * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS | |
22 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
23 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
25 | * SOFTWARE. | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Authors: | |
30 | * Kevin E. Martin <kem@redhat.com> | |
31 | * | |
32 | */ | |
33 | ||
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | #include <X11/Xlib.h> | |
37 | #include <X11/extensions/dmxext.h> | |
38 | ||
39 | int | |
40 | main(int argc, char **argv) | |
41 | { | |
42 | Display *display = NULL; | |
43 | int event_base; | |
44 | int error_base; | |
45 | int major_version, minor_version, patch_version; | |
46 | int screen; | |
47 | DMXScreenAttributes attr; | |
48 | unsigned int mask = 0; | |
49 | int status; | |
50 | int errorScreen; | |
51 | ||
52 | if (argc != 13) { | |
53 | fprintf(stderr, | |
54 | "Usage: %s display screen scrnx scrny scrnw scrnh rootx rooty rootw rooth originx originy\n", | |
55 | argv[0]); | |
56 | return -1; | |
57 | } | |
58 | ||
59 | if (!(display = XOpenDisplay(argv[1]))) { | |
60 | fprintf(stderr, "Cannot open display %s\n", argv[1]); | |
61 | return -1; | |
62 | } | |
63 | ||
64 | screen = strtol(argv[2], NULL, 0); | |
65 | ||
66 | mask |= (DMXScreenWindowXoffset | | |
67 | DMXScreenWindowYoffset | | |
68 | DMXScreenWindowWidth | DMXScreenWindowHeight); | |
69 | attr.screenWindowXoffset = strtol(argv[3], NULL, 0); | |
70 | attr.screenWindowYoffset = strtol(argv[4], NULL, 0); | |
71 | attr.screenWindowWidth = strtol(argv[5], NULL, 0); | |
72 | attr.screenWindowHeight = strtol(argv[6], NULL, 0); | |
73 | ||
74 | mask |= (DMXRootWindowXoffset | | |
75 | DMXRootWindowYoffset | DMXRootWindowWidth | DMXRootWindowHeight); | |
76 | attr.rootWindowXoffset = strtol(argv[7], NULL, 0); | |
77 | attr.rootWindowYoffset = strtol(argv[8], NULL, 0); | |
78 | attr.rootWindowWidth = strtol(argv[9], NULL, 0); | |
79 | attr.rootWindowHeight = strtol(argv[10], NULL, 0); | |
80 | ||
81 | mask |= DMXRootWindowXorigin | DMXRootWindowYorigin; | |
82 | attr.rootWindowXorigin = strtol(argv[11], NULL, 0); | |
83 | attr.rootWindowYorigin = strtol(argv[12], NULL, 0); | |
84 | ||
85 | if (!DMXQueryExtension(display, &event_base, &error_base)) { | |
86 | fprintf(stderr, "DMX extension not present\n"); | |
87 | return -1; | |
88 | } | |
89 | printf("DMX extension present: event_base = %d, error_base = %d\n", | |
90 | event_base, error_base); | |
91 | ||
92 | if (!DMXQueryVersion(display, | |
93 | &major_version, &minor_version, &patch_version)) { | |
94 | fprintf(stderr, "Could not get extension version\n"); | |
95 | return -1; | |
96 | } | |
97 | printf("Extension version: %d.%d patch %d\n", | |
98 | major_version, minor_version, patch_version); | |
99 | ||
100 | if (major_version == 1 && minor_version < 3) { | |
101 | fprintf(stderr, | |
102 | "ReconfigureScreen not supported in this extension version\n"); | |
103 | return -1; | |
104 | } | |
105 | ||
106 | if (major_version < 2) { | |
107 | fprintf(stderr, | |
108 | "ChangeScreensAttributes not supported in this extension " | |
109 | "version\n"); | |
110 | return -1; | |
111 | } | |
112 | ||
113 | if (!(status = DMXChangeScreensAttributes(display, 1, &screen, 1, &mask, | |
114 | &attr, &errorScreen))) { | |
115 | printf("Reconfigured screen #%d to " | |
116 | "%dx%d%s%d%s%d %dx%d%s%d%s%d %s%d%s%d\n", | |
117 | screen, | |
118 | attr.screenWindowWidth, | |
119 | attr.screenWindowHeight, | |
120 | (attr.screenWindowXoffset < 0 ? "" : "+"), | |
121 | attr.screenWindowXoffset, | |
122 | (attr.screenWindowYoffset < 0 ? "" : "+"), | |
123 | attr.screenWindowYoffset, | |
124 | attr.rootWindowWidth, | |
125 | attr.rootWindowHeight, | |
126 | (attr.rootWindowXoffset < 0 ? "" : "+"), | |
127 | attr.rootWindowXoffset, | |
128 | (attr.rootWindowYoffset < 0 ? "" : "+"), | |
129 | attr.rootWindowYoffset, | |
130 | (attr.rootWindowXorigin < 0 ? "" : "+"), | |
131 | attr.rootWindowXorigin, | |
132 | (attr.rootWindowYorigin < 0 ? "" : "+"), attr.rootWindowYorigin); | |
133 | } | |
134 | else { | |
135 | fprintf(stderr, | |
136 | "Could not set screen #%d to " | |
137 | "%dx%d%s%d%s%d %dx%d%s%d%s%d %s%d%s%d\n" | |
138 | "[status = %d, errorScreen=%d]\n", | |
139 | screen, | |
140 | attr.screenWindowWidth, | |
141 | attr.screenWindowHeight, | |
142 | (attr.screenWindowXoffset < 0 ? "" : "+"), | |
143 | attr.screenWindowXoffset, | |
144 | (attr.screenWindowYoffset < 0 ? "" : "+"), | |
145 | attr.screenWindowYoffset, | |
146 | attr.rootWindowWidth, | |
147 | attr.rootWindowHeight, | |
148 | (attr.rootWindowXoffset < 0 ? "" : "+"), | |
149 | attr.rootWindowXoffset, | |
150 | (attr.rootWindowYoffset < 0 ? "" : "+"), | |
151 | attr.rootWindowYoffset, | |
152 | (attr.rootWindowXorigin < 0 ? "" : "+"), | |
153 | attr.rootWindowXorigin, | |
154 | (attr.rootWindowYorigin < 0 ? "" : "+"), | |
155 | attr.rootWindowYorigin, status, errorScreen); | |
156 | return -1; | |
157 | } | |
158 | ||
159 | XCloseDisplay(display); | |
160 | return 0; | |
161 | } |