First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xnest / Screen.c
blobe66b4f743e102c1a2a7f929b63f1ca5ce00e31af
1 /*
3 Copyright 1993 by Davor Matic
5 Permission to use, copy, modify, distribute, and sell this software
6 and its documentation for any purpose is hereby granted without fee,
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in
9 supporting documentation. Davor Matic makes no representations about
10 the suitability of this software for any purpose. It is provided "as
11 is" without express or implied warranty.
15 #ifdef HAVE_XNEST_CONFIG_H
16 #include <xnest-config.h>
17 #endif
19 #include <X11/X.h>
20 #include <X11/Xproto.h>
21 #include "scrnintstr.h"
22 #include "dix.h"
23 #include "mi.h"
24 #include "mibstore.h"
25 #include "micmap.h"
26 #include "colormapst.h"
27 #include "resource.h"
29 #include "Xnest.h"
31 #include "Display.h"
32 #include "Screen.h"
33 #include "XNGC.h"
34 #include "GCOps.h"
35 #include "Drawable.h"
36 #include "XNFont.h"
37 #include "Color.h"
38 #include "XNCursor.h"
39 #include "Visual.h"
40 #include "Events.h"
41 #include "Init.h"
42 #include "mipointer.h"
43 #include "Args.h"
45 Window xnestDefaultWindows[MAXSCREENS];
46 Window xnestScreenSaverWindows[MAXSCREENS];
48 #ifdef GLXEXT
49 extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
50 #endif
52 static int xnestScreenGeneration = -1;
54 ScreenPtr
55 xnestScreen(Window window)
57 int i;
59 for (i = 0; i < xnestNumScreens; i++)
60 if (xnestDefaultWindows[i] == window)
61 return screenInfo.screens[i];
63 return NULL;
66 static int
67 offset(unsigned long mask)
69 int count;
71 for (count = 0; !(mask & 1) && count < 32; count++)
72 mask >>= 1;
74 return count;
77 static Bool
78 xnestSaveScreen(ScreenPtr pScreen, int what)
80 if (xnestSoftwareScreenSaver)
81 return False;
82 else {
83 switch (what) {
84 case SCREEN_SAVER_ON:
85 XMapRaised(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
86 xnestSetScreenSaverColormapWindow(pScreen);
87 break;
89 case SCREEN_SAVER_OFF:
90 XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
91 xnestSetInstalledColormapWindows(pScreen);
92 break;
94 case SCREEN_SAVER_FORCER:
95 lastEventTime = GetTimeInMillis();
96 XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
97 xnestSetInstalledColormapWindows(pScreen);
98 break;
100 case SCREEN_SAVER_CYCLE:
101 XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
102 xnestSetInstalledColormapWindows(pScreen);
103 break;
105 return True;
109 static Bool
110 xnestCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
112 return FALSE;
115 static void
116 xnestCrossScreen(ScreenPtr pScreen, Bool entering)
120 static miPointerScreenFuncRec xnestPointerCursorFuncs =
122 xnestCursorOffScreen,
123 xnestCrossScreen,
124 miPointerWarpCursor
127 static miPointerSpriteFuncRec xnestPointerSpriteFuncs =
129 xnestRealizeCursor,
130 xnestUnrealizeCursor,
131 xnestSetCursor,
132 xnestMoveCursor,
135 Bool
136 xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
138 VisualPtr visuals;
139 DepthPtr depths;
140 int numVisuals, numDepths;
141 int i, j, depthIndex;
142 unsigned long valuemask;
143 XSetWindowAttributes attributes;
144 XWindowAttributes gattributes;
145 XSizeHints sizeHints;
146 VisualID defaultVisual;
147 int rootDepth;
149 if (!(AllocateWindowPrivate(pScreen, xnestWindowPrivateIndex,
150 sizeof(xnestPrivWin)) &&
151 AllocateGCPrivate(pScreen, xnestGCPrivateIndex,
152 sizeof(xnestPrivGC))))
153 return False;
155 if (xnestScreenGeneration != serverGeneration) {
156 if ((xnestPixmapPrivateIndex = AllocatePixmapPrivateIndex()) < 0)
157 return False;
158 xnestScreenGeneration = serverGeneration;
161 if (!AllocatePixmapPrivate(pScreen,xnestPixmapPrivateIndex,
162 sizeof (xnestPrivPixmap)))
163 return False;
164 visuals = (VisualPtr)xalloc(xnestNumVisuals * sizeof(VisualRec));
165 numVisuals = 0;
167 depths = (DepthPtr)xalloc(MAXDEPTH * sizeof(DepthRec));
168 depths[0].depth = 1;
169 depths[0].numVids = 0;
170 depths[0].vids = (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
171 numDepths = 1;
173 for (i = 0; i < xnestNumVisuals; i++) {
174 visuals[numVisuals].class = xnestVisuals[i].class;
175 visuals[numVisuals].bitsPerRGBValue = xnestVisuals[i].bits_per_rgb;
176 visuals[numVisuals].ColormapEntries = xnestVisuals[i].colormap_size;
177 visuals[numVisuals].nplanes = xnestVisuals[i].depth;
178 visuals[numVisuals].redMask = xnestVisuals[i].red_mask;
179 visuals[numVisuals].greenMask = xnestVisuals[i].green_mask;
180 visuals[numVisuals].blueMask = xnestVisuals[i].blue_mask;
181 visuals[numVisuals].offsetRed = offset(xnestVisuals[i].red_mask);
182 visuals[numVisuals].offsetGreen = offset(xnestVisuals[i].green_mask);
183 visuals[numVisuals].offsetBlue = offset(xnestVisuals[i].blue_mask);
185 /* Check for and remove duplicates. */
186 for (j = 0; j < numVisuals; j++) {
187 if (visuals[numVisuals].class == visuals[j].class &&
188 visuals[numVisuals].bitsPerRGBValue == visuals[j].bitsPerRGBValue &&
189 visuals[numVisuals].ColormapEntries == visuals[j].ColormapEntries &&
190 visuals[numVisuals].nplanes == visuals[j].nplanes &&
191 visuals[numVisuals].redMask == visuals[j].redMask &&
192 visuals[numVisuals].greenMask == visuals[j].greenMask &&
193 visuals[numVisuals].blueMask == visuals[j].blueMask &&
194 visuals[numVisuals].offsetRed == visuals[j].offsetRed &&
195 visuals[numVisuals].offsetGreen == visuals[j].offsetGreen &&
196 visuals[numVisuals].offsetBlue == visuals[j].offsetBlue)
197 break;
199 if (j < numVisuals)
200 break;
202 visuals[numVisuals].vid = FakeClientID(0);
204 depthIndex = UNDEFINED;
205 for (j = 0; j < numDepths; j++)
206 if (depths[j].depth == xnestVisuals[i].depth) {
207 depthIndex = j;
208 break;
211 if (depthIndex == UNDEFINED) {
212 depthIndex = numDepths;
213 depths[depthIndex].depth = xnestVisuals[i].depth;
214 depths[depthIndex].numVids = 0;
215 depths[depthIndex].vids =
216 (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
217 numDepths++;
219 if (depths[depthIndex].numVids >= MAXVISUALSPERDEPTH) {
220 FatalError("Visual table overflow");
222 depths[depthIndex].vids[depths[depthIndex].numVids] =
223 visuals[numVisuals].vid;
224 depths[depthIndex].numVids++;
226 numVisuals++;
228 visuals = (VisualPtr)xrealloc(visuals, numVisuals * sizeof(VisualRec));
230 defaultVisual = visuals[xnestDefaultVisualIndex].vid;
231 rootDepth = visuals[xnestDefaultVisualIndex].nplanes;
233 #ifdef GLXEXT
235 miInitVisualsProcPtr proc = NULL;
237 GlxWrapInitVisuals(&proc);
238 /* GlxInitVisuals ignores the last three arguments. */
239 proc(&visuals, &depths, &numVisuals, &numDepths,
240 &rootDepth, &defaultVisual, 0, 0, 0);
242 #endif
244 if (xnestParentWindow != 0) {
245 XGetWindowAttributes(xnestDisplay, xnestParentWindow, &gattributes);
246 xnestWidth = gattributes.width;
247 xnestHeight = gattributes.height;
250 /* myNum */
251 /* id */
252 miScreenInit(pScreen, NULL, xnestWidth, xnestHeight, 1, 1, xnestWidth,
253 rootDepth,
254 numDepths, depths,
255 defaultVisual, /* root visual */
256 numVisuals, visuals);
258 /* miInitializeBackingStore(pScreen); */
260 pScreen->defColormap = (Colormap) FakeClientID(0);
261 pScreen->minInstalledCmaps = MINCMAPS;
262 pScreen->maxInstalledCmaps = MAXCMAPS;
263 pScreen->backingStoreSupport = NotUseful;
264 pScreen->saveUnderSupport = NotUseful;
265 pScreen->whitePixel = xnestWhitePixel;
266 pScreen->blackPixel = xnestBlackPixel;
267 /* rgf */
268 /* GCperDepth */
269 /* PixmapPerDepth */
270 pScreen->devPrivate = NULL;
271 /* WindowPrivateLen */
272 /* WindowPrivateSizes */
273 /* totalWindowSize */
274 /* GCPrivateLen */
275 /* GCPrivateSizes */
276 /* totalGCSize */
278 /* Random screen procedures */
280 pScreen->QueryBestSize = xnestQueryBestSize;
281 pScreen->SaveScreen = xnestSaveScreen;
282 pScreen->GetImage = xnestGetImage;
283 pScreen->GetSpans = xnestGetSpans;
284 pScreen->PointerNonInterestBox = NULL;
285 pScreen->SourceValidate = NULL;
287 /* Window Procedures */
289 pScreen->CreateWindow = xnestCreateWindow;
290 pScreen->DestroyWindow = xnestDestroyWindow;
291 pScreen->PositionWindow = xnestPositionWindow;
292 pScreen->ChangeWindowAttributes = xnestChangeWindowAttributes;
293 pScreen->RealizeWindow = xnestRealizeWindow;
294 pScreen->UnrealizeWindow = xnestUnrealizeWindow;
295 pScreen->PostValidateTree = NULL;
296 pScreen->WindowExposures = xnestWindowExposures;
297 pScreen->PaintWindowBackground = xnestPaintWindowBackground;
298 pScreen->PaintWindowBorder = xnestPaintWindowBorder;
299 pScreen->CopyWindow = xnestCopyWindow;
300 pScreen->ClipNotify = xnestClipNotify;
302 /* Pixmap procedures */
304 pScreen->CreatePixmap = xnestCreatePixmap;
305 pScreen->DestroyPixmap = xnestDestroyPixmap;
307 /* Backing store procedures */
309 pScreen->SaveDoomedAreas = NULL;
310 pScreen->RestoreAreas = NULL;
311 pScreen->ExposeCopy = NULL;
312 pScreen->TranslateBackingStore = NULL;
313 pScreen->ClearBackingStore = NULL;
314 pScreen->DrawGuarantee = NULL;
316 /* Font procedures */
318 pScreen->RealizeFont = xnestRealizeFont;
319 pScreen->UnrealizeFont = xnestUnrealizeFont;
321 /* GC procedures */
323 pScreen->CreateGC = xnestCreateGC;
325 /* Colormap procedures */
327 pScreen->CreateColormap = xnestCreateColormap;
328 pScreen->DestroyColormap = xnestDestroyColormap;
329 pScreen->InstallColormap = xnestInstallColormap;
330 pScreen->UninstallColormap = xnestUninstallColormap;
331 pScreen->ListInstalledColormaps = xnestListInstalledColormaps;
332 pScreen->StoreColors = xnestStoreColors;
333 pScreen->ResolveColor = xnestResolveColor;
335 pScreen->BitmapToRegion = xnestPixmapToRegion;
337 /* OS layer procedures */
339 pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA;
340 pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA;
341 pScreen->blockData = NULL;
342 pScreen->wakeupData = NULL;
344 miPointerInitialize (pScreen, &xnestPointerSpriteFuncs,
345 &xnestPointerCursorFuncs, True);
347 pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay,
348 DefaultScreen(xnestDisplay)) /
349 DisplayWidth(xnestDisplay,
350 DefaultScreen(xnestDisplay));
351 pScreen->mmHeight = xnestHeight * DisplayHeightMM(xnestDisplay,
352 DefaultScreen(xnestDisplay)) /
353 DisplayHeight(xnestDisplay,
354 DefaultScreen(xnestDisplay));
356 /* overwrite miCloseScreen with our own */
357 pScreen->CloseScreen = xnestCloseScreen;
359 if (!miScreenDevPrivateInit(pScreen, xnestWidth, NULL))
360 return FALSE;
362 #ifdef SHAPE
363 /* overwrite miSetShape with our own */
364 pScreen->SetShape = xnestSetShape;
365 #endif /* SHAPE */
367 /* devPrivates */
369 #define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32)
371 if (xnestDoFullGeneration) {
373 valuemask = CWBackPixel | CWEventMask | CWColormap;
374 attributes.background_pixel = xnestWhitePixel;
375 attributes.event_mask = xnestEventMask;
376 attributes.colormap = xnestDefaultVisualColormap(xnestDefaultVisual(pScreen));
378 if (xnestParentWindow != 0) {
379 xnestDefaultWindows[pScreen->myNum] = xnestParentWindow;
380 XSelectInput (xnestDisplay, xnestDefaultWindows[pScreen->myNum],
381 xnestEventMask);
382 } else
383 xnestDefaultWindows[pScreen->myNum] =
384 XCreateWindow(xnestDisplay,
385 DefaultRootWindow(xnestDisplay),
386 xnestX + POSITION_OFFSET,
387 xnestY + POSITION_OFFSET,
388 xnestWidth, xnestHeight,
389 xnestBorderWidth,
390 pScreen->rootDepth,
391 InputOutput,
392 xnestDefaultVisual(pScreen),
393 valuemask, &attributes);
395 if (!xnestWindowName)
396 xnestWindowName = argv[0];
398 sizeHints.flags = PPosition | PSize | PMaxSize;
399 sizeHints.x = xnestX + POSITION_OFFSET;
400 sizeHints.y = xnestY + POSITION_OFFSET;
401 sizeHints.width = sizeHints.max_width = xnestWidth;
402 sizeHints.height = sizeHints.max_height = xnestHeight;
403 if (xnestUserGeometry & XValue || xnestUserGeometry & YValue)
404 sizeHints.flags |= USPosition;
405 if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue)
406 sizeHints.flags |= USSize;
407 XSetStandardProperties(xnestDisplay,
408 xnestDefaultWindows[pScreen->myNum],
409 xnestWindowName,
410 xnestWindowName,
411 xnestIconBitmap,
412 argv, argc, &sizeHints);
414 XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]);
416 valuemask = CWBackPixmap | CWColormap;
417 attributes.background_pixmap = xnestScreenSaverPixmap;
418 attributes.colormap =
419 DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay));
420 xnestScreenSaverWindows[pScreen->myNum] =
421 XCreateWindow(xnestDisplay,
422 xnestDefaultWindows[pScreen->myNum],
423 0, 0, xnestWidth, xnestHeight, 0,
424 DefaultDepth(xnestDisplay, DefaultScreen(xnestDisplay)),
425 InputOutput,
426 DefaultVisual(xnestDisplay, DefaultScreen(xnestDisplay)),
427 valuemask, &attributes);
430 if (!xnestCreateDefaultColormap(pScreen)) return False;
432 return True;
435 Bool
436 xnestCloseScreen(int index, ScreenPtr pScreen)
438 int i;
440 for (i = 0; i < pScreen->numDepths; i++)
441 xfree(pScreen->allowedDepths[i].vids);
442 xfree(pScreen->allowedDepths);
443 xfree(pScreen->visuals);
444 xfree(pScreen->devPrivate);
447 If xnestDoFullGeneration all x resources will be destroyed upon closing
448 the display connection. There is no need to generate extra protocol.
451 return True;