Release 970120
[wine/multimedia.git] / misc / main.c
blob14608d0eae39f1791e9ec338c8553c5fc8345974
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 /* #include <locale.h> */
13 #ifdef MALLOC_DEBUGGING
14 #include <malloc.h>
15 #endif
16 #include <X11/Xlib.h>
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19 #include <X11/Xlocale.h>
20 #include <X11/cursorfont.h>
21 #include "heap.h"
22 #include "message.h"
23 #include "module.h"
24 #include "msdos.h"
25 #include "windows.h"
26 #include "color.h"
27 #include "winsock.h"
28 #include "options.h"
29 #include "desktop.h"
30 #include "shell.h"
31 #include "winbase.h"
32 #define DEBUG_DEFINE_VARIABLES
33 #include "stddebug.h"
34 #include "debug.h"
35 #include "xmalloc.h"
37 const char people[] = "Wine is available thanks to the work of "
38 "Bob Amstadt, Dag Asheim, Martin Ayotte, Ross Biro, Uwe Bonnes, Erik Bos, "
39 "Fons Botman, John Brezak, Andrew Bulhak, John Burton, "
40 "Niels de Carpentier, Roman Dolejsi, Frans van Dorsselaer, Paul Falstad, "
41 "Olaf Flebbe, Peter Galbavy, Ramon Garcia, Hans de Graaff, "
42 "Charles M. Hannum, John Harvey, Cameron Heide, Jochen Hoenicke, "
43 "Onno Hovers, Jeffrey Hsu, Miguel de Icaza, Jukka Iivonen, "
44 "Alexandre Julliard, Jochen Karrer, Andreas Kirschbaum, Albrecht Kleine, "
45 "Jon Konrath, Alex Korobka, Greg Kreider, Anand Kumria, Scott A. Laird, "
46 "Martin von Loewis, Kenneth MacDonald, Peter MacDonald, William Magro, "
47 "Juergen Marquardt, Marcus Meissner, Graham Menhennitt, David Metcalfe, "
48 "Steffen Moeller, Philippe De Muyter, Itai Nahshon, Michael Patra, "
49 "Jim Peterson, Robert Pouliot, Keith Reynolds, John Richardson, "
50 "Johannes Ruscheinski, Thomas Sandford, Constantine Sapuntzakis, "
51 "Daniel Schepler, Ulrich Schmid, Bernd Schmidt, Yngvi Sigurjonsson, "
52 "Rick Sladkey, William Smith, Erik Svendsen, Tristan Tarrant, "
53 "Andrew Taylor, Duncan C Thomson, Goran Thyni, Jimmy Tirtawangsa, "
54 "Jon Tombs, Linus Torvalds, Gregory Trubetskoy, Michael Veksler, "
55 "Sven Verdoolaege, Eric Warnke, Manfred Weichel, Morten Welinder, "
56 "Jan Willamowius, Carl Williams, Karl Guenter Wuensch, Eric Youngdale, "
57 "and James Youngman. ";
59 const WINE_LANGUAGE_DEF Languages[] =
61 {"En",0x0409}, /* LANG_En */
62 {"Es",0x040A}, /* LANG_Es */
63 {"De",0x0407}, /* LANG_De */
64 {"No",0x0414}, /* LANG_No */
65 {"Fr",0x0400}, /* LANG_Fr */
66 {"Fi",0x040B}, /* LANG_Fi */
67 {"Da",0x0406}, /* LANG_Da */
68 {"Cz",0x0405}, /* LANG_Cz */
69 {"Eo", 0}, /* LANG_Eo */ /* FIXME languageid */
70 {"It",0x0410}, /* LANG_It */
71 {"Ko",0x0412}, /* LANG_Ko */
72 {NULL,0}
75 WORD WINE_LanguageId = 0;
77 #define WINE_CLASS "Wine" /* Class name for resources */
79 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
81 typedef struct tagENVENTRY {
82 LPSTR Name;
83 LPSTR Value;
84 WORD wSize;
85 struct tagENVENTRY *Prev;
86 struct tagENVENTRY *Next;
87 } ENVENTRY, *LPENVENTRY;
89 LPENVENTRY lpEnvList = NULL;
91 Display *display;
92 Screen *screen;
93 Window rootWindow;
94 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
95 int screenDepth = 0; /* Screen depth to use */
96 int desktopX = 0, desktopY = 0; /* Desktop window position (if any) */
97 int getVersion16 = 0;
98 int getVersion32 = 0;
99 OSVERSIONINFO32A getVersionEx;
101 struct options Options =
102 { /* default options */
103 NULL, /* desktopGeometry */
104 NULL, /* programName */
105 FALSE, /* usePrivateMap */
106 FALSE, /* useFixedMap */
107 FALSE, /* synchronous */
108 FALSE, /* backing store */
109 SW_SHOWNORMAL, /* cmdShow */
110 FALSE,
111 FALSE, /* failReadOnly */
112 MODE_ENHANCED, /* Enhanced mode */
113 FALSE, /* IPC enabled */
114 #ifdef DEFAULT_LANG
115 DEFAULT_LANG, /* Default language */
116 #else
117 LANG_En,
118 #endif
119 FALSE, /* Managed windows */
120 FALSE /* Perfect graphics */
124 static XrmOptionDescRec optionsTable[] =
126 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
127 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
128 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
129 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
130 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
131 { "-ipc", ".ipc", XrmoptionNoArg, (caddr_t)"off"},
132 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
133 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
134 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
135 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
136 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
137 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
138 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
139 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
140 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
141 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
142 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
143 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
144 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL }
147 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
149 #define USAGE \
150 "Usage: %s [options] program_name [arguments]\n" \
151 "\n" \
152 "Options:\n" \
153 " -backingstore Turn on backing store\n" \
154 " -debug Enter debugger before starting application\n" \
155 " -debugmsg name Turn debugging-messages on or off\n" \
156 " -depth n Change the depth to use for multiple-depth screens\n" \
157 " -desktop geom Use a desktop window of the given geometry\n" \
158 " -display name Use the specified display\n" \
159 " -dll name Enable or disable built-in DLLs\n" \
160 " -failreadonly Read only files may not be opened in write mode\n" \
161 " -fixedmap Use a \"standard\" color map\n" \
162 " -iconic Start as an icon\n" \
163 " -ipc Enable IPC facilities\n" \
164 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko)\n" \
165 " -managed Allow the window manager to manage created windows\n" \
166 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
167 " -name name Set the application name\n" \
168 " -perfect Favor correctness over speed for graphical operations\n" \
169 " -privatemap Use a private color map\n" \
170 " -synchronous Turn on synchronous display mode\n" \
171 " -winver Version to imitate (one of win31,win95,nt351)\n"
175 /***********************************************************************
176 * MAIN_Usage
178 #ifndef WINELIB32
179 void MAIN_Usage( char *name )
181 fprintf( stderr, USAGE, name );
182 exit(1);
184 #endif
187 /***********************************************************************
188 * MAIN_GetProgramName
190 * Get the program name. The name is specified by (in order of precedence):
191 * - the option '-name'.
192 * - the environment variable 'WINE_NAME'.
193 * - the last component of argv[0].
195 static char *MAIN_GetProgramName( int argc, char *argv[] )
197 int i;
198 char *p;
200 for (i = 1; i < argc-1; i++)
201 if (!strcmp( argv[i], "-name" )) return argv[i+1];
202 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
203 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
204 return argv[0];
208 /***********************************************************************
209 * MAIN_GetResource
211 * Fetch the value of resource 'name' using the correct instance name.
212 * 'name' must begin with '.' or '*'
214 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
216 char *buff_instance, *buff_class;
217 char *dummy;
218 int retval;
220 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
221 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
223 strcpy( buff_instance, Options.programName );
224 strcat( buff_instance, name );
225 strcpy( buff_class, WINE_CLASS );
226 strcat( buff_class, name );
227 retval = XrmGetResource( db, buff_instance, buff_class, &dummy, value );
228 free( buff_instance );
229 free( buff_class );
230 return retval;
234 /***********************************************************************
235 * ParseDebugOptions
237 * Turns specific debug messages on or off, according to "options".
238 * Returns TRUE if parsing was successful
240 #ifdef DEBUG_RUNTIME
242 BOOL ParseDebugOptions(char *options)
244 int l;
245 if (strlen(options)<3)
246 return FALSE;
249 if ((*options!='+')&&(*options!='-'))
250 return FALSE;
251 if (strchr(options,','))
252 l=strchr(options,',')-options;
253 else
254 l=strlen(options);
255 if (!lstrncmpi32A(options+1,"all",l-1))
257 int i;
258 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
259 debug_msg_enabled[i]=(*options=='+');
261 else
263 int i;
264 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
265 if (debug_msg_name && (!lstrncmpi32A(options+1,debug_msg_name[i],l-1)))
267 debug_msg_enabled[i]=(*options=='+');
268 break;
270 if (i==sizeof(debug_msg_enabled)/sizeof(short))
271 return FALSE;
273 options+=l;
275 while((*options==',')&&(*(++options)));
276 if (*options)
277 return FALSE;
278 else
279 return TRUE;
282 #endif
285 /***********************************************************************
286 * MAIN_ParseLanguageOption
288 * Parse -language option.
290 static void MAIN_ParseLanguageOption( char *arg )
292 const WINE_LANGUAGE_DEF *p = Languages;
294 Options.language = LANG_En; /* First language */
295 for (;p->name;p++)
297 if (!lstrcmpi32A( p->name, arg ))
299 WINE_LanguageId = p->langid;
300 return;
302 Options.language++;
304 fprintf( stderr, "Invalid language specified '%s'. Supported languages are: ", arg );
305 for (p = Languages; p->name; p++) fprintf( stderr, "%s ", p->name );
306 fprintf( stderr, "\n" );
307 exit(1);
311 /***********************************************************************
312 * MAIN_ParseModeOption
314 * Parse -mode option.
316 static void MAIN_ParseModeOption( char *arg )
318 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
319 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
320 else
322 fprintf(stderr, "Invalid mode '%s' specified.\n", arg);
323 fprintf(stderr, "Valid modes are: 'standard', 'enhanced' (default).\n");
324 exit(1);
328 /**********************************************************************
329 * MAIN_ParseVersion
331 static void MAIN_ParseVersion( char *arg )
333 /* If you add any other options,
334 verify the values you return on the real thing */
335 if(strcmp(arg,"win31")==0)
337 getVersion16 = 0x06160A03;
338 /* FIXME: My Win32s installation failed to execute the
339 MSVC 4 test program. So check these values */
340 getVersion32 = 0x80000A03;
341 getVersionEx.dwMajorVersion=3;
342 getVersionEx.dwMinorVersion=10;
343 getVersionEx.dwBuildNumber=0;
344 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32s;
345 strcpy(getVersionEx.szCSDVersion,"Win32s 1.3");
347 else if(strcmp(arg, "win95")==0)
349 getVersion16 = 0x07005F03;
350 getVersion32 = 0xC0000004;
351 getVersionEx.dwMajorVersion=4;
352 getVersionEx.dwMinorVersion=0;
353 getVersionEx.dwBuildNumber=0x40003B6;
354 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
355 strcpy(getVersionEx.szCSDVersion,"");
357 else if(strcmp(arg, "nt351")==0)
359 getVersion16 = 0x05000A03;
360 getVersion32 = 0x04213303;
361 getVersionEx.dwMajorVersion=3;
362 getVersionEx.dwMinorVersion=51;
363 getVersionEx.dwBuildNumber=0x421;
364 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_NT;
365 strcpy(getVersionEx.szCSDVersion,"Service Pack 2");
367 else fprintf(stderr, "Unknown winver system code - ignored\n");
370 /***********************************************************************
371 * MAIN_ParseOptions
373 * Parse command line options and open display.
375 static void MAIN_ParseOptions( int *argc, char *argv[] )
377 char *display_name = NULL;
378 XrmValue value;
379 XrmDatabase db = XrmGetFileDatabase(WINE_APP_DEFAULTS);
380 int i;
381 char *xrm_string;
383 Options.programName = MAIN_GetProgramName( *argc, argv );
385 /* Get display name from command line */
386 for (i = 1; i < *argc - 1; i++)
387 if (!strcmp( argv[i], "-display" ))
389 display_name = argv[i+1];
390 break;
393 #ifdef WINELIB
394 /* Need to assemble command line and pass it to WinMain */
395 #else
396 if (*argc < 2 || lstrcmpi32A(argv[1], "-h") == 0)
397 MAIN_Usage( argv[0] );
398 #endif
400 /* Open display */
402 if (display_name == NULL &&
403 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
405 if (!(display = XOpenDisplay( display_name )))
407 fprintf( stderr, "%s: Can't open display: %s\n",
408 argv[0], display_name ? display_name : "(none specified)" );
409 exit(1);
412 /* Merge file and screen databases */
413 if ((xrm_string = XResourceManagerString( display )) != NULL)
415 XrmDatabase display_db = XrmGetStringDatabase( xrm_string );
416 XrmMergeDatabases( display_db, &db );
419 /* Parse command line */
420 XrmParseCommand( &db, optionsTable, NB_OPTIONS,
421 Options.programName, argc, argv );
423 /* Get all options */
424 if (MAIN_GetResource( db, ".iconic", &value ))
425 Options.cmdShow = SW_SHOWMINIMIZED;
426 if (MAIN_GetResource( db, ".privatemap", &value ))
427 Options.usePrivateMap = TRUE;
428 if (MAIN_GetResource( db, ".fixedmap", &value ))
429 Options.useFixedMap = TRUE;
430 if (MAIN_GetResource( db, ".synchronous", &value ))
431 Options.synchronous = TRUE;
432 if (MAIN_GetResource( db, ".backingstore", &value ))
433 Options.backingstore = TRUE;
434 if (MAIN_GetResource( db, ".debug", &value ))
435 Options.debug = TRUE;
436 if (MAIN_GetResource( db, ".failreadonly", &value ))
437 Options.failReadOnly = TRUE;
438 if (MAIN_GetResource( db, ".ipc", &value ))
439 Options.ipc = TRUE;
440 if (MAIN_GetResource( db, ".perfect", &value ))
441 Options.perfectGraphics = TRUE;
442 if (MAIN_GetResource( db, ".depth", &value))
443 screenDepth = atoi( value.addr );
444 if (MAIN_GetResource( db, ".desktop", &value))
445 Options.desktopGeometry = value.addr;
446 if (MAIN_GetResource( db, ".language", &value))
447 MAIN_ParseLanguageOption( (char *)value.addr );
448 if (MAIN_GetResource( db, ".managed", &value))
449 Options.managed = TRUE;
450 if (MAIN_GetResource( db, ".mode", &value))
451 MAIN_ParseModeOption( (char *)value.addr );
453 #ifdef DEBUG_RUNTIME
454 if (MAIN_GetResource( db, ".debugoptions", &value))
455 ParseDebugOptions((char*)value.addr);
456 #endif
457 if (MAIN_GetResource( db, ".debugmsg", &value))
459 #ifndef DEBUG_RUNTIME
460 fprintf(stderr,"%s: Option \"-debugmsg\" not implemented.\n" \
461 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
462 argv[0]);
463 exit(1);
464 #else
465 if (ParseDebugOptions((char*)value.addr)==FALSE)
467 int i;
468 fprintf(stderr,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv[0]);
469 fprintf(stderr,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
470 fprintf(stderr,"Available message types:\n");
471 fprintf(stderr,"%-9s ","all");
472 for(i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
473 if(debug_msg_name[i])
474 fprintf(stderr,"%-9s%c",debug_msg_name[i],
475 (((i+2)%8==0)?'\n':' '));
476 fprintf(stderr,"\n\n");
477 exit(1);
479 #endif
482 if(MAIN_GetResource( db, ".dll", &value))
484 #ifndef WINELIB
485 if (!BUILTIN_ParseDLLOptions( (char*)value.addr ))
487 fprintf(stderr,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv[0]);
488 fprintf(stderr,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
489 fprintf(stderr,"Available DLLs:\n");
490 BUILTIN_PrintDLLs();
491 exit(1);
493 #else
494 fprintf(stderr,"-dll not supported in libwine\n");
495 #endif
498 if(MAIN_GetResource( db, ".winver", &value))
499 MAIN_ParseVersion( (char*)value.addr );
503 /***********************************************************************
504 * MAIN_CreateDesktop
506 static void MAIN_CreateDesktop( int argc, char *argv[] )
508 int flags;
509 unsigned int width = 640, height = 480; /* Default size = 640x480 */
510 char *name = "Wine desktop";
511 XSizeHints *size_hints;
512 XWMHints *wm_hints;
513 XClassHint *class_hints;
514 XSetWindowAttributes win_attr;
515 XTextProperty window_name;
516 Atom XA_WM_DELETE_WINDOW;
518 flags = XParseGeometry( Options.desktopGeometry,
519 &desktopX, &desktopY, &width, &height );
520 screenWidth = width;
521 screenHeight = height;
523 /* Create window */
525 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
526 PointerMotionMask | ButtonPressMask |
527 ButtonReleaseMask | EnterWindowMask |
528 StructureNotifyMask;
529 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
531 rootWindow = XCreateWindow( display, DefaultRootWindow(display),
532 desktopX, desktopY, width, height, 0,
533 CopyFromParent, InputOutput, CopyFromParent,
534 CWEventMask | CWCursor, &win_attr );
536 /* Set window manager properties */
538 size_hints = XAllocSizeHints();
539 wm_hints = XAllocWMHints();
540 class_hints = XAllocClassHint();
541 if (!size_hints || !wm_hints || !class_hints)
543 fprintf( stderr, "Not enough memory for window manager hints.\n" );
544 exit(1);
546 size_hints->min_width = size_hints->max_width = width;
547 size_hints->min_height = size_hints->max_height = height;
548 size_hints->flags = PMinSize | PMaxSize;
549 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
550 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
551 else size_hints->flags |= PSize;
553 wm_hints->flags = InputHint | StateHint;
554 wm_hints->input = True;
555 wm_hints->initial_state = NormalState;
556 class_hints->res_name = argv[0];
557 class_hints->res_class = "Wine";
559 XStringListToTextProperty( &name, 1, &window_name );
560 XSetWMProperties( display, rootWindow, &window_name, &window_name,
561 argv, argc, size_hints, wm_hints, class_hints );
562 XA_WM_DELETE_WINDOW = XInternAtom( display, "WM_DELETE_WINDOW", False );
563 XSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
564 XFree( size_hints );
565 XFree( wm_hints );
566 XFree( class_hints );
568 /* Map window */
570 XMapWindow( display, rootWindow );
574 XKeyboardState keyboard_state;
576 /***********************************************************************
577 * MAIN_SaveSetup
579 static void MAIN_SaveSetup(void)
581 XGetKeyboardControl(display, &keyboard_state);
584 /***********************************************************************
585 * MAIN_RestoreSetup
587 static void MAIN_RestoreSetup(void)
589 XKeyboardControl keyboard_value;
591 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
592 keyboard_value.bell_percent = keyboard_state.bell_percent;
593 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
594 keyboard_value.bell_duration = keyboard_state.bell_duration;
595 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
597 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
598 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
602 static void called_at_exit(void)
604 MAIN_RestoreSetup();
605 COLOR_Cleanup();
606 WINSOCK_Shutdown();
609 /***********************************************************************
610 * MAIN_WineInit
612 * Wine initialisation and command-line parsing
614 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
616 int depth_count, i;
617 int *depth_list;
618 struct timeval tv;
620 extern int _WinMain(int argc, char **argv);
622 #ifdef MALLOC_DEBUGGING
623 char *trace;
625 mcheck(NULL);
626 if (!(trace = getenv("MALLOC_TRACE")))
628 fprintf( stderr, "MALLOC_TRACE not set. No trace generated\n" );
630 else
632 fprintf( stderr, "malloc trace goes to %s\n", trace );
633 mtrace();
635 #endif
637 setbuf(stdout,NULL);
638 setbuf(stderr,NULL);
640 setlocale(LC_CTYPE,"");
641 gettimeofday( &tv, NULL);
642 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
644 XrmInitialize();
646 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
648 MAIN_ParseOptions( argc, argv );
650 if (Options.desktopGeometry && Options.managed)
652 fprintf( stderr, "%s: -managed and -desktop options cannot be used together\n",
653 Options.programName );
654 exit(1);
657 screen = DefaultScreenOfDisplay( display );
658 screenWidth = WidthOfScreen( screen );
659 screenHeight = HeightOfScreen( screen );
660 if (screenDepth) /* -depth option specified */
662 depth_list = XListDepths(display,DefaultScreen(display),&depth_count);
663 for (i = 0; i < depth_count; i++)
664 if (depth_list[i] == screenDepth) break;
665 XFree( depth_list );
666 if (i >= depth_count)
668 fprintf( stderr, "%s: Depth %d not supported on this screen.\n",
669 Options.programName, screenDepth );
670 exit(1);
673 else screenDepth = DefaultDepthOfScreen( screen );
674 if (Options.synchronous) XSynchronize( display, True );
675 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
676 else rootWindow = DefaultRootWindow( display );
678 MAIN_SaveSetup();
679 atexit(called_at_exit);
680 return TRUE;
684 /***********************************************************************
685 * MessageBeep (USER.104)
687 void MessageBeep(WORD i)
689 XBell(display, 100);
693 /***********************************************************************
694 * Beep (KERNEL32.11)
696 BOOL32 Beep( DWORD dwFreq, DWORD dwDur )
698 /* dwFreq and dwDur are ignored by Win95 */
699 XBell(display, 100);
700 return TRUE;
704 /***********************************************************************
705 * GetVersion16 (KERNEL.3)
707 LONG GetVersion16(void)
709 if (getVersion16) return getVersion16;
710 return MAKELONG( WINVERSION, WINDOSVER );
714 /***********************************************************************
715 * GetVersion32
717 LONG GetVersion32(void)
719 if (getVersion32) return getVersion32;
720 return MAKELONG( 4, DOSVERSION);
724 /***********************************************************************
725 * GetVersionExA
727 BOOL32 GetVersionEx32A(OSVERSIONINFO32A *v)
729 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
731 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
732 return FALSE;
734 if(!getVersion32)
736 /* Return something like NT 3.5 */
737 v->dwMajorVersion = 3;
738 v->dwMinorVersion = 5;
739 v->dwBuildNumber = 42;
740 v->dwPlatformId = VER_PLATFORM_WIN32_NT;
741 strcpy(v->szCSDVersion, "Wine is not an emulator");
742 return TRUE;
744 v->dwMajorVersion = getVersionEx.dwMajorVersion;
745 v->dwMinorVersion = getVersionEx.dwMinorVersion;
746 v->dwBuildNumber = getVersionEx.dwBuildNumber;
747 v->dwPlatformId = getVersionEx.dwPlatformId;
748 strcpy(v->szCSDVersion, getVersionEx.szCSDVersion);
749 return TRUE;
753 /***********************************************************************
754 * GetVersionExW
756 BOOL32 GetVersionEx32W(OSVERSIONINFO32W *v)
758 OSVERSIONINFO32A v1;
759 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
761 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
762 return FALSE;
764 v1.dwOSVersionInfoSize=sizeof(v1);
765 GetVersionEx32A(&v1);
766 v->dwMajorVersion = v1.dwMajorVersion;
767 v->dwMinorVersion = v1.dwMinorVersion;
768 v->dwBuildNumber = v1.dwBuildNumber;
769 v->dwPlatformId = v1.dwPlatformId;
770 lstrcpyAtoW( v->szCSDVersion, v1.szCSDVersion );
771 return TRUE;
774 /***********************************************************************
775 * GetWinFlags (KERNEL.132)
777 LONG GetWinFlags(void)
779 static const long cpuflags[5] =
780 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
782 long result = 0;
784 /* There doesn't seem to be any Pentium flag. */
785 long cpuflag = cpuflags[MIN (runtime_cpu (), 4)];
787 switch(Options.mode) {
788 case MODE_STANDARD:
789 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
790 break;
792 case MODE_ENHANCED:
793 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
794 break;
796 default:
797 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
798 break;
800 if( getVersionEx.dwPlatformId == VER_PLATFORM_WIN32_NT )
801 result |= 0x4000; /* undocumented WF_WINNT */
802 return result;
805 /***********************************************************************
806 * SetEnvironment (GDI.132)
808 int SetEnvironment(LPCSTR lpPortName, LPCSTR lpEnviron, WORD nCount)
810 LPENVENTRY lpNewEnv;
811 LPENVENTRY lpEnv = lpEnvList;
812 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
813 lpPortName, lpEnviron, nCount);
814 if (lpPortName == NULL) return -1;
815 while (lpEnv != NULL) {
816 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
817 if (nCount == 0 || lpEnviron == NULL) {
818 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
819 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
820 free(lpEnv->Value);
821 free(lpEnv->Name);
822 free(lpEnv);
823 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
824 return -1;
826 free(lpEnv->Value);
827 lpEnv->Value = malloc(nCount);
828 if (lpEnv->Value == NULL) {
829 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
830 return 0;
832 memcpy(lpEnv->Value, lpEnviron, nCount);
833 lpEnv->wSize = nCount;
834 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
835 return nCount;
837 if (lpEnv->Next == NULL) break;
838 lpEnv = lpEnv->Next;
840 if (nCount == 0 || lpEnviron == NULL) return -1;
841 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
842 lpNewEnv = malloc(sizeof(ENVENTRY));
843 if (lpNewEnv == NULL) {
844 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
845 return 0;
847 if (lpEnvList == NULL) {
848 lpEnvList = lpNewEnv;
849 lpNewEnv->Prev = NULL;
851 else
853 lpEnv->Next = lpNewEnv;
854 lpNewEnv->Prev = lpEnv;
856 lpNewEnv->Next = NULL;
857 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
858 if (lpNewEnv->Name == NULL) {
859 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
860 return 0;
862 strcpy(lpNewEnv->Name, lpPortName);
863 lpNewEnv->Value = malloc(nCount);
864 if (lpNewEnv->Value == NULL) {
865 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
866 return 0;
868 memcpy(lpNewEnv->Value, lpEnviron, nCount);
869 lpNewEnv->wSize = nCount;
870 return nCount;
874 /***********************************************************************
875 * GetEnvironment (GDI.134)
877 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
879 WORD nCount;
880 LPENVENTRY lpEnv = lpEnvList;
882 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
883 lpPortName, lpEnviron, nMaxSiz);
884 while (lpEnv != NULL) {
885 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
886 if( lpEnviron == NULL ) return lpEnv->wSize;
887 nCount = MIN(nMaxSiz, lpEnv->wSize);
888 memcpy(lpEnviron, lpEnv->Value, nCount);
889 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnv->Value);
890 return nCount;
892 lpEnv = lpEnv->Next;
894 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
895 return 0;
899 /***********************************************************************
900 * GetTimerResolution (USER.14)
902 LONG GetTimerResolution(void)
904 return (1000);
907 /***********************************************************************
908 * SystemParametersInfo32A (USER32.539)
910 BOOL32 SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
911 LPVOID lpvParam, UINT32 fuWinIni )
913 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
917 /***********************************************************************
918 * SystemParametersInfo16 (USER.483)
920 BOOL16 SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
921 LPVOID lpvParam, UINT16 fuWinIni )
923 int timeout, temp;
924 char buffer[256];
925 XKeyboardState keyboard_state;
926 XKeyboardControl keyboard_value;
929 switch (uAction)
931 case SPI_GETBEEP:
932 XGetKeyboardControl(display, &keyboard_state);
933 if (keyboard_state.bell_percent == 0)
934 *(BOOL *) lpvParam = FALSE;
935 else
936 *(BOOL *) lpvParam = TRUE;
937 break;
939 case SPI_GETBORDER:
940 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
941 break;
943 case SPI_GETFASTTASKSWITCH:
944 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
945 *(BOOL *) lpvParam = TRUE;
946 else
947 *(BOOL *) lpvParam = FALSE;
948 break;
950 case SPI_GETGRIDGRANULARITY:
951 *(INT *) lpvParam = GetProfileInt32A( "desktop",
952 "GridGranularity",
953 1 );
954 break;
956 case SPI_GETICONTITLEWRAP:
957 *(BOOL *) lpvParam = GetProfileInt32A( "desktop",
958 "IconTitleWrap",
959 TRUE );
960 break;
962 case SPI_GETKEYBOARDDELAY:
963 *(INT *) lpvParam = GetProfileInt32A( "keyboard",
964 "KeyboardDelay", 1 );
965 break;
967 case SPI_GETKEYBOARDSPEED:
968 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
969 "KeyboardSpeed",
970 30 );
971 break;
973 case SPI_GETMENUDROPALIGNMENT:
974 *(BOOL *) lpvParam = GetSystemMetrics( SM_MENUDROPALIGNMENT ); /* XXX check this */
975 break;
977 case SPI_GETSCREENSAVEACTIVE:
978 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
979 *(BOOL *) lpvParam = TRUE;
980 else
981 *(BOOL *) lpvParam = FALSE;
982 break;
984 case SPI_GETSCREENSAVETIMEOUT:
985 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
986 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
987 *(INT *) lpvParam = timeout * 1000;
988 break;
990 case SPI_ICONHORIZONTALSPACING:
991 /* FIXME Get/SetProfileInt */
992 if (lpvParam == NULL)
993 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
994 else
995 *(INT *) lpvParam = GetSystemMetrics( SM_CXICONSPACING );
996 break;
998 case SPI_ICONVERTICALSPACING:
999 /* FIXME Get/SetProfileInt */
1000 if (lpvParam == NULL)
1001 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1002 else
1003 *(INT *) lpvParam = GetSystemMetrics(SM_CYICONSPACING);
1004 break;
1006 case SPI_SETBEEP:
1007 if (uParam == TRUE)
1008 keyboard_value.bell_percent = -1;
1009 else
1010 keyboard_value.bell_percent = 0;
1011 XChangeKeyboardControl(display, KBBellPercent,
1012 &keyboard_value);
1013 break;
1015 case SPI_SETSCREENSAVEACTIVE:
1016 if (uParam == TRUE)
1017 XActivateScreenSaver(display);
1018 else
1019 XResetScreenSaver(display);
1020 break;
1022 case SPI_SETSCREENSAVETIMEOUT:
1023 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
1024 DefaultExposures);
1025 break;
1027 case SPI_SETDESKWALLPAPER:
1028 return (SetDeskWallPaper32((LPSTR) lpvParam));
1029 break;
1031 case SPI_SETDESKPATTERN:
1032 if ((INT16)uParam == -1) {
1033 GetProfileString32A("Desktop", "Pattern",
1034 "170 85 170 85 170 85 170 85",
1035 buffer, sizeof(buffer) );
1036 return (DESKTOP_SetPattern((LPSTR) buffer));
1037 } else
1038 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1039 break;
1041 case SPI_GETICONTITLELOGFONT:
1043 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1044 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1045 lpLogFont->lfHeight = 10;
1046 lpLogFont->lfWidth = 0;
1047 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1048 lpLogFont->lfWeight = FW_NORMAL;
1049 lpLogFont->lfItalic = FALSE;
1050 lpLogFont->lfStrikeOut = FALSE;
1051 lpLogFont->lfUnderline = FALSE;
1052 lpLogFont->lfCharSet = ANSI_CHARSET;
1053 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1054 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1055 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1056 break;
1059 case SPI_LANGDRIVER:
1060 case SPI_SETBORDER:
1061 case SPI_SETDOUBLECLKHEIGHT:
1062 case SPI_SETDOUBLECLICKTIME:
1063 case SPI_SETDOUBLECLKWIDTH:
1064 case SPI_SETFASTTASKSWITCH:
1065 case SPI_SETKEYBOARDDELAY:
1066 case SPI_SETKEYBOARDSPEED:
1067 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uAction);
1068 break;
1070 case SPI_GETWORKAREA:
1071 SetRect16( (RECT16 *)lpvParam, 0, 0,
1072 GetSystemMetrics( SM_CXSCREEN ),
1073 GetSystemMetrics( SM_CYSCREEN ) );
1074 break;
1076 default:
1077 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uAction);
1078 break;
1080 return 1;
1083 /***********************************************************************
1084 * SystemParametersInfo32W (USER32.540)
1086 BOOL32 SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1087 LPVOID lpvParam, UINT32 fuWinIni )
1089 char buffer[256];
1091 switch (uAction)
1093 case SPI_SETDESKWALLPAPER:
1094 if (lpvParam)
1096 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1097 return SetDeskWallPaper32(buffer);
1099 return SetDeskWallPaper32(NULL);
1101 case SPI_SETDESKPATTERN:
1102 if ((INT) uParam == -1)
1104 GetProfileString32A("Desktop", "Pattern",
1105 "170 85 170 85 170 85 170 85",
1106 buffer, sizeof(buffer) );
1107 return (DESKTOP_SetPattern((LPSTR) buffer));
1109 if (lpvParam)
1111 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1112 return DESKTOP_SetPattern(buffer);
1114 return DESKTOP_SetPattern(NULL);
1116 case SPI_GETICONTITLELOGFONT:
1118 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1119 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1120 lpLogFont->lfHeight = 10;
1121 lpLogFont->lfWidth = 0;
1122 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1123 lpLogFont->lfWeight = FW_NORMAL;
1124 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1125 lpLogFont->lfCharSet = ANSI_CHARSET;
1126 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1127 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1128 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1130 break;
1132 default:
1133 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1136 return TRUE;
1140 /***********************************************************************
1141 * SWAPMOUSEBUTTON (USER.186)
1143 BOOL SwapMouseButton(BOOL fSwap)
1145 return 0; /* don't swap */
1148 /***********************************************************************
1149 * FileCDR (KERNEL.130)
1151 void FileCDR(FARPROC16 x)
1153 printf("FileCDR(%8x)\n", (int) x);
1156 /***********************************************************************
1157 * GetWinDebugInfo (KERNEL.355)
1159 BOOL GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT flags)
1161 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1162 /* 0 means not in debugging mode/version */
1163 /* Can this type of debugging be used in wine ? */
1164 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1165 return 0;
1168 /***********************************************************************
1169 * GetWinDebugInfo (KERNEL.355)
1171 BOOL SetWinDebugInfo(WINDEBUGINFO *lpwdi)
1173 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1174 /* 0 means not in debugging mode/version */
1175 /* Can this type of debugging be used in wine ? */
1176 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1177 return 0;