ephyrinit.c revision 4642e01f
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 EPHYR_DBG("mark argv[%d]='%s'", i, argv[i] ); 151 152 if (i == 1) 153 { 154 hostx_use_resname(basename(argv[0]), 0); 155 } 156 157 if (!strcmp (argv[i], "-parent")) 158 { 159 if(i+1 < argc) 160 { 161 processScreenArg ("100x100", argv[i+1]); 162 return 2; 163 } 164 165 UseMsg(); 166 exit(1); 167 } 168 else if (!strcmp (argv[i], "-screen")) 169 { 170 if ((i+1) < argc) 171 { 172 processScreenArg (argv[i+1], NULL); 173 return 2; 174 } 175 176 UseMsg(); 177 exit(1); 178 } 179 else if (!strcmp (argv[i], "-host-cursor")) 180 { 181 hostx_use_host_cursor(); 182 return 1; 183 } 184 else if (!strcmp (argv[i], "-fullscreen")) 185 { 186 hostx_use_fullscreen(); 187 return 1; 188 } 189 else if (!strcmp (argv[i], "-grayscale")) 190 { 191 EphyrWantGrayScale = 1; 192 return 1; 193 } 194 else if (!strcmp (argv[i], "-fakexa")) 195 { 196 ephyrFuncs.initAccel = ephyrDrawInit; 197 ephyrFuncs.enableAccel = ephyrDrawEnable; 198 ephyrFuncs.disableAccel = ephyrDrawDisable; 199 ephyrFuncs.finiAccel = ephyrDrawFini; 200 return 1; 201 } 202 else if (!strcmp (argv[i], "-verbosity")) 203 { 204 if(i+1 < argc && argv[i+1][0] != '-') 205 { 206 int verbosity=atoi (argv[i+1]) ; 207 LogSetParameter (XLOG_VERBOSITY, verbosity) ; 208 EPHYR_LOG ("set verbosiry to %d\n", verbosity) ; 209 return 2 ; 210 } 211 else 212 { 213 UseMsg() ; 214 exit(1) ; 215 } 216 } 217#ifdef GLXEXT 218 else if (!strcmp (argv[i], "-nodri")) 219 { 220 noGlxVisualInit = FALSE ; 221 ephyrNoDRI = TRUE ; 222 EPHYR_LOG ("no direct rendering enabled\n") ; 223 return 1 ; 224 } 225#endif 226 else if (!strcmp (argv[i], "-noxv")) 227 { 228 ephyrNoXV = TRUE ; 229 EPHYR_LOG ("no XVideo enabled\n") ; 230 return 1 ; 231 } 232 else if (!strcmp (argv[i], "-name")) 233 { 234 if (i+1 < argc && argv[i+1][0] != '-') 235 { 236 hostx_use_resname(argv[i+1], 1); 237 return 2; 238 } 239 else 240 { 241 UseMsg(); 242 return 0; 243 } 244 } 245 else if (argv[i][0] == ':') 246 { 247 hostx_set_display_name(argv[i]); 248 } 249 250 return KdProcessArgument (argc, argv, i); 251} 252 253void 254OsVendorInit (void) 255{ 256 EPHYR_DBG("mark"); 257 258 if (hostx_want_host_cursor()) 259 { 260 ephyrFuncs.initCursor = &ephyrCursorInit; 261 ephyrFuncs.enableCursor = &ephyrCursorEnable; 262 } 263 264 KdOsInit (&EphyrOsFuncs); 265} 266 267/* 'Fake' cursor stuff, could be improved */ 268 269static Bool 270ephyrRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) 271{ 272 return TRUE; 273} 274 275static Bool 276ephyrUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) 277{ 278 return TRUE; 279} 280 281static void 282ephyrSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y) 283{ 284 ; 285} 286 287static void 288ephyrMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) 289{ 290 ; 291} 292 293static Bool 294ephyrDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) 295{ 296 return TRUE; 297} 298 299miPointerSpriteFuncRec EphyrPointerSpriteFuncs = { 300 ephyrRealizeCursor, 301 ephyrUnrealizeCursor, 302 ephyrSetCursor, 303 ephyrMoveCursor, 304 ephyrDeviceCursorInitialize, 305 NULL 306}; 307 308 309Bool 310ephyrCursorInit(ScreenPtr pScreen) 311{ 312 miPointerInitialize(pScreen, 313 &EphyrPointerSpriteFuncs, 314 &ephyrPointerScreenFuncs, 315 FALSE); 316 317 return TRUE; 318} 319 320void 321ephyrCursorEnable(ScreenPtr pScreen) 322{ 323 ; 324} 325 326KdCardFuncs ephyrFuncs = { 327 ephyrCardInit, /* cardinit */ 328 ephyrScreenInit, /* scrinit */ 329 ephyrInitScreen, /* initScreen */ 330 ephyrFinishInitScreen, /* finishInitScreen */ 331 ephyrCreateResources, /* createRes */ 332 ephyrPreserve, /* preserve */ 333 ephyrEnable, /* enable */ 334 ephyrDPMS, /* dpms */ 335 ephyrDisable, /* disable */ 336 ephyrRestore, /* restore */ 337 ephyrScreenFini, /* scrfini */ 338 ephyrCardFini, /* cardfini */ 339 340 0, /* initCursor */ 341 0, /* enableCursor */ 342 0, /* disableCursor */ 343 0, /* finiCursor */ 344 0, /* recolorCursor */ 345 346 0, /* initAccel */ 347 0, /* enableAccel */ 348 0, /* disableAccel */ 349 0, /* finiAccel */ 350 351 ephyrGetColors,/* getColors */ 352 ephyrPutColors, /* putColors */ 353}; 354