xwayland: Add xdg-system-bell support
[xserver.git] / hw / xwin / winprocarg.c
blob4f753982f6b723d356ff290e6c397c1c4ad05ec2
1 /*
3 Copyright 1993, 1998 The Open Group
4 Copyright (C) Colin Harrison 2005-2008
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of The Open Group shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
26 from The Open Group.
30 #ifdef HAVE_XWIN_CONFIG_H
31 #include <xwin-config.h>
32 #endif
34 #ifdef HAVE_SYS_UTSNAME_H
35 #include <sys/utsname.h>
36 #endif
38 #include "os/cmdline.h"
39 #include "os/osdep.h"
40 #include "os/ddx_priv.h"
42 #include <../xfree86/common/xorgVersion.h>
43 #include "win.h"
44 #include "winconfig.h"
45 #include "winmsg.h"
46 #include "winmonitors.h"
47 #include "winprefs.h"
49 #include "winclipboard/winclipboard.h"
52 * Function prototypes
55 void
56 winLogCommandLine(int argc, char *argv[]);
58 void
59 winLogVersionInfo(void);
62 * Process arguments on the command line
65 static int iLastScreen = -1;
66 static winScreenInfo defaultScreenInfo;
68 static void
69 winInitializeScreenDefaults(void)
71 DWORD dwWidth, dwHeight;
72 static Bool fInitializedScreenDefaults = FALSE;
74 /* Bail out early if default screen has already been initialized */
75 if (fInitializedScreenDefaults)
76 return;
78 /* Zero the memory used for storing the screen info */
79 memset(&defaultScreenInfo, 0, sizeof(winScreenInfo));
81 /* Get default width and height */
83 * NOTE: These defaults will cause the window to cover only
84 * the primary monitor in the case that we have multiple monitors.
86 dwWidth = GetSystemMetrics(SM_CXSCREEN);
87 dwHeight = GetSystemMetrics(SM_CYSCREEN);
89 winErrorFVerb(2,
90 "winInitializeScreenDefaults - primary monitor w %d h %d\n",
91 (int) dwWidth, (int) dwHeight);
93 /* Set a default DPI, if no '-dpi' option was used */
94 if (monitorResolution == 0) {
95 HDC hdc = GetDC(NULL);
97 if (hdc) {
98 int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
99 int dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
101 winErrorFVerb(2,
102 "winInitializeScreenDefaults - native DPI x %d y %d\n",
103 dpiX, dpiY);
105 monitorResolution = dpiY;
106 ReleaseDC(NULL, hdc);
108 else {
109 winErrorFVerb(1,
110 "winInitializeScreenDefaults - Failed to retrieve native DPI, falling back to default of %d DPI\n",
111 WIN_DEFAULT_DPI);
112 monitorResolution = WIN_DEFAULT_DPI;
116 defaultScreenInfo.iMonitor = 1;
117 defaultScreenInfo.hMonitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
118 defaultScreenInfo.dwWidth = dwWidth;
119 defaultScreenInfo.dwHeight = dwHeight;
120 defaultScreenInfo.dwUserWidth = dwWidth;
121 defaultScreenInfo.dwUserHeight = dwHeight;
122 defaultScreenInfo.fUserGaveHeightAndWidth =
123 WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH;
124 defaultScreenInfo.fUserGavePosition = FALSE;
125 defaultScreenInfo.dwBPP = WIN_DEFAULT_BPP;
126 defaultScreenInfo.dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES;
127 #ifdef XWIN_EMULATEPSEUDO
128 defaultScreenInfo.fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO;
129 #endif
130 defaultScreenInfo.dwRefreshRate = WIN_DEFAULT_REFRESH;
131 defaultScreenInfo.pfb = NULL;
132 defaultScreenInfo.fFullScreen = FALSE;
133 defaultScreenInfo.fDecoration = TRUE;
134 defaultScreenInfo.fRootless = FALSE;
135 defaultScreenInfo.fMultiWindow = FALSE;
136 defaultScreenInfo.fCompositeWM = TRUE;
137 defaultScreenInfo.fMultiMonitorOverride = FALSE;
138 defaultScreenInfo.fMultipleMonitors = FALSE;
139 defaultScreenInfo.fLessPointer = FALSE;
140 defaultScreenInfo.iResizeMode = resizeDefault;
141 defaultScreenInfo.fNoTrayIcon = FALSE;
142 defaultScreenInfo.iE3BTimeout = WIN_E3B_DEFAULT;
143 defaultScreenInfo.fUseWinKillKey = WIN_DEFAULT_WIN_KILL;
144 defaultScreenInfo.fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
145 defaultScreenInfo.fIgnoreInput = FALSE;
146 defaultScreenInfo.fExplicitScreen = FALSE;
147 defaultScreenInfo.hIcon = (HICON)
148 LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
149 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
150 defaultScreenInfo.hIconSm = (HICON)
151 LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
152 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
153 LR_DEFAULTSIZE);
155 /* Note that the default screen has been initialized */
156 fInitializedScreenDefaults = TRUE;
159 static void
160 winInitializeScreen(int i)
162 winErrorFVerb(3, "winInitializeScreen - %d\n", i);
164 /* Initialize default screen values, if needed */
165 winInitializeScreenDefaults();
167 /* Copy the default screen info */
168 g_ScreenInfo[i] = defaultScreenInfo;
170 /* Set the screen number */
171 g_ScreenInfo[i].dwScreen = i;
174 void
175 winInitializeScreens(int maxscreens)
177 int i;
179 winErrorFVerb(3, "winInitializeScreens - %i\n", maxscreens);
181 if (maxscreens > g_iNumScreens) {
182 /* Reallocate the memory for DDX-specific screen info */
183 g_ScreenInfo =
184 realloc(g_ScreenInfo, maxscreens * sizeof(winScreenInfo));
186 /* Set default values for any new screens */
187 for (i = g_iNumScreens; i < maxscreens; i++)
188 winInitializeScreen(i);
190 /* Keep a count of the number of screens */
191 g_iNumScreens = maxscreens;
195 /* See Porting Layer Definition - p. 57 */
197 * INPUT
198 * argv: pointer to an array of null-terminated strings, one for
199 * each token in the X Server command line; the first token
200 * is 'XWin.exe', or similar.
201 * argc: a count of the number of tokens stored in argv.
202 * i: a zero-based index into argv indicating the current token being
203 * processed.
205 * OUTPUT
206 * return: return the number of tokens processed correctly.
208 * NOTE
209 * When looking for n tokens, check that i + n is less than argc. Or,
210 * you may check if i is greater than or equal to argc, in which case
211 * you should display the UseMsg () and return 0.
214 /* Check if enough arguments are given for the option */
215 #define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; }
217 /* Compare the current option with the string. */
218 #define IS_OPTION(name) (strcmp (argv[i], name) == 0)
221 ddxProcessArgument(int argc, char *argv[], int i)
223 static Bool s_fBeenHere = FALSE;
224 winScreenInfo *screenInfoPtr = NULL;
226 /* Initialize once */
227 if (!s_fBeenHere) {
229 * This initialises our hook into VErrorF () for catching log messages
230 * that are generated before OsInit () is called.
232 OsVendorVErrorFProc = OsVendorVErrorF;
234 s_fBeenHere = TRUE;
236 /* Initialize only if option is not -help */
237 if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") &&
238 !IS_OPTION("-version") && !IS_OPTION("--version")) {
240 /* Log the version information */
241 winLogVersionInfo();
243 /* Log the command line */
244 winLogCommandLine(argc, argv);
247 * Initialize default screen settings. We have to do this before
248 * OsVendorInit () gets called, otherwise we will overwrite
249 * settings changed by parameters such as -fullscreen, etc.
251 winErrorFVerb(3, "ddxProcessArgument - Initializing default "
252 "screens\n");
253 winInitializeScreenDefaults();
257 #if ENABLE_DEBUG
258 winDebug("ddxProcessArgument - arg: %s\n", argv[i]);
259 #endif
262 * Look for the '-help' and similar options
264 if (IS_OPTION("-help") || IS_OPTION("-h") || IS_OPTION("--help")) {
265 /* Reset logfile. We don't need that helpmessage in the logfile */
266 g_pszLogFile = NULL;
267 g_fNoHelpMessageBox = TRUE;
268 UseMsg();
269 exit(0);
270 return 1;
273 if (IS_OPTION("-version") || IS_OPTION("--version")) {
274 /* Reset logfile. We don't need that versioninfo in the logfile */
275 g_pszLogFile = NULL;
276 winLogVersionInfo();
277 exit(0);
278 return 1;
282 * Look for the '-screen scr_num [width height]' argument
284 if (IS_OPTION("-screen")) {
285 int iArgsProcessed = 1;
286 int nScreenNum;
287 int iWidth, iHeight, iX, iY;
288 int iMonitor;
290 #if ENABLE_DEBUG
291 winDebug("ddxProcessArgument - screen - argc: %d i: %d\n", argc, i);
292 #endif
294 /* Display the usage message if the argument is malformed */
295 if (i + 1 >= argc) {
296 return 0;
299 /* Grab screen number */
300 nScreenNum = atoi(argv[i + 1]);
302 /* Validate the specified screen number */
303 if (nScreenNum < 0) {
304 ErrorF("ddxProcessArgument - screen - Invalid screen number %d\n",
305 nScreenNum);
306 UseMsg();
307 return 0;
311 Initialize default values for any new screens
313 Note that default values can't change after a -screen option is
314 seen, so it's safe to do this for each screen as it is introduced
316 winInitializeScreens(nScreenNum + 1);
318 /* look for @m where m is monitor number */
319 if (i + 2 < argc && 1 == sscanf(argv[i + 2], "@%d", (int *) &iMonitor)) {
320 struct GetMonitorInfoData data;
322 if (QueryMonitor(iMonitor, &data)) {
323 winErrorFVerb(2,
324 "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n",
325 iMonitor);
326 iArgsProcessed = 3;
327 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
328 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
329 g_ScreenInfo[nScreenNum].iMonitor = iMonitor;
330 g_ScreenInfo[nScreenNum].hMonitor = data.monitorHandle;
331 g_ScreenInfo[nScreenNum].dwWidth = data.monitorWidth;
332 g_ScreenInfo[nScreenNum].dwHeight = data.monitorHeight;
333 g_ScreenInfo[nScreenNum].dwUserWidth = data.monitorWidth;
334 g_ScreenInfo[nScreenNum].dwUserHeight = data.monitorHeight;
335 g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
336 g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
338 else {
339 /* monitor does not exist, error out */
340 ErrorF
341 ("ddxProcessArgument - screen - Invalid monitor number %d\n",
342 iMonitor);
343 exit(1);
344 return 0;
348 /* Look for 'WxD' or 'W D' */
349 else if (i + 2 < argc
350 && 2 == sscanf(argv[i + 2], "%dx%d",
351 (int *) &iWidth, (int *) &iHeight)) {
352 winErrorFVerb(2,
353 "ddxProcessArgument - screen - Found ``WxD'' arg\n");
354 iArgsProcessed = 3;
355 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
356 g_ScreenInfo[nScreenNum].dwWidth = iWidth;
357 g_ScreenInfo[nScreenNum].dwHeight = iHeight;
358 g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
359 g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
360 /* Look for WxD+X+Y */
361 if (2 == sscanf(argv[i + 2], "%*dx%*d+%d+%d",
362 (int *) &iX, (int *) &iY)) {
363 winErrorFVerb(2,
364 "ddxProcessArgument - screen - Found ``X+Y'' arg\n");
365 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
366 g_ScreenInfo[nScreenNum].dwInitialX = iX;
367 g_ScreenInfo[nScreenNum].dwInitialY = iY;
369 /* look for WxD+X+Y@m where m is monitor number. take X,Y to be offsets from monitor's root position */
370 if (1 == sscanf(argv[i + 2], "%*dx%*d+%*d+%*d@%d",
371 (int *) &iMonitor)) {
372 struct GetMonitorInfoData data;
374 if (QueryMonitor(iMonitor, &data)) {
375 g_ScreenInfo[nScreenNum].iMonitor = iMonitor;
376 g_ScreenInfo[nScreenNum].hMonitor = data.monitorHandle;
377 g_ScreenInfo[nScreenNum].dwInitialX +=
378 data.monitorOffsetX;
379 g_ScreenInfo[nScreenNum].dwInitialY +=
380 data.monitorOffsetY;
382 else {
383 /* monitor does not exist, error out */
384 ErrorF
385 ("ddxProcessArgument - screen - Invalid monitor number %d\n",
386 iMonitor);
387 exit(1);
388 return 0;
393 /* look for WxD@m where m is monitor number */
394 else if (1 == sscanf(argv[i + 2], "%*dx%*d@%d", (int *) &iMonitor)) {
395 struct GetMonitorInfoData data;
397 if (QueryMonitor(iMonitor, &data)) {
398 winErrorFVerb(2,
399 "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n",
400 iMonitor);
401 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
402 g_ScreenInfo[nScreenNum].iMonitor = iMonitor;
403 g_ScreenInfo[nScreenNum].hMonitor = data.monitorHandle;
404 g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
405 g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
407 else {
408 /* monitor does not exist, error out */
409 ErrorF
410 ("ddxProcessArgument - screen - Invalid monitor number %d\n",
411 iMonitor);
412 exit(1);
413 return 0;
417 else if (i + 3 < argc && 1 == sscanf(argv[i + 2], "%d", (int *) &iWidth)
418 && 1 == sscanf(argv[i + 3], "%d", (int *) &iHeight)) {
419 winErrorFVerb(2,
420 "ddxProcessArgument - screen - Found ``W D'' arg\n");
421 iArgsProcessed = 4;
422 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
423 g_ScreenInfo[nScreenNum].dwWidth = iWidth;
424 g_ScreenInfo[nScreenNum].dwHeight = iHeight;
425 g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
426 g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
427 if (i + 5 < argc && 1 == sscanf(argv[i + 4], "%d", (int *) &iX)
428 && 1 == sscanf(argv[i + 5], "%d", (int *) &iY)) {
429 winErrorFVerb(2,
430 "ddxProcessArgument - screen - Found ``X Y'' arg\n");
431 iArgsProcessed = 6;
432 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
433 g_ScreenInfo[nScreenNum].dwInitialX = iX;
434 g_ScreenInfo[nScreenNum].dwInitialY = iY;
437 else {
438 winErrorFVerb(2,
439 "ddxProcessArgument - screen - Did not find size arg. "
440 "dwWidth: %d dwHeight: %d\n",
441 (int) g_ScreenInfo[nScreenNum].dwWidth,
442 (int) g_ScreenInfo[nScreenNum].dwHeight);
443 iArgsProcessed = 2;
444 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
447 /* Flag that this screen was explicitly specified by the user */
448 g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE;
451 * Keep track of the last screen number seen, as parameters seen
452 * before a screen number apply to all screens, whereas parameters
453 * seen after a screen number apply to that screen number only.
455 iLastScreen = nScreenNum;
457 return iArgsProcessed;
461 * Is this parameter attached to a screen or global?
463 * If the parameter is for all screens (appears before
464 * any -screen option), store it in the default screen
465 * info
467 * If the parameter is for a single screen (appears
468 * after a -screen option), store it in the screen info
469 * for that screen
472 if (iLastScreen == -1) {
473 screenInfoPtr = &defaultScreenInfo;
475 else {
476 screenInfoPtr = &(g_ScreenInfo[iLastScreen]);
480 * Look for the '-engine n' argument
482 if (IS_OPTION("-engine")) {
483 DWORD dwEngine = 0;
484 CARD8 c8OnBits = 0;
486 /* Display the usage message if the argument is malformed */
487 if (++i >= argc) {
488 UseMsg();
489 return 0;
492 /* Grab the argument */
493 dwEngine = atoi(argv[i]);
495 /* Count the one bits in the engine argument */
496 c8OnBits = winCountBits(dwEngine);
498 /* Argument should only have a single bit on */
499 if (c8OnBits != 1) {
500 UseMsg();
501 return 0;
504 screenInfoPtr->dwEnginePreferred = dwEngine;
506 /* Indicate that we have processed the argument */
507 return 2;
511 * Look for the '-fullscreen' argument
513 if (IS_OPTION("-fullscreen")) {
514 if (!screenInfoPtr->fMultiMonitorOverride)
515 screenInfoPtr->fMultipleMonitors = FALSE;
516 screenInfoPtr->fFullScreen = TRUE;
518 /* Indicate that we have processed this argument */
519 return 1;
523 * Look for the '-lesspointer' argument
525 if (IS_OPTION("-lesspointer")) {
526 screenInfoPtr->fLessPointer = TRUE;
528 /* Indicate that we have processed this argument */
529 return 1;
533 * Look for the '-nodecoration' argument
535 if (IS_OPTION("-nodecoration")) {
536 if (!screenInfoPtr->fMultiMonitorOverride)
537 screenInfoPtr->fMultipleMonitors = FALSE;
538 screenInfoPtr->fDecoration = FALSE;
540 /* Indicate that we have processed this argument */
541 return 1;
545 * Look for the '-rootless' argument
547 if (IS_OPTION("-rootless")) {
548 if (!screenInfoPtr->fMultiMonitorOverride)
549 screenInfoPtr->fMultipleMonitors = FALSE;
550 screenInfoPtr->fRootless = TRUE;
552 /* Indicate that we have processed this argument */
553 return 1;
557 * Look for the '-multiwindow' argument
559 if (IS_OPTION("-multiwindow")) {
560 if (!screenInfoPtr->fMultiMonitorOverride)
561 screenInfoPtr->fMultipleMonitors = TRUE;
562 screenInfoPtr->fMultiWindow = TRUE;
564 /* Indicate that we have processed this argument */
565 return 1;
569 * Look for the '-compositewm' argument
571 if (IS_OPTION("-compositewm")) {
572 screenInfoPtr->fCompositeWM = TRUE;
574 /* Indicate that we have processed this argument */
575 return 1;
578 * Look for the '-nocompositewm' argument
580 if (IS_OPTION("-nocompositewm")) {
581 screenInfoPtr->fCompositeWM = FALSE;
583 /* Indicate that we have processed this argument */
584 return 1;
588 * Look for the '-compositealpha' argument
590 if (IS_OPTION("-compositealpha")) {
591 g_fCompositeAlpha = TRUE;
593 /* Indicate that we have processed this argument */
594 return 1;
597 * Look for the '-nocompositealpha' argument
599 if (IS_OPTION("-nocompositealpha")) {
600 g_fCompositeAlpha = FALSE;
602 /* Indicate that we have processed this argument */
603 return 1;
607 * Look for the '-multiplemonitors' argument
609 if (IS_OPTION("-multiplemonitors")
610 || IS_OPTION("-multimonitors")) {
611 screenInfoPtr->fMultiMonitorOverride = TRUE;
612 screenInfoPtr->fMultipleMonitors = TRUE;
614 /* Indicate that we have processed this argument */
615 return 1;
619 * Look for the '-nomultiplemonitors' argument
621 if (IS_OPTION("-nomultiplemonitors")
622 || IS_OPTION("-nomultimonitors")) {
623 screenInfoPtr->fMultiMonitorOverride = TRUE;
624 screenInfoPtr->fMultipleMonitors = FALSE;
626 /* Indicate that we have processed this argument */
627 return 1;
631 * Look for the '-scrollbars' argument
633 if (IS_OPTION("-scrollbars")) {
635 screenInfoPtr->iResizeMode = resizeWithScrollbars;
637 /* Indicate that we have processed this argument */
638 return 1;
642 * Look for the '-resize' argument
644 if (IS_OPTION("-resize") || IS_OPTION("-noresize") ||
645 (strncmp(argv[i], "-resize=", strlen("-resize=")) == 0)) {
646 winResizeMode mode;
648 if (IS_OPTION("-resize"))
649 mode = resizeWithRandr;
650 else if (IS_OPTION("-noresize"))
651 mode = resizeNotAllowed;
652 else if (strncmp(argv[i], "-resize=", strlen("-resize=")) == 0) {
653 char *option = argv[i] + strlen("-resize=");
655 if (strcmp(option, "randr") == 0)
656 mode = resizeWithRandr;
657 else if (strcmp(option, "scrollbars") == 0)
658 mode = resizeWithScrollbars;
659 else if (strcmp(option, "none") == 0)
660 mode = resizeNotAllowed;
661 else {
662 ErrorF("ddxProcessArgument - resize - Invalid resize mode %s\n",
663 option);
664 return 0;
667 else {
668 ErrorF("ddxProcessArgument - resize - Invalid resize option %s\n",
669 argv[i]);
670 return 0;
673 screenInfoPtr->iResizeMode = mode;
675 /* Indicate that we have processed this argument */
676 return 1;
680 * Look for the '-clipboard' argument
682 if (IS_OPTION("-clipboard")) {
683 /* Now the default, we still accept the arg for backwards compatibility */
684 g_fClipboard = TRUE;
686 /* Indicate that we have processed this argument */
687 return 1;
691 * Look for the '-noclipboard' argument
693 if (IS_OPTION("-noclipboard")) {
694 g_fClipboard = FALSE;
696 /* Indicate that we have processed this argument */
697 return 1;
701 * Look for the '-primary' argument
703 if (IS_OPTION("-primary")) {
704 fPrimarySelection = TRUE;
706 /* Indicate that we have processed this argument */
707 return 1;
711 * Look for the '-noprimary' argument
713 if (IS_OPTION("-noprimary")) {
714 fPrimarySelection = FALSE;
716 /* Indicate that we have processed this argument */
717 return 1;
721 * Look for the '-ignoreinput' argument
723 if (IS_OPTION("-ignoreinput")) {
724 screenInfoPtr->fIgnoreInput = TRUE;
726 /* Indicate that we have processed this argument */
727 return 1;
731 * Look for the '-emulate3buttons' argument
733 if (IS_OPTION("-emulate3buttons")) {
734 int iArgsProcessed = 1;
735 int iE3BTimeout = WIN_DEFAULT_E3B_TIME;
737 /* Grab the optional timeout value */
738 if (i + 1 < argc && 1 == sscanf(argv[i + 1], "%d", &iE3BTimeout)) {
739 /* Indicate that we have processed the next argument */
740 iArgsProcessed++;
742 else {
744 * sscanf () won't modify iE3BTimeout if it doesn't find
745 * the specified format; however, I want to be explicit
746 * about setting the default timeout in such cases to
747 * prevent some programs (me) from getting confused.
749 iE3BTimeout = WIN_DEFAULT_E3B_TIME;
752 screenInfoPtr->iE3BTimeout = iE3BTimeout;
754 /* Indicate that we have processed this argument */
755 return iArgsProcessed;
759 * Look for the '-noemulate3buttons' argument
761 if (IS_OPTION("-noemulate3buttons")) {
762 screenInfoPtr->iE3BTimeout = WIN_E3B_OFF;
764 /* Indicate that we have processed this argument */
765 return 1;
769 * Look for the '-depth n' argument
771 if (IS_OPTION("-depth")) {
772 DWORD dwBPP = 0;
774 /* Display the usage message if the argument is malformed */
775 if (++i >= argc) {
776 UseMsg();
777 return 0;
780 /* Grab the argument */
781 dwBPP = atoi(argv[i]);
783 screenInfoPtr->dwBPP = dwBPP;
785 /* Indicate that we have processed the argument */
786 return 2;
790 * Look for the '-refresh n' argument
792 if (IS_OPTION("-refresh")) {
793 DWORD dwRefreshRate = 0;
795 /* Display the usage message if the argument is malformed */
796 if (++i >= argc) {
797 UseMsg();
798 return 0;
801 /* Grab the argument */
802 dwRefreshRate = atoi(argv[i]);
804 screenInfoPtr->dwRefreshRate = dwRefreshRate;
806 /* Indicate that we have processed the argument */
807 return 2;
811 * Look for the '-clipupdates num_boxes' argument
813 if (IS_OPTION("-clipupdates")) {
814 DWORD dwNumBoxes = 0;
816 /* Display the usage message if the argument is malformed */
817 if (++i >= argc) {
818 UseMsg();
819 return 0;
822 /* Grab the argument */
823 dwNumBoxes = atoi(argv[i]);
825 screenInfoPtr->dwClipUpdatesNBoxes = dwNumBoxes;
827 /* Indicate that we have processed the argument */
828 return 2;
831 #ifdef XWIN_EMULATEPSEUDO
833 * Look for the '-emulatepseudo' argument
835 if (IS_OPTION("-emulatepseudo")) {
836 screenInfoPtr->fEmulatePseudo = TRUE;
838 /* Indicate that we have processed this argument */
839 return 1;
841 #endif
844 * Look for the '-nowinkill' argument
846 if (IS_OPTION("-nowinkill")) {
847 screenInfoPtr->fUseWinKillKey = FALSE;
849 /* Indicate that we have processed this argument */
850 return 1;
854 * Look for the '-winkill' argument
856 if (IS_OPTION("-winkill")) {
857 screenInfoPtr->fUseWinKillKey = TRUE;
859 /* Indicate that we have processed this argument */
860 return 1;
864 * Look for the '-nounixkill' argument
866 if (IS_OPTION("-nounixkill")) {
867 screenInfoPtr->fUseUnixKillKey = FALSE;
869 /* Indicate that we have processed this argument */
870 return 1;
874 * Look for the '-unixkill' argument
876 if (IS_OPTION("-unixkill")) {
877 screenInfoPtr->fUseUnixKillKey = TRUE;
879 /* Indicate that we have processed this argument */
880 return 1;
884 * Look for the '-notrayicon' argument
886 if (IS_OPTION("-notrayicon")) {
887 screenInfoPtr->fNoTrayIcon = TRUE;
889 /* Indicate that we have processed this argument */
890 return 1;
894 * Look for the '-trayicon' argument
896 if (IS_OPTION("-trayicon")) {
897 screenInfoPtr->fNoTrayIcon = FALSE;
899 /* Indicate that we have processed this argument */
900 return 1;
904 * Look for the '-fp' argument
906 if (IS_OPTION("-fp")) {
907 CHECK_ARGS(1);
908 g_cmdline.fontPath = argv[++i];
909 return 0; /* Let DIX parse this again */
913 * Look for the '-query' argument
915 if (IS_OPTION("-query")) {
916 CHECK_ARGS(1);
917 g_fXdmcpEnabled = TRUE;
918 g_pszQueryHost = argv[++i];
919 return 0; /* Let DIX parse this again */
923 * Look for the '-auth' argument
925 if (IS_OPTION("-auth")) {
926 g_fAuthEnabled = TRUE;
927 return 0; /* Let DIX parse this again */
931 * Look for the '-indirect' or '-broadcast' arguments
933 if (IS_OPTION("-indirect")
934 || IS_OPTION("-broadcast")) {
935 g_fXdmcpEnabled = TRUE;
936 return 0; /* Let DIX parse this again */
940 * Look for the '-config' argument
942 if (IS_OPTION("-config")
943 || IS_OPTION("-xf86config")) {
944 CHECK_ARGS(1);
945 #ifdef XWIN_XF86CONFIG
946 g_cmdline.configFile = argv[++i];
947 #else
948 winMessageBoxF("The %s option is not supported in this "
949 "release.\n"
950 "Ignoring this option and continuing.\n",
951 MB_ICONINFORMATION, argv[i]);
952 #endif
953 return 2;
957 * Look for the '-configdir' argument
959 if (IS_OPTION("-configdir")) {
960 CHECK_ARGS(1);
961 #ifdef XWIN_XF86CONFIG
962 g_cmdline.configDir = argv[++i];
963 #else
964 winMessageBoxF("The %s option is not supported in this "
965 "release.\n"
966 "Ignoring this option and continuing.\n",
967 MB_ICONINFORMATION, argv[i]);
968 #endif
969 return 2;
973 * Look for the '-keyboard' argument
975 if (IS_OPTION("-keyboard")) {
976 #ifdef XWIN_XF86CONFIG
977 CHECK_ARGS(1);
978 g_cmdline.keyboard = argv[++i];
979 #else
980 winMessageBoxF("The -keyboard option is not supported in this "
981 "release.\n"
982 "Ignoring this option and continuing.\n",
983 MB_ICONINFORMATION);
984 #endif
985 return 2;
989 * Look for the '-logfile' argument
991 if (IS_OPTION("-logfile")) {
992 CHECK_ARGS(1);
993 g_pszLogFile = argv[++i];
994 #ifdef RELOCATE_PROJECTROOT
995 g_fLogFileChanged = TRUE;
996 #endif
997 return 2;
1001 * Look for the '-logverbose' argument
1003 if (IS_OPTION("-logverbose")) {
1004 CHECK_ARGS(1);
1005 g_iLogVerbose = atoi(argv[++i]);
1006 return 2;
1009 if (IS_OPTION("-xkbrules")) {
1010 CHECK_ARGS(1);
1011 g_cmdline.xkbRules = argv[++i];
1012 return 2;
1014 if (IS_OPTION("-xkbmodel")) {
1015 CHECK_ARGS(1);
1016 g_cmdline.xkbModel = argv[++i];
1017 return 2;
1019 if (IS_OPTION("-xkblayout")) {
1020 CHECK_ARGS(1);
1021 g_cmdline.xkbLayout = argv[++i];
1022 return 2;
1024 if (IS_OPTION("-xkbvariant")) {
1025 CHECK_ARGS(1);
1026 g_cmdline.xkbVariant = argv[++i];
1027 return 2;
1029 if (IS_OPTION("-xkboptions")) {
1030 CHECK_ARGS(1);
1031 g_cmdline.xkbOptions = argv[++i];
1032 return 2;
1035 if (IS_OPTION("-keyhook")) {
1036 g_fKeyboardHookLL = TRUE;
1037 return 1;
1040 if (IS_OPTION("-nokeyhook")) {
1041 g_fKeyboardHookLL = FALSE;
1042 return 1;
1045 if (IS_OPTION("-swcursor")) {
1046 g_fSoftwareCursor = TRUE;
1047 return 1;
1050 if (IS_OPTION("-wgl")) {
1051 g_fNativeGl = TRUE;
1052 return 1;
1055 if (IS_OPTION("-nowgl")) {
1056 g_fNativeGl = FALSE;
1057 return 1;
1060 if (IS_OPTION("-hostintitle")) {
1061 g_fHostInTitle = TRUE;
1062 return 1;
1065 if (IS_OPTION("-nohostintitle")) {
1066 g_fHostInTitle = FALSE;
1067 return 1;
1070 if (IS_OPTION("-icon")) {
1071 char *iconspec;
1072 CHECK_ARGS(1);
1073 iconspec = argv[++i];
1074 screenInfoPtr->hIcon = LoadImageComma(iconspec, NULL,
1075 GetSystemMetrics(SM_CXICON),
1076 GetSystemMetrics(SM_CYICON),
1078 screenInfoPtr->hIconSm = LoadImageComma(iconspec, NULL,
1079 GetSystemMetrics(SM_CXSMICON),
1080 GetSystemMetrics(SM_CYSMICON),
1081 LR_DEFAULTSIZE);
1082 if ((screenInfoPtr->hIcon == NULL) ||
1083 (screenInfoPtr->hIconSm == NULL)) {
1084 ErrorF("ddxProcessArgument - icon - Invalid icon specification %s\n",
1085 iconspec);
1086 exit(1);
1089 /* Indicate that we have processed the argument */
1090 return 2;
1093 return 0;
1097 * winLogCommandLine - Write entire command line to the log file
1100 void
1101 winLogCommandLine(int argc, char *argv[])
1103 int i;
1104 int iSize = 0;
1105 int iCurrLen = 0;
1107 #define CHARS_PER_LINE 60
1109 /* Bail if command line has already been logged */
1110 if (g_pszCommandLine)
1111 return;
1113 /* Count how much memory is needed for concatenated command line */
1114 for (i = 0, iCurrLen = 0; i < argc; ++i)
1115 if (argv[i]) {
1116 /* Adds two characters for lines that overflow */
1117 if ((strlen(argv[i]) < CHARS_PER_LINE
1118 && iCurrLen + strlen(argv[i]) > CHARS_PER_LINE)
1119 || strlen(argv[i]) > CHARS_PER_LINE) {
1120 iCurrLen = 0;
1121 iSize += 2;
1124 /* Add space for item and trailing space */
1125 iSize += strlen(argv[i]) + 1;
1127 /* Update current line length */
1128 iCurrLen += strlen(argv[i]);
1131 /* Allocate memory for concatenated command line */
1132 g_pszCommandLine = malloc(iSize + 1);
1133 if (!g_pszCommandLine)
1134 FatalError("winLogCommandLine - Could not allocate memory for "
1135 "command line string. Exiting.\n");
1137 /* Set first character to concatenated command line to null */
1138 g_pszCommandLine[0] = '\0';
1140 /* Loop through all args */
1141 for (i = 0, iCurrLen = 0; i < argc; ++i) {
1142 /* Add a character for lines that overflow */
1143 if ((strlen(argv[i]) < CHARS_PER_LINE
1144 && iCurrLen + strlen(argv[i]) > CHARS_PER_LINE)
1145 || strlen(argv[i]) > CHARS_PER_LINE) {
1146 iCurrLen = 0;
1148 /* Add line break if it fits */
1149 strncat(g_pszCommandLine, "\n ", iSize - strlen(g_pszCommandLine));
1152 strncat(g_pszCommandLine, argv[i], iSize - strlen(g_pszCommandLine));
1153 strncat(g_pszCommandLine, " ", iSize - strlen(g_pszCommandLine));
1155 /* Save new line length */
1156 iCurrLen += strlen(argv[i]);
1159 ErrorF("XWin was started with the following command line:\n\n"
1160 "%s\n\n", g_pszCommandLine);
1164 * winLogVersionInfo - Log version information
1167 void
1168 winLogVersionInfo(void)
1170 static Bool s_fBeenHere = FALSE;
1172 if (s_fBeenHere)
1173 return;
1174 s_fBeenHere = TRUE;
1176 ErrorF("Welcome to the XWin X Server\n");
1177 ErrorF("Vendor: %s\n", XVENDORNAME);
1178 ErrorF("Release: %d.%d.%d.%d\n", XORG_VERSION_MAJOR,
1179 XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP);
1180 #ifdef HAVE_SYS_UTSNAME_H
1182 struct utsname name;
1184 if (uname(&name) >= 0) {
1185 ErrorF("OS: %s %s %s %s %s\n", name.sysname, name.nodename,
1186 name.release, name.version, name.machine);
1189 #endif
1190 winOS();
1191 if (strlen(BUILDERSTRING))
1192 ErrorF("%s\n", BUILDERSTRING);
1193 ErrorF("Contact: %s\n", BUILDERADDR);
1194 ErrorF("\n");