Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winprocarg.c
blobbd0b99977faa2ae0b6cc7f913f322fcec3afa870
1 /*
3 Copyright 1993, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
25 from The Open Group.
29 #ifdef HAVE_XWIN_CONFIG_H
30 #include <xwin-config.h>
31 #endif
32 #ifdef XVENDORNAME
33 #define VENDOR_STRING XVENDORNAME
34 #define VERSION_STRING XORG_RELEASE
35 #define VENDOR_CONTACT BUILDERADDR
36 #endif
37 #include "win.h"
38 #include "winconfig.h"
39 #include "winprefs.h"
40 #include "winmsg.h"
43 * References to external symbols
46 extern int g_iNumScreens;
47 extern winScreenInfo g_ScreenInfo[];
48 extern int g_iLastScreen;
49 extern Bool g_fInitializedDefaultScreens;
50 #ifdef XWIN_CLIPBOARD
51 extern Bool g_fUnicodeClipboard;
52 extern Bool g_fClipboard;
53 #endif
54 extern int g_iLogVerbose;
55 extern char * g_pszLogFile;
56 #ifdef RELOCATE_PROJECTROOT
57 extern Bool g_fLogFileChanged;
58 #endif
59 extern Bool g_fXdmcpEnabled;
60 extern char * g_pszCommandLine;
61 extern Bool g_fKeyboardHookLL;
62 extern Bool g_fNoHelpMessageBox;
63 extern Bool g_fSoftwareCursor;
64 extern Bool g_fSilentDupError;
66 /* globals required by callback function for monitor information */
67 struct GetMonitorInfoData {
68 int requestedMonitor;
69 int monitorNum;
70 Bool bUserSpecifiedMonitor;
71 Bool bMonitorSpecifiedExists;
72 int monitorOffsetX;
73 int monitorOffsetY;
74 int monitorHeight;
75 int monitorWidth;
78 typedef wBOOL (*ENUMDISPLAYMONITORSPROC)(HDC,LPCRECT,MONITORENUMPROC,LPARAM);
79 ENUMDISPLAYMONITORSPROC _EnumDisplayMonitors;
81 wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data);
83 static Bool QueryMonitor(int index, struct GetMonitorInfoData *data)
85 /* Load EnumDisplayMonitors from DLL */
86 HMODULE user32;
87 FARPROC func;
88 user32 = LoadLibrary("user32.dll");
89 if (user32 == NULL)
91 winW32Error(2, "Could not open user32.dll");
92 return FALSE;
94 func = GetProcAddress(user32, "EnumDisplayMonitors");
95 if (func == NULL)
97 winW32Error(2, "Could not resolve EnumDisplayMonitors: ");
98 return FALSE;
100 _EnumDisplayMonitors = (ENUMDISPLAYMONITORSPROC)func;
102 /* prepare data */
103 if (data == NULL)
104 return FALSE;
105 memset(data, 0, sizeof(*data));
106 data->requestedMonitor = index;
108 /* query information */
109 _EnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data);
111 /* cleanup */
112 FreeLibrary(user32);
113 return TRUE;
117 * Function prototypes
120 void
121 winLogCommandLine (int argc, char *argv[]);
123 void
124 winLogVersionInfo (void);
126 #ifdef DDXOSVERRORF
127 void OsVendorVErrorF (const char *pszFormat, va_list va_args);
128 #endif
130 void
131 winInitializeDefaultScreens (void);
134 * Process arguments on the command line
137 void
138 winInitializeDefaultScreens (void)
140 int i;
141 DWORD dwWidth, dwHeight;
143 /* Bail out early if default screens have already been initialized */
144 if (g_fInitializedDefaultScreens)
145 return;
147 /* Zero the memory used for storing the screen info */
148 ZeroMemory (g_ScreenInfo, MAXSCREENS * sizeof (winScreenInfo));
150 /* Get default width and height */
152 * NOTE: These defaults will cause the window to cover only
153 * the primary monitor in the case that we have multiple monitors.
155 dwWidth = GetSystemMetrics (SM_CXSCREEN);
156 dwHeight = GetSystemMetrics (SM_CYSCREEN);
158 winErrorFVerb (2, "winInitializeDefaultScreens - w %d h %d\n",
159 (int) dwWidth, (int) dwHeight);
161 /* Set a default DPI, if no parameter was passed */
162 if (monitorResolution == 0)
163 monitorResolution = WIN_DEFAULT_DPI;
165 for (i = 0; i < MAXSCREENS; ++i)
167 g_ScreenInfo[i].dwScreen = i;
168 g_ScreenInfo[i].dwWidth = dwWidth;
169 g_ScreenInfo[i].dwHeight = dwHeight;
170 g_ScreenInfo[i].dwUserWidth = dwWidth;
171 g_ScreenInfo[i].dwUserHeight = dwHeight;
172 g_ScreenInfo[i].fUserGaveHeightAndWidth
173 = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH;
174 g_ScreenInfo[i].fUserGavePosition = FALSE;
175 g_ScreenInfo[i].dwBPP = WIN_DEFAULT_BPP;
176 g_ScreenInfo[i].dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES;
177 #ifdef XWIN_EMULATEPSEUDO
178 g_ScreenInfo[i].fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO;
179 #endif
180 g_ScreenInfo[i].dwRefreshRate = WIN_DEFAULT_REFRESH;
181 g_ScreenInfo[i].pfb = NULL;
182 g_ScreenInfo[i].fFullScreen = FALSE;
183 g_ScreenInfo[i].fDecoration = TRUE;
184 #ifdef XWIN_MULTIWINDOWEXTWM
185 g_ScreenInfo[i].fMWExtWM = FALSE;
186 g_ScreenInfo[i].fInternalWM = FALSE;
187 #endif
188 g_ScreenInfo[i].fRootless = FALSE;
189 #ifdef XWIN_MULTIWINDOW
190 g_ScreenInfo[i].fMultiWindow = FALSE;
191 #endif
192 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
193 g_ScreenInfo[i].fMultiMonitorOverride = FALSE;
194 #endif
195 g_ScreenInfo[i].fMultipleMonitors = FALSE;
196 g_ScreenInfo[i].fLessPointer = FALSE;
197 g_ScreenInfo[i].fScrollbars = FALSE;
198 g_ScreenInfo[i].fNoTrayIcon = FALSE;
199 g_ScreenInfo[i].iE3BTimeout = WIN_E3B_OFF;
200 g_ScreenInfo[i].dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI)
201 * 25.4;
202 g_ScreenInfo[i].dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI)
203 * 25.4;
204 g_ScreenInfo[i].fUseWinKillKey = WIN_DEFAULT_WIN_KILL;
205 g_ScreenInfo[i].fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
206 g_ScreenInfo[i].fIgnoreInput = FALSE;
207 g_ScreenInfo[i].fExplicitScreen = FALSE;
210 /* Signal that the default screens have been initialized */
211 g_fInitializedDefaultScreens = TRUE;
213 winErrorFVerb (2, "winInitializeDefaultScreens - Returning\n");
216 /* See Porting Layer Definition - p. 57 */
218 * INPUT
219 * argv: pointer to an array of null-terminated strings, one for
220 * each token in the X Server command line; the first token
221 * is 'XWin.exe', or similar.
222 * argc: a count of the number of tokens stored in argv.
223 * i: a zero-based index into argv indicating the current token being
224 * processed.
226 * OUTPUT
227 * return: return the number of tokens processed correctly.
229 * NOTE
230 * When looking for n tokens, check that i + n is less than argc. Or,
231 * you may check if i is greater than or equal to argc, in which case
232 * you should display the UseMsg () and return 0.
235 /* Check if enough arguments are given for the option */
236 #define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; }
238 /* Compare the current option with the string. */
239 #define IS_OPTION(name) (strcmp (argv[i], name) == 0)
242 ddxProcessArgument (int argc, char *argv[], int i)
244 static Bool s_fBeenHere = FALSE;
246 /* Initialize once */
247 if (!s_fBeenHere)
249 #ifdef DDXOSVERRORF
251 * This initialises our hook into VErrorF () for catching log messages
252 * that are generated before OsInit () is called.
254 OsVendorVErrorFProc = OsVendorVErrorF;
255 #endif
257 s_fBeenHere = TRUE;
259 /* Initialize only if option is not -help */
260 if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") &&
261 !IS_OPTION("-version") && !IS_OPTION("--version"))
264 /* Log the version information */
265 winLogVersionInfo ();
267 /* Log the command line */
268 winLogCommandLine (argc, argv);
271 * Initialize default screen settings. We have to do this before
272 * OsVendorInit () gets called, otherwise we will overwrite
273 * settings changed by parameters such as -fullscreen, etc.
275 winErrorFVerb (2, "ddxProcessArgument - Initializing default "
276 "screens\n");
277 winInitializeDefaultScreens ();
281 #if CYGDEBUG
282 winDebug ("ddxProcessArgument - arg: %s\n", argv[i]);
283 #endif
286 * Look for the '-help' and similar options
288 if (IS_OPTION ("-help") || IS_OPTION("-h") || IS_OPTION("--help"))
290 /* Reset logfile. We don't need that helpmessage in the logfile */
291 g_pszLogFile = NULL;
292 g_fNoHelpMessageBox = TRUE;
293 UseMsg();
294 exit (0);
295 return 1;
298 if (IS_OPTION ("-version") || IS_OPTION("--version"))
300 /* Reset logfile. We don't need that versioninfo in the logfile */
301 g_pszLogFile = NULL;
302 winLogVersionInfo ();
303 exit (0);
304 return 1;
308 * Look for the '-screen scr_num [width height]' argument
310 if (IS_OPTION ("-screen"))
312 int iArgsProcessed = 1;
313 int nScreenNum;
314 int iWidth, iHeight, iX, iY;
315 int iMonitor;
317 #if CYGDEBUG
318 winDebug ("ddxProcessArgument - screen - argc: %d i: %d\n",
319 argc, i);
320 #endif
322 /* Display the usage message if the argument is malformed */
323 if (i + 1 >= argc)
325 return 0;
328 /* Grab screen number */
329 nScreenNum = atoi (argv[i + 1]);
331 /* Validate the specified screen number */
332 if (nScreenNum < 0 || nScreenNum >= MAXSCREENS)
334 ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n",
335 nScreenNum);
336 UseMsg ();
337 return 0;
340 /* look for @m where m is monitor number */
341 if (i + 2 < argc
342 && 1 == sscanf(argv[i + 2], "@%d", (int *) &iMonitor))
344 struct GetMonitorInfoData data;
345 if (!QueryMonitor(iMonitor, &data))
347 ErrorF ("ddxProcessArgument - screen - "
348 "Querying monitors is not supported on NT4 and Win95\n");
349 } else if (data.bMonitorSpecifiedExists == TRUE)
351 winErrorFVerb(2, "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
352 iArgsProcessed = 3;
353 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
354 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
355 g_ScreenInfo[nScreenNum].dwWidth = data.monitorWidth;
356 g_ScreenInfo[nScreenNum].dwHeight = data.monitorHeight;
357 g_ScreenInfo[nScreenNum].dwUserWidth = data.monitorWidth;
358 g_ScreenInfo[nScreenNum].dwUserHeight = data.monitorHeight;
359 g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
360 g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
362 else
364 /* monitor does not exist, error out */
365 ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
366 iMonitor);
367 UseMsg ();
368 exit (0);
369 return 0;
373 /* Look for 'WxD' or 'W D' */
374 else if (i + 2 < argc
375 && 2 == sscanf (argv[i + 2], "%dx%d",
376 (int *) &iWidth,
377 (int *) &iHeight))
379 winErrorFVerb (2, "ddxProcessArgument - screen - Found ``WxD'' arg\n");
380 iArgsProcessed = 3;
381 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
382 g_ScreenInfo[nScreenNum].dwWidth = iWidth;
383 g_ScreenInfo[nScreenNum].dwHeight = iHeight;
384 g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
385 g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
386 /* Look for WxD+X+Y */
387 if (2 == sscanf (argv[i + 2], "%*dx%*d+%d+%d",
388 (int *) &iX,
389 (int *) &iY))
391 winErrorFVerb (2, "ddxProcessArgument - screen - Found ``X+Y'' arg\n");
392 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
393 g_ScreenInfo[nScreenNum].dwInitialX = iX;
394 g_ScreenInfo[nScreenNum].dwInitialY = iY;
396 /* look for WxD+X+Y@m where m is monitor number. take X,Y to be offsets from monitor's root position */
397 if (1 == sscanf (argv[i + 2], "%*dx%*d+%*d+%*d@%d",
398 (int *) &iMonitor))
400 struct GetMonitorInfoData data;
401 if (!QueryMonitor(iMonitor, &data))
403 ErrorF ("ddxProcessArgument - screen - "
404 "Querying monitors is not supported on NT4 and Win95\n");
405 } else if (data.bMonitorSpecifiedExists == TRUE)
407 g_ScreenInfo[nScreenNum].dwInitialX += data.monitorOffsetX;
408 g_ScreenInfo[nScreenNum].dwInitialY += data.monitorOffsetY;
410 else
412 /* monitor does not exist, error out */
413 ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
414 iMonitor);
415 UseMsg ();
416 exit (0);
417 return 0;
423 /* look for WxD@m where m is monitor number */
424 else if (1 == sscanf(argv[i + 2], "%*dx%*d@%d",
425 (int *) &iMonitor))
427 struct GetMonitorInfoData data;
428 if (!QueryMonitor(iMonitor, &data))
430 ErrorF ("ddxProcessArgument - screen - "
431 "Querying monitors is not supported on NT4 and Win95\n");
432 } else if (data.bMonitorSpecifiedExists == TRUE)
434 winErrorFVerb (2, "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
435 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
436 g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
437 g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
439 else
441 /* monitor does not exist, error out */
442 ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
443 iMonitor);
444 UseMsg ();
445 exit (0);
446 return 0;
451 else if (i + 3 < argc
452 && 1 == sscanf (argv[i + 2], "%d",
453 (int *) &iWidth)
454 && 1 == sscanf (argv[i + 3], "%d",
455 (int *) &iHeight))
457 winErrorFVerb (2, "ddxProcessArgument - screen - Found ``W D'' arg\n");
458 iArgsProcessed = 4;
459 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
460 g_ScreenInfo[nScreenNum].dwWidth = iWidth;
461 g_ScreenInfo[nScreenNum].dwHeight = iHeight;
462 g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
463 g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
464 if (i + 5 < argc
465 && 1 == sscanf (argv[i + 4], "%d",
466 (int *) &iX)
467 && 1 == sscanf (argv[i + 5], "%d",
468 (int *) &iY))
470 winErrorFVerb (2, "ddxProcessArgument - screen - Found ``X Y'' arg\n");
471 iArgsProcessed = 6;
472 g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
473 g_ScreenInfo[nScreenNum].dwInitialX = iX;
474 g_ScreenInfo[nScreenNum].dwInitialY = iY;
477 else
479 winErrorFVerb (2, "ddxProcessArgument - screen - Did not find size arg. "
480 "dwWidth: %d dwHeight: %d\n",
481 (int) g_ScreenInfo[nScreenNum].dwWidth,
482 (int) g_ScreenInfo[nScreenNum].dwHeight);
483 iArgsProcessed = 2;
484 g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
487 /* Calculate the screen width and height in millimeters */
488 if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth)
490 g_ScreenInfo[nScreenNum].dwWidth_mm
491 = (g_ScreenInfo[nScreenNum].dwWidth
492 / monitorResolution) * 25.4;
493 g_ScreenInfo[nScreenNum].dwHeight_mm
494 = (g_ScreenInfo[nScreenNum].dwHeight
495 / monitorResolution) * 25.4;
498 /* Flag that this screen was explicity specified by the user */
499 g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE;
502 * Keep track of the last screen number seen, as parameters seen
503 * before a screen number apply to all screens, whereas parameters
504 * seen after a screen number apply to that screen number only.
506 g_iLastScreen = nScreenNum;
508 /* Keep a count of the number of screens */
509 ++g_iNumScreens;
511 return iArgsProcessed;
515 * Look for the '-engine n' argument
517 if (IS_OPTION ("-engine"))
519 DWORD dwEngine = 0;
520 CARD8 c8OnBits = 0;
522 /* Display the usage message if the argument is malformed */
523 if (++i >= argc)
525 UseMsg ();
526 return 0;
529 /* Grab the argument */
530 dwEngine = atoi (argv[i]);
532 /* Count the one bits in the engine argument */
533 c8OnBits = winCountBits (dwEngine);
535 /* Argument should only have a single bit on */
536 if (c8OnBits != 1)
538 UseMsg ();
539 return 0;
542 /* Is this parameter attached to a screen or global? */
543 if (-1 == g_iLastScreen)
545 int j;
547 /* Parameter is for all screens */
548 for (j = 0; j < MAXSCREENS; j++)
550 g_ScreenInfo[j].dwEnginePreferred = dwEngine;
553 else
555 /* Parameter is for a single screen */
556 g_ScreenInfo[g_iLastScreen].dwEnginePreferred = dwEngine;
559 /* Indicate that we have processed the argument */
560 return 2;
564 * Look for the '-fullscreen' argument
566 if (IS_OPTION ("-fullscreen"))
568 /* Is this parameter attached to a screen or is it global? */
569 if (-1 == g_iLastScreen)
571 int j;
573 /* Parameter is for all screens */
574 for (j = 0; j < MAXSCREENS; j++)
576 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
577 if (!g_ScreenInfo[j].fMultiMonitorOverride)
578 g_ScreenInfo[j].fMultipleMonitors = FALSE;
579 #endif
580 g_ScreenInfo[j].fFullScreen = TRUE;
583 else
585 /* Parameter is for a single screen */
586 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
587 if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
588 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
589 #endif
590 g_ScreenInfo[g_iLastScreen].fFullScreen = TRUE;
593 /* Indicate that we have processed this argument */
594 return 1;
598 * Look for the '-lesspointer' argument
600 if (IS_OPTION ("-lesspointer"))
602 /* Is this parameter attached to a screen or is it global? */
603 if (-1 == g_iLastScreen)
605 int j;
607 /* Parameter is for all screens */
608 for (j = 0; j < MAXSCREENS; j++)
610 g_ScreenInfo[j].fLessPointer = TRUE;
613 else
615 /* Parameter is for a single screen */
616 g_ScreenInfo[g_iLastScreen].fLessPointer = TRUE;
619 /* Indicate that we have processed this argument */
620 return 1;
624 * Look for the '-nodecoration' argument
626 if (IS_OPTION ("-nodecoration"))
628 /* Is this parameter attached to a screen or is it global? */
629 if (-1 == g_iLastScreen)
631 int j;
633 /* Parameter is for all screens */
634 for (j = 0; j < MAXSCREENS; j++)
636 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
637 if (!g_ScreenInfo[j].fMultiMonitorOverride)
638 g_ScreenInfo[j].fMultipleMonitors = FALSE;
639 #endif
640 g_ScreenInfo[j].fDecoration = FALSE;
643 else
645 /* Parameter is for a single screen */
646 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
647 if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
648 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
649 #endif
650 g_ScreenInfo[g_iLastScreen].fDecoration = FALSE;
653 /* Indicate that we have processed this argument */
654 return 1;
657 #ifdef XWIN_MULTIWINDOWEXTWM
659 * Look for the '-mwextwm' argument
661 if (IS_OPTION ("-mwextwm"))
663 /* Is this parameter attached to a screen or is it global? */
664 if (-1 == g_iLastScreen)
666 int j;
668 /* Parameter is for all screens */
669 for (j = 0; j < MAXSCREENS; j++)
671 if (!g_ScreenInfo[j].fMultiMonitorOverride)
672 g_ScreenInfo[j].fMultipleMonitors = TRUE;
673 g_ScreenInfo[j].fMWExtWM = TRUE;
676 else
678 /* Parameter is for a single screen */
679 if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
680 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
681 g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE;
684 /* Indicate that we have processed this argument */
685 return 1;
688 * Look for the '-internalwm' argument
690 if (IS_OPTION ("-internalwm"))
692 /* Is this parameter attached to a screen or is it global? */
693 if (-1 == g_iLastScreen)
695 int j;
697 /* Parameter is for all screens */
698 for (j = 0; j < MAXSCREENS; j++)
700 if (!g_ScreenInfo[j].fMultiMonitorOverride)
701 g_ScreenInfo[j].fMultipleMonitors = TRUE;
702 g_ScreenInfo[j].fMWExtWM = TRUE;
703 g_ScreenInfo[j].fInternalWM = TRUE;
706 else
708 /* Parameter is for a single screen */
709 if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
710 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
711 g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE;
712 g_ScreenInfo[g_iLastScreen].fInternalWM = TRUE;
715 /* Indicate that we have processed this argument */
716 return 1;
718 #endif
721 * Look for the '-rootless' argument
723 if (IS_OPTION ("-rootless"))
725 /* Is this parameter attached to a screen or is it global? */
726 if (-1 == g_iLastScreen)
728 int j;
730 /* Parameter is for all screens */
731 for (j = 0; j < MAXSCREENS; j++)
733 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
734 if (!g_ScreenInfo[j].fMultiMonitorOverride)
735 g_ScreenInfo[j].fMultipleMonitors = FALSE;
736 #endif
737 g_ScreenInfo[j].fRootless = TRUE;
740 else
742 /* Parameter is for a single screen */
743 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
744 if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
745 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
746 #endif
747 g_ScreenInfo[g_iLastScreen].fRootless = TRUE;
750 /* Indicate that we have processed this argument */
751 return 1;
754 #ifdef XWIN_MULTIWINDOW
756 * Look for the '-multiwindow' argument
758 if (IS_OPTION ("-multiwindow"))
760 /* Is this parameter attached to a screen or is it global? */
761 if (-1 == g_iLastScreen)
763 int j;
765 /* Parameter is for all screens */
766 for (j = 0; j < MAXSCREENS; j++)
768 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
769 if (!g_ScreenInfo[j].fMultiMonitorOverride)
770 g_ScreenInfo[j].fMultipleMonitors = TRUE;
771 #endif
772 g_ScreenInfo[j].fMultiWindow = TRUE;
775 else
777 /* Parameter is for a single screen */
778 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
779 if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
780 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
781 #endif
782 g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE;
785 /* Indicate that we have processed this argument */
786 return 1;
788 #endif
791 * Look for the '-multiplemonitors' argument
793 if (IS_OPTION ("-multiplemonitors")
794 || IS_OPTION ("-multimonitors"))
796 /* Is this parameter attached to a screen or is it global? */
797 if (-1 == g_iLastScreen)
799 int j;
801 /* Parameter is for all screens */
802 for (j = 0; j < MAXSCREENS; j++)
804 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
805 g_ScreenInfo[j].fMultiMonitorOverride = TRUE;
806 #endif
807 g_ScreenInfo[j].fMultipleMonitors = TRUE;
810 else
812 /* Parameter is for a single screen */
813 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
814 g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride = TRUE;
815 #endif
816 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
819 /* Indicate that we have processed this argument */
820 return 1;
824 * Look for the '-nomultiplemonitors' argument
826 if (IS_OPTION ("-nomultiplemonitors")
827 || IS_OPTION ("-nomultimonitors"))
829 /* Is this parameter attached to a screen or is it global? */
830 if (-1 == g_iLastScreen)
832 int j;
834 /* Parameter is for all screens */
835 for (j = 0; j < MAXSCREENS; j++)
837 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
838 g_ScreenInfo[j].fMultiMonitorOverride = TRUE;
839 #endif
840 g_ScreenInfo[j].fMultipleMonitors = FALSE;
843 else
845 /* Parameter is for a single screen */
846 #if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
847 g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride = TRUE;
848 #endif
849 g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
852 /* Indicate that we have processed this argument */
853 return 1;
858 * Look for the '-scrollbars' argument
860 if (IS_OPTION ("-scrollbars"))
862 /* Is this parameter attached to a screen or is it global? */
863 if (-1 == g_iLastScreen)
865 int j;
867 /* Parameter is for all screens */
868 for (j = 0; j < MAXSCREENS; j++)
870 g_ScreenInfo[j].fScrollbars = TRUE;
873 else
875 /* Parameter is for a single screen */
876 g_ScreenInfo[g_iLastScreen].fScrollbars = TRUE;
879 /* Indicate that we have processed this argument */
880 return 1;
884 #ifdef XWIN_CLIPBOARD
886 * Look for the '-clipboard' argument
888 if (IS_OPTION ("-clipboard"))
890 g_fClipboard = TRUE;
892 /* Indicate that we have processed this argument */
893 return 1;
895 #endif
899 * Look for the '-ignoreinput' argument
901 if (IS_OPTION ("-ignoreinput"))
903 /* Is this parameter attached to a screen or is it global? */
904 if (-1 == g_iLastScreen)
906 int j;
908 /* Parameter is for all screens */
909 for (j = 0; j < MAXSCREENS; j++)
911 g_ScreenInfo[j].fIgnoreInput = TRUE;
914 else
916 /* Parameter is for a single screen */
917 g_ScreenInfo[g_iLastScreen].fIgnoreInput = TRUE;
920 /* Indicate that we have processed this argument */
921 return 1;
925 * Look for the '-emulate3buttons' argument
927 if (IS_OPTION ("-emulate3buttons"))
929 int iArgsProcessed = 1;
930 int iE3BTimeout = WIN_DEFAULT_E3B_TIME;
932 /* Grab the optional timeout value */
933 if (i + 1 < argc
934 && 1 == sscanf (argv[i + 1], "%d",
935 &iE3BTimeout))
937 /* Indicate that we have processed the next argument */
938 iArgsProcessed++;
940 else
943 * sscanf () won't modify iE3BTimeout if it doesn't find
944 * the specified format; however, I want to be explicit
945 * about setting the default timeout in such cases to
946 * prevent some programs (me) from getting confused.
948 iE3BTimeout = WIN_DEFAULT_E3B_TIME;
951 /* Is this parameter attached to a screen or is it global? */
952 if (-1 == g_iLastScreen)
954 int j;
956 /* Parameter is for all screens */
957 for (j = 0; j < MAXSCREENS; j++)
959 g_ScreenInfo[j].iE3BTimeout = iE3BTimeout;
962 else
964 /* Parameter is for a single screen */
965 g_ScreenInfo[g_iLastScreen].iE3BTimeout = iE3BTimeout;
968 /* Indicate that we have processed this argument */
969 return iArgsProcessed;
973 * Look for the '-depth n' argument
975 if (IS_OPTION ("-depth"))
977 DWORD dwBPP = 0;
979 /* Display the usage message if the argument is malformed */
980 if (++i >= argc)
982 UseMsg ();
983 return 0;
986 /* Grab the argument */
987 dwBPP = atoi (argv[i]);
989 /* Is this parameter attached to a screen or global? */
990 if (-1 == g_iLastScreen)
992 int j;
994 /* Parameter is for all screens */
995 for (j = 0; j < MAXSCREENS; j++)
997 g_ScreenInfo[j].dwBPP = dwBPP;
1000 else
1002 /* Parameter is for a single screen */
1003 g_ScreenInfo[g_iLastScreen].dwBPP = dwBPP;
1006 /* Indicate that we have processed the argument */
1007 return 2;
1011 * Look for the '-refresh n' argument
1013 if (IS_OPTION ("-refresh"))
1015 DWORD dwRefreshRate = 0;
1017 /* Display the usage message if the argument is malformed */
1018 if (++i >= argc)
1020 UseMsg ();
1021 return 0;
1024 /* Grab the argument */
1025 dwRefreshRate = atoi (argv[i]);
1027 /* Is this parameter attached to a screen or global? */
1028 if (-1 == g_iLastScreen)
1030 int j;
1032 /* Parameter is for all screens */
1033 for (j = 0; j < MAXSCREENS; j++)
1035 g_ScreenInfo[j].dwRefreshRate = dwRefreshRate;
1038 else
1040 /* Parameter is for a single screen */
1041 g_ScreenInfo[g_iLastScreen].dwRefreshRate = dwRefreshRate;
1044 /* Indicate that we have processed the argument */
1045 return 2;
1049 * Look for the '-clipupdates num_boxes' argument
1051 if (IS_OPTION ("-clipupdates"))
1053 DWORD dwNumBoxes = 0;
1055 /* Display the usage message if the argument is malformed */
1056 if (++i >= argc)
1058 UseMsg ();
1059 return 0;
1062 /* Grab the argument */
1063 dwNumBoxes = atoi (argv[i]);
1065 /* Is this parameter attached to a screen or global? */
1066 if (-1 == g_iLastScreen)
1068 int j;
1070 /* Parameter is for all screens */
1071 for (j = 0; j < MAXSCREENS; j++)
1073 g_ScreenInfo[j].dwClipUpdatesNBoxes = dwNumBoxes;
1076 else
1078 /* Parameter is for a single screen */
1079 g_ScreenInfo[g_iLastScreen].dwClipUpdatesNBoxes = dwNumBoxes;
1082 /* Indicate that we have processed the argument */
1083 return 2;
1086 #ifdef XWIN_EMULATEPSEUDO
1088 * Look for the '-emulatepseudo' argument
1090 if (IS_OPTION ("-emulatepseudo"))
1092 /* Is this parameter attached to a screen or is it global? */
1093 if (-1 == g_iLastScreen)
1095 int j;
1097 /* Parameter is for all screens */
1098 for (j = 0; j < MAXSCREENS; j++)
1100 g_ScreenInfo[j].fEmulatePseudo = TRUE;
1103 else
1105 /* Parameter is for a single screen */
1106 g_ScreenInfo[g_iLastScreen].fEmulatePseudo = TRUE;
1109 /* Indicate that we have processed this argument */
1110 return 1;
1112 #endif
1115 * Look for the '-nowinkill' argument
1117 if (IS_OPTION ("-nowinkill"))
1119 /* Is this parameter attached to a screen or is it global? */
1120 if (-1 == g_iLastScreen)
1122 int j;
1124 /* Parameter is for all screens */
1125 for (j = 0; j < MAXSCREENS; j++)
1127 g_ScreenInfo[j].fUseWinKillKey = FALSE;
1130 else
1132 /* Parameter is for a single screen */
1133 g_ScreenInfo[g_iLastScreen].fUseWinKillKey = FALSE;
1136 /* Indicate that we have processed this argument */
1137 return 1;
1141 * Look for the '-winkill' argument
1143 if (IS_OPTION ("-winkill"))
1145 /* Is this parameter attached to a screen or is it global? */
1146 if (-1 == g_iLastScreen)
1148 int j;
1150 /* Parameter is for all screens */
1151 for (j = 0; j < MAXSCREENS; j++)
1153 g_ScreenInfo[j].fUseWinKillKey = TRUE;
1156 else
1158 /* Parameter is for a single screen */
1159 g_ScreenInfo[g_iLastScreen].fUseWinKillKey = TRUE;
1162 /* Indicate that we have processed this argument */
1163 return 1;
1167 * Look for the '-nounixkill' argument
1169 if (IS_OPTION ("-nounixkill"))
1171 /* Is this parameter attached to a screen or is it global? */
1172 if (-1 == g_iLastScreen)
1174 int j;
1176 /* Parameter is for all screens */
1177 for (j = 0; j < MAXSCREENS; j++)
1179 g_ScreenInfo[j].fUseUnixKillKey = FALSE;
1182 else
1184 /* Parameter is for a single screen */
1185 g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = FALSE;
1188 /* Indicate that we have processed this argument */
1189 return 1;
1193 * Look for the '-unixkill' argument
1195 if (IS_OPTION ("-unixkill"))
1197 /* Is this parameter attached to a screen or is it global? */
1198 if (-1 == g_iLastScreen)
1200 int j;
1202 /* Parameter is for all screens */
1203 for (j = 0; j < MAXSCREENS; j++)
1205 g_ScreenInfo[j].fUseUnixKillKey = TRUE;
1208 else
1210 /* Parameter is for a single screen */
1211 g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = TRUE;
1214 /* Indicate that we have processed this argument */
1215 return 1;
1219 * Look for the '-notrayicon' argument
1221 if (IS_OPTION ("-notrayicon"))
1223 /* Is this parameter attached to a screen or is it global? */
1224 if (-1 == g_iLastScreen)
1226 int j;
1228 /* Parameter is for all screens */
1229 for (j = 0; j < MAXSCREENS; j++)
1231 g_ScreenInfo[j].fNoTrayIcon = TRUE;
1234 else
1236 /* Parameter is for a single screen */
1237 g_ScreenInfo[g_iLastScreen].fNoTrayIcon = TRUE;
1240 /* Indicate that we have processed this argument */
1241 return 1;
1245 * Look for the '-trayicon' argument
1247 if (IS_OPTION ("-trayicon"))
1249 /* Is this parameter attached to a screen or is it global? */
1250 if (-1 == g_iLastScreen)
1252 int j;
1254 /* Parameter is for all screens */
1255 for (j = 0; j < MAXSCREENS; j++)
1257 g_ScreenInfo[j].fNoTrayIcon = FALSE;
1260 else
1262 /* Parameter is for a single screen */
1263 g_ScreenInfo[g_iLastScreen].fNoTrayIcon = FALSE;
1266 /* Indicate that we have processed this argument */
1267 return 1;
1271 * Look for the '-fp' argument
1273 if (IS_OPTION ("-fp"))
1275 CHECK_ARGS (1);
1276 g_cmdline.fontPath = argv[++i];
1277 return 0; /* Let DIX parse this again */
1281 * Look for the '-co' argument
1283 if (IS_OPTION ("-co"))
1285 CHECK_ARGS (1);
1286 g_cmdline.rgbPath = argv[++i];
1287 return 0; /* Let DIX parse this again */
1291 * Look for the '-query' argument
1293 if (IS_OPTION ("-query"))
1295 CHECK_ARGS (1);
1296 g_fXdmcpEnabled = TRUE;
1297 g_pszQueryHost = argv[++i];
1298 return 0; /* Let DIX parse this again */
1302 * Look for the '-indirect' or '-broadcast' arguments
1304 if (IS_OPTION ("-indirect")
1305 || IS_OPTION ("-broadcast"))
1307 g_fXdmcpEnabled = TRUE;
1308 return 0; /* Let DIX parse this again */
1312 * Look for the '-config' argument
1314 if (IS_OPTION ("-config")
1315 || IS_OPTION ("-xf86config"))
1317 CHECK_ARGS (1);
1318 #ifdef XWIN_XF86CONFIG
1319 g_cmdline.configFile = argv[++i];
1320 #else
1321 winMessageBoxF ("The %s option is not supported in this "
1322 "release.\n"
1323 "Ignoring this option and continuing.\n",
1324 MB_ICONINFORMATION,
1325 argv[i]);
1326 #endif
1327 return 2;
1331 * Look for the '-keyboard' argument
1333 if (IS_OPTION ("-keyboard"))
1335 #ifdef XWIN_XF86CONFIG
1336 CHECK_ARGS (1);
1337 g_cmdline.keyboard = argv[++i];
1338 #else
1339 winMessageBoxF ("The -keyboard option is not supported in this "
1340 "release.\n"
1341 "Ignoring this option and continuing.\n",
1342 MB_ICONINFORMATION);
1343 #endif
1344 return 2;
1348 * Look for the '-logfile' argument
1350 if (IS_OPTION ("-logfile"))
1352 CHECK_ARGS (1);
1353 g_pszLogFile = argv[++i];
1354 #ifdef RELOCATE_PROJECTROOT
1355 g_fLogFileChanged = TRUE;
1356 #endif
1357 return 2;
1361 * Look for the '-logverbose' argument
1363 if (IS_OPTION ("-logverbose"))
1365 CHECK_ARGS (1);
1366 g_iLogVerbose = atoi(argv[++i]);
1367 return 2;
1370 #ifdef XWIN_CLIPBOARD
1372 * Look for the '-nounicodeclipboard' argument
1374 if (IS_OPTION ("-nounicodeclipboard"))
1376 g_fUnicodeClipboard = FALSE;
1377 /* Indicate that we have processed the argument */
1378 return 1;
1380 #endif
1382 #ifdef XKB
1384 * Look for the '-kb' argument
1386 if (IS_OPTION ("-kb"))
1388 g_cmdline.noXkbExtension = TRUE;
1389 return 0; /* Let DIX parse this again */
1392 if (IS_OPTION ("-xkbrules"))
1394 CHECK_ARGS (1);
1395 g_cmdline.xkbRules = argv[++i];
1396 return 2;
1398 if (IS_OPTION ("-xkbmodel"))
1400 CHECK_ARGS (1);
1401 g_cmdline.xkbModel = argv[++i];
1402 return 2;
1404 if (IS_OPTION ("-xkblayout"))
1406 CHECK_ARGS (1);
1407 g_cmdline.xkbLayout = argv[++i];
1408 return 2;
1410 if (IS_OPTION ("-xkbvariant"))
1412 CHECK_ARGS (1);
1413 g_cmdline.xkbVariant = argv[++i];
1414 return 2;
1416 if (IS_OPTION ("-xkboptions"))
1418 CHECK_ARGS (1);
1419 g_cmdline.xkbOptions = argv[++i];
1420 return 2;
1422 #endif
1424 if (IS_OPTION ("-keyhook"))
1426 g_fKeyboardHookLL = TRUE;
1427 return 1;
1430 if (IS_OPTION ("-nokeyhook"))
1432 g_fKeyboardHookLL = FALSE;
1433 return 1;
1436 if (IS_OPTION ("-swcursor"))
1438 g_fSoftwareCursor = TRUE;
1439 return 1;
1442 if (IS_OPTION ("-silent-dup-error"))
1444 g_fSilentDupError = TRUE;
1445 return 1;
1447 return 0;
1452 * winLogCommandLine - Write entire command line to the log file
1455 void
1456 winLogCommandLine (int argc, char *argv[])
1458 int i;
1459 int iSize = 0;
1460 int iCurrLen = 0;
1462 #define CHARS_PER_LINE 60
1464 /* Bail if command line has already been logged */
1465 if (g_pszCommandLine)
1466 return;
1468 /* Count how much memory is needed for concatenated command line */
1469 for (i = 0, iCurrLen = 0; i < argc; ++i)
1470 if (argv[i])
1472 /* Add a character for lines that overflow */
1473 if ((strlen (argv[i]) < CHARS_PER_LINE
1474 && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE)
1475 || strlen (argv[i]) > CHARS_PER_LINE)
1477 iCurrLen = 0;
1478 ++iSize;
1481 /* Add space for item and trailing space */
1482 iSize += strlen (argv[i]) + 1;
1484 /* Update current line length */
1485 iCurrLen += strlen (argv[i]);
1488 /* Allocate memory for concatenated command line */
1489 g_pszCommandLine = malloc (iSize + 1);
1490 if (!g_pszCommandLine)
1491 FatalError ("winLogCommandLine - Could not allocate memory for "
1492 "command line string. Exiting.\n");
1494 /* Set first character to concatenated command line to null */
1495 g_pszCommandLine[0] = '\0';
1497 /* Loop through all args */
1498 for (i = 0, iCurrLen = 0; i < argc; ++i)
1500 /* Add a character for lines that overflow */
1501 if ((strlen (argv[i]) < CHARS_PER_LINE
1502 && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE)
1503 || strlen (argv[i]) > CHARS_PER_LINE)
1505 iCurrLen = 0;
1507 /* Add line break if it fits */
1508 strncat (g_pszCommandLine, "\n", iSize - strlen (g_pszCommandLine));
1511 strncat (g_pszCommandLine, argv[i], iSize - strlen (g_pszCommandLine));
1512 strncat (g_pszCommandLine, " ", iSize - strlen (g_pszCommandLine));
1514 /* Save new line length */
1515 iCurrLen += strlen (argv[i]);
1518 ErrorF ("XWin was started with the following command line:\n\n"
1519 "%s\n\n", g_pszCommandLine);
1524 * winLogVersionInfo - Log Cygwin/X version information
1527 void
1528 winLogVersionInfo (void)
1530 static Bool s_fBeenHere = FALSE;
1532 if (s_fBeenHere)
1533 return;
1534 s_fBeenHere = TRUE;
1536 ErrorF ("Welcome to the XWin X Server\n");
1537 ErrorF ("Vendor: %s\n", VENDOR_STRING);
1538 ErrorF ("Release: %s\n\n", VERSION_STRING);
1539 ErrorF ("Contact: %s\n\n", VENDOR_CONTACT);
1543 * getMonitorInfo - callback function used to return information from the enumeration of monitors attached
1546 wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data)
1548 struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data;
1549 // only get data for monitor number specified in <data>
1550 data->monitorNum++;
1551 if (data->monitorNum == data->requestedMonitor)
1553 data->bMonitorSpecifiedExists = TRUE;
1554 data->monitorOffsetX = rect->left;
1555 data->monitorOffsetY = rect->top;
1556 data->monitorHeight = rect->bottom - rect->top;
1557 data->monitorWidth = rect->right - rect->left;
1558 return FALSE;
1560 return TRUE;