First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xnest / Display.c
blob01290417c0ecf4eca29a8d48692b7f93620406f0
1 /*
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>
18 #endif
20 #include <X11/X.h>
21 #include <X11/Xproto.h>
22 #include "screenint.h"
23 #include "input.h"
24 #include "misc.h"
25 #include "scrnintstr.h"
26 #include "servermd.h"
28 #include "Xnest.h"
30 #include "Display.h"
31 #include "Init.h"
32 #include "Args.h"
34 #include "icon"
35 #include "screensaver"
37 Display *xnestDisplay = NULL;
38 XVisualInfo *xnestVisuals;
39 int xnestNumVisuals;
40 int xnestDefaultVisualIndex;
41 Colormap *xnestDefaultColormaps;
42 static int xnestNumDefaultColormaps;
43 int *xnestDepths;
44 int xnestNumDepths;
45 XPixmapFormatValues *xnestPixmapFormats;
46 int xnestNumPixmapFormats;
47 Pixel xnestBlackPixel;
48 Pixel xnestWhitePixel;
49 Drawable xnestDefaultDrawables[MAXDEPTH + 1];
50 Pixmap xnestIconBitmap;
51 Pixmap xnestScreenSaverPixmap;
52 XlibGC xnestBitmapGC;
53 unsigned long xnestEventMask;
55 void
56 xnestOpenDisplay(int argc, char *argv[])
58 XVisualInfo vi;
59 long mask;
60 int i, j;
62 if (!xnestDoFullGeneration) return;
64 xnestCloseDisplay();
66 xnestDisplay = XOpenDisplay(xnestDisplayName);
67 if (xnestDisplay == NULL)
68 FatalError("Unable to open display \"%s\".\n",
69 XDisplayName(xnestDisplayName));
71 if (xnestSynchronize)
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;
89 break;
91 if (xnestDefaultVisualIndex == UNDEFINED)
92 FatalError("Unable to find desired default visual.\n");
94 else {
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 *
105 sizeof(Colormap));
106 for (i = 0; i < xnestNumDefaultColormaps; i++)
107 xnestDefaultColormaps[i] = XCreateColormap(xnestDisplay,
108 DefaultRootWindow(xnestDisplay),
109 xnestVisuals[i].visual,
110 AllocNone);
112 xnestDepths = XListDepths(xnestDisplay, DefaultScreen(xnestDisplay),
113 &xnestNumDepths);
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;
123 else
124 xnestEventMask = 0L;
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))
141 xnestX = 0;
143 if (!(xnestUserGeometry & YValue))
144 xnestY = 0;
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;
159 xnestIconBitmap =
160 XCreateBitmapFromData(xnestDisplay,
161 DefaultRootWindow(xnestDisplay),
162 (char *)icon_bits,
163 icon_width,
164 icon_height);
166 xnestScreenSaverPixmap =
167 XCreatePixmapFromBitmapData(xnestDisplay,
168 DefaultRootWindow(xnestDisplay),
169 (char *)screensaver_bits,
170 screensaver_width,
171 screensaver_height,
172 xnestWhitePixel,
173 xnestBlackPixel,
174 DefaultDepth(xnestDisplay,
175 DefaultScreen(xnestDisplay)));
178 void
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);
189 XFree(xnestVisuals);
190 XFree(xnestDepths);
191 XFree(xnestPixmapFormats);
192 XCloseDisplay(xnestDisplay);