Release 980927
[wine.git] / misc / main.c
blob830f9845d74953072a88998d5736c4d5ff145529
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 /* #include <locale.h> */
12 #ifdef MALLOC_DEBUGGING
13 #include <malloc.h>
14 #endif
15 #include "ts_xlib.h"
16 #include "ts_xresource.h"
17 #include "ts_xutil.h"
18 #include <X11/Xlocale.h>
19 #include <X11/cursorfont.h>
20 #include "winsock.h"
21 #include "heap.h"
22 #include "message.h"
23 #include "msdos.h"
24 #include "windows.h"
25 #include "color.h"
26 #include "options.h"
27 #include "desktop.h"
28 #include "process.h"
29 #include "shell.h"
30 #include "winbase.h"
31 #include "debug.h"
32 #include "debugdefs.h"
33 #include "xmalloc.h"
34 #include "version.h"
36 /* when adding new languages look at ole/ole2nls.c
37 * for proper iso name and Windows code (add 0x0400
38 * to the code listed there)
40 const WINE_LANGUAGE_DEF Languages[] =
42 {"En",0x0409}, /* LANG_En */
43 {"Es",0x040A}, /* LANG_Es */
44 {"De",0x0407}, /* LANG_De */
45 {"No",0x0414}, /* LANG_No */
46 {"Fr",0x040C}, /* LANG_Fr */
47 {"Fi",0x040B}, /* LANG_Fi */
48 {"Da",0x0406}, /* LANG_Da */
49 {"Cs",0x0405}, /* LANG_Cs */
50 {"Eo",0x048f}, /* LANG_Eo */
51 {"It",0x0410}, /* LANG_It */
52 {"Ko",0x0412}, /* LANG_Ko */
53 {"Hu",0x040e}, /* LANG_Hu */
54 {"Pl",0x0415}, /* LANG_Pl */
55 {"Pt",0x0416}, /* LANG_Pt */
56 {"Sv",0x041d}, /* LANG_Sv */
57 {"Ca",0x0403}, /* LANG_Ca */
58 /* for compatibility whith non-iso names previously used */
59 {"Sw",0x041d}, /* LANG_Sv */
60 {"Cz",0x0405}, /* LANG_Cs */
61 {"Po",0x0416}, /* LANG_Pt */
62 {NULL,0}
65 WORD WINE_LanguageId = 0;
67 #define WINE_CLASS "Wine" /* Class name for resources */
69 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
71 Display *display;
72 Screen *screen;
73 Window rootWindow;
74 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
75 int screenDepth = 0; /* Screen depth to use */
77 struct options Options =
78 { /* default options */
79 NULL, /* desktopGeometry */
80 NULL, /* programName */
81 NULL, /* argv0 */
82 NULL, /* dllFlags */
83 FALSE, /* usePrivateMap */
84 FALSE, /* useFixedMap */
85 FALSE, /* synchronous */
86 FALSE, /* backing store */
87 SW_SHOWNORMAL, /* cmdShow */
88 FALSE,
89 FALSE, /* failReadOnly */
90 MODE_ENHANCED, /* Enhanced mode */
91 #ifdef DEFAULT_LANG
92 DEFAULT_LANG, /* Default language */
93 #else
94 LANG_En,
95 #endif
96 FALSE, /* Managed windows */
97 FALSE, /* Perfect graphics */
98 NULL /* Alternate config file name */
102 static XrmOptionDescRec optionsTable[] =
104 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
105 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
106 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
107 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
108 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
109 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
110 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
111 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
112 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
113 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
114 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
115 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
116 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
117 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
118 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
119 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
120 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
121 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL },
122 { "-config", ".config", XrmoptionSepArg, (caddr_t)NULL }
125 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
127 #define USAGE \
128 "%s\n" \
129 "Usage: %s [options] \"program_name [arguments]\"\n" \
130 "\n" \
131 "Options:\n" \
132 " -backingstore Turn on backing store\n" \
133 " -config name Specify config file to use\n" \
134 " -debug Enter debugger before starting application\n" \
135 " -debugmsg name Turn debugging-messages on or off\n" \
136 " -depth n Change the depth to use for multiple-depth screens\n" \
137 " -desktop geom Use a desktop window of the given geometry\n" \
138 " -display name Use the specified display\n" \
139 " -dll name Enable or disable built-in DLLs\n" \
140 " -failreadonly Read only files may not be opened in write mode\n" \
141 " -fixedmap Use a \"standard\" color map\n" \
142 " -help Show this help message\n" \
143 " -iconic Start as an icon\n" \
144 " -language xx Set the language (one of Ca,Cs,Da,De,En,Eo,Es,Fi,Fr,Hu,It,\n Ko,No,Pl,Pt,Sv)\n" \
145 " -managed Allow the window manager to manage created windows\n" \
146 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
147 " -name name Set the application name\n" \
148 " -perfect Favor correctness over speed for graphical operations\n" \
149 " -privatemap Use a private color map\n" \
150 " -synchronous Turn on synchronous display mode\n" \
151 " -version Display the Wine version\n" \
152 " -winver Version to imitate (one of win31,win95,nt351,nt40)\n"
156 /***********************************************************************
157 * MAIN_Usage
159 void MAIN_Usage( char *name )
161 MSG( USAGE, WINE_RELEASE_INFO, name );
162 exit(1);
166 /***********************************************************************
167 * MAIN_GetProgramName
169 * Get the program name. The name is specified by (in order of precedence):
170 * - the option '-name'.
171 * - the environment variable 'WINE_NAME'.
172 * - the last component of argv[0].
174 static char *MAIN_GetProgramName( int argc, char *argv[] )
176 int i;
177 char *p;
179 for (i = 1; i < argc-1; i++)
180 if (!strcmp( argv[i], "-name" )) return argv[i+1];
181 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
182 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
183 return argv[0];
187 /***********************************************************************
188 * MAIN_GetResource
190 * Fetch the value of resource 'name' using the correct instance name.
191 * 'name' must begin with '.' or '*'
193 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
195 char *buff_instance, *buff_class;
196 char *dummy;
197 int retval;
199 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
200 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
202 strcpy( buff_instance, Options.programName );
203 strcat( buff_instance, name );
204 strcpy( buff_class, WINE_CLASS );
205 strcat( buff_class, name );
206 retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
207 free( buff_instance );
208 free( buff_class );
209 return retval;
213 /***********************************************************************
214 * MAIN_ParseDebugOptions
216 * Turns specific debug messages on or off, according to "options".
218 * RETURNS
219 * TRUE if parsing was successful
221 static BOOL32 MAIN_ParseDebugOptions(char *options)
223 /* defined in relay32/relay386.c */
224 extern char **debug_relay_includelist;
225 extern char **debug_relay_excludelist;
226 /* defined in relay32/snoop.c */
227 extern char **debug_snoop_includelist;
228 extern char **debug_snoop_excludelist;
230 int l, cls;
231 if (strlen(options)<3)
232 return FALSE;
235 if ((*options!='+')&&(*options!='-')){
236 int j;
238 for(j=0; j<DEBUG_CLASS_COUNT; j++)
239 if(!lstrncmpi32A(options, debug_cl_name[j], strlen(debug_cl_name[j])))
240 break;
241 if(j==DEBUG_CLASS_COUNT)
242 return FALSE;
243 options += strlen(debug_cl_name[j]);
244 if ((*options!='+')&&(*options!='-'))
245 return FALSE;
246 cls = j;
248 else
249 cls = -1; /* all classes */
251 if (strchr(options,','))
252 l=strchr(options,',')-options;
253 else
254 l=strlen(options);
256 if (!lstrncmpi32A(options+1,"all",l-1))
258 int i, j;
259 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
260 for(j=0; j<DEBUG_CLASS_COUNT; j++)
261 if(cls == -1 || cls == j)
262 debug_msg_enabled[i][j]=(*options=='+');
264 else if (!lstrncmpi32A(options+1, "relay=", 6) ||
265 !lstrncmpi32A(options+1, "snoop=", 6))
267 int i, j;
268 char *s, *s2, ***output, c;
270 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
271 if (debug_ch_name && (!lstrncmpi32A(debug_ch_name[i],options+1,5))){
272 for(j=0; j<DEBUG_CLASS_COUNT; j++)
273 if(cls == -1 || cls == j)
274 debug_msg_enabled[i][j]=TRUE;
275 break;
277 /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
278 if (i==DEBUG_CHANNEL_COUNT)
279 return FALSE;
280 output = (*options == '+') ?
281 ((*(options+1) == 'r') ?
282 &debug_relay_includelist :
283 &debug_snoop_includelist) :
284 ((*(options+1) == 'r') ?
285 &debug_relay_excludelist :
286 &debug_snoop_excludelist);
287 s = options + 7;
288 i = 1;
289 while((s = strchr(s, ':'))) i++, s++;
290 *output = malloc(sizeof(char **) * i + 1);
291 i = 0;
292 s = options + 7;
293 while((s2 = strchr(s, ':'))) {
294 c = *s2;
295 *s2 = '\0';
296 *((*output)+i) = strdup(s);
297 *s2 = c;
298 s = s2 + 1;
299 i++;
301 c = *(options + l);
302 *(options + l) = '\0';
303 *((*output)+i) = strdup(s);
304 *(options + l) = c;
305 *((*output)+i+1) = NULL;
307 else
309 int i, j;
310 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
311 if (debug_ch_name && (!lstrncmpi32A(options+1,debug_ch_name[i],l-1))){
312 for(j=0; j<DEBUG_CLASS_COUNT; j++)
313 if(cls == -1 || cls == j)
314 debug_msg_enabled[i][j]=(*options=='+');
315 break;
317 if (i==DEBUG_CHANNEL_COUNT)
318 return FALSE;
320 options+=l;
322 while((*options==',')&&(*(++options)));
323 if (*options)
324 return FALSE;
325 else
326 return TRUE;
329 /***********************************************************************
330 * MAIN_ParseLanguageOption
332 * Parse -language option.
334 static void MAIN_ParseLanguageOption( char *arg )
336 const WINE_LANGUAGE_DEF *p = Languages;
338 Options.language = LANG_En; /* First language */
339 for (;p->name;p++)
341 if (!lstrcmpi32A( p->name, arg ))
343 WINE_LanguageId = p->langid;
344 return;
346 Options.language++;
348 MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
349 for (p = Languages; p->name; p++) MSG( "%s ", p->name );
350 MSG( "\n" );
351 exit(1);
355 /***********************************************************************
356 * MAIN_ParseModeOption
358 * Parse -mode option.
360 static void MAIN_ParseModeOption( char *arg )
362 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
363 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
364 else
366 MSG( "Invalid mode '%s' specified.\n", arg);
367 MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
368 exit(1);
372 /***********************************************************************
373 * MAIN_ParseOptions
375 * Parse command line options and open display.
377 static void MAIN_ParseOptions( int *argc, char *argv[] )
379 char *display_name = NULL;
380 XrmValue value;
381 XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
382 int i;
383 char *xrm_string;
385 Options.programName = MAIN_GetProgramName( *argc, argv );
386 Options.argv0 = argv[0];
388 /* Get display name from command line */
389 for (i = 1; i < *argc; i++)
391 if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
392 if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
394 MSG( "%s\n", WINE_RELEASE_INFO );
395 exit(0);
397 if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
399 MAIN_Usage(argv[0]);
400 exit(0);
404 /* Open display */
406 if (display_name == NULL &&
407 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
409 if (!(display = TSXOpenDisplay( display_name )))
411 MSG( "%s: Can't open display: %s\n",
412 argv[0], display_name ? display_name : "(none specified)" );
413 exit(1);
416 /* tell the libX11 that we will do input method handling ourselves
417 * that keep libX11 from doing anything whith dead keys, allowing Wine
418 * to have total control over dead keys, that is this line allows
419 * them to work in Wine, even whith a libX11 including the dead key
420 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
422 TSXOpenIM(display,NULL,NULL,NULL);
424 /* Merge file and screen databases */
425 if ((xrm_string = TSXResourceManagerString( display )) != NULL)
427 XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
428 TSXrmMergeDatabases( display_db, &db );
431 /* Parse command line */
432 TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
433 Options.programName, argc, argv );
435 /* Get all options */
436 if (MAIN_GetResource( db, ".iconic", &value ))
437 Options.cmdShow = SW_SHOWMINIMIZED;
438 if (MAIN_GetResource( db, ".privatemap", &value ))
439 Options.usePrivateMap = TRUE;
440 if (MAIN_GetResource( db, ".fixedmap", &value ))
441 Options.useFixedMap = TRUE;
442 if (MAIN_GetResource( db, ".synchronous", &value ))
443 Options.synchronous = TRUE;
444 if (MAIN_GetResource( db, ".backingstore", &value ))
445 Options.backingstore = TRUE;
446 if (MAIN_GetResource( db, ".debug", &value ))
447 Options.debug = TRUE;
448 if (MAIN_GetResource( db, ".failreadonly", &value ))
449 Options.failReadOnly = TRUE;
450 if (MAIN_GetResource( db, ".perfect", &value ))
451 Options.perfectGraphics = TRUE;
452 if (MAIN_GetResource( db, ".depth", &value))
453 screenDepth = atoi( value.addr );
454 if (MAIN_GetResource( db, ".desktop", &value))
455 Options.desktopGeometry = value.addr;
456 if (MAIN_GetResource( db, ".language", &value))
457 MAIN_ParseLanguageOption( (char *)value.addr );
458 if (MAIN_GetResource( db, ".managed", &value))
459 Options.managed = TRUE;
460 if (MAIN_GetResource( db, ".mode", &value))
461 MAIN_ParseModeOption( (char *)value.addr );
462 if (MAIN_GetResource( db, ".debugoptions", &value))
463 MAIN_ParseDebugOptions((char*)value.addr);
464 if (MAIN_GetResource( db, ".debugmsg", &value))
466 #ifndef DEBUG_RUNTIME
467 MSG("%s: Option \"-debugmsg\" not implemented.\n" \
468 " Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
469 argv[0]);
470 exit(1);
471 #else
472 if (MAIN_ParseDebugOptions((char*)value.addr)==FALSE)
474 int i;
475 MSG("%s: Syntax: -debugmsg [class]+xxx,... or "
476 "-debugmsg [class]-xxx,...\n",argv[0]);
477 MSG("Example: -debugmsg +all,warn-heap\n"
478 " turn on all messages except warning heap messages\n");
479 MSG("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
480 " turn on -debugmsg +relay only as specified\n"
481 "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
482 " turn on -debugmsg +relay except as specified\n"
483 "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
485 MSG("Available message classes:\n");
486 for(i=0;i<DEBUG_CLASS_COUNT;i++)
487 MSG( "%-9s", debug_cl_name[i]);
488 MSG("\n\n");
490 MSG("Available message types:\n");
491 MSG("%-9s ","all");
492 for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
493 if(debug_ch_name[i])
494 MSG("%-9s%c",debug_ch_name[i],
495 (((i+2)%8==0)?'\n':' '));
496 MSG("\n\n");
497 exit(1);
499 #endif
502 if (MAIN_GetResource( db, ".dll", &value))
504 /* Hack: store option value in Options to be retrieved */
505 /* later on inside the emulator code. */
506 if (!__winelib) Options.dllFlags = xstrdup((char *)value.addr);
507 else
509 MSG("-dll not supported in Winelib\n" );
510 exit(1);
514 if (MAIN_GetResource( db, ".winver", &value))
515 VERSION_ParseVersion( (char*)value.addr );
516 if (MAIN_GetResource( db, ".config", &value))
517 Options.configFileName = xstrdup((char *)value.addr);
521 /***********************************************************************
522 * MAIN_CreateDesktop
524 static void MAIN_CreateDesktop( int argc, char *argv[] )
526 int x, y, flags;
527 unsigned int width = 640, height = 480; /* Default size = 640x480 */
528 char *name = "Wine desktop";
529 XSizeHints *size_hints;
530 XWMHints *wm_hints;
531 XClassHint *class_hints;
532 XSetWindowAttributes win_attr;
533 XTextProperty window_name;
534 Atom XA_WM_DELETE_WINDOW;
536 flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
537 screenWidth = width;
538 screenHeight = height;
540 /* Create window */
542 win_attr.background_pixel = BlackPixel(display,0);
543 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
544 PointerMotionMask | ButtonPressMask |
545 ButtonReleaseMask | EnterWindowMask;
546 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
548 rootWindow = TSXCreateWindow( display, DefaultRootWindow(display),
549 x, y, width, height, 0,
550 CopyFromParent, InputOutput, CopyFromParent,
551 CWBackPixel | CWEventMask | CWCursor, &win_attr );
553 /* Set window manager properties */
555 size_hints = TSXAllocSizeHints();
556 wm_hints = TSXAllocWMHints();
557 class_hints = TSXAllocClassHint();
558 if (!size_hints || !wm_hints || !class_hints)
560 MSG("Not enough memory for window manager hints.\n" );
561 exit(1);
563 size_hints->min_width = size_hints->max_width = width;
564 size_hints->min_height = size_hints->max_height = height;
565 size_hints->flags = PMinSize | PMaxSize;
566 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
567 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
568 else size_hints->flags |= PSize;
570 wm_hints->flags = InputHint | StateHint;
571 wm_hints->input = True;
572 wm_hints->initial_state = NormalState;
573 class_hints->res_name = argv[0];
574 class_hints->res_class = "Wine";
576 TSXStringListToTextProperty( &name, 1, &window_name );
577 TSXSetWMProperties( display, rootWindow, &window_name, &window_name,
578 argv, argc, size_hints, wm_hints, class_hints );
579 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
580 TSXSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
581 TSXFree( size_hints );
582 TSXFree( wm_hints );
583 TSXFree( class_hints );
585 /* Map window */
587 TSXMapWindow( display, rootWindow );
591 XKeyboardState keyboard_state;
593 /***********************************************************************
594 * MAIN_SaveSetup
596 static void MAIN_SaveSetup(void)
598 TSXGetKeyboardControl(display, &keyboard_state);
601 /***********************************************************************
602 * MAIN_RestoreSetup
604 static void MAIN_RestoreSetup(void)
606 XKeyboardControl keyboard_value;
608 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
609 keyboard_value.bell_percent = keyboard_state.bell_percent;
610 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
611 keyboard_value.bell_duration = keyboard_state.bell_duration;
612 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
614 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
615 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
619 /***********************************************************************
620 * called_at_exit
622 static void called_at_exit(void)
624 MAIN_RestoreSetup();
625 COLOR_Cleanup();
626 WINSOCK_Shutdown();
627 /* FIXME: should check for other processes or threads */
628 DeleteCriticalSection( HEAP_SystemLock );
631 /***********************************************************************
632 * MAIN_WineInit
634 * Wine initialisation and command-line parsing
636 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
638 int depth_count, i;
639 int *depth_list;
640 struct timeval tv;
642 #ifdef MALLOC_DEBUGGING
643 char *trace;
645 mcheck(NULL);
646 if (!(trace = getenv("MALLOC_TRACE")))
648 MSG( "MALLOC_TRACE not set. No trace generated\n" );
650 else
652 MSG( "malloc trace goes to %s\n", trace );
653 mtrace();
655 #endif
657 setbuf(stdout,NULL);
658 setbuf(stderr,NULL);
660 setlocale(LC_CTYPE,"");
661 gettimeofday( &tv, NULL);
662 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
664 /* We need this before calling any Xlib function */
665 InitializeCriticalSection( &X11DRV_CritSection );
667 TSXrmInitialize();
669 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
671 MAIN_ParseOptions( argc, argv );
673 if (Options.desktopGeometry && Options.managed)
675 #if 0
676 MSG( "%s: -managed and -desktop options cannot be used together\n",
677 Options.programName );
678 exit(1);
679 #else
680 Options.managed = FALSE;
681 #endif
684 screen = DefaultScreenOfDisplay( display );
685 screenWidth = WidthOfScreen( screen );
686 screenHeight = HeightOfScreen( screen );
687 if (screenDepth) /* -depth option specified */
689 depth_list = TSXListDepths(display,DefaultScreen(display),&depth_count);
690 for (i = 0; i < depth_count; i++)
691 if (depth_list[i] == screenDepth) break;
692 TSXFree( depth_list );
693 if (i >= depth_count)
695 MSG( "%s: Depth %d not supported on this screen.\n",
696 Options.programName, screenDepth );
697 exit(1);
700 else screenDepth = DefaultDepthOfScreen( screen );
701 if (Options.synchronous) TSXSynchronize( display, True );
702 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
703 else rootWindow = DefaultRootWindow( display );
705 MAIN_SaveSetup();
706 atexit(called_at_exit);
707 return TRUE;
711 /***********************************************************************
712 * MessageBeep16 (USER.104)
714 void WINAPI MessageBeep16( UINT16 i )
716 MessageBeep32( i );
720 /***********************************************************************
721 * MessageBeep32 (USER32.390)
723 BOOL32 WINAPI MessageBeep32( UINT32 i )
725 TSXBell( display, 0 );
726 return TRUE;
730 /***********************************************************************
731 * Beep (KERNEL32.11)
733 BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
735 /* dwFreq and dwDur are ignored by Win95 */
736 TSXBell(display, 0);
737 return TRUE;
741 /***********************************************************************
742 * GetTimerResolution (USER.14)
744 LONG WINAPI GetTimerResolution(void)
746 return (1000);
749 /***********************************************************************
750 * SystemParametersInfo32A (USER32.540)
752 BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
753 LPVOID lpvParam, UINT32 fuWinIni )
755 int timeout, temp;
756 XKeyboardState keyboard_state;
758 switch (uAction) {
759 case SPI_GETBEEP:
760 TSXGetKeyboardControl(display, &keyboard_state);
761 if (keyboard_state.bell_percent == 0)
762 *(BOOL32 *) lpvParam = FALSE;
763 else
764 *(BOOL32 *) lpvParam = TRUE;
765 break;
767 case SPI_GETBORDER:
768 *(INT32 *)lpvParam = GetSystemMetrics32( SM_CXFRAME );
769 break;
771 case SPI_GETFASTTASKSWITCH:
772 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
773 *(BOOL32 *) lpvParam = TRUE;
774 else
775 *(BOOL32 *) lpvParam = FALSE;
776 break;
778 case SPI_GETDRAGFULLWINDOWS:
779 *(BOOL32 *) lpvParam = FALSE;
781 case SPI_GETGRIDGRANULARITY:
782 *(INT32*)lpvParam=GetProfileInt32A("desktop","GridGranularity",1);
783 break;
785 case SPI_GETICONTITLEWRAP:
786 *(BOOL32*)lpvParam=GetProfileInt32A("desktop","IconTitleWrap",TRUE);
787 break;
789 case SPI_GETKEYBOARDDELAY:
790 *(INT32*)lpvParam=GetProfileInt32A("keyboard","KeyboardDelay",1);
791 break;
793 case SPI_GETKEYBOARDSPEED:
794 *(DWORD*)lpvParam=GetProfileInt32A("keyboard","KeyboardSpeed",30);
795 break;
797 case SPI_GETMENUDROPALIGNMENT:
798 *(BOOL32*)lpvParam=GetSystemMetrics32(SM_MENUDROPALIGNMENT); /* XXX check this */
799 break;
801 case SPI_GETSCREENSAVEACTIVE:
802 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
803 *(BOOL32*)lpvParam = TRUE;
804 else
805 *(BOOL32*)lpvParam = FALSE;
806 break;
808 case SPI_GETSCREENSAVETIMEOUT:
809 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
810 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
811 *(INT32 *) lpvParam = timeout * 1000;
812 break;
814 case SPI_ICONHORIZONTALSPACING:
815 /* FIXME Get/SetProfileInt */
816 if (lpvParam == NULL)
817 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
818 else
819 *(INT32*)lpvParam=GetSystemMetrics32(SM_CXICONSPACING);
820 break;
822 case SPI_ICONVERTICALSPACING:
823 /* FIXME Get/SetProfileInt */
824 if (lpvParam == NULL)
825 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
826 else
827 *(INT32*)lpvParam=GetSystemMetrics32(SM_CYICONSPACING);
828 break;
830 case SPI_GETICONTITLELOGFONT: {
831 LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
833 /* from now on we always have an alias for MS Sans Serif */
835 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
836 lpLogFont->lfFaceName, LF_FACESIZE );
837 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
838 lpLogFont->lfWidth = 0;
839 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
840 lpLogFont->lfWeight = FW_NORMAL;
841 lpLogFont->lfItalic = FALSE;
842 lpLogFont->lfStrikeOut = FALSE;
843 lpLogFont->lfUnderline = FALSE;
844 lpLogFont->lfCharSet = ANSI_CHARSET;
845 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
846 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
847 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
848 break;
850 case SPI_GETWORKAREA:
851 SetRect32( (RECT32 *)lpvParam, 0, 0,
852 GetSystemMetrics32( SM_CXSCREEN ),
853 GetSystemMetrics32( SM_CYSCREEN )
855 break;
856 case SPI_GETNONCLIENTMETRICS:
858 #define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
860 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
862 /* FIXME: initialize geometry entries */
864 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
865 (LPVOID)&(lpnm->lfCaptionFont),0);
866 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
867 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
868 (LPVOID)&(lpnm->lfMenuFont),0);
869 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
870 (LPVOID)&(lpnm->lfStatusFont),0);
871 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
872 (LPVOID)&(lpnm->lfMessageFont),0);
874 #undef lpnm
875 break;
877 case SPI_GETANIMATION: {
878 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
880 /* Tell it "disabled" */
881 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
882 uParam = sizeof(ANIMATIONINFO);
883 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
884 break;
887 case SPI_SETANIMATION: {
888 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
890 /* Do nothing */
891 WARN(system, "SPI_SETANIMATION ignored.\n");
892 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
893 uParam = sizeof(ANIMATIONINFO);
894 break;
897 case SPI_GETHIGHCONTRAST:
899 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
901 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
903 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
905 /* Indicate that there is no high contrast available */
906 lpHighContrastA->dwFlags = 0;
907 lpHighContrastA->lpszDefaultScheme = NULL;
909 else
911 return FALSE;
914 break;
917 default:
918 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
920 return TRUE;
924 /***********************************************************************
925 * SystemParametersInfo16 (USER.483)
927 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
928 LPVOID lpvParam, UINT16 fuWinIni )
930 int timeout, temp;
931 char buffer[256];
932 XKeyboardState keyboard_state;
933 XKeyboardControl keyboard_value;
936 switch (uAction)
938 case SPI_GETBEEP:
939 TSXGetKeyboardControl(display, &keyboard_state);
940 if (keyboard_state.bell_percent == 0)
941 *(BOOL16 *) lpvParam = FALSE;
942 else
943 *(BOOL16 *) lpvParam = TRUE;
944 break;
946 case SPI_GETBORDER:
947 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
948 break;
950 case SPI_GETFASTTASKSWITCH:
951 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
952 *(BOOL16 *) lpvParam = TRUE;
953 else
954 *(BOOL16 *) lpvParam = FALSE;
955 break;
957 case SPI_GETGRIDGRANULARITY:
958 *(INT16 *) lpvParam = GetProfileInt32A( "desktop",
959 "GridGranularity",
960 1 );
961 break;
963 case SPI_GETICONTITLEWRAP:
964 *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
965 "IconTitleWrap",
966 TRUE );
967 break;
969 case SPI_GETKEYBOARDDELAY:
970 *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
971 "KeyboardDelay", 1 );
972 break;
974 case SPI_GETKEYBOARDSPEED:
975 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
976 "KeyboardSpeed",
977 30 );
978 break;
980 case SPI_GETMENUDROPALIGNMENT:
981 *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
982 break;
984 case SPI_GETSCREENSAVEACTIVE:
985 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
986 *(BOOL16 *) lpvParam = TRUE;
987 else
988 *(BOOL16 *) lpvParam = FALSE;
989 break;
991 case SPI_GETSCREENSAVETIMEOUT:
992 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
993 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
994 *(INT16 *) lpvParam = timeout;
995 break;
997 case SPI_ICONHORIZONTALSPACING:
998 /* FIXME Get/SetProfileInt */
999 if (lpvParam == NULL)
1000 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1001 else
1002 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1003 break;
1005 case SPI_ICONVERTICALSPACING:
1006 /* FIXME Get/SetProfileInt */
1007 if (lpvParam == NULL)
1008 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1009 else
1010 *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1011 break;
1013 case SPI_SETBEEP:
1014 if (uParam == TRUE)
1015 keyboard_value.bell_percent = -1;
1016 else
1017 keyboard_value.bell_percent = 0;
1018 TSXChangeKeyboardControl(display, KBBellPercent,
1019 &keyboard_value);
1020 break;
1022 case SPI_SETSCREENSAVEACTIVE:
1023 if (uParam == TRUE)
1024 TSXActivateScreenSaver(display);
1025 else
1026 TSXResetScreenSaver(display);
1027 break;
1029 case SPI_SETSCREENSAVETIMEOUT:
1030 TSXSetScreenSaver(display, uParam, 60, DefaultBlanking,
1031 DefaultExposures);
1032 break;
1034 case SPI_SETDESKWALLPAPER:
1035 return (SetDeskWallPaper32((LPSTR) lpvParam));
1036 break;
1038 case SPI_SETDESKPATTERN:
1039 if ((INT16)uParam == -1) {
1040 GetProfileString32A("Desktop", "Pattern",
1041 "170 85 170 85 170 85 170 85",
1042 buffer, sizeof(buffer) );
1043 return (DESKTOP_SetPattern((LPSTR) buffer));
1044 } else
1045 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1046 break;
1048 case SPI_GETICONTITLELOGFONT:
1050 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1052 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1053 lpLogFont->lfFaceName, LF_FACESIZE );
1054 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1055 lpLogFont->lfWidth = 0;
1056 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1057 lpLogFont->lfWeight = FW_NORMAL;
1058 lpLogFont->lfItalic = FALSE;
1059 lpLogFont->lfStrikeOut = FALSE;
1060 lpLogFont->lfUnderline = FALSE;
1061 lpLogFont->lfCharSet = ANSI_CHARSET;
1062 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1063 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1064 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1065 break;
1067 case SPI_GETNONCLIENTMETRICS:
1069 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1070 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1072 /* FIXME: initialize geometry entries */
1073 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1074 (LPVOID)&(lpnm->lfCaptionFont),0);
1075 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1076 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1077 (LPVOID)&(lpnm->lfMenuFont),0);
1078 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1079 (LPVOID)&(lpnm->lfStatusFont),0);
1080 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1081 (LPVOID)&(lpnm->lfMessageFont),0);
1083 else /* winfile 95 sets sbSize to 340 */
1084 SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
1085 #undef lpnm
1086 break;
1088 case SPI_LANGDRIVER:
1089 case SPI_SETBORDER:
1090 case SPI_SETDOUBLECLKHEIGHT:
1091 case SPI_SETDOUBLECLICKTIME:
1092 case SPI_SETDOUBLECLKWIDTH:
1093 case SPI_SETFASTTASKSWITCH:
1094 case SPI_SETKEYBOARDDELAY:
1095 case SPI_SETKEYBOARDSPEED:
1096 WARN(system, "Option %d ignored.\n", uAction);
1097 break;
1099 case SPI_GETWORKAREA:
1100 SetRect16( (RECT16 *)lpvParam, 0, 0,
1101 GetSystemMetrics16( SM_CXSCREEN ),
1102 GetSystemMetrics16( SM_CYSCREEN ) );
1103 break;
1105 default:
1106 WARN(system, "Unknown option %d.\n", uAction);
1107 break;
1109 return 1;
1112 /***********************************************************************
1113 * SystemParametersInfo32W (USER32.541)
1115 BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1116 LPVOID lpvParam, UINT32 fuWinIni )
1118 char buffer[256];
1120 switch (uAction)
1122 case SPI_SETDESKWALLPAPER:
1123 if (lpvParam)
1125 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1126 return SetDeskWallPaper32(buffer);
1128 return SetDeskWallPaper32(NULL);
1130 case SPI_SETDESKPATTERN:
1131 if ((INT32) uParam == -1)
1133 GetProfileString32A("Desktop", "Pattern",
1134 "170 85 170 85 170 85 170 85",
1135 buffer, sizeof(buffer) );
1136 return (DESKTOP_SetPattern((LPSTR) buffer));
1138 if (lpvParam)
1140 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1141 return DESKTOP_SetPattern(buffer);
1143 return DESKTOP_SetPattern(NULL);
1145 case SPI_GETICONTITLELOGFONT:
1147 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1148 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1149 lpLogFont->lfHeight = 10;
1150 lpLogFont->lfWidth = 0;
1151 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1152 lpLogFont->lfWeight = FW_NORMAL;
1153 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1154 lpLogFont->lfCharSet = ANSI_CHARSET;
1155 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1156 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1157 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1159 break;
1160 case SPI_GETNONCLIENTMETRICS: {
1161 /* FIXME: implement correctly */
1162 LPNONCLIENTMETRICS32W lpnm=(LPNONCLIENTMETRICS32W)lpvParam;
1164 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1165 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1166 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1167 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1168 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1169 break;
1172 case SPI_GETHIGHCONTRAST:
1174 LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1176 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1178 if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1180 /* Indicate that there is no high contrast available */
1181 lpHighContrastW->dwFlags = 0;
1182 lpHighContrastW->lpszDefaultScheme = NULL;
1184 else
1186 return FALSE;
1189 break;
1192 default:
1193 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1196 return TRUE;
1200 /***********************************************************************
1201 * FileCDR (KERNEL.130)
1203 FARPROC16 WINAPI FileCDR(FARPROC16 x)
1205 FIXME(file,"(0x%8x): stub\n", (int) x);
1206 return (FARPROC16)TRUE;