Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / kdrive / ephyr / ephyrinit.c
1 /*
2 * Xephyr - A kdrive X server thats runs in a host X window.
3 * Authored by Matthew Allum <mallum@o-hand.com>
4 *
5 * Copyright © 2004 Nokia
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of Nokia not be used in
12 * advertising or publicity pertaining to distribution of the software without
13 * specific, written prior permission. Nokia makes no
14 * representations about the suitability of this software for any purpose. It
15 * is provided "as is" without express or implied warranty.
16 *
17 * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23 * PERFORMANCE OF THIS SOFTWARE.
24 */
25
26 #ifdef HAVE_CONFIG_H
27 #include <kdrive-config.h>
28 #endif
29 #include "ephyr.h"
30 #include "ephyrlog.h"
31 #include "glx_extinit.h"
32
33 extern Window EphyrPreExistingHostWin;
34 extern Bool EphyrWantGrayScale;
35 extern Bool EphyrWantResize;
36 extern Bool kdHasPointer;
37 extern Bool kdHasKbd;
38
39 #ifdef GLXEXT
40 extern Bool ephyrNoDRI;
41 #endif
42 extern Bool ephyrNoXV;
43
44 #ifdef KDRIVE_EVDEV
45 extern KdPointerDriver LinuxEvdevMouseDriver;
46 extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
47 #endif
48
49 void processScreenArg(const char *screen_size, char *parent_id);
50
51 void
52 InitCard(char *name)
53 {
54 EPHYR_DBG("mark");
55 KdCardInfoAdd(&ephyrFuncs, 0);
56 }
57
58 static const ExtensionModule ephyrExtensions[] = {
59 #ifdef GLXEXT
60 { GlxExtensionInit, "GLX", &noGlxExtension },
61 #endif
62 };
63
64 static
65 void ephyrExtensionInit(void)
66 {
67 int i;
68
69 for (i = 0; i < ARRAY_SIZE(ephyrExtensions); i++)
70 LoadExtension(&ephyrExtensions[i], TRUE);
71 }
72
73
74 void
75 InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
76 {
77 if (serverGeneration == 1)
78 ephyrExtensionInit();
79
80 KdInitOutput(pScreenInfo, argc, argv);
81 }
82
83 void
84 InitInput(int argc, char **argv)
85 {
86 KdKeyboardInfo *ki;
87 KdPointerInfo *pi;
88
89 KdAddKeyboardDriver(&EphyrKeyboardDriver);
90 #ifdef KDRIVE_EVDEV
91 KdAddKeyboardDriver(&LinuxEvdevKeyboardDriver);
92 #endif
93 KdAddPointerDriver(&EphyrMouseDriver);
94 #ifdef KDRIVE_EVDEV
95 KdAddPointerDriver(&LinuxEvdevMouseDriver);
96 #endif
97
98 if (!kdHasKbd) {
99 ki = KdNewKeyboard();
100 if (!ki)
101 FatalError("Couldn't create Xephyr keyboard\n");
102 ki->driver = &EphyrKeyboardDriver;
103 KdAddKeyboard(ki);
104 }
105
106 if (!kdHasPointer) {
107 pi = KdNewPointer();
108 if (!pi)
109 FatalError("Couldn't create Xephyr pointer\n");
110 pi->driver = &EphyrMouseDriver;
111 KdAddPointer(pi);
112 }
113
114 KdInitInput();
115 }
116
117 void
118 CloseInput(void)
119 {
120 KdCloseInput();
121 }
122
123 #ifdef DDXBEFORERESET
124 void
125 ddxBeforeReset(void)
126 {
127 }
128 #endif
129
130 void
131 ddxUseMsg(void)
132 {
133 KdUseMsg();
134
135 ErrorF("\nXephyr Option Usage:\n");
136 ErrorF("-parent <XID> Use existing window as Xephyr root win\n");
137 ErrorF("-sw-cursor Render cursors in software in Xephyr\n");
138 ErrorF("-fullscreen Attempt to run Xephyr fullscreen\n");
139 ErrorF("-grayscale Simulate 8bit grayscale\n");
140 ErrorF("-resizeable Make Xephyr windows resizeable\n");
141 ErrorF
142 ("-fakexa Simulate acceleration using software rendering\n");
143 ErrorF("-verbosity <level> Set log verbosity level\n");
144 #ifdef GLXEXT
145 ErrorF("-nodri do not use DRI\n");
146 #endif
147 ErrorF("-noxv do not use XV\n");
148 ErrorF("-name [name] define the name in the WM_CLASS property\n");
149 ErrorF
150 ("-title [title] set the window title in the WM_NAME property\n");
151 ErrorF("\n");
152
153 exit(1);
154 }
155
156 void
157 processScreenArg(const char *screen_size, char *parent_id)
158 {
159 KdCardInfo *card;
160
161 InitCard(0); /*Put each screen on a separate card */
162 card = KdCardInfoLast();
163
164 if (card) {
165 KdScreenInfo *screen;
166 unsigned long p_id = 0;
167
168 screen = KdScreenInfoAdd(card);
169 KdParseScreen(screen, screen_size);
170 screen->driver = calloc(1, sizeof(EphyrScrPriv));
171 if (!screen->driver)
172 FatalError("Couldn't alloc screen private\n");
173
174 if (parent_id) {
175 p_id = strtol(parent_id, NULL, 0);
176 }
177 EPHYR_DBG("screen number:%d\n", screen->mynum);
178 hostx_add_screen(screen, p_id, screen->mynum);
179 }
180 else {
181 ErrorF("No matching card found!\n");
182 }
183 }
184
185 int
186 ddxProcessArgument(int argc, char **argv, int i)
187 {
188 static char *parent = NULL;
189
190 EPHYR_DBG("mark argv[%d]='%s'", i, argv[i]);
191
192 if (i == 1) {
193 hostx_use_resname(basename(argv[0]), 0);
194 }
195
196 if (!strcmp(argv[i], "-parent")) {
197 if (i + 1 < argc) {
198 int j;
199
200 /* If parent is specified and a screen argument follows, don't do
201 * anything, let the -screen handling init the rest */
202 for (j = i; j < argc; j++) {
203 if (!strcmp(argv[j], "-screen")) {
204 parent = argv[i + 1];
205 return 2;
206 }
207 }
208
209 processScreenArg("100x100", argv[i + 1]);
210 return 2;
211 }
212
213 UseMsg();
214 exit(1);
215 }
216 else if (!strcmp(argv[i], "-screen")) {
217 if ((i + 1) < argc) {
218 processScreenArg(argv[i + 1], parent);
219 parent = NULL;
220 return 2;
221 }
222
223 UseMsg();
224 exit(1);
225 }
226 else if (!strcmp(argv[i], "-sw-cursor")) {
227 hostx_use_sw_cursor();
228 return 1;
229 }
230 else if (!strcmp(argv[i], "-host-cursor")) {
231 /* Compatibility with the old command line argument, now the default. */
232 return 1;
233 }
234 else if (!strcmp(argv[i], "-fullscreen")) {
235 hostx_use_fullscreen();
236 return 1;
237 }
238 else if (!strcmp(argv[i], "-grayscale")) {
239 EphyrWantGrayScale = 1;
240 return 1;
241 }
242 else if (!strcmp(argv[i], "-resizeable")) {
243 EphyrWantResize = 1;
244 return 1;
245 }
246 else if (!strcmp(argv[i], "-fakexa")) {
247 ephyrFuncs.initAccel = ephyrDrawInit;
248 ephyrFuncs.enableAccel = ephyrDrawEnable;
249 ephyrFuncs.disableAccel = ephyrDrawDisable;
250 ephyrFuncs.finiAccel = ephyrDrawFini;
251 return 1;
252 }
253 else if (!strcmp(argv[i], "-verbosity")) {
254 if (i + 1 < argc && argv[i + 1][0] != '-') {
255 int verbosity = atoi(argv[i + 1]);
256
257 LogSetParameter(XLOG_VERBOSITY, verbosity);
258 EPHYR_LOG("set verbosiry to %d\n", verbosity);
259 return 2;
260 }
261 else {
262 UseMsg();
263 exit(1);
264 }
265 }
266 #ifdef GLXEXT
267 else if (!strcmp(argv[i], "-nodri")) {
268 ephyrNoDRI = TRUE;
269 EPHYR_LOG("no direct rendering enabled\n");
270 return 1;
271 }
272 #endif
273 else if (!strcmp(argv[i], "-noxv")) {
274 ephyrNoXV = TRUE;
275 EPHYR_LOG("no XVideo enabled\n");
276 return 1;
277 }
278 else if (!strcmp(argv[i], "-name")) {
279 if (i + 1 < argc && argv[i + 1][0] != '-') {
280 hostx_use_resname(argv[i + 1], 1);
281 return 2;
282 }
283 else {
284 UseMsg();
285 return 0;
286 }
287 }
288 else if (!strcmp(argv[i], "-title")) {
289 if (i + 1 < argc && argv[i + 1][0] != '-') {
290 hostx_set_title(argv[i + 1]);
291 return 2;
292 }
293 else {
294 UseMsg();
295 return 0;
296 }
297 }
298 else if (argv[i][0] == ':') {
299 hostx_set_display_name(argv[i]);
300 }
301 /* Xnest compatibility */
302 else if (!strcmp(argv[i], "-display")) {
303 hostx_set_display_name(argv[i + 1]);
304 return 2;
305 }
306 else if (!strcmp(argv[i], "-sync") ||
307 !strcmp(argv[i], "-full") ||
308 !strcmp(argv[i], "-sss") || !strcmp(argv[i], "-install")) {
309 return 1;
310 }
311 else if (!strcmp(argv[i], "-bw") ||
312 !strcmp(argv[i], "-class") ||
313 !strcmp(argv[i], "-geometry") || !strcmp(argv[i], "-scrns")) {
314 return 2;
315 }
316 /* end Xnest compat */
317
318 return KdProcessArgument(argc, argv, i);
319 }
320
321 void
322 OsVendorInit(void)
323 {
324 EPHYR_DBG("mark");
325
326 if (hostx_want_host_cursor()) {
327 ephyrFuncs.initCursor = &ephyrCursorInit;
328 ephyrFuncs.enableCursor = &ephyrCursorEnable;
329 }
330
331 KdOsInit(&EphyrOsFuncs);
332 }
333
334 /* 'Fake' cursor stuff, could be improved */
335
336 static Bool
337 ephyrRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
338 {
339 return TRUE;
340 }
341
342 static Bool
343 ephyrUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
344 {
345 return TRUE;
346 }
347
348 static void
349 ephyrSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x,
350 int y)
351 {
352 ;
353 }
354
355 static void
356 ephyrMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
357 {
358 ;
359 }
360
361 static Bool
362 ephyrDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
363 {
364 return TRUE;
365 }
366
367 static void
368 ephyrDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
369 {
370 }
371
372 miPointerSpriteFuncRec EphyrPointerSpriteFuncs = {
373 ephyrRealizeCursor,
374 ephyrUnrealizeCursor,
375 ephyrSetCursor,
376 ephyrMoveCursor,
377 ephyrDeviceCursorInitialize,
378 ephyrDeviceCursorCleanup
379 };
380
381 Bool
382 ephyrCursorInit(ScreenPtr pScreen)
383 {
384 miPointerInitialize(pScreen,
385 &EphyrPointerSpriteFuncs,
386 &ephyrPointerScreenFuncs, FALSE);
387
388 return TRUE;
389 }
390
391 void
392 ephyrCursorEnable(ScreenPtr pScreen)
393 {
394 ;
395 }
396
397 KdCardFuncs ephyrFuncs = {
398 ephyrCardInit, /* cardinit */
399 ephyrScreenInitialize, /* scrinit */
400 ephyrInitScreen, /* initScreen */
401 ephyrFinishInitScreen, /* finishInitScreen */
402 ephyrCreateResources, /* createRes */
403 ephyrPreserve, /* preserve */
404 ephyrEnable, /* enable */
405 ephyrDPMS, /* dpms */
406 ephyrDisable, /* disable */
407 ephyrRestore, /* restore */
408 ephyrScreenFini, /* scrfini */
409 ephyrCardFini, /* cardfini */
410
411 0, /* initCursor */
412 0, /* enableCursor */
413 0, /* disableCursor */
414 0, /* finiCursor */
415 0, /* recolorCursor */
416
417 0, /* initAccel */
418 0, /* enableAccel */
419 0, /* disableAccel */
420 0, /* finiAccel */
421
422 ephyrGetColors, /* getColors */
423 ephyrPutColors, /* putColors */
424 };