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"
25 #include "colormapst.h"
41 #include "mipointer.h"
43 #include "mipointrst.h"
45 Window xnestDefaultWindows
[MAXSCREENS
];
46 Window xnestScreenSaverWindows
[MAXSCREENS
];
47 DevPrivateKeyRec xnestCursorScreenKeyRec
;
50 xnestScreen(Window window
)
54 for (i
= 0; i
< xnestNumScreens
; i
++)
55 if (xnestDefaultWindows
[i
] == window
)
56 return screenInfo
.screens
[i
];
62 offset(unsigned long mask
)
66 for (count
= 0; !(mask
& 1) && count
< 32; count
++)
73 xnestSaveScreen(ScreenPtr pScreen
, int what
)
75 if (xnestSoftwareScreenSaver
)
80 XMapRaised(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
81 xnestSetScreenSaverColormapWindow(pScreen
);
84 case SCREEN_SAVER_OFF
:
85 XUnmapWindow(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
86 xnestSetInstalledColormapWindows(pScreen
);
89 case SCREEN_SAVER_FORCER
:
90 lastEventTime
= GetTimeInMillis();
91 XUnmapWindow(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
92 xnestSetInstalledColormapWindows(pScreen
);
95 case SCREEN_SAVER_CYCLE
:
96 XUnmapWindow(xnestDisplay
, xnestScreenSaverWindows
[pScreen
->myNum
]);
97 xnestSetInstalledColormapWindows(pScreen
);
105 xnestCursorOffScreen(ScreenPtr
*ppScreen
, int *x
, int *y
)
111 xnestCrossScreen(ScreenPtr pScreen
, Bool entering
)
115 static miPointerScreenFuncRec xnestPointerCursorFuncs
= {
116 xnestCursorOffScreen
,
121 static miPointerSpriteFuncRec xnestPointerSpriteFuncs
= {
123 xnestUnrealizeCursor
,
126 xnestDeviceCursorInitialize
,
127 xnestDeviceCursorCleanup
131 xnestOpenScreen(ScreenPtr pScreen
, int argc
, char *argv
[])
135 int numVisuals
, numDepths
;
136 int i
, j
, depthIndex
;
137 unsigned long valuemask
;
138 XSetWindowAttributes attributes
;
139 XWindowAttributes gattributes
;
140 XSizeHints sizeHints
;
141 VisualID defaultVisual
;
143 miPointerScreenPtr PointPriv
;
145 if (!dixRegisterPrivateKey
146 (&xnestWindowPrivateKeyRec
, PRIVATE_WINDOW
, sizeof(xnestPrivWin
)))
148 if (!dixRegisterPrivateKey
149 (&xnestGCPrivateKeyRec
, PRIVATE_GC
, sizeof(xnestPrivGC
)))
151 if (!dixRegisterPrivateKey
152 (&xnestPixmapPrivateKeyRec
, PRIVATE_PIXMAP
, sizeof(xnestPrivPixmap
)))
154 if (!dixRegisterPrivateKey
155 (&xnestColormapPrivateKeyRec
, PRIVATE_COLORMAP
,
156 sizeof(xnestPrivColormap
)))
158 if (!dixRegisterPrivateKey(&xnestCursorScreenKeyRec
, PRIVATE_SCREEN
, 0))
161 visuals
= (VisualPtr
) malloc(xnestNumVisuals
* sizeof(VisualRec
));
164 depths
= (DepthPtr
) malloc(MAXDEPTH
* sizeof(DepthRec
));
166 depths
[0].numVids
= 0;
167 depths
[0].vids
= (VisualID
*) malloc(MAXVISUALSPERDEPTH
* sizeof(VisualID
));
170 for (i
= 0; i
< xnestNumVisuals
; i
++) {
171 visuals
[numVisuals
].class = xnestVisuals
[i
].class;
172 visuals
[numVisuals
].bitsPerRGBValue
= xnestVisuals
[i
].bits_per_rgb
;
173 visuals
[numVisuals
].ColormapEntries
= xnestVisuals
[i
].colormap_size
;
174 visuals
[numVisuals
].nplanes
= xnestVisuals
[i
].depth
;
175 visuals
[numVisuals
].redMask
= xnestVisuals
[i
].red_mask
;
176 visuals
[numVisuals
].greenMask
= xnestVisuals
[i
].green_mask
;
177 visuals
[numVisuals
].blueMask
= xnestVisuals
[i
].blue_mask
;
178 visuals
[numVisuals
].offsetRed
= offset(xnestVisuals
[i
].red_mask
);
179 visuals
[numVisuals
].offsetGreen
= offset(xnestVisuals
[i
].green_mask
);
180 visuals
[numVisuals
].offsetBlue
= offset(xnestVisuals
[i
].blue_mask
);
182 /* Check for and remove duplicates. */
183 for (j
= 0; j
< numVisuals
; j
++) {
184 if (visuals
[numVisuals
].class == visuals
[j
].class &&
185 visuals
[numVisuals
].bitsPerRGBValue
==
186 visuals
[j
].bitsPerRGBValue
&&
187 visuals
[numVisuals
].ColormapEntries
==
188 visuals
[j
].ColormapEntries
&&
189 visuals
[numVisuals
].nplanes
== visuals
[j
].nplanes
&&
190 visuals
[numVisuals
].redMask
== visuals
[j
].redMask
&&
191 visuals
[numVisuals
].greenMask
== visuals
[j
].greenMask
&&
192 visuals
[numVisuals
].blueMask
== visuals
[j
].blueMask
&&
193 visuals
[numVisuals
].offsetRed
== visuals
[j
].offsetRed
&&
194 visuals
[numVisuals
].offsetGreen
== visuals
[j
].offsetGreen
&&
195 visuals
[numVisuals
].offsetBlue
== visuals
[j
].offsetBlue
)
201 visuals
[numVisuals
].vid
= FakeClientID(0);
203 depthIndex
= UNDEFINED
;
204 for (j
= 0; j
< numDepths
; j
++)
205 if (depths
[j
].depth
== xnestVisuals
[i
].depth
) {
210 if (depthIndex
== UNDEFINED
) {
211 depthIndex
= numDepths
;
212 depths
[depthIndex
].depth
= xnestVisuals
[i
].depth
;
213 depths
[depthIndex
].numVids
= 0;
214 depths
[depthIndex
].vids
=
215 (VisualID
*) malloc(MAXVISUALSPERDEPTH
* sizeof(VisualID
));
218 if (depths
[depthIndex
].numVids
>= MAXVISUALSPERDEPTH
) {
219 FatalError("Visual table overflow");
221 depths
[depthIndex
].vids
[depths
[depthIndex
].numVids
] =
222 visuals
[numVisuals
].vid
;
223 depths
[depthIndex
].numVids
++;
227 visuals
= (VisualPtr
) realloc(visuals
, numVisuals
* sizeof(VisualRec
));
229 defaultVisual
= visuals
[xnestDefaultVisualIndex
].vid
;
230 rootDepth
= visuals
[xnestDefaultVisualIndex
].nplanes
;
232 if (xnestParentWindow
!= 0) {
233 XGetWindowAttributes(xnestDisplay
, xnestParentWindow
, &gattributes
);
234 xnestWidth
= gattributes
.width
;
235 xnestHeight
= gattributes
.height
;
240 miScreenInit(pScreen
, NULL
, xnestWidth
, xnestHeight
, 1, 1, xnestWidth
, rootDepth
, numDepths
, depths
, defaultVisual
, /* root visual */
241 numVisuals
, visuals
);
243 pScreen
->defColormap
= (Colormap
) FakeClientID(0);
244 pScreen
->minInstalledCmaps
= MINCMAPS
;
245 pScreen
->maxInstalledCmaps
= MAXCMAPS
;
246 pScreen
->backingStoreSupport
= NotUseful
;
247 pScreen
->saveUnderSupport
= NotUseful
;
248 pScreen
->whitePixel
= xnestWhitePixel
;
249 pScreen
->blackPixel
= xnestBlackPixel
;
252 pScreen
->devPrivate
= NULL
;
253 /* WindowPrivateLen */
254 /* WindowPrivateSizes */
255 /* totalWindowSize */
260 /* Random screen procedures */
262 pScreen
->QueryBestSize
= xnestQueryBestSize
;
263 pScreen
->SaveScreen
= xnestSaveScreen
;
264 pScreen
->GetImage
= xnestGetImage
;
265 pScreen
->GetSpans
= xnestGetSpans
;
266 pScreen
->SourceValidate
= NULL
;
268 /* Window Procedures */
270 pScreen
->CreateWindow
= xnestCreateWindow
;
271 pScreen
->DestroyWindow
= xnestDestroyWindow
;
272 pScreen
->PositionWindow
= xnestPositionWindow
;
273 pScreen
->ChangeWindowAttributes
= xnestChangeWindowAttributes
;
274 pScreen
->RealizeWindow
= xnestRealizeWindow
;
275 pScreen
->UnrealizeWindow
= xnestUnrealizeWindow
;
276 pScreen
->PostValidateTree
= NULL
;
277 pScreen
->WindowExposures
= xnestWindowExposures
;
278 pScreen
->CopyWindow
= xnestCopyWindow
;
279 pScreen
->ClipNotify
= xnestClipNotify
;
281 /* Pixmap procedures */
283 pScreen
->CreatePixmap
= xnestCreatePixmap
;
284 pScreen
->DestroyPixmap
= xnestDestroyPixmap
;
285 pScreen
->ModifyPixmapHeader
= xnestModifyPixmapHeader
;
287 /* Font procedures */
289 pScreen
->RealizeFont
= xnestRealizeFont
;
290 pScreen
->UnrealizeFont
= xnestUnrealizeFont
;
294 pScreen
->CreateGC
= xnestCreateGC
;
296 /* Colormap procedures */
298 pScreen
->CreateColormap
= xnestCreateColormap
;
299 pScreen
->DestroyColormap
= xnestDestroyColormap
;
300 pScreen
->InstallColormap
= xnestInstallColormap
;
301 pScreen
->UninstallColormap
= xnestUninstallColormap
;
302 pScreen
->ListInstalledColormaps
= xnestListInstalledColormaps
;
303 pScreen
->StoreColors
= xnestStoreColors
;
304 pScreen
->ResolveColor
= xnestResolveColor
;
306 pScreen
->BitmapToRegion
= xnestPixmapToRegion
;
308 /* OS layer procedures */
310 pScreen
->BlockHandler
= (ScreenBlockHandlerProcPtr
) NoopDDA
;
311 pScreen
->WakeupHandler
= (ScreenWakeupHandlerProcPtr
) NoopDDA
;
313 miDCInitialize(pScreen
, &xnestPointerCursorFuncs
); /* init SW rendering */
314 PointPriv
= dixLookupPrivate(&pScreen
->devPrivates
, miPointerScreenKey
);
315 xnestCursorFuncs
.spriteFuncs
= PointPriv
->spriteFuncs
;
316 dixSetPrivate(&pScreen
->devPrivates
, xnestCursorScreenKey
,
318 PointPriv
->spriteFuncs
= &xnestPointerSpriteFuncs
;
320 pScreen
->mmWidth
= xnestWidth
* DisplayWidthMM(xnestDisplay
,
321 DefaultScreen(xnestDisplay
))
322 / DisplayWidth(xnestDisplay
, DefaultScreen(xnestDisplay
));
324 xnestHeight
* DisplayHeightMM(xnestDisplay
,
325 DefaultScreen(xnestDisplay
)) /
326 DisplayHeight(xnestDisplay
, DefaultScreen(xnestDisplay
));
328 /* overwrite miCloseScreen with our own */
329 pScreen
->CloseScreen
= xnestCloseScreen
;
331 if (!miScreenDevPrivateInit(pScreen
, xnestWidth
, NULL
))
334 /* overwrite miSetShape with our own */
335 pScreen
->SetShape
= xnestSetShape
;
339 #define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32)
341 if (xnestDoFullGeneration
) {
343 valuemask
= CWBackPixel
| CWEventMask
| CWColormap
;
344 attributes
.background_pixel
= xnestWhitePixel
;
345 attributes
.event_mask
= xnestEventMask
;
346 attributes
.colormap
=
347 xnestDefaultVisualColormap(xnestDefaultVisual(pScreen
));
349 if (xnestParentWindow
!= 0) {
350 xnestDefaultWindows
[pScreen
->myNum
] = xnestParentWindow
;
351 XSelectInput(xnestDisplay
, xnestDefaultWindows
[pScreen
->myNum
],
355 xnestDefaultWindows
[pScreen
->myNum
] =
356 XCreateWindow(xnestDisplay
,
357 DefaultRootWindow(xnestDisplay
),
358 xnestX
+ POSITION_OFFSET
,
359 xnestY
+ POSITION_OFFSET
,
360 xnestWidth
, xnestHeight
,
364 xnestDefaultVisual(pScreen
),
365 valuemask
, &attributes
);
367 if (!xnestWindowName
)
368 xnestWindowName
= argv
[0];
370 sizeHints
.flags
= PPosition
| PSize
| PMaxSize
;
371 sizeHints
.x
= xnestX
+ POSITION_OFFSET
;
372 sizeHints
.y
= xnestY
+ POSITION_OFFSET
;
373 sizeHints
.width
= sizeHints
.max_width
= xnestWidth
;
374 sizeHints
.height
= sizeHints
.max_height
= xnestHeight
;
375 if (xnestUserGeometry
& XValue
|| xnestUserGeometry
& YValue
)
376 sizeHints
.flags
|= USPosition
;
377 if (xnestUserGeometry
& WidthValue
|| xnestUserGeometry
& HeightValue
)
378 sizeHints
.flags
|= USSize
;
379 XSetStandardProperties(xnestDisplay
,
380 xnestDefaultWindows
[pScreen
->myNum
],
383 xnestIconBitmap
, argv
, argc
, &sizeHints
);
385 XMapWindow(xnestDisplay
, xnestDefaultWindows
[pScreen
->myNum
]);
387 valuemask
= CWBackPixmap
| CWColormap
;
388 attributes
.background_pixmap
= xnestScreenSaverPixmap
;
389 attributes
.colormap
=
390 DefaultColormap(xnestDisplay
, DefaultScreen(xnestDisplay
));
391 xnestScreenSaverWindows
[pScreen
->myNum
] =
392 XCreateWindow(xnestDisplay
,
393 xnestDefaultWindows
[pScreen
->myNum
],
394 0, 0, xnestWidth
, xnestHeight
, 0,
395 DefaultDepth(xnestDisplay
,
396 DefaultScreen(xnestDisplay
)),
397 InputOutput
, DefaultVisual(xnestDisplay
,
399 (xnestDisplay
)), valuemask
,
403 if (!xnestCreateDefaultColormap(pScreen
))
410 xnestCloseScreen(ScreenPtr pScreen
)
414 for (i
= 0; i
< pScreen
->numDepths
; i
++)
415 free(pScreen
->allowedDepths
[i
].vids
);
416 free(pScreen
->allowedDepths
);
417 free(pScreen
->visuals
);
418 free(pScreen
->devPrivate
);
421 If xnestDoFullGeneration all x resources will be destroyed upon closing
422 the display connection. There is no need to generate extra protocol.