ephyrinit.c revision b1d344b3
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
32extern Window EphyrPreExistingHostWin;
33extern Bool   EphyrWantGrayScale;
34extern Bool   kdHasPointer;
35extern Bool   kdHasKbd;
36
37#ifdef GLXEXT
38extern Bool   ephyrNoDRI;
39extern Bool noGlxVisualInit;
40#endif
41extern Bool   ephyrNoXV;
42
43void processScreenArg (char *screen_size, char *parent_id) ;
44
45void
46InitCard (char *name)
47{
48    KdCardAttr	attr;
49
50    EPHYR_DBG("mark");
51
52
53    KdCardInfoAdd (&ephyrFuncs, &attr, 0);
54}
55
56void
57InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv)
58{
59  KdInitOutput (pScreenInfo, argc, argv);
60}
61
62void
63InitInput (int argc, char **argv)
64{
65  KdKeyboardInfo *ki;
66  KdPointerInfo *pi;
67
68  KdAddKeyboardDriver(&EphyrKeyboardDriver);
69#ifdef linux
70  KdAddKeyboardDriver(&LinuxEvdevKeyboardDriver);
71#endif
72  KdAddPointerDriver(&EphyrMouseDriver);
73#ifdef linux
74  KdAddPointerDriver(&LinuxEvdevMouseDriver);
75#endif
76
77  if (!kdHasKbd) {
78    ki = KdNewKeyboard();
79    if (!ki)
80      FatalError("Couldn't create Xephyr keyboard\n");
81    ki->driver = &EphyrKeyboardDriver;
82    KdAddKeyboard(ki);
83  }
84
85  if (!kdHasPointer) {
86    pi = KdNewPointer();
87    if (!pi)
88      FatalError("Couldn't create Xephyr pointer\n");
89    pi->driver = &EphyrMouseDriver;
90    KdAddPointer(pi);
91  }
92
93  KdInitInput();
94}
95
96void
97ddxUseMsg (void)
98{
99  KdUseMsg();
100
101  ErrorF("\nXephyr Option Usage:\n");
102  ErrorF("-parent <XID>        Use existing window as Xephyr root win\n");
103  ErrorF("-host-cursor         Re-use exisiting X host server cursor\n");
104  ErrorF("-fullscreen          Attempt to run Xephyr fullscreen\n");
105  ErrorF("-grayscale           Simulate 8bit grayscale\n");
106  ErrorF("-fakexa              Simulate acceleration using software rendering\n");
107  ErrorF("-verbosity <level>   Set log verbosity level\n");
108#ifdef GLXEXT
109  ErrorF("-nodri               do not use DRI\n");
110#endif
111  ErrorF("-noxv                do not use XV\n");
112  ErrorF("-name [name]         define the name in the WM_CLASS property\n");
113  ErrorF("\n");
114
115  exit(1);
116}
117
118void
119processScreenArg (char *screen_size, char *parent_id)
120{
121  KdCardInfo   *card;
122
123  InitCard (0);  /*Put each screen on a separate card*/
124  card = KdCardInfoLast ();
125
126  if (card)
127    {
128      KdScreenInfo *screen;
129      unsigned long p_id = 0;
130
131      screen = KdScreenInfoAdd (card);
132      KdParseScreen (screen, screen_size);
133
134      if (parent_id)
135        {
136          p_id = strtol (parent_id, NULL, 0);
137        }
138      EPHYR_DBG ("screen number:%d\n", screen->mynum) ;
139      hostx_add_screen (screen, p_id, screen->mynum);
140    }
141  else
142    {
143      ErrorF("No matching card found!\n");
144    }
145}
146
147int
148ddxProcessArgument (int argc, char **argv, int i)
149{
150  static char* parent = NULL;
151  EPHYR_DBG("mark argv[%d]='%s'", i, argv[i] );
152
153  if (i == 1)
154    {
155      hostx_use_resname(basename(argv[0]), 0);
156    }
157
158  if (!strcmp (argv[i], "-parent"))
159    {
160      if(i+1 < argc)
161	{
162	  int j;
163	  /* If parent is specified and a screen argument follows, don't do
164           * anything, let the -screen handling init the rest */
165	  for (j = i; j < argc; j++)
166	    {
167	      if (!strcmp(argv[j], "-screen"))
168		{
169		  parent = argv[i + 1];
170		  return 2;
171		}
172	    }
173
174	  processScreenArg ("100x100", argv[i+1]);
175	  return 2;
176	}
177
178      UseMsg();
179      exit(1);
180    }
181  else if (!strcmp (argv[i], "-screen"))
182    {
183      if ((i+1) < argc)
184	{
185	  processScreenArg (argv[i+1], parent);
186	  parent = NULL;
187	  return 2;
188	}
189
190      UseMsg();
191      exit(1);
192    }
193  else if (!strcmp (argv[i], "-host-cursor"))
194    {
195      hostx_use_host_cursor();
196      return 1;
197    }
198  else if (!strcmp (argv[i], "-fullscreen"))
199    {
200      hostx_use_fullscreen();
201      return 1;
202    }
203  else if (!strcmp (argv[i], "-grayscale"))
204    {
205      EphyrWantGrayScale = 1;
206      return 1;
207    }
208  else if (!strcmp (argv[i], "-fakexa"))
209    {
210      ephyrFuncs.initAccel = ephyrDrawInit;
211      ephyrFuncs.enableAccel = ephyrDrawEnable;
212      ephyrFuncs.disableAccel = ephyrDrawDisable;
213      ephyrFuncs.finiAccel = ephyrDrawFini;
214      return 1;
215    }
216  else if (!strcmp (argv[i], "-verbosity"))
217    {
218      if(i+1 < argc && argv[i+1][0] != '-')
219	{
220	  int verbosity=atoi (argv[i+1]) ;
221	  LogSetParameter (XLOG_VERBOSITY, verbosity) ;
222	  EPHYR_LOG ("set verbosiry to %d\n", verbosity) ;
223	  return 2 ;
224	}
225      else
226	{
227	  UseMsg() ;
228	  exit(1) ;
229	}
230    }
231#ifdef GLXEXT
232  else if (!strcmp (argv[i], "-nodri"))
233   {
234       noGlxVisualInit = FALSE ;
235       ephyrNoDRI = TRUE ;
236       EPHYR_LOG ("no direct rendering enabled\n") ;
237       return 1 ;
238   }
239#endif
240  else if (!strcmp (argv[i], "-noxv"))
241   {
242       ephyrNoXV = TRUE ;
243       EPHYR_LOG ("no XVideo enabled\n") ;
244       return 1 ;
245   }
246  else if (!strcmp (argv[i], "-name"))
247   {
248       if (i+1 < argc && argv[i+1][0] != '-')
249         {
250           hostx_use_resname(argv[i+1], 1);
251           return 2;
252         }
253       else
254         {
255           UseMsg();
256           return 0;
257         }
258   }
259  else if (argv[i][0] == ':')
260    {
261      hostx_set_display_name(argv[i]);
262    }
263
264  return KdProcessArgument (argc, argv, i);
265}
266
267void
268OsVendorInit (void)
269{
270  EPHYR_DBG("mark");
271
272  if (hostx_want_host_cursor())
273    {
274      ephyrFuncs.initCursor   = &ephyrCursorInit;
275      ephyrFuncs.enableCursor = &ephyrCursorEnable;
276    }
277
278  KdOsInit (&EphyrOsFuncs);
279}
280
281/* 'Fake' cursor stuff, could be improved */
282
283static Bool
284ephyrRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
285{
286  return TRUE;
287}
288
289static Bool
290ephyrUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
291{
292  return TRUE;
293}
294
295static void
296ephyrSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
297{
298  ;
299}
300
301static void
302ephyrMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
303{
304  ;
305}
306
307static Bool
308ephyrDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
309{
310  return TRUE;
311}
312
313miPointerSpriteFuncRec EphyrPointerSpriteFuncs = {
314	ephyrRealizeCursor,
315	ephyrUnrealizeCursor,
316	ephyrSetCursor,
317	ephyrMoveCursor,
318	ephyrDeviceCursorInitialize,
319	NULL
320};
321
322
323Bool
324ephyrCursorInit(ScreenPtr pScreen)
325{
326  miPointerInitialize(pScreen,
327		      &EphyrPointerSpriteFuncs,
328		      &ephyrPointerScreenFuncs,
329		      FALSE);
330
331  return TRUE;
332}
333
334void
335ephyrCursorEnable(ScreenPtr pScreen)
336{
337  ;
338}
339
340KdCardFuncs ephyrFuncs = {
341    ephyrCardInit,	    /* cardinit */
342    ephyrScreenInit,	    /* scrinit */
343    ephyrInitScreen,	    /* initScreen */
344    ephyrFinishInitScreen,  /* finishInitScreen */
345    ephyrCreateResources,   /* createRes */
346    ephyrPreserve,	    /* preserve */
347    ephyrEnable,	    /* enable */
348    ephyrDPMS,		    /* dpms */
349    ephyrDisable,	    /* disable */
350    ephyrRestore,	    /* restore */
351    ephyrScreenFini,	    /* scrfini */
352    ephyrCardFini,	    /* cardfini */
353
354    0,			    /* initCursor */
355    0,			    /* enableCursor */
356    0,			    /* disableCursor */
357    0,			    /* finiCursor */
358    0,			    /* recolorCursor */
359
360    0,			    /* initAccel */
361    0,			    /* enableAccel */
362    0,			    /* disableAccel */
363    0,			    /* finiAccel */
364
365    ephyrGetColors,/* getColors */
366    ephyrPutColors,	    /* putColors */
367};
368