1 /*
2 * Copyright 2001-2004 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 */
28 /*
29 * Authors:
30 * Rickard E. (Rik) Faith <faith@redhat.com>
31 *
32 */
34 /** \file
35 * This code queries and modifies the connection block. */
37 #ifdef HAVE_DMX_CONFIG_H
38 #include <dmx-config.h>
39 #endif
41 #include "dmx.h"
42 #include "dmxcb.h"
43 #include "dmxinput.h"
44 #include "dmxlog.h"
46 extern int connBlockScreenStart;
48 #ifdef PANORAMIX
49 #include "panoramiXsrv.h"
50 extern int PanoramiXPixWidth;
51 extern int PanoramiXPixHeight;
52 extern int PanoramiXNumScreens;
53 #endif
55 int dmxGlobalWidth, dmxGlobalHeight;
57 /** We may want the wall dimensions to be different from the bounding
58 * box dimensions that Xinerama computes, so save those and update them
59 * here.
60 */
61 void dmxSetWidthHeight(int width, int height)
62 {
63 dmxGlobalWidth = width;
64 dmxGlobalHeight = height;
65 }
67 /** Computes the global bounding box for DMX. This may be larger than
68 * the one computed by Xinerama because of the DMX configuration
69 * file. */
70 void dmxComputeWidthHeight(DMXRecomputeFlag flag)
71 {
72 int i;
73 DMXScreenInfo *dmxScreen;
74 int w = 0;
75 int h = 0;
77 for (i = 0; i < dmxNumScreens; i++) {
78 /* Don't use root* here because this is
79 * the global bounding box. */
80 dmxScreen = &dmxScreens[i];
81 if (w < dmxScreen->scrnWidth + dmxScreen->rootXOrigin)
82 w = dmxScreen->scrnWidth + dmxScreen->rootXOrigin;
83 if (h < dmxScreen->scrnHeight + dmxScreen->rootYOrigin)
84 h = dmxScreen->scrnHeight + dmxScreen->rootYOrigin;
85 }
86 if (!dmxGlobalWidth && !dmxGlobalHeight) {
87 dmxLog(dmxInfo, "Using %dx%d as global bounding box\n", w, h);
88 } else {
89 switch (flag) {
90 case DMX_NO_RECOMPUTE_BOUNDING_BOX:
91 dmxLog(dmxInfo,
92 "Using old bounding box (%dx%d) instead of new (%dx%d)\n",
93 dmxGlobalWidth, dmxGlobalHeight, w, h);
94 w = dmxGlobalWidth;
95 h = dmxGlobalHeight;
96 break;
97 case DMX_RECOMPUTE_BOUNDING_BOX:
98 dmxLog(dmxInfo,
99 "Using %dx%d as global bounding box, instead of %dx%d\n",
100 w, h, dmxGlobalWidth, dmxGlobalHeight);
101 break;
102 }
103 }
105 dmxGlobalWidth = w;
106 dmxGlobalHeight = h;
107 }
109 /** A callback routine that hooks into Xinerama and provides a
110 * convenient place to print summary log information during server
111 * startup. This routine does not modify any values. */
112 void dmxConnectionBlockCallback(void)
113 {
114 xWindowRoot *root = (xWindowRoot *)(ConnectionInfo+connBlockScreenStart);
115 int offset = connBlockScreenStart + sizeof(xWindowRoot);
116 int i;
117 Bool *found = NULL;
119 MAXSCREENSALLOC(found);
120 if (!found)
121 dmxLog(dmxFatal, "dmxConnectionBlockCallback: out of memory\n");
123 dmxLog(dmxInfo, "===== Start of Summary =====\n");
124 #ifdef PANORAMIX
125 if (!noPanoramiXExtension) {
126 if (dmxGlobalWidth && dmxGlobalHeight
127 && (dmxGlobalWidth != PanoramiXPixWidth
128 || dmxGlobalHeight != PanoramiXPixHeight)) {
129 dmxLog(dmxInfo,
130 "Changing Xinerama dimensions from %d %d to %d %d\n",
131 PanoramiXPixWidth, PanoramiXPixHeight,
132 dmxGlobalWidth, dmxGlobalHeight);
133 PanoramiXPixWidth = root->pixWidth = dmxGlobalWidth;
134 PanoramiXPixHeight = root->pixHeight = dmxGlobalHeight;
135 } else {
136 dmxGlobalWidth = PanoramiXPixWidth;
137 dmxGlobalHeight = PanoramiXPixHeight;
138 }
139 dmxLog(dmxInfo, "%d screens configured with Xinerama (%d %d)\n",
140 PanoramiXNumScreens, PanoramiXPixWidth, PanoramiXPixHeight);
141 FOR_NSCREENS(i) found[i] = FALSE;
142 } else {
143 #endif
144 /* This never happens because we're
145 * either called from a Xinerama
146 * callback or during reconfiguration
147 * (which only works with Xinerama on).
148 * In any case, be reasonable. */
149 dmxLog(dmxInfo, "%d screens configured (%d %d)\n",
150 screenInfo.numScreens, root->pixWidth, root->pixHeight);
151 #ifdef PANORAMIX
152 }
153 #endif
155 for (i = 0; i < root->nDepths; i++) {
156 xDepth *depth = (xDepth *)(ConnectionInfo + offset);
157 int voffset = offset + sizeof(xDepth);
158 xVisualType *visual = (xVisualType *)(ConnectionInfo + voffset);
159 int j;
161 dmxLog(dmxInfo, "%d visuals at depth %d:\n",
162 depth->nVisuals, depth->depth);
163 for (j = 0; j < depth->nVisuals; j++, visual++) {
164 XVisualInfo vi;
166 vi.visual = NULL;
167 vi.visualid = visual->visualID;
168 vi.screen = 0;
169 vi.depth = depth->depth;
170 vi.class = visual->class;
171 vi.red_mask = visual->redMask;
172 vi.green_mask = visual->greenMask;
173 vi.blue_mask = visual->blueMask;
174 vi.colormap_size = visual->colormapEntries;
175 vi.bits_per_rgb = visual->bitsPerRGB;
176 dmxLogVisual(NULL, &vi, 0);
178 #ifdef PANORAMIX
179 if (!noPanoramiXExtension) {
180 int k;
181 FOR_NSCREENS(k) {
182 DMXScreenInfo *dmxScreen = &dmxScreens[k];
184 if (dmxScreen->beDisplay) {
185 XVisualInfo *pvi =
186 &dmxScreen->beVisuals[dmxScreen->beDefVisualIndex];
187 if (pvi->depth == depth->depth &&
188 pvi->class == visual->class)
189 found[k] = TRUE;
190 } else {
191 /* Screen #k is detatched, so it always succeeds */
192 found[k] = TRUE;
193 }
194 }
195 }
196 #endif
197 }
198 offset = voffset + depth->nVisuals * sizeof(xVisualType);
199 }
201 dmxInputLogDevices();
202 dmxLog(dmxInfo, "===== End of Summary =====\n");
204 #ifdef PANORAMIX
205 if (!noPanoramiXExtension) {
206 Bool fatal = FALSE;
207 FOR_NSCREENS(i) {
208 fatal |= !found[i];
209 if (!found[i]) {
210 dmxLog(dmxError,
211 "The default visual for screen #%d does not match "
212 "any of the\n", i);
213 dmxLog(dmxError,
214 "consolidated visuals from Xinerama (listed above)\n");
215 }
216 }
217 if (fatal)
218 dmxLog(dmxFatal,
219 "dmxConnectionBlockCallback: invalid screen(s) found");
220 }
221 #endif
222 MAXSCREENSFREE(found);
223 }