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