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>
23 #include <X11/Xproto.h>
24 #include "screenint.h"
27 #include "scrnintstr.h"
37 #include "screensaver"
39 Display
*xnestDisplay
= NULL
;
40 XVisualInfo
*xnestVisuals
;
42 int xnestDefaultVisualIndex
;
43 Colormap
*xnestDefaultColormaps
;
44 static int xnestNumDefaultColormaps
;
47 XPixmapFormatValues
*xnestPixmapFormats
;
48 int xnestNumPixmapFormats
;
49 Pixel xnestBlackPixel
;
50 Pixel xnestWhitePixel
;
51 Drawable xnestDefaultDrawables
[MAXDEPTH
+ 1];
52 Pixmap xnestIconBitmap
;
53 Pixmap xnestScreenSaverPixmap
;
55 unsigned long xnestEventMask
;
58 /* prevent "Function has no return statement" error for x_io_error_handler */
59 #pragma does_not_return(exit)
62 static int _X_NORETURN
63 x_io_error_handler(Display
* dpy
)
65 ErrorF("Lost connection to X server: %s\n", strerror(errno
));
66 CloseWellKnownConnections();
72 xnestOpenDisplay(int argc
, char *argv
[])
78 if (!xnestDoFullGeneration
)
81 XSetIOErrorHandler(x_io_error_handler
);
85 xnestDisplay
= XOpenDisplay(xnestDisplayName
);
86 if (xnestDisplay
== NULL
)
87 FatalError("Unable to open display \"%s\".\n",
88 XDisplayName(xnestDisplayName
));
91 XSynchronize(xnestDisplay
, True
);
93 mask
= VisualScreenMask
;
94 vi
.screen
= DefaultScreen(xnestDisplay
);
95 xnestVisuals
= XGetVisualInfo(xnestDisplay
, mask
, &vi
, &xnestNumVisuals
);
96 if (xnestNumVisuals
== 0 || xnestVisuals
== NULL
)
97 FatalError("Unable to find any visuals.\n");
99 if (xnestUserDefaultClass
|| xnestUserDefaultDepth
) {
100 xnestDefaultVisualIndex
= UNDEFINED
;
101 for (i
= 0; i
< xnestNumVisuals
; i
++)
102 if ((!xnestUserDefaultClass
||
103 xnestVisuals
[i
].class == xnestDefaultClass
)
105 (!xnestUserDefaultDepth
||
106 xnestVisuals
[i
].depth
== xnestDefaultDepth
)) {
107 xnestDefaultVisualIndex
= i
;
110 if (xnestDefaultVisualIndex
== UNDEFINED
)
111 FatalError("Unable to find desired default visual.\n");
114 vi
.visualid
= XVisualIDFromVisual(DefaultVisual(xnestDisplay
,
117 xnestDefaultVisualIndex
= 0;
118 for (i
= 0; i
< xnestNumVisuals
; i
++)
119 if (vi
.visualid
== xnestVisuals
[i
].visualid
)
120 xnestDefaultVisualIndex
= i
;
123 xnestNumDefaultColormaps
= xnestNumVisuals
;
124 xnestDefaultColormaps
= (Colormap
*) malloc(xnestNumDefaultColormaps
*
126 for (i
= 0; i
< xnestNumDefaultColormaps
; i
++)
127 xnestDefaultColormaps
[i
] = XCreateColormap(xnestDisplay
,
130 xnestVisuals
[i
].visual
,
133 xnestDepths
= XListDepths(xnestDisplay
, DefaultScreen(xnestDisplay
),
136 xnestPixmapFormats
= XListPixmapFormats(xnestDisplay
,
137 &xnestNumPixmapFormats
);
139 xnestBlackPixel
= BlackPixel(xnestDisplay
, DefaultScreen(xnestDisplay
));
140 xnestWhitePixel
= WhitePixel(xnestDisplay
, DefaultScreen(xnestDisplay
));
142 if (xnestParentWindow
!= (Window
) 0)
143 xnestEventMask
= StructureNotifyMask
;
147 for (i
= 0; i
<= MAXDEPTH
; i
++)
148 xnestDefaultDrawables
[i
] = None
;
150 for (i
= 0; i
< xnestNumPixmapFormats
; i
++)
151 for (j
= 0; j
< xnestNumDepths
; j
++)
152 if (xnestPixmapFormats
[i
].depth
== 1 ||
153 xnestPixmapFormats
[i
].depth
== xnestDepths
[j
]) {
154 xnestDefaultDrawables
[xnestPixmapFormats
[i
].depth
] =
155 XCreatePixmap(xnestDisplay
, DefaultRootWindow(xnestDisplay
),
156 1, 1, xnestPixmapFormats
[i
].depth
);
159 xnestBitmapGC
= XCreateGC(xnestDisplay
, xnestDefaultDrawables
[1], 0L, NULL
);
161 if (!(xnestUserGeometry
& XValue
))
164 if (!(xnestUserGeometry
& YValue
))
167 if (xnestParentWindow
== 0) {
168 if (!(xnestUserGeometry
& WidthValue
))
169 xnestWidth
= 3 * DisplayWidth(xnestDisplay
,
170 DefaultScreen(xnestDisplay
)) / 4;
172 if (!(xnestUserGeometry
& HeightValue
))
173 xnestHeight
= 3 * DisplayHeight(xnestDisplay
,
174 DefaultScreen(xnestDisplay
)) / 4;
177 if (!xnestUserBorderWidth
)
178 xnestBorderWidth
= 1;
181 XCreateBitmapFromData(xnestDisplay
,
182 DefaultRootWindow(xnestDisplay
),
183 (char *) icon_bits
, icon_width
, icon_height
);
185 xnestScreenSaverPixmap
=
186 XCreatePixmapFromBitmapData(xnestDisplay
,
187 DefaultRootWindow(xnestDisplay
),
188 (char *) screensaver_bits
,
193 DefaultDepth(xnestDisplay
,
194 DefaultScreen(xnestDisplay
)));
198 xnestCloseDisplay(void)
200 if (!xnestDoFullGeneration
|| !xnestDisplay
)
204 If xnestDoFullGeneration all x resources will be destroyed upon closing
205 the display connection. There is no need to generate extra protocol.
208 free(xnestDefaultColormaps
);
211 XFree(xnestPixmapFormats
);
212 XCloseDisplay(xnestDisplay
);