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.
16 #ifdef HAVE_XNEST_CONFIG_H
17 #include <xnest-config.h>
21 #include <X11/Xproto.h>
22 #include "screenint.h"
25 #include "scrnintstr.h"
35 #include "screensaver"
37 Display
*xnestDisplay
= NULL
;
38 XVisualInfo
*xnestVisuals
;
40 int xnestDefaultVisualIndex
;
41 Colormap
*xnestDefaultColormaps
;
42 static int xnestNumDefaultColormaps
;
45 XPixmapFormatValues
*xnestPixmapFormats
;
46 int xnestNumPixmapFormats
;
47 Pixel xnestBlackPixel
;
48 Pixel xnestWhitePixel
;
49 Drawable xnestDefaultDrawables
[MAXDEPTH
+ 1];
50 Pixmap xnestIconBitmap
;
51 Pixmap xnestScreenSaverPixmap
;
53 unsigned long xnestEventMask
;
56 xnestOpenDisplay(int argc
, char *argv
[])
62 if (!xnestDoFullGeneration
) return;
66 xnestDisplay
= XOpenDisplay(xnestDisplayName
);
67 if (xnestDisplay
== NULL
)
68 FatalError("Unable to open display \"%s\".\n",
69 XDisplayName(xnestDisplayName
));
72 XSynchronize(xnestDisplay
, True
);
74 mask
= VisualScreenMask
;
75 vi
.screen
= DefaultScreen(xnestDisplay
);
76 xnestVisuals
= XGetVisualInfo(xnestDisplay
, mask
, &vi
, &xnestNumVisuals
);
77 if (xnestNumVisuals
== 0 || xnestVisuals
== NULL
)
78 FatalError("Unable to find any visuals.\n");
80 if (xnestUserDefaultClass
|| xnestUserDefaultDepth
) {
81 xnestDefaultVisualIndex
= UNDEFINED
;
82 for (i
= 0; i
< xnestNumVisuals
; i
++)
83 if ((!xnestUserDefaultClass
||
84 xnestVisuals
[i
].class == xnestDefaultClass
)
86 (!xnestUserDefaultDepth
||
87 xnestVisuals
[i
].depth
== xnestDefaultDepth
)) {
88 xnestDefaultVisualIndex
= i
;
91 if (xnestDefaultVisualIndex
== UNDEFINED
)
92 FatalError("Unable to find desired default visual.\n");
95 vi
.visualid
= XVisualIDFromVisual(DefaultVisual(xnestDisplay
,
96 DefaultScreen(xnestDisplay
)));
97 xnestDefaultVisualIndex
= 0;
98 for (i
= 0; i
< xnestNumVisuals
; i
++)
99 if (vi
.visualid
== xnestVisuals
[i
].visualid
)
100 xnestDefaultVisualIndex
= i
;
103 xnestNumDefaultColormaps
= xnestNumVisuals
;
104 xnestDefaultColormaps
= (Colormap
*)xalloc(xnestNumDefaultColormaps
*
106 for (i
= 0; i
< xnestNumDefaultColormaps
; i
++)
107 xnestDefaultColormaps
[i
] = XCreateColormap(xnestDisplay
,
108 DefaultRootWindow(xnestDisplay
),
109 xnestVisuals
[i
].visual
,
112 xnestDepths
= XListDepths(xnestDisplay
, DefaultScreen(xnestDisplay
),
115 xnestPixmapFormats
= XListPixmapFormats(xnestDisplay
,
116 &xnestNumPixmapFormats
);
118 xnestBlackPixel
= BlackPixel(xnestDisplay
, DefaultScreen(xnestDisplay
));
119 xnestWhitePixel
= WhitePixel(xnestDisplay
, DefaultScreen(xnestDisplay
));
121 if (xnestParentWindow
!= (Window
) 0)
122 xnestEventMask
= StructureNotifyMask
;
126 for (i
= 0; i
<= MAXDEPTH
; i
++)
127 xnestDefaultDrawables
[i
] = None
;
129 for (i
= 0; i
< xnestNumPixmapFormats
; i
++)
130 for (j
= 0; j
< xnestNumDepths
; j
++)
131 if (xnestPixmapFormats
[i
].depth
== 1 ||
132 xnestPixmapFormats
[i
].depth
== xnestDepths
[j
]) {
133 xnestDefaultDrawables
[xnestPixmapFormats
[i
].depth
] =
134 XCreatePixmap(xnestDisplay
, DefaultRootWindow(xnestDisplay
),
135 1, 1, xnestPixmapFormats
[i
].depth
);
138 xnestBitmapGC
= XCreateGC(xnestDisplay
, xnestDefaultDrawables
[1], 0L, NULL
);
140 if (!(xnestUserGeometry
& XValue
))
143 if (!(xnestUserGeometry
& YValue
))
146 if (xnestParentWindow
== 0) {
147 if (!(xnestUserGeometry
& WidthValue
))
148 xnestWidth
= 3 * DisplayWidth(xnestDisplay
,
149 DefaultScreen(xnestDisplay
)) / 4;
151 if (!(xnestUserGeometry
& HeightValue
))
152 xnestHeight
= 3 * DisplayHeight(xnestDisplay
,
153 DefaultScreen(xnestDisplay
)) / 4;
156 if (!xnestUserBorderWidth
)
157 xnestBorderWidth
= 1;
160 XCreateBitmapFromData(xnestDisplay
,
161 DefaultRootWindow(xnestDisplay
),
166 xnestScreenSaverPixmap
=
167 XCreatePixmapFromBitmapData(xnestDisplay
,
168 DefaultRootWindow(xnestDisplay
),
169 (char *)screensaver_bits
,
174 DefaultDepth(xnestDisplay
,
175 DefaultScreen(xnestDisplay
)));
179 xnestCloseDisplay(void)
181 if (!xnestDoFullGeneration
|| !xnestDisplay
) return;
184 If xnestDoFullGeneration all x resources will be destroyed upon closing
185 the display connection. There is no need to generate extra protocol.
188 xfree(xnestDefaultColormaps
);
191 XFree(xnestPixmapFormats
);
192 XCloseDisplay(xnestDisplay
);