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