1
/* $Xorg: Screen.c,v 1.3 2000/08/17 19:53:28 cpqbld Exp $ */
4
Copyright 1993 by Davor Matic
6
Permission to use, copy, modify, distribute, and sell this software
7
and its documentation for any purpose is hereby granted without fee,
8
provided that the above copyright notice appear in all copies and that
9
both that copyright notice and this permission notice appear in
10
supporting documentation. Davor Matic makes no representations about
11
the suitability of this software for any purpose. It is provided "as
12
is" without express or implied warranty.
15
/* $XFree86: xc/programs/Xserver/hw/xnest/Screen.c,v 3.12 2003/11/14 22:25:59 dawes Exp $ */
17
#ifdef HAVE_XNEST_CONFIG_H
18
#include <xnest-config.h>
22
#include <X11/Xproto.h>
23
#include "scrnintstr.h"
28
#include "colormapst.h"
44
#include "mipointer.h"
47
Window xnestDefaultWindows[MAXSCREENS];
48
Window xnestScreenSaverWindows[MAXSCREENS];
51
extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
55
int xnestScreenGeneration = -1;
59
xnestScreen(Window window)
63
for (i = 0; i < xnestNumScreens; i++)
64
if (xnestDefaultWindows[i] == window)
65
return screenInfo.screens[i];
71
offset(unsigned long mask)
75
for (count = 0; !(mask & 1) && count < 32; count++)
82
xnestSaveScreen(ScreenPtr pScreen, int what)
84
if (xnestSoftwareScreenSaver)
89
XMapRaised(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
90
xnestSetScreenSaverColormapWindow(pScreen);
93
case SCREEN_SAVER_OFF:
94
XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
95
xnestSetInstalledColormapWindows(pScreen);
98
case SCREEN_SAVER_FORCER:
99
lastEventTime = GetTimeInMillis();
100
XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
101
xnestSetInstalledColormapWindows(pScreen);
104
case SCREEN_SAVER_CYCLE:
105
XUnmapWindow(xnestDisplay, xnestScreenSaverWindows[pScreen->myNum]);
106
xnestSetInstalledColormapWindows(pScreen);
114
xnestCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
120
xnestCrossScreen(ScreenPtr pScreen, Bool entering)
124
static miPointerScreenFuncRec xnestPointerCursorFuncs =
126
xnestCursorOffScreen,
131
static miPointerSpriteFuncRec xnestPointerSpriteFuncs =
134
xnestUnrealizeCursor,
140
xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
144
int numVisuals, numDepths;
145
int i, j, depthIndex;
146
unsigned long valuemask;
147
XSetWindowAttributes attributes;
148
XWindowAttributes gattributes;
149
XSizeHints sizeHints;
150
VisualID defaultVisual;
153
if (!(AllocateWindowPrivate(pScreen, xnestWindowPrivateIndex,
154
sizeof(xnestPrivWin)) &&
155
AllocateGCPrivate(pScreen, xnestGCPrivateIndex,
156
sizeof(xnestPrivGC))))
160
if (xnestScreenGeneration != serverGeneration) {
161
if ((xnestPixmapPrivateIndex = AllocatePixmapPrivateIndex()) < 0)
163
xnestScreenGeneration = serverGeneration;
166
if (!AllocatePixmapPrivate(pScreen,xnestPixmapPrivateIndex,
167
sizeof (xnestPrivPixmap)))
170
visuals = (VisualPtr)xalloc(xnestNumVisuals * sizeof(VisualRec));
173
depths = (DepthPtr)xalloc(MAXDEPTH * sizeof(DepthRec));
175
depths[0].numVids = 0;
176
depths[0].vids = (VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
179
for (i = 0; i < xnestNumVisuals; i++) {
180
visuals[numVisuals].class = xnestVisuals[i].class;
181
visuals[numVisuals].bitsPerRGBValue = xnestVisuals[i].bits_per_rgb;
182
visuals[numVisuals].ColormapEntries = xnestVisuals[i].colormap_size;
183
visuals[numVisuals].nplanes = xnestVisuals[i].depth;
184
visuals[numVisuals].redMask = xnestVisuals[i].red_mask;
185
visuals[numVisuals].greenMask = xnestVisuals[i].green_mask;
186
visuals[numVisuals].blueMask = xnestVisuals[i].blue_mask;
187
visuals[numVisuals].offsetRed = offset(xnestVisuals[i].red_mask);
188
visuals[numVisuals].offsetGreen = offset(xnestVisuals[i].green_mask);
189
visuals[numVisuals].offsetBlue = offset(xnestVisuals[i].blue_mask);
191
/* Check for and remove duplicates. */
192
for (j = 0; j < numVisuals; j++) {
193
if (visuals[numVisuals].class == visuals[j].class &&
194
visuals[numVisuals].bitsPerRGBValue == visuals[j].bitsPerRGBValue &&
195
visuals[numVisuals].ColormapEntries == visuals[j].ColormapEntries &&
196
visuals[numVisuals].nplanes == visuals[j].nplanes &&
197
visuals[numVisuals].redMask == visuals[j].redMask &&
198
visuals[numVisuals].greenMask == visuals[j].greenMask &&
199
visuals[numVisuals].blueMask == visuals[j].blueMask &&
200
visuals[numVisuals].offsetRed == visuals[j].offsetRed &&
201
visuals[numVisuals].offsetGreen == visuals[j].offsetGreen &&
202
visuals[numVisuals].offsetBlue == visuals[j].offsetBlue)
208
visuals[numVisuals].vid = FakeClientID(0);
210
depthIndex = UNDEFINED;
211
for (j = 0; j < numDepths; j++)
212
if (depths[j].depth == xnestVisuals[i].depth) {
217
if (depthIndex == UNDEFINED) {
218
depthIndex = numDepths;
219
depths[depthIndex].depth = xnestVisuals[i].depth;
220
depths[depthIndex].numVids = 0;
221
depths[depthIndex].vids =
222
(VisualID *)xalloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
225
if (depths[depthIndex].numVids >= MAXVISUALSPERDEPTH) {
226
FatalError("Visual table overflow");
228
depths[depthIndex].vids[depths[depthIndex].numVids] =
229
visuals[numVisuals].vid;
230
depths[depthIndex].numVids++;
234
visuals = (VisualPtr)xrealloc(visuals, numVisuals * sizeof(VisualRec));
236
defaultVisual = visuals[xnestDefaultVisualIndex].vid;
237
rootDepth = visuals[xnestDefaultVisualIndex].nplanes;
241
miInitVisualsProcPtr proc = NULL;
243
GlxWrapInitVisuals(&proc);
244
/* GlxInitVisuals ignores the last three arguments. */
245
proc(&visuals, &depths, &numVisuals, &numDepths,
246
&rootDepth, &defaultVisual, 0, 0, 0);
250
if (xnestParentWindow != 0) {
251
XGetWindowAttributes(xnestDisplay, xnestParentWindow, &gattributes);
252
xnestWidth = gattributes.width;
253
xnestHeight = gattributes.height;
258
miScreenInit(pScreen, NULL, xnestWidth, xnestHeight, 1, 1, xnestWidth,
261
defaultVisual, /* root visual */
262
numVisuals, visuals);
264
/* miInitializeBackingStore(pScreen); */
266
pScreen->defColormap = (Colormap) FakeClientID(0);
267
pScreen->minInstalledCmaps = MINCMAPS;
268
pScreen->maxInstalledCmaps = MAXCMAPS;
269
pScreen->backingStoreSupport = NotUseful;
270
pScreen->saveUnderSupport = NotUseful;
271
pScreen->whitePixel = xnestWhitePixel;
272
pScreen->blackPixel = xnestBlackPixel;
276
pScreen->devPrivate = NULL;
277
/* WindowPrivateLen */
278
/* WindowPrivateSizes */
279
/* totalWindowSize */
284
/* Random screen procedures */
286
pScreen->QueryBestSize = xnestQueryBestSize;
287
pScreen->SaveScreen = xnestSaveScreen;
288
pScreen->GetImage = xnestGetImage;
289
pScreen->GetSpans = xnestGetSpans;
290
pScreen->PointerNonInterestBox = NULL;
291
pScreen->SourceValidate = NULL;
293
/* Window Procedures */
295
pScreen->CreateWindow = xnestCreateWindow;
296
pScreen->DestroyWindow = xnestDestroyWindow;
297
pScreen->PositionWindow = xnestPositionWindow;
298
pScreen->ChangeWindowAttributes = xnestChangeWindowAttributes;
299
pScreen->RealizeWindow = xnestRealizeWindow;
300
pScreen->UnrealizeWindow = xnestUnrealizeWindow;
301
pScreen->PostValidateTree = NULL;
302
pScreen->WindowExposures = xnestWindowExposures;
303
pScreen->PaintWindowBackground = xnestPaintWindowBackground;
304
pScreen->PaintWindowBorder = xnestPaintWindowBorder;
305
pScreen->CopyWindow = xnestCopyWindow;
306
pScreen->ClipNotify = xnestClipNotify;
308
/* Pixmap procedures */
310
pScreen->CreatePixmap = xnestCreatePixmap;
311
pScreen->DestroyPixmap = xnestDestroyPixmap;
313
/* Backing store procedures */
315
pScreen->SaveDoomedAreas = NULL;
316
pScreen->RestoreAreas = NULL;
317
pScreen->ExposeCopy = NULL;
318
pScreen->TranslateBackingStore = NULL;
319
pScreen->ClearBackingStore = NULL;
320
pScreen->DrawGuarantee = NULL;
322
/* Font procedures */
324
pScreen->RealizeFont = xnestRealizeFont;
325
pScreen->UnrealizeFont = xnestUnrealizeFont;
329
pScreen->CreateGC = xnestCreateGC;
331
/* Colormap procedures */
333
pScreen->CreateColormap = xnestCreateColormap;
334
pScreen->DestroyColormap = xnestDestroyColormap;
335
pScreen->InstallColormap = xnestInstallColormap;
336
pScreen->UninstallColormap = xnestUninstallColormap;
337
pScreen->ListInstalledColormaps = xnestListInstalledColormaps;
338
pScreen->StoreColors = xnestStoreColors;
339
pScreen->ResolveColor = xnestResolveColor;
341
pScreen->BitmapToRegion = xnestPixmapToRegion;
343
/* OS layer procedures */
345
pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA;
346
pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA;
347
pScreen->blockData = NULL;
348
pScreen->wakeupData = NULL;
350
miPointerInitialize (pScreen, &xnestPointerSpriteFuncs,
351
&xnestPointerCursorFuncs, True);
353
pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay,
354
DefaultScreen(xnestDisplay)) /
355
DisplayWidth(xnestDisplay,
356
DefaultScreen(xnestDisplay));
357
pScreen->mmHeight = xnestHeight * DisplayHeightMM(xnestDisplay,
358
DefaultScreen(xnestDisplay)) /
359
DisplayHeight(xnestDisplay,
360
DefaultScreen(xnestDisplay));
362
/* overwrite miCloseScreen with our own */
363
pScreen->CloseScreen = xnestCloseScreen;
365
if (!miScreenDevPrivateInit(pScreen, xnestWidth, NULL))
369
/* overwrite miSetShape with our own */
370
pScreen->SetShape = xnestSetShape;
375
#define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32)
377
if (xnestDoFullGeneration) {
379
valuemask = CWBackPixel | CWEventMask | CWColormap;
380
attributes.background_pixel = xnestWhitePixel;
381
attributes.event_mask = xnestEventMask;
382
attributes.colormap = xnestDefaultVisualColormap(xnestDefaultVisual(pScreen));
384
if (xnestParentWindow != 0) {
385
xnestDefaultWindows[pScreen->myNum] = xnestParentWindow;
386
XSelectInput (xnestDisplay, xnestDefaultWindows[pScreen->myNum],
389
xnestDefaultWindows[pScreen->myNum] =
390
XCreateWindow(xnestDisplay,
391
DefaultRootWindow(xnestDisplay),
392
xnestX + POSITION_OFFSET,
393
xnestY + POSITION_OFFSET,
394
xnestWidth, xnestHeight,
398
xnestDefaultVisual(pScreen),
399
valuemask, &attributes);
401
if (!xnestWindowName)
402
xnestWindowName = argv[0];
404
sizeHints.flags = PPosition | PSize | PMaxSize;
405
sizeHints.x = xnestX + POSITION_OFFSET;
406
sizeHints.y = xnestY + POSITION_OFFSET;
407
sizeHints.width = sizeHints.max_width = xnestWidth;
408
sizeHints.height = sizeHints.max_height = xnestHeight;
409
if (xnestUserGeometry & XValue || xnestUserGeometry & YValue)
410
sizeHints.flags |= USPosition;
411
if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue)
412
sizeHints.flags |= USSize;
413
XSetStandardProperties(xnestDisplay,
414
xnestDefaultWindows[pScreen->myNum],
418
argv, argc, &sizeHints);
420
XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]);
422
valuemask = CWBackPixmap | CWColormap;
423
attributes.background_pixmap = xnestScreenSaverPixmap;
424
attributes.colormap =
425
DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay));
426
xnestScreenSaverWindows[pScreen->myNum] =
427
XCreateWindow(xnestDisplay,
428
xnestDefaultWindows[pScreen->myNum],
429
0, 0, xnestWidth, xnestHeight, 0,
430
DefaultDepth(xnestDisplay, DefaultScreen(xnestDisplay)),
432
DefaultVisual(xnestDisplay, DefaultScreen(xnestDisplay)),
433
valuemask, &attributes);
436
if (!xnestCreateDefaultColormap(pScreen)) return False;
442
xnestCloseScreen(int index, ScreenPtr pScreen)
446
for (i = 0; i < pScreen->numDepths; i++)
447
xfree(pScreen->allowedDepths[i].vids);
448
xfree(pScreen->allowedDepths);
449
xfree(pScreen->visuals);
450
xfree(pScreen->devPrivate);
453
If xnestDoFullGeneration all x resources will be destroyed upon closing
454
the display connection. There is no need to generate extra protocol.