winprocarg.c revision 6747b715
105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1993, 1998  The Open Group
46747b715SmrgCopyright (C) Colin Harrison 2005-2008
505b261ecSmrg
605b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
705b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
805b261ecSmrgthe above copyright notice appear in all copies and that both that
905b261ecSmrgcopyright notice and this permission notice appear in supporting
1005b261ecSmrgdocumentation.
1105b261ecSmrg
1205b261ecSmrgThe above copyright notice and this permission notice shall be included
1305b261ecSmrgin all copies or substantial portions of the Software.
1405b261ecSmrg
1505b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1605b261ecSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1705b261ecSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1805b261ecSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
1905b261ecSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2005b261ecSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2105b261ecSmrgOTHER DEALINGS IN THE SOFTWARE.
2205b261ecSmrg
2305b261ecSmrgExcept as contained in this notice, the name of The Open Group shall
2405b261ecSmrgnot be used in advertising or otherwise to promote the sale, use or
2505b261ecSmrgother dealings in this Software without prior written authorization
2605b261ecSmrgfrom The Open Group.
2705b261ecSmrg
2805b261ecSmrg*/
2905b261ecSmrg
3005b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H
3105b261ecSmrg#include <xwin-config.h>
3205b261ecSmrg#endif
3305b261ecSmrg#ifdef XVENDORNAME
3405b261ecSmrg#define VENDOR_STRING XVENDORNAME
3505b261ecSmrg#define VENDOR_CONTACT BUILDERADDR
3605b261ecSmrg#endif
376747b715Smrg#include <../xfree86/common/xorgVersion.h>
3805b261ecSmrg#include "win.h"
3905b261ecSmrg#include "winconfig.h"
4005b261ecSmrg#include "winprefs.h"
4105b261ecSmrg#include "winmsg.h"
4205b261ecSmrg
4305b261ecSmrg/*
4405b261ecSmrg * References to external symbols
4505b261ecSmrg */
4605b261ecSmrg
4705b261ecSmrgextern int			g_iNumScreens;
486747b715Smrgextern winScreenInfo *		g_ScreenInfo;
4905b261ecSmrg#ifdef XWIN_CLIPBOARD
5005b261ecSmrgextern Bool			g_fUnicodeClipboard;
5105b261ecSmrgextern Bool			g_fClipboard;
5205b261ecSmrg#endif
5305b261ecSmrgextern int			g_iLogVerbose;
546747b715Smrgextern const char *		g_pszLogFile;
5505b261ecSmrg#ifdef RELOCATE_PROJECTROOT
5605b261ecSmrgextern Bool			g_fLogFileChanged;
5705b261ecSmrg#endif
5805b261ecSmrgextern Bool			g_fXdmcpEnabled;
596747b715Smrgextern Bool			g_fAuthEnabled;
6005b261ecSmrgextern char *			g_pszCommandLine;
6105b261ecSmrgextern Bool			g_fKeyboardHookLL;
6205b261ecSmrgextern Bool			g_fNoHelpMessageBox;
6305b261ecSmrgextern Bool			g_fSoftwareCursor;
6405b261ecSmrgextern Bool			g_fSilentDupError;
656747b715Smrgextern Bool                     g_fNativeGl;
6605b261ecSmrg
6705b261ecSmrg/* globals required by callback function for monitor information */
6805b261ecSmrgstruct GetMonitorInfoData {
6905b261ecSmrg    int  requestedMonitor;
7005b261ecSmrg    int  monitorNum;
7105b261ecSmrg    Bool bUserSpecifiedMonitor;
7205b261ecSmrg    Bool bMonitorSpecifiedExists;
7305b261ecSmrg    int  monitorOffsetX;
7405b261ecSmrg    int  monitorOffsetY;
7505b261ecSmrg    int  monitorHeight;
7605b261ecSmrg    int  monitorWidth;
7705b261ecSmrg};
7805b261ecSmrg
7905b261ecSmrgtypedef wBOOL (*ENUMDISPLAYMONITORSPROC)(HDC,LPCRECT,MONITORENUMPROC,LPARAM);
8005b261ecSmrgENUMDISPLAYMONITORSPROC _EnumDisplayMonitors;
8105b261ecSmrg
8205b261ecSmrgwBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data);
8305b261ecSmrg
8405b261ecSmrgstatic Bool QueryMonitor(int index, struct GetMonitorInfoData *data)
8505b261ecSmrg{
8605b261ecSmrg    /* Load EnumDisplayMonitors from DLL */
8705b261ecSmrg    HMODULE user32;
8805b261ecSmrg    FARPROC func;
8905b261ecSmrg    user32 = LoadLibrary("user32.dll");
9005b261ecSmrg    if (user32 == NULL)
9105b261ecSmrg    {
9205b261ecSmrg        winW32Error(2, "Could not open user32.dll");
9305b261ecSmrg        return FALSE;
9405b261ecSmrg    }
9505b261ecSmrg    func = GetProcAddress(user32, "EnumDisplayMonitors");
9605b261ecSmrg    if (func == NULL)
9705b261ecSmrg    {
9805b261ecSmrg        winW32Error(2, "Could not resolve EnumDisplayMonitors: ");
9905b261ecSmrg        return FALSE;
10005b261ecSmrg    }
10105b261ecSmrg    _EnumDisplayMonitors = (ENUMDISPLAYMONITORSPROC)func;
10205b261ecSmrg
10305b261ecSmrg    /* prepare data */
10405b261ecSmrg    if (data == NULL)
10505b261ecSmrg        return FALSE;
10605b261ecSmrg    memset(data, 0, sizeof(*data));
10705b261ecSmrg    data->requestedMonitor = index;
10805b261ecSmrg
10905b261ecSmrg    /* query information */
11005b261ecSmrg    _EnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data);
11105b261ecSmrg
11205b261ecSmrg    /* cleanup */
11305b261ecSmrg    FreeLibrary(user32);
11405b261ecSmrg    return TRUE;
11505b261ecSmrg}
11605b261ecSmrg
11705b261ecSmrg/*
11805b261ecSmrg * Function prototypes
11905b261ecSmrg */
12005b261ecSmrg
12105b261ecSmrgvoid
12205b261ecSmrgwinLogCommandLine (int argc, char *argv[]);
12305b261ecSmrg
12405b261ecSmrgvoid
12505b261ecSmrgwinLogVersionInfo (void);
12605b261ecSmrg
12705b261ecSmrg#ifdef DDXOSVERRORF
12805b261ecSmrgvoid OsVendorVErrorF (const char *pszFormat, va_list va_args);
12905b261ecSmrg#endif
13005b261ecSmrg
13105b261ecSmrg/*
13205b261ecSmrg * Process arguments on the command line
13305b261ecSmrg */
13405b261ecSmrg
1356747b715Smrgstatic int iLastScreen = -1;
1366747b715Smrgstatic winScreenInfo defaultScreenInfo;
1376747b715Smrg
1386747b715Smrgstatic void
1396747b715SmrgwinInitializeScreenDefaults(void)
14005b261ecSmrg{
1416747b715Smrg  DWORD dwWidth, dwHeight;
1426747b715Smrg  static Bool fInitializedScreenDefaults = FALSE;
14305b261ecSmrg
1446747b715Smrg  /* Bail out early if default screen has already been initialized */
1456747b715Smrg  if (fInitializedScreenDefaults)
14605b261ecSmrg    return;
14705b261ecSmrg
14805b261ecSmrg  /* Zero the memory used for storing the screen info */
1496747b715Smrg  memset(&defaultScreenInfo, 0, sizeof(winScreenInfo));
15005b261ecSmrg
15105b261ecSmrg  /* Get default width and height */
15205b261ecSmrg  /*
15305b261ecSmrg   * NOTE: These defaults will cause the window to cover only
15405b261ecSmrg   * the primary monitor in the case that we have multiple monitors.
15505b261ecSmrg   */
15605b261ecSmrg  dwWidth = GetSystemMetrics (SM_CXSCREEN);
15705b261ecSmrg  dwHeight = GetSystemMetrics (SM_CYSCREEN);
15805b261ecSmrg
1596747b715Smrg  winErrorFVerb (2, "winInitializeScreenDefaults - w %d h %d\n",
16005b261ecSmrg	  (int) dwWidth, (int) dwHeight);
16105b261ecSmrg
16205b261ecSmrg  /* Set a default DPI, if no parameter was passed */
16305b261ecSmrg  if (monitorResolution == 0)
16405b261ecSmrg    monitorResolution = WIN_DEFAULT_DPI;
16505b261ecSmrg
1666747b715Smrg  defaultScreenInfo.dwWidth  = dwWidth;
1676747b715Smrg  defaultScreenInfo.dwHeight = dwHeight;
1686747b715Smrg  defaultScreenInfo.dwUserWidth  = dwWidth;
1696747b715Smrg  defaultScreenInfo.dwUserHeight = dwHeight;
1706747b715Smrg  defaultScreenInfo.fUserGaveHeightAndWidth = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH;
1716747b715Smrg  defaultScreenInfo.fUserGavePosition = FALSE;
1726747b715Smrg  defaultScreenInfo.dwBPP = WIN_DEFAULT_BPP;
1736747b715Smrg  defaultScreenInfo.dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES;
17405b261ecSmrg#ifdef XWIN_EMULATEPSEUDO
1756747b715Smrg  defaultScreenInfo.fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO;
17605b261ecSmrg#endif
1776747b715Smrg  defaultScreenInfo.dwRefreshRate = WIN_DEFAULT_REFRESH;
1786747b715Smrg  defaultScreenInfo.pfb = NULL;
1796747b715Smrg  defaultScreenInfo.fFullScreen = FALSE;
1806747b715Smrg  defaultScreenInfo.fDecoration = TRUE;
18105b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
1826747b715Smrg  defaultScreenInfo.fMWExtWM = FALSE;
1836747b715Smrg  defaultScreenInfo.fInternalWM = FALSE;
18405b261ecSmrg#endif
1856747b715Smrg  defaultScreenInfo.fRootless = FALSE;
18605b261ecSmrg#ifdef XWIN_MULTIWINDOW
1876747b715Smrg  defaultScreenInfo.fMultiWindow = FALSE;
18805b261ecSmrg#endif
18905b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
1906747b715Smrg  defaultScreenInfo.fMultiMonitorOverride = FALSE;
19105b261ecSmrg#endif
1926747b715Smrg  defaultScreenInfo.fMultipleMonitors = FALSE;
1936747b715Smrg  defaultScreenInfo.fLessPointer = FALSE;
1946747b715Smrg  defaultScreenInfo.fScrollbars = FALSE;
1956747b715Smrg  defaultScreenInfo.fNoTrayIcon = FALSE;
1966747b715Smrg  defaultScreenInfo.iE3BTimeout = WIN_E3B_OFF;
1976747b715Smrg  defaultScreenInfo.dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI) * 25.4;
1986747b715Smrg  defaultScreenInfo.dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI) * 25.4;
1996747b715Smrg  defaultScreenInfo.fUseWinKillKey = WIN_DEFAULT_WIN_KILL;
2006747b715Smrg  defaultScreenInfo.fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
2016747b715Smrg  defaultScreenInfo.fIgnoreInput = FALSE;
2026747b715Smrg  defaultScreenInfo.fExplicitScreen = FALSE;
2036747b715Smrg
2046747b715Smrg  /* Note that the default screen has been initialized */
2056747b715Smrg  fInitializedScreenDefaults = TRUE;
2066747b715Smrg}
20705b261ecSmrg
2086747b715Smrgstatic void
2096747b715SmrgwinInitializeScreen(int i)
2106747b715Smrg{
2116747b715Smrg  winErrorFVerb (2, "winInitializeScreen - %d\n",i);
21205b261ecSmrg
2136747b715Smrg  /* Initialize default screen values, if needed */
2146747b715Smrg  winInitializeScreenDefaults();
2156747b715Smrg
2166747b715Smrg  /* Copy the default screen info */
2176747b715Smrg  g_ScreenInfo[i] = defaultScreenInfo;
2186747b715Smrg
2196747b715Smrg  /* Set the screen number */
2206747b715Smrg  g_ScreenInfo[i].dwScreen = i;
2216747b715Smrg}
2226747b715Smrg
2236747b715Smrgvoid
2246747b715SmrgwinInitializeScreens(int maxscreens)
2256747b715Smrg{
2266747b715Smrg  int i;
2276747b715Smrg  winErrorFVerb (2, "winInitializeScreens - %i\n", maxscreens);
2286747b715Smrg
2296747b715Smrg  if (maxscreens > g_iNumScreens)
2306747b715Smrg    {
2316747b715Smrg      /* Reallocate the memory for DDX-specific screen info */
2326747b715Smrg      g_ScreenInfo = realloc(g_ScreenInfo, maxscreens * sizeof (winScreenInfo));
2336747b715Smrg
2346747b715Smrg      /* Set default values for any new screens */
2356747b715Smrg      for (i = g_iNumScreens; i < maxscreens ; i++)
2366747b715Smrg        winInitializeScreen(i);
2376747b715Smrg
2386747b715Smrg      /* Keep a count of the number of screens */
2396747b715Smrg      g_iNumScreens = maxscreens;
2406747b715Smrg    }
24105b261ecSmrg}
24205b261ecSmrg
24305b261ecSmrg/* See Porting Layer Definition - p. 57 */
24405b261ecSmrg/*
24505b261ecSmrg * INPUT
24605b261ecSmrg * argv: pointer to an array of null-terminated strings, one for
24705b261ecSmrg *   each token in the X Server command line; the first token
24805b261ecSmrg *   is 'XWin.exe', or similar.
24905b261ecSmrg * argc: a count of the number of tokens stored in argv.
25005b261ecSmrg * i: a zero-based index into argv indicating the current token being
25105b261ecSmrg *   processed.
25205b261ecSmrg *
25305b261ecSmrg * OUTPUT
25405b261ecSmrg * return: return the number of tokens processed correctly.
25505b261ecSmrg *
25605b261ecSmrg * NOTE
25705b261ecSmrg * When looking for n tokens, check that i + n is less than argc.  Or,
25805b261ecSmrg *   you may check if i is greater than or equal to argc, in which case
25905b261ecSmrg *   you should display the UseMsg () and return 0.
26005b261ecSmrg */
26105b261ecSmrg
26205b261ecSmrg/* Check if enough arguments are given for the option */
26305b261ecSmrg#define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; }
26405b261ecSmrg
26505b261ecSmrg/* Compare the current option with the string. */
26605b261ecSmrg#define IS_OPTION(name) (strcmp (argv[i], name) == 0)
26705b261ecSmrg
26805b261ecSmrgint
26905b261ecSmrgddxProcessArgument (int argc, char *argv[], int i)
27005b261ecSmrg{
27105b261ecSmrg  static Bool		s_fBeenHere = FALSE;
2726747b715Smrg  winScreenInfo	*screenInfoPtr = NULL;
27305b261ecSmrg
27405b261ecSmrg  /* Initialize once */
27505b261ecSmrg  if (!s_fBeenHere)
27605b261ecSmrg    {
27705b261ecSmrg#ifdef DDXOSVERRORF
27805b261ecSmrg      /*
27905b261ecSmrg       * This initialises our hook into VErrorF () for catching log messages
28005b261ecSmrg       * that are generated before OsInit () is called.
28105b261ecSmrg       */
28205b261ecSmrg      OsVendorVErrorFProc = OsVendorVErrorF;
28305b261ecSmrg#endif
28405b261ecSmrg
28505b261ecSmrg      s_fBeenHere = TRUE;
28605b261ecSmrg
28705b261ecSmrg      /* Initialize only if option is not -help */
28805b261ecSmrg      if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") &&
28905b261ecSmrg          !IS_OPTION("-version") && !IS_OPTION("--version"))
29005b261ecSmrg	{
29105b261ecSmrg
29205b261ecSmrg          /* Log the version information */
29305b261ecSmrg          winLogVersionInfo ();
29405b261ecSmrg
29505b261ecSmrg          /* Log the command line */
29605b261ecSmrg          winLogCommandLine (argc, argv);
29705b261ecSmrg
29805b261ecSmrg	  /*
29905b261ecSmrg	   * Initialize default screen settings.  We have to do this before
30005b261ecSmrg	   * OsVendorInit () gets called, otherwise we will overwrite
30105b261ecSmrg	   * settings changed by parameters such as -fullscreen, etc.
30205b261ecSmrg	   */
30305b261ecSmrg	  winErrorFVerb (2, "ddxProcessArgument - Initializing default "
30405b261ecSmrg			 "screens\n");
3056747b715Smrg	  winInitializeScreenDefaults();
30605b261ecSmrg	}
30705b261ecSmrg    }
30805b261ecSmrg
30905b261ecSmrg#if CYGDEBUG
31005b261ecSmrg  winDebug ("ddxProcessArgument - arg: %s\n", argv[i]);
31105b261ecSmrg#endif
31205b261ecSmrg
31305b261ecSmrg  /*
31405b261ecSmrg   * Look for the '-help' and similar options
31505b261ecSmrg   */
31605b261ecSmrg  if (IS_OPTION ("-help") || IS_OPTION("-h") || IS_OPTION("--help"))
31705b261ecSmrg    {
31805b261ecSmrg      /* Reset logfile. We don't need that helpmessage in the logfile */
31905b261ecSmrg      g_pszLogFile = NULL;
32005b261ecSmrg      g_fNoHelpMessageBox = TRUE;
32105b261ecSmrg      UseMsg();
32205b261ecSmrg      exit (0);
32305b261ecSmrg      return 1;
32405b261ecSmrg    }
32505b261ecSmrg
32605b261ecSmrg  if (IS_OPTION ("-version") || IS_OPTION("--version"))
32705b261ecSmrg    {
32805b261ecSmrg      /* Reset logfile. We don't need that versioninfo in the logfile */
32905b261ecSmrg      g_pszLogFile = NULL;
33005b261ecSmrg      winLogVersionInfo ();
33105b261ecSmrg      exit (0);
33205b261ecSmrg      return 1;
33305b261ecSmrg    }
33405b261ecSmrg
33505b261ecSmrg  /*
33605b261ecSmrg   * Look for the '-screen scr_num [width height]' argument
33705b261ecSmrg   */
33805b261ecSmrg  if (IS_OPTION ("-screen"))
33905b261ecSmrg    {
34005b261ecSmrg      int		iArgsProcessed = 1;
34105b261ecSmrg      int		nScreenNum;
34205b261ecSmrg      int		iWidth, iHeight, iX, iY;
34305b261ecSmrg      int		iMonitor;
34405b261ecSmrg
34505b261ecSmrg#if CYGDEBUG
34605b261ecSmrg      winDebug ("ddxProcessArgument - screen - argc: %d i: %d\n",
34705b261ecSmrg	      argc, i);
34805b261ecSmrg#endif
34905b261ecSmrg
35005b261ecSmrg      /* Display the usage message if the argument is malformed */
35105b261ecSmrg      if (i + 1 >= argc)
35205b261ecSmrg	{
35305b261ecSmrg	  return 0;
35405b261ecSmrg	}
35505b261ecSmrg
35605b261ecSmrg      /* Grab screen number */
35705b261ecSmrg      nScreenNum = atoi (argv[i + 1]);
35805b261ecSmrg
35905b261ecSmrg      /* Validate the specified screen number */
3606747b715Smrg      if (nScreenNum < 0)
36105b261ecSmrg        {
36205b261ecSmrg          ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n",
36305b261ecSmrg		  nScreenNum);
36405b261ecSmrg          UseMsg ();
36505b261ecSmrg	  return 0;
36605b261ecSmrg        }
36705b261ecSmrg
3686747b715Smrg      /*
3696747b715Smrg        Initialize default values for any new screens
3706747b715Smrg
3716747b715Smrg        Note that default values can't change after a -screen option is
3726747b715Smrg        seen, so it's safe to do this for each screen as it is introduced
3736747b715Smrg      */
3746747b715Smrg      winInitializeScreens(nScreenNum+1);
3756747b715Smrg
37605b261ecSmrg	  /* look for @m where m is monitor number */
37705b261ecSmrg	  if (i + 2 < argc
37805b261ecSmrg		  && 1 == sscanf(argv[i + 2], "@%d", (int *) &iMonitor))
37905b261ecSmrg      {
38005b261ecSmrg        struct GetMonitorInfoData data;
38105b261ecSmrg        if (!QueryMonitor(iMonitor, &data))
38205b261ecSmrg        {
38305b261ecSmrg            ErrorF ("ddxProcessArgument - screen - "
38405b261ecSmrg                    "Querying monitors is not supported on NT4 and Win95\n");
38505b261ecSmrg        } else if (data.bMonitorSpecifiedExists == TRUE)
38605b261ecSmrg        {
38705b261ecSmrg		  winErrorFVerb(2, "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
38805b261ecSmrg		  iArgsProcessed = 3;
38905b261ecSmrg		  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
39005b261ecSmrg		  g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
39105b261ecSmrg		  g_ScreenInfo[nScreenNum].dwWidth = data.monitorWidth;
39205b261ecSmrg		  g_ScreenInfo[nScreenNum].dwHeight = data.monitorHeight;
39305b261ecSmrg		  g_ScreenInfo[nScreenNum].dwUserWidth = data.monitorWidth;
39405b261ecSmrg		  g_ScreenInfo[nScreenNum].dwUserHeight = data.monitorHeight;
39505b261ecSmrg		  g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
39605b261ecSmrg		  g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
39705b261ecSmrg		}
39805b261ecSmrg		else
39905b261ecSmrg        {
40005b261ecSmrg		  /* monitor does not exist, error out */
40105b261ecSmrg		  ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
40205b261ecSmrg				  iMonitor);
40305b261ecSmrg		  UseMsg ();
40405b261ecSmrg		  exit (0);
40505b261ecSmrg		  return 0;
40605b261ecSmrg		}
40705b261ecSmrg	  }
40805b261ecSmrg
40905b261ecSmrg      /* Look for 'WxD' or 'W D' */
41005b261ecSmrg      else if (i + 2 < argc
41105b261ecSmrg	  && 2 == sscanf (argv[i + 2], "%dx%d",
41205b261ecSmrg			  (int *) &iWidth,
41305b261ecSmrg			  (int *) &iHeight))
41405b261ecSmrg	{
41505b261ecSmrg	  winErrorFVerb (2, "ddxProcessArgument - screen - Found ``WxD'' arg\n");
41605b261ecSmrg	  iArgsProcessed = 3;
41705b261ecSmrg	  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
41805b261ecSmrg	  g_ScreenInfo[nScreenNum].dwWidth = iWidth;
41905b261ecSmrg	  g_ScreenInfo[nScreenNum].dwHeight = iHeight;
42005b261ecSmrg	  g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
42105b261ecSmrg	  g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
42205b261ecSmrg	  /* Look for WxD+X+Y */
42305b261ecSmrg	  if (2 == sscanf (argv[i + 2], "%*dx%*d+%d+%d",
42405b261ecSmrg			   (int *) &iX,
42505b261ecSmrg			   (int *) &iY))
42605b261ecSmrg	  {
42705b261ecSmrg	    winErrorFVerb (2, "ddxProcessArgument - screen - Found ``X+Y'' arg\n");
42805b261ecSmrg	    g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
42905b261ecSmrg	    g_ScreenInfo[nScreenNum].dwInitialX = iX;
43005b261ecSmrg	    g_ScreenInfo[nScreenNum].dwInitialY = iY;
43105b261ecSmrg
43205b261ecSmrg		/* look for WxD+X+Y@m where m is monitor number. take X,Y to be offsets from monitor's root position */
43305b261ecSmrg		if (1 == sscanf (argv[i + 2], "%*dx%*d+%*d+%*d@%d",
43405b261ecSmrg						 (int *) &iMonitor))
43505b261ecSmrg        {
43605b261ecSmrg          struct GetMonitorInfoData data;
43705b261ecSmrg          if (!QueryMonitor(iMonitor, &data))
43805b261ecSmrg          {
43905b261ecSmrg              ErrorF ("ddxProcessArgument - screen - "
44005b261ecSmrg                      "Querying monitors is not supported on NT4 and Win95\n");
44105b261ecSmrg          } else if (data.bMonitorSpecifiedExists == TRUE)
44205b261ecSmrg          {
44305b261ecSmrg			g_ScreenInfo[nScreenNum].dwInitialX += data.monitorOffsetX;
44405b261ecSmrg			g_ScreenInfo[nScreenNum].dwInitialY += data.monitorOffsetY;
44505b261ecSmrg		  }
44605b261ecSmrg		  else
44705b261ecSmrg          {
44805b261ecSmrg			/* monitor does not exist, error out */
44905b261ecSmrg			ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
45005b261ecSmrg					iMonitor);
45105b261ecSmrg			UseMsg ();
45205b261ecSmrg			exit (0);
45305b261ecSmrg			return 0;
45405b261ecSmrg		  }
45505b261ecSmrg
45605b261ecSmrg		}
45705b261ecSmrg	  }
45805b261ecSmrg
45905b261ecSmrg	  /* look for WxD@m where m is monitor number */
46005b261ecSmrg	  else if (1 == sscanf(argv[i + 2], "%*dx%*d@%d",
46105b261ecSmrg						   (int *) &iMonitor))
46205b261ecSmrg      {
46305b261ecSmrg        struct GetMonitorInfoData data;
46405b261ecSmrg        if (!QueryMonitor(iMonitor, &data))
46505b261ecSmrg        {
46605b261ecSmrg		  ErrorF ("ddxProcessArgument - screen - "
46705b261ecSmrg                  "Querying monitors is not supported on NT4 and Win95\n");
46805b261ecSmrg        } else if (data.bMonitorSpecifiedExists == TRUE)
46905b261ecSmrg        {
47005b261ecSmrg		  winErrorFVerb (2, "ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
47105b261ecSmrg		  g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
47205b261ecSmrg		  g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
47305b261ecSmrg		  g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
47405b261ecSmrg		}
47505b261ecSmrg		else
47605b261ecSmrg        {
47705b261ecSmrg		  /* monitor does not exist, error out */
47805b261ecSmrg		  ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
47905b261ecSmrg				  iMonitor);
48005b261ecSmrg		  UseMsg ();
48105b261ecSmrg		  exit (0);
48205b261ecSmrg		  return 0;
48305b261ecSmrg		}
48405b261ecSmrg
48505b261ecSmrg	  }
48605b261ecSmrg	}
48705b261ecSmrg      else if (i + 3 < argc
48805b261ecSmrg	       && 1 == sscanf (argv[i + 2], "%d",
48905b261ecSmrg			       (int *) &iWidth)
49005b261ecSmrg	       && 1 == sscanf (argv[i + 3], "%d",
49105b261ecSmrg			       (int *) &iHeight))
49205b261ecSmrg	{
49305b261ecSmrg	  winErrorFVerb (2, "ddxProcessArgument - screen - Found ``W D'' arg\n");
49405b261ecSmrg	  iArgsProcessed = 4;
49505b261ecSmrg	  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
49605b261ecSmrg	  g_ScreenInfo[nScreenNum].dwWidth = iWidth;
49705b261ecSmrg	  g_ScreenInfo[nScreenNum].dwHeight = iHeight;
49805b261ecSmrg	  g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
49905b261ecSmrg	  g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
50005b261ecSmrg	  if (i + 5 < argc
50105b261ecSmrg	      && 1 == sscanf (argv[i + 4], "%d",
50205b261ecSmrg			      (int *) &iX)
50305b261ecSmrg	      && 1 == sscanf (argv[i + 5], "%d",
50405b261ecSmrg			      (int *) &iY))
50505b261ecSmrg	  {
50605b261ecSmrg	    winErrorFVerb (2, "ddxProcessArgument - screen - Found ``X Y'' arg\n");
50705b261ecSmrg	    iArgsProcessed = 6;
50805b261ecSmrg	    g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
50905b261ecSmrg	    g_ScreenInfo[nScreenNum].dwInitialX = iX;
51005b261ecSmrg	    g_ScreenInfo[nScreenNum].dwInitialY = iY;
51105b261ecSmrg	  }
51205b261ecSmrg	}
51305b261ecSmrg      else
51405b261ecSmrg	{
51505b261ecSmrg	  winErrorFVerb (2, "ddxProcessArgument - screen - Did not find size arg. "
51605b261ecSmrg		  "dwWidth: %d dwHeight: %d\n",
51705b261ecSmrg		  (int) g_ScreenInfo[nScreenNum].dwWidth,
51805b261ecSmrg		  (int) g_ScreenInfo[nScreenNum].dwHeight);
51905b261ecSmrg	  iArgsProcessed = 2;
52005b261ecSmrg	  g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
52105b261ecSmrg	}
52205b261ecSmrg
52305b261ecSmrg      /* Calculate the screen width and height in millimeters */
52405b261ecSmrg      if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth)
52505b261ecSmrg	{
52605b261ecSmrg	  g_ScreenInfo[nScreenNum].dwWidth_mm
52705b261ecSmrg	    = (g_ScreenInfo[nScreenNum].dwWidth
52805b261ecSmrg	       / monitorResolution) * 25.4;
52905b261ecSmrg	  g_ScreenInfo[nScreenNum].dwHeight_mm
53005b261ecSmrg	    = (g_ScreenInfo[nScreenNum].dwHeight
53105b261ecSmrg	       / monitorResolution) * 25.4;
53205b261ecSmrg	}
53305b261ecSmrg
53405b261ecSmrg      /* Flag that this screen was explicity specified by the user */
53505b261ecSmrg      g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE;
53605b261ecSmrg
53705b261ecSmrg      /*
53805b261ecSmrg       * Keep track of the last screen number seen, as parameters seen
53905b261ecSmrg       * before a screen number apply to all screens, whereas parameters
54005b261ecSmrg       * seen after a screen number apply to that screen number only.
54105b261ecSmrg       */
5426747b715Smrg      iLastScreen = nScreenNum;
54305b261ecSmrg
54405b261ecSmrg      return iArgsProcessed;
54505b261ecSmrg    }
54605b261ecSmrg
5476747b715Smrg
5486747b715Smrg  /*
5496747b715Smrg   * Is this parameter attached to a screen or global?
5506747b715Smrg   *
5516747b715Smrg   * If the parameter is for all screens (appears before
5526747b715Smrg   * any -screen option), store it in the default screen
5536747b715Smrg   * info
5546747b715Smrg   *
5556747b715Smrg   * If the parameter is for a single screen (appears
5566747b715Smrg   * after a -screen option), store it in the screen info
5576747b715Smrg   * for that screen
5586747b715Smrg   *
5596747b715Smrg   */
5606747b715Smrg  if (iLastScreen == -1)
5616747b715Smrg    {
5626747b715Smrg      screenInfoPtr = &defaultScreenInfo;
5636747b715Smrg    }
5646747b715Smrg  else
5656747b715Smrg    {
5666747b715Smrg      screenInfoPtr = &(g_ScreenInfo[iLastScreen]);
5676747b715Smrg    }
5686747b715Smrg
56905b261ecSmrg  /*
57005b261ecSmrg   * Look for the '-engine n' argument
57105b261ecSmrg   */
57205b261ecSmrg  if (IS_OPTION ("-engine"))
57305b261ecSmrg    {
57405b261ecSmrg      DWORD		dwEngine = 0;
57505b261ecSmrg      CARD8		c8OnBits = 0;
57605b261ecSmrg
57705b261ecSmrg      /* Display the usage message if the argument is malformed */
57805b261ecSmrg      if (++i >= argc)
57905b261ecSmrg	{
58005b261ecSmrg	  UseMsg ();
58105b261ecSmrg	  return 0;
58205b261ecSmrg	}
58305b261ecSmrg
58405b261ecSmrg      /* Grab the argument */
58505b261ecSmrg      dwEngine = atoi (argv[i]);
58605b261ecSmrg
58705b261ecSmrg      /* Count the one bits in the engine argument */
58805b261ecSmrg      c8OnBits = winCountBits (dwEngine);
58905b261ecSmrg
59005b261ecSmrg      /* Argument should only have a single bit on */
59105b261ecSmrg      if (c8OnBits != 1)
59205b261ecSmrg	{
59305b261ecSmrg	  UseMsg ();
59405b261ecSmrg	  return 0;
59505b261ecSmrg	}
59605b261ecSmrg
5976747b715Smrg      screenInfoPtr->dwEnginePreferred = dwEngine;
59805b261ecSmrg
59905b261ecSmrg      /* Indicate that we have processed the argument */
60005b261ecSmrg      return 2;
60105b261ecSmrg    }
60205b261ecSmrg
60305b261ecSmrg  /*
60405b261ecSmrg   * Look for the '-fullscreen' argument
60505b261ecSmrg   */
60605b261ecSmrg  if (IS_OPTION ("-fullscreen"))
60705b261ecSmrg    {
60805b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
6096747b715Smrg          if (!screenInfoPtr->fMultiMonitorOverride)
6106747b715Smrg            screenInfoPtr->fMultipleMonitors = FALSE;
61105b261ecSmrg#endif
6126747b715Smrg	  screenInfoPtr->fFullScreen = TRUE;
61305b261ecSmrg
61405b261ecSmrg      /* Indicate that we have processed this argument */
61505b261ecSmrg      return 1;
61605b261ecSmrg    }
61705b261ecSmrg
61805b261ecSmrg  /*
61905b261ecSmrg   * Look for the '-lesspointer' argument
62005b261ecSmrg   */
62105b261ecSmrg  if (IS_OPTION ("-lesspointer"))
62205b261ecSmrg    {
6236747b715Smrg      screenInfoPtr->fLessPointer = TRUE;
62405b261ecSmrg
62505b261ecSmrg      /* Indicate that we have processed this argument */
62605b261ecSmrg      return 1;
62705b261ecSmrg    }
62805b261ecSmrg
62905b261ecSmrg  /*
63005b261ecSmrg   * Look for the '-nodecoration' argument
63105b261ecSmrg   */
63205b261ecSmrg  if (IS_OPTION ("-nodecoration"))
63305b261ecSmrg    {
63405b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
6356747b715Smrg      if (!screenInfoPtr->fMultiMonitorOverride)
6366747b715Smrg        screenInfoPtr->fMultipleMonitors = FALSE;
63705b261ecSmrg#endif
6386747b715Smrg      screenInfoPtr->fDecoration = FALSE;
63905b261ecSmrg
64005b261ecSmrg      /* Indicate that we have processed this argument */
64105b261ecSmrg      return 1;
64205b261ecSmrg    }
64305b261ecSmrg
64405b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
64505b261ecSmrg  /*
64605b261ecSmrg   * Look for the '-mwextwm' argument
64705b261ecSmrg   */
64805b261ecSmrg  if (IS_OPTION ("-mwextwm"))
64905b261ecSmrg    {
6506747b715Smrg      if (!screenInfoPtr->fMultiMonitorOverride)
6516747b715Smrg        screenInfoPtr->fMultipleMonitors = TRUE;
6526747b715Smrg      screenInfoPtr->fMWExtWM = TRUE;
65305b261ecSmrg
65405b261ecSmrg      /* Indicate that we have processed this argument */
65505b261ecSmrg      return 1;
65605b261ecSmrg    }
65705b261ecSmrg  /*
65805b261ecSmrg   * Look for the '-internalwm' argument
65905b261ecSmrg   */
66005b261ecSmrg  if (IS_OPTION ("-internalwm"))
66105b261ecSmrg    {
6626747b715Smrg      if (!screenInfoPtr->fMultiMonitorOverride)
6636747b715Smrg        screenInfoPtr->fMultipleMonitors = TRUE;
6646747b715Smrg      screenInfoPtr->fMWExtWM = TRUE;
6656747b715Smrg      screenInfoPtr->fInternalWM = TRUE;
66605b261ecSmrg
66705b261ecSmrg      /* Indicate that we have processed this argument */
66805b261ecSmrg      return 1;
66905b261ecSmrg    }
67005b261ecSmrg#endif
67105b261ecSmrg
67205b261ecSmrg  /*
67305b261ecSmrg   * Look for the '-rootless' argument
67405b261ecSmrg   */
67505b261ecSmrg  if (IS_OPTION ("-rootless"))
67605b261ecSmrg    {
67705b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
6786747b715Smrg      if (!screenInfoPtr->fMultiMonitorOverride)
6796747b715Smrg        screenInfoPtr->fMultipleMonitors = FALSE;
68005b261ecSmrg#endif
6816747b715Smrg      screenInfoPtr->fRootless = TRUE;
68205b261ecSmrg
68305b261ecSmrg      /* Indicate that we have processed this argument */
68405b261ecSmrg      return 1;
68505b261ecSmrg    }
68605b261ecSmrg
68705b261ecSmrg#ifdef XWIN_MULTIWINDOW
68805b261ecSmrg  /*
68905b261ecSmrg   * Look for the '-multiwindow' argument
69005b261ecSmrg   */
69105b261ecSmrg  if (IS_OPTION ("-multiwindow"))
69205b261ecSmrg    {
69305b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
6946747b715Smrg      if (!screenInfoPtr->fMultiMonitorOverride)
6956747b715Smrg        screenInfoPtr->fMultipleMonitors = TRUE;
69605b261ecSmrg#endif
6976747b715Smrg      screenInfoPtr->fMultiWindow = TRUE;
69805b261ecSmrg
69905b261ecSmrg      /* Indicate that we have processed this argument */
70005b261ecSmrg      return 1;
70105b261ecSmrg    }
70205b261ecSmrg#endif
70305b261ecSmrg
70405b261ecSmrg  /*
70505b261ecSmrg   * Look for the '-multiplemonitors' argument
70605b261ecSmrg   */
70705b261ecSmrg  if (IS_OPTION ("-multiplemonitors")
70805b261ecSmrg      || IS_OPTION ("-multimonitors"))
70905b261ecSmrg    {
71005b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
7116747b715Smrg      screenInfoPtr->fMultiMonitorOverride = TRUE;
71205b261ecSmrg#endif
7136747b715Smrg      screenInfoPtr->fMultipleMonitors = TRUE;
71405b261ecSmrg
71505b261ecSmrg      /* Indicate that we have processed this argument */
71605b261ecSmrg      return 1;
71705b261ecSmrg    }
71805b261ecSmrg
71905b261ecSmrg  /*
72005b261ecSmrg   * Look for the '-nomultiplemonitors' argument
72105b261ecSmrg   */
72205b261ecSmrg  if (IS_OPTION ("-nomultiplemonitors")
72305b261ecSmrg      || IS_OPTION ("-nomultimonitors"))
72405b261ecSmrg    {
72505b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
7266747b715Smrg      screenInfoPtr->fMultiMonitorOverride = TRUE;
72705b261ecSmrg#endif
7286747b715Smrg      screenInfoPtr->fMultipleMonitors = FALSE;
72905b261ecSmrg
73005b261ecSmrg      /* Indicate that we have processed this argument */
73105b261ecSmrg      return 1;
73205b261ecSmrg    }
73305b261ecSmrg
73405b261ecSmrg
73505b261ecSmrg  /*
73605b261ecSmrg   * Look for the '-scrollbars' argument
73705b261ecSmrg   */
73805b261ecSmrg  if (IS_OPTION ("-scrollbars"))
73905b261ecSmrg    {
7406747b715Smrg      screenInfoPtr->fScrollbars = TRUE;
74105b261ecSmrg
74205b261ecSmrg      /* Indicate that we have processed this argument */
74305b261ecSmrg      return 1;
74405b261ecSmrg    }
74505b261ecSmrg
74605b261ecSmrg
74705b261ecSmrg#ifdef XWIN_CLIPBOARD
74805b261ecSmrg  /*
74905b261ecSmrg   * Look for the '-clipboard' argument
75005b261ecSmrg   */
75105b261ecSmrg  if (IS_OPTION ("-clipboard"))
75205b261ecSmrg    {
7536747b715Smrg      /* Now the default, we still accept the arg for backwards compatibility */
75405b261ecSmrg      g_fClipboard = TRUE;
75505b261ecSmrg
7566747b715Smrg      /* Indicate that we have processed this argument */
7576747b715Smrg      return 1;
7586747b715Smrg    }
7596747b715Smrg
7606747b715Smrg  /*
7616747b715Smrg   * Look for the '-noclipboard' argument
7626747b715Smrg   */
7636747b715Smrg  if (IS_OPTION ("-noclipboard"))
7646747b715Smrg    {
7656747b715Smrg      g_fClipboard = FALSE;
7666747b715Smrg
76705b261ecSmrg      /* Indicate that we have processed this argument */
76805b261ecSmrg      return 1;
76905b261ecSmrg    }
77005b261ecSmrg#endif
77105b261ecSmrg
77205b261ecSmrg
77305b261ecSmrg  /*
77405b261ecSmrg   * Look for the '-ignoreinput' argument
77505b261ecSmrg   */
77605b261ecSmrg  if (IS_OPTION ("-ignoreinput"))
77705b261ecSmrg    {
7786747b715Smrg      screenInfoPtr->fIgnoreInput = TRUE;
77905b261ecSmrg
78005b261ecSmrg      /* Indicate that we have processed this argument */
78105b261ecSmrg      return 1;
78205b261ecSmrg    }
78305b261ecSmrg
78405b261ecSmrg  /*
78505b261ecSmrg   * Look for the '-emulate3buttons' argument
78605b261ecSmrg   */
78705b261ecSmrg  if (IS_OPTION ("-emulate3buttons"))
78805b261ecSmrg    {
78905b261ecSmrg      int	iArgsProcessed = 1;
79005b261ecSmrg      int	iE3BTimeout = WIN_DEFAULT_E3B_TIME;
79105b261ecSmrg
79205b261ecSmrg      /* Grab the optional timeout value */
79305b261ecSmrg      if (i + 1 < argc
79405b261ecSmrg	  && 1 == sscanf (argv[i + 1], "%d",
79505b261ecSmrg			  &iE3BTimeout))
79605b261ecSmrg        {
79705b261ecSmrg	  /* Indicate that we have processed the next argument */
79805b261ecSmrg	  iArgsProcessed++;
79905b261ecSmrg        }
80005b261ecSmrg      else
80105b261ecSmrg	{
80205b261ecSmrg	  /*
80305b261ecSmrg	   * sscanf () won't modify iE3BTimeout if it doesn't find
80405b261ecSmrg	   * the specified format; however, I want to be explicit
80505b261ecSmrg	   * about setting the default timeout in such cases to
80605b261ecSmrg	   * prevent some programs (me) from getting confused.
80705b261ecSmrg	   */
80805b261ecSmrg	  iE3BTimeout = WIN_DEFAULT_E3B_TIME;
80905b261ecSmrg	}
81005b261ecSmrg
8116747b715Smrg      screenInfoPtr->iE3BTimeout = iE3BTimeout;
81205b261ecSmrg
81305b261ecSmrg      /* Indicate that we have processed this argument */
81405b261ecSmrg      return iArgsProcessed;
81505b261ecSmrg    }
81605b261ecSmrg
81705b261ecSmrg  /*
81805b261ecSmrg   * Look for the '-depth n' argument
81905b261ecSmrg   */
82005b261ecSmrg  if (IS_OPTION ("-depth"))
82105b261ecSmrg    {
82205b261ecSmrg      DWORD		dwBPP = 0;
82305b261ecSmrg
82405b261ecSmrg      /* Display the usage message if the argument is malformed */
82505b261ecSmrg      if (++i >= argc)
82605b261ecSmrg	{
82705b261ecSmrg	  UseMsg ();
82805b261ecSmrg	  return 0;
82905b261ecSmrg	}
83005b261ecSmrg
83105b261ecSmrg      /* Grab the argument */
83205b261ecSmrg      dwBPP = atoi (argv[i]);
83305b261ecSmrg
8346747b715Smrg      screenInfoPtr->dwBPP = dwBPP;
83505b261ecSmrg
83605b261ecSmrg      /* Indicate that we have processed the argument */
83705b261ecSmrg      return 2;
83805b261ecSmrg    }
83905b261ecSmrg
84005b261ecSmrg  /*
84105b261ecSmrg   * Look for the '-refresh n' argument
84205b261ecSmrg   */
84305b261ecSmrg  if (IS_OPTION ("-refresh"))
84405b261ecSmrg    {
84505b261ecSmrg      DWORD		dwRefreshRate = 0;
84605b261ecSmrg
84705b261ecSmrg      /* Display the usage message if the argument is malformed */
84805b261ecSmrg      if (++i >= argc)
84905b261ecSmrg	{
85005b261ecSmrg	  UseMsg ();
85105b261ecSmrg	  return 0;
85205b261ecSmrg	}
85305b261ecSmrg
85405b261ecSmrg      /* Grab the argument */
85505b261ecSmrg      dwRefreshRate = atoi (argv[i]);
85605b261ecSmrg
8576747b715Smrg      screenInfoPtr->dwRefreshRate = dwRefreshRate;
85805b261ecSmrg
85905b261ecSmrg      /* Indicate that we have processed the argument */
86005b261ecSmrg      return 2;
86105b261ecSmrg    }
86205b261ecSmrg
86305b261ecSmrg  /*
86405b261ecSmrg   * Look for the '-clipupdates num_boxes' argument
86505b261ecSmrg   */
86605b261ecSmrg  if (IS_OPTION ("-clipupdates"))
86705b261ecSmrg    {
86805b261ecSmrg      DWORD		dwNumBoxes = 0;
86905b261ecSmrg
87005b261ecSmrg      /* Display the usage message if the argument is malformed */
87105b261ecSmrg      if (++i >= argc)
87205b261ecSmrg	{
87305b261ecSmrg	  UseMsg ();
87405b261ecSmrg	  return 0;
87505b261ecSmrg	}
87605b261ecSmrg
87705b261ecSmrg      /* Grab the argument */
87805b261ecSmrg      dwNumBoxes = atoi (argv[i]);
87905b261ecSmrg
8806747b715Smrg      screenInfoPtr->dwClipUpdatesNBoxes = dwNumBoxes;
88105b261ecSmrg
88205b261ecSmrg      /* Indicate that we have processed the argument */
88305b261ecSmrg      return 2;
88405b261ecSmrg    }
88505b261ecSmrg
88605b261ecSmrg#ifdef XWIN_EMULATEPSEUDO
88705b261ecSmrg  /*
88805b261ecSmrg   * Look for the '-emulatepseudo' argument
88905b261ecSmrg   */
89005b261ecSmrg  if (IS_OPTION ("-emulatepseudo"))
89105b261ecSmrg    {
8926747b715Smrg      screenInfoPtr->fEmulatePseudo = TRUE;
89305b261ecSmrg
89405b261ecSmrg      /* Indicate that we have processed this argument */
89505b261ecSmrg      return 1;
89605b261ecSmrg    }
89705b261ecSmrg#endif
89805b261ecSmrg
89905b261ecSmrg  /*
90005b261ecSmrg   * Look for the '-nowinkill' argument
90105b261ecSmrg   */
90205b261ecSmrg  if (IS_OPTION ("-nowinkill"))
90305b261ecSmrg    {
9046747b715Smrg      screenInfoPtr->fUseWinKillKey = FALSE;
90505b261ecSmrg
90605b261ecSmrg      /* Indicate that we have processed this argument */
90705b261ecSmrg      return 1;
90805b261ecSmrg    }
90905b261ecSmrg
91005b261ecSmrg  /*
91105b261ecSmrg   * Look for the '-winkill' argument
91205b261ecSmrg   */
91305b261ecSmrg  if (IS_OPTION ("-winkill"))
91405b261ecSmrg    {
9156747b715Smrg      screenInfoPtr->fUseWinKillKey = TRUE;
91605b261ecSmrg
91705b261ecSmrg      /* Indicate that we have processed this argument */
91805b261ecSmrg      return 1;
91905b261ecSmrg    }
92005b261ecSmrg
92105b261ecSmrg  /*
92205b261ecSmrg   * Look for the '-nounixkill' argument
92305b261ecSmrg   */
92405b261ecSmrg  if (IS_OPTION ("-nounixkill"))
92505b261ecSmrg    {
9266747b715Smrg      screenInfoPtr->fUseUnixKillKey = FALSE;
92705b261ecSmrg
92805b261ecSmrg      /* Indicate that we have processed this argument */
92905b261ecSmrg      return 1;
93005b261ecSmrg    }
93105b261ecSmrg
93205b261ecSmrg  /*
93305b261ecSmrg   * Look for the '-unixkill' argument
93405b261ecSmrg   */
93505b261ecSmrg  if (IS_OPTION ("-unixkill"))
93605b261ecSmrg    {
9376747b715Smrg      screenInfoPtr->fUseUnixKillKey = TRUE;
93805b261ecSmrg
93905b261ecSmrg      /* Indicate that we have processed this argument */
94005b261ecSmrg      return 1;
94105b261ecSmrg    }
94205b261ecSmrg
94305b261ecSmrg  /*
94405b261ecSmrg   * Look for the '-notrayicon' argument
94505b261ecSmrg   */
94605b261ecSmrg  if (IS_OPTION ("-notrayicon"))
94705b261ecSmrg    {
9486747b715Smrg      screenInfoPtr->fNoTrayIcon = TRUE;
94905b261ecSmrg
95005b261ecSmrg      /* Indicate that we have processed this argument */
95105b261ecSmrg      return 1;
95205b261ecSmrg    }
95305b261ecSmrg
95405b261ecSmrg  /*
95505b261ecSmrg   * Look for the '-trayicon' argument
95605b261ecSmrg   */
95705b261ecSmrg  if (IS_OPTION ("-trayicon"))
95805b261ecSmrg    {
9596747b715Smrg      screenInfoPtr->fNoTrayIcon = FALSE;
96005b261ecSmrg
96105b261ecSmrg      /* Indicate that we have processed this argument */
96205b261ecSmrg      return 1;
96305b261ecSmrg    }
96405b261ecSmrg
96505b261ecSmrg  /*
96605b261ecSmrg   * Look for the '-fp' argument
96705b261ecSmrg   */
96805b261ecSmrg  if (IS_OPTION ("-fp"))
96905b261ecSmrg    {
97005b261ecSmrg      CHECK_ARGS (1);
97105b261ecSmrg      g_cmdline.fontPath = argv[++i];
97205b261ecSmrg      return 0; /* Let DIX parse this again */
97305b261ecSmrg    }
97405b261ecSmrg
97505b261ecSmrg  /*
97605b261ecSmrg   * Look for the '-query' argument
97705b261ecSmrg   */
97805b261ecSmrg  if (IS_OPTION ("-query"))
97905b261ecSmrg    {
98005b261ecSmrg      CHECK_ARGS (1);
98105b261ecSmrg      g_fXdmcpEnabled = TRUE;
98205b261ecSmrg      g_pszQueryHost = argv[++i];
98305b261ecSmrg      return 0; /* Let DIX parse this again */
98405b261ecSmrg    }
98505b261ecSmrg
9866747b715Smrg  /*
9876747b715Smrg   * Look for the '-auth' argument
9886747b715Smrg   */
9896747b715Smrg  if (IS_OPTION ("-auth"))
9906747b715Smrg    {
9916747b715Smrg      g_fAuthEnabled = TRUE;
9926747b715Smrg      return 0; /* Let DIX parse this again */
9936747b715Smrg    }
9946747b715Smrg
99505b261ecSmrg  /*
99605b261ecSmrg   * Look for the '-indirect' or '-broadcast' arguments
99705b261ecSmrg   */
99805b261ecSmrg  if (IS_OPTION ("-indirect")
99905b261ecSmrg      || IS_OPTION ("-broadcast"))
100005b261ecSmrg    {
100105b261ecSmrg      g_fXdmcpEnabled = TRUE;
100205b261ecSmrg      return 0; /* Let DIX parse this again */
100305b261ecSmrg    }
100405b261ecSmrg
100505b261ecSmrg  /*
100605b261ecSmrg   * Look for the '-config' argument
100705b261ecSmrg   */
100805b261ecSmrg  if (IS_OPTION ("-config")
100905b261ecSmrg      || IS_OPTION ("-xf86config"))
101005b261ecSmrg    {
101105b261ecSmrg      CHECK_ARGS (1);
101205b261ecSmrg#ifdef XWIN_XF86CONFIG
101305b261ecSmrg      g_cmdline.configFile = argv[++i];
101405b261ecSmrg#else
101505b261ecSmrg      winMessageBoxF ("The %s option is not supported in this "
101605b261ecSmrg		      "release.\n"
101705b261ecSmrg		      "Ignoring this option and continuing.\n",
101805b261ecSmrg		      MB_ICONINFORMATION,
101905b261ecSmrg		      argv[i]);
102005b261ecSmrg#endif
102105b261ecSmrg      return 2;
102205b261ecSmrg    }
102305b261ecSmrg
10246747b715Smrg  /*
10256747b715Smrg   * Look for the '-configdir' argument
10266747b715Smrg   */
10276747b715Smrg  if (IS_OPTION ("-configdir"))
10286747b715Smrg    {
10296747b715Smrg      CHECK_ARGS (1);
10306747b715Smrg#ifdef XWIN_XF86CONFIG
10316747b715Smrg      g_cmdline.configDir = argv[++i];
10326747b715Smrg#else
10336747b715Smrg      winMessageBoxF ("The %s option is not supported in this "
10346747b715Smrg		      "release.\n"
10356747b715Smrg		      "Ignoring this option and continuing.\n",
10366747b715Smrg		      MB_ICONINFORMATION,
10376747b715Smrg		      argv[i]);
10386747b715Smrg#endif
10396747b715Smrg      return 2;
10406747b715Smrg    }
10416747b715Smrg
104205b261ecSmrg  /*
104305b261ecSmrg   * Look for the '-keyboard' argument
104405b261ecSmrg   */
104505b261ecSmrg  if (IS_OPTION ("-keyboard"))
104605b261ecSmrg    {
104705b261ecSmrg#ifdef XWIN_XF86CONFIG
104805b261ecSmrg      CHECK_ARGS (1);
104905b261ecSmrg      g_cmdline.keyboard = argv[++i];
105005b261ecSmrg#else
105105b261ecSmrg      winMessageBoxF ("The -keyboard option is not supported in this "
105205b261ecSmrg		      "release.\n"
105305b261ecSmrg		      "Ignoring this option and continuing.\n",
105405b261ecSmrg		      MB_ICONINFORMATION);
105505b261ecSmrg#endif
105605b261ecSmrg      return 2;
105705b261ecSmrg    }
105805b261ecSmrg
105905b261ecSmrg  /*
106005b261ecSmrg   * Look for the '-logfile' argument
106105b261ecSmrg   */
106205b261ecSmrg  if (IS_OPTION ("-logfile"))
106305b261ecSmrg    {
106405b261ecSmrg      CHECK_ARGS (1);
106505b261ecSmrg      g_pszLogFile = argv[++i];
106605b261ecSmrg#ifdef RELOCATE_PROJECTROOT
106705b261ecSmrg      g_fLogFileChanged = TRUE;
106805b261ecSmrg#endif
106905b261ecSmrg      return 2;
107005b261ecSmrg    }
107105b261ecSmrg
107205b261ecSmrg  /*
107305b261ecSmrg   * Look for the '-logverbose' argument
107405b261ecSmrg   */
107505b261ecSmrg  if (IS_OPTION ("-logverbose"))
107605b261ecSmrg    {
107705b261ecSmrg      CHECK_ARGS (1);
107805b261ecSmrg      g_iLogVerbose = atoi(argv[++i]);
107905b261ecSmrg      return 2;
108005b261ecSmrg    }
108105b261ecSmrg
108205b261ecSmrg#ifdef XWIN_CLIPBOARD
108305b261ecSmrg  /*
108405b261ecSmrg   * Look for the '-nounicodeclipboard' argument
108505b261ecSmrg   */
108605b261ecSmrg  if (IS_OPTION ("-nounicodeclipboard"))
108705b261ecSmrg    {
108805b261ecSmrg      g_fUnicodeClipboard = FALSE;
108905b261ecSmrg      /* Indicate that we have processed the argument */
109005b261ecSmrg      return 1;
109105b261ecSmrg    }
109205b261ecSmrg#endif
109305b261ecSmrg
109405b261ecSmrg  if (IS_OPTION ("-xkbrules"))
109505b261ecSmrg    {
109605b261ecSmrg      CHECK_ARGS (1);
109705b261ecSmrg      g_cmdline.xkbRules = argv[++i];
109805b261ecSmrg      return 2;
109905b261ecSmrg    }
110005b261ecSmrg  if (IS_OPTION ("-xkbmodel"))
110105b261ecSmrg    {
110205b261ecSmrg      CHECK_ARGS (1);
110305b261ecSmrg      g_cmdline.xkbModel = argv[++i];
110405b261ecSmrg      return 2;
110505b261ecSmrg    }
110605b261ecSmrg  if (IS_OPTION ("-xkblayout"))
110705b261ecSmrg    {
110805b261ecSmrg      CHECK_ARGS (1);
110905b261ecSmrg      g_cmdline.xkbLayout = argv[++i];
111005b261ecSmrg      return 2;
111105b261ecSmrg    }
111205b261ecSmrg  if (IS_OPTION ("-xkbvariant"))
111305b261ecSmrg    {
111405b261ecSmrg      CHECK_ARGS (1);
111505b261ecSmrg      g_cmdline.xkbVariant = argv[++i];
111605b261ecSmrg      return 2;
111705b261ecSmrg    }
111805b261ecSmrg  if (IS_OPTION ("-xkboptions"))
111905b261ecSmrg    {
112005b261ecSmrg      CHECK_ARGS (1);
112105b261ecSmrg      g_cmdline.xkbOptions = argv[++i];
112205b261ecSmrg      return 2;
112305b261ecSmrg    }
112405b261ecSmrg
112505b261ecSmrg  if (IS_OPTION ("-keyhook"))
112605b261ecSmrg    {
112705b261ecSmrg      g_fKeyboardHookLL = TRUE;
112805b261ecSmrg      return 1;
112905b261ecSmrg    }
113005b261ecSmrg
113105b261ecSmrg  if (IS_OPTION ("-nokeyhook"))
113205b261ecSmrg    {
113305b261ecSmrg      g_fKeyboardHookLL = FALSE;
113405b261ecSmrg      return 1;
113505b261ecSmrg    }
113605b261ecSmrg
113705b261ecSmrg  if (IS_OPTION ("-swcursor"))
113805b261ecSmrg    {
113905b261ecSmrg      g_fSoftwareCursor = TRUE;
114005b261ecSmrg      return 1;
114105b261ecSmrg    }
114205b261ecSmrg
114305b261ecSmrg  if (IS_OPTION ("-silent-dup-error"))
114405b261ecSmrg    {
114505b261ecSmrg      g_fSilentDupError = TRUE;
114605b261ecSmrg      return 1;
114705b261ecSmrg    }
11486747b715Smrg
11496747b715Smrg  if (IS_OPTION("-wgl"))
11506747b715Smrg    {
11516747b715Smrg      g_fNativeGl = TRUE;
11526747b715Smrg      return 1;
11536747b715Smrg    }
11546747b715Smrg
11556747b715Smrg  if (IS_OPTION("-nowgl"))
11566747b715Smrg    {
11576747b715Smrg      g_fNativeGl = FALSE;
11586747b715Smrg      return 1;
11596747b715Smrg    }
11606747b715Smrg
116105b261ecSmrg  return 0;
116205b261ecSmrg}
116305b261ecSmrg
116405b261ecSmrg
116505b261ecSmrg/*
116605b261ecSmrg * winLogCommandLine - Write entire command line to the log file
116705b261ecSmrg */
116805b261ecSmrg
116905b261ecSmrgvoid
117005b261ecSmrgwinLogCommandLine (int argc, char *argv[])
117105b261ecSmrg{
117205b261ecSmrg  int		i;
117305b261ecSmrg  int		iSize = 0;
117405b261ecSmrg  int		iCurrLen = 0;
117505b261ecSmrg
117605b261ecSmrg#define CHARS_PER_LINE 60
117705b261ecSmrg
117805b261ecSmrg  /* Bail if command line has already been logged */
117905b261ecSmrg  if (g_pszCommandLine)
118005b261ecSmrg    return;
118105b261ecSmrg
118205b261ecSmrg  /* Count how much memory is needed for concatenated command line */
118305b261ecSmrg  for (i = 0, iCurrLen = 0; i < argc; ++i)
118405b261ecSmrg    if (argv[i])
118505b261ecSmrg      {
11866747b715Smrg	/* Adds two characters for lines that overflow */
118705b261ecSmrg	if ((strlen (argv[i]) < CHARS_PER_LINE
118805b261ecSmrg	    && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE)
118905b261ecSmrg	    || strlen (argv[i]) > CHARS_PER_LINE)
119005b261ecSmrg	  {
119105b261ecSmrg	    iCurrLen = 0;
11926747b715Smrg	    iSize += 2;
119305b261ecSmrg	  }
119405b261ecSmrg
119505b261ecSmrg	/* Add space for item and trailing space */
119605b261ecSmrg	iSize += strlen (argv[i]) + 1;
119705b261ecSmrg
119805b261ecSmrg	/* Update current line length */
119905b261ecSmrg	iCurrLen += strlen (argv[i]);
120005b261ecSmrg      }
120105b261ecSmrg
120205b261ecSmrg  /* Allocate memory for concatenated command line */
120305b261ecSmrg  g_pszCommandLine = malloc (iSize + 1);
120405b261ecSmrg  if (!g_pszCommandLine)
120505b261ecSmrg    FatalError ("winLogCommandLine - Could not allocate memory for "
120605b261ecSmrg		"command line string.  Exiting.\n");
120705b261ecSmrg
120805b261ecSmrg  /* Set first character to concatenated command line to null */
120905b261ecSmrg  g_pszCommandLine[0] = '\0';
121005b261ecSmrg
121105b261ecSmrg  /* Loop through all args */
121205b261ecSmrg  for (i = 0, iCurrLen = 0; i < argc; ++i)
121305b261ecSmrg    {
121405b261ecSmrg      /* Add a character for lines that overflow */
121505b261ecSmrg      if ((strlen (argv[i]) < CHARS_PER_LINE
121605b261ecSmrg	   && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE)
121705b261ecSmrg	  || strlen (argv[i]) > CHARS_PER_LINE)
121805b261ecSmrg      {
121905b261ecSmrg	iCurrLen = 0;
122005b261ecSmrg
122105b261ecSmrg	/* Add line break if it fits */
12226747b715Smrg	strncat (g_pszCommandLine, "\n ", iSize - strlen (g_pszCommandLine));
122305b261ecSmrg      }
122405b261ecSmrg
122505b261ecSmrg      strncat (g_pszCommandLine, argv[i], iSize - strlen (g_pszCommandLine));
122605b261ecSmrg      strncat (g_pszCommandLine, " ", iSize - strlen (g_pszCommandLine));
122705b261ecSmrg
122805b261ecSmrg      /* Save new line length */
122905b261ecSmrg      iCurrLen += strlen (argv[i]);
123005b261ecSmrg    }
123105b261ecSmrg
123205b261ecSmrg  ErrorF ("XWin was started with the following command line:\n\n"
123305b261ecSmrg	  "%s\n\n", g_pszCommandLine);
123405b261ecSmrg}
123505b261ecSmrg
123605b261ecSmrg
123705b261ecSmrg/*
123805b261ecSmrg * winLogVersionInfo - Log Cygwin/X version information
123905b261ecSmrg */
124005b261ecSmrg
124105b261ecSmrgvoid
124205b261ecSmrgwinLogVersionInfo (void)
124305b261ecSmrg{
124405b261ecSmrg  static Bool		s_fBeenHere = FALSE;
124505b261ecSmrg
124605b261ecSmrg  if (s_fBeenHere)
124705b261ecSmrg    return;
124805b261ecSmrg  s_fBeenHere = TRUE;
124905b261ecSmrg
125005b261ecSmrg  ErrorF ("Welcome to the XWin X Server\n");
125105b261ecSmrg  ErrorF ("Vendor: %s\n", VENDOR_STRING);
12526747b715Smrg  ErrorF ("Release: %d.%d.%d.%d (%d)\n", XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT);
12536747b715Smrg  ErrorF ("%s\n\n", BUILDERSTRING);
12546747b715Smrg  ErrorF ("Contact: %s\n", VENDOR_CONTACT);
125505b261ecSmrg}
125605b261ecSmrg
125705b261ecSmrg/*
125805b261ecSmrg * getMonitorInfo - callback function used to return information from the enumeration of monitors attached
125905b261ecSmrg */
126005b261ecSmrg
126105b261ecSmrgwBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data)
126205b261ecSmrg{
126305b261ecSmrg  struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data;
126405b261ecSmrg  // only get data for monitor number specified in <data>
126505b261ecSmrg  data->monitorNum++;
126605b261ecSmrg  if (data->monitorNum == data->requestedMonitor)
126705b261ecSmrg  {
126805b261ecSmrg	data->bMonitorSpecifiedExists = TRUE;
126905b261ecSmrg	data->monitorOffsetX = rect->left;
127005b261ecSmrg	data->monitorOffsetY = rect->top;
127105b261ecSmrg	data->monitorHeight  = rect->bottom - rect->top;
127205b261ecSmrg	data->monitorWidth   = rect->right  - rect->left;
127305b261ecSmrg    return FALSE;
127405b261ecSmrg  }
127505b261ecSmrg  return TRUE;
127605b261ecSmrg}
1277