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>
20 #include <X11/Xproto.h>
21 #include "scrnintstr.h"
26 #include "colormapst.h"
42 #include "mipointer.h"
45 Window xnestDefaultWindows
[MAXSCREENS
];
46 Window xnestScreenSaverWindows
[MAXSCREENS
];
49 extern void GlxWrapInitVisuals(miInitVisualsProcPtr
*);
52 static int xnestScreenGeneration
= -1;
55 xnestScreen(Window window
)
59 for (i
= 0; i
< xnestNumScreens
; i
++)
60 if (xnestDefaultWindows
[i
] == window
)
61 return screenInfo
.screens
[i
];
67 offset(unsigned long mask
)
71 for (count
= 0; !(mask
& 1) && count
< 32; count
++)
78 xnestSaveScreen(ScreenPtr pScreen
, int what
)
80 if (xnestSoftwareScreenSaver
)
85 XMapRaised(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
86 xnestSetScreenSaverColormapWindow(pScreen
);
89 case SCREEN_SAVER_OFF
:
90 XUnmapWindow(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
91 xnestSetInstalledColormapWindows(pScreen
);
94 case SCREEN_SAVER_FORCER
:
95 lastEventTime
= GetTimeInMillis();
96 XUnmapWindow(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
97 xnestSetInstalledColormapWindows(pScreen
);
100 case SCREEN_SAVER_CYCLE
:
101 XUnmapWindow(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
102 xnestSetInstalledColormapWindows(pScreen
);
110 xnestCursorOffScreen(ScreenPtr
*ppScreen
, int *x
, int *y
)
116 xnestCrossScreen(ScreenPtr pScreen
, Bool entering
)
120 static miPointerScreenFuncRec xnestPointerCursorFuncs
=
122 xnestCursorOffScreen
,
127 static miPointerSpriteFuncRec xnestPointerSpriteFuncs
=
130 xnestUnrealizeCursor
,
136 xnestOpenScreen(int index
, ScreenPtr pScreen
, int argc
, char *argv
[])
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
;
149 if (!(AllocateWindowPrivate(pScreen
, xnestWindowPrivateIndex
,
150 sizeof(xnestPrivWin
)) &&
151 AllocateGCPrivate(pScreen
, xnestGCPrivateIndex
,
152 sizeof(xnestPrivGC
))))
155 if (xnestScreenGeneration
!= serverGeneration
) {
156 if ((xnestPixmapPrivateIndex
= AllocatePixmapPrivateIndex()) < 0)
158 xnestScreenGeneration
= serverGeneration
;
161 if (!AllocatePixmapPrivate(pScreen
,xnestPixmapPrivateIndex
,
162 sizeof (xnestPrivPixmap
)))
164 visuals
= (VisualPtr
)xalloc(xnestNumVisuals
* sizeof(VisualRec
));
167 depths
= (DepthPtr
)xalloc(MAXDEPTH
* sizeof(DepthRec
));
169 depths
[0].numVids
= 0;
170 depths
[0].vids
= (VisualID
*)xalloc(MAXVISUALSPERDEPTH
* sizeof(VisualID
));
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
)
202 visuals
[numVisuals
].vid
= FakeClientID(0);
204 depthIndex
= UNDEFINED
;
205 for (j
= 0; j
< numDepths
; j
++)
206 if (depths
[j
].depth
== xnestVisuals
[i
].depth
) {
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
));
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
++;
228 visuals
= (VisualPtr
)xrealloc(visuals
, numVisuals
* sizeof(VisualRec
));
230 defaultVisual
= visuals
[xnestDefaultVisualIndex
].vid
;
231 rootDepth
= visuals
[xnestDefaultVisualIndex
].nplanes
;
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);
244 if (xnestParentWindow
!= 0) {
245 XGetWindowAttributes(xnestDisplay
, xnestParentWindow
, &gattributes
);
246 xnestWidth
= gattributes
.width
;
247 xnestHeight
= gattributes
.height
;
252 miScreenInit(pScreen
, NULL
, xnestWidth
, xnestHeight
, 1, 1, xnestWidth
,
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
;
270 pScreen
->devPrivate
= NULL
;
271 /* WindowPrivateLen */
272 /* WindowPrivateSizes */
273 /* totalWindowSize */
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
;
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
))
363 /* overwrite miSetShape with our own */
364 pScreen
->SetShape
= xnestSetShape
;
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
],
383 xnestDefaultWindows
[pScreen
->myNum
] =
384 XCreateWindow(xnestDisplay
,
385 DefaultRootWindow(xnestDisplay
),
386 xnestX
+ POSITION_OFFSET
,
387 xnestY
+ POSITION_OFFSET
,
388 xnestWidth
, xnestHeight
,
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
],
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
)),
426 DefaultVisual(xnestDisplay
, DefaultScreen(xnestDisplay
)),
427 valuemask
, &attributes
);
430 if (!xnestCreateDefaultColormap(pScreen
)) return False
;
436 xnestCloseScreen(int index
, ScreenPtr pScreen
)
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.