winvalargs.c revision 05b261ec
105b261ecSmrg/*
205b261ecSmrg *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
305b261ecSmrg *
405b261ecSmrg *Permission is hereby granted, free of charge, to any person obtaining
505b261ecSmrg * a copy of this software and associated documentation files (the
605b261ecSmrg *"Software"), to deal in the Software without restriction, including
705b261ecSmrg *without limitation the rights to use, copy, modify, merge, publish,
805b261ecSmrg *distribute, sublicense, and/or sell copies of the Software, and to
905b261ecSmrg *permit persons to whom the Software is furnished to do so, subject to
1005b261ecSmrg *the following conditions:
1105b261ecSmrg *
1205b261ecSmrg *The above copyright notice and this permission notice shall be
1305b261ecSmrg *included in all copies or substantial portions of the Software.
1405b261ecSmrg *
1505b261ecSmrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1605b261ecSmrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1705b261ecSmrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1805b261ecSmrg *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
1905b261ecSmrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
2005b261ecSmrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2105b261ecSmrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2205b261ecSmrg *
2305b261ecSmrg *Except as contained in this notice, the name of Harold L Hunt II
2405b261ecSmrg *shall not be used in advertising or otherwise to promote the sale, use
2505b261ecSmrg *or other dealings in this Software without prior written authorization
2605b261ecSmrg *from Harold L Hunt II.
2705b261ecSmrg *
2805b261ecSmrg * Authors:	Harold L Hunt II
2905b261ecSmrg */
3005b261ecSmrg
3105b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H
3205b261ecSmrg#include <xwin-config.h>
3305b261ecSmrg#endif
3405b261ecSmrg#include "win.h"
3505b261ecSmrg#include "winmsg.h"
3605b261ecSmrg
3705b261ecSmrg
3805b261ecSmrg/*
3905b261ecSmrg * References to external symbols
4005b261ecSmrg */
4105b261ecSmrg
4205b261ecSmrgextern int			g_iNumScreens;
4305b261ecSmrgextern winScreenInfo		g_ScreenInfo[];
4405b261ecSmrgextern Bool			g_fXdmcpEnabled;
4505b261ecSmrg
4605b261ecSmrg
4705b261ecSmrg/*
4805b261ecSmrg * Prototypes
4905b261ecSmrg */
5005b261ecSmrg
5105b261ecSmrgBool
5205b261ecSmrgwinValidateArgs (void);
5305b261ecSmrg
5405b261ecSmrg
5505b261ecSmrg/*
5605b261ecSmrg * winValidateArgs - Look for invalid argument combinations
5705b261ecSmrg */
5805b261ecSmrg
5905b261ecSmrgBool
6005b261ecSmrgwinValidateArgs (void)
6105b261ecSmrg{
6205b261ecSmrg  int		i;
6305b261ecSmrg  int		iMaxConsecutiveScreen = 0;
6405b261ecSmrg  BOOL		fHasNormalScreen0 = FALSE;
6505b261ecSmrg
6605b261ecSmrg  /*
6705b261ecSmrg   * Check for a malformed set of -screen parameters.
6805b261ecSmrg   * Examples of malformed parameters:
6905b261ecSmrg   *	XWin -screen 1
7005b261ecSmrg   *	XWin -screen 0 -screen 2
7105b261ecSmrg   *	XWin -screen 1 -screen 2
7205b261ecSmrg   */
7305b261ecSmrg  for (i = 0; i < MAXSCREENS; i++)
7405b261ecSmrg    {
7505b261ecSmrg      if (g_ScreenInfo[i].fExplicitScreen)
7605b261ecSmrg	iMaxConsecutiveScreen = i + 1;
7705b261ecSmrg    }
7805b261ecSmrg  winErrorFVerb (2, "winValidateArgs - g_iNumScreens: %d "
7905b261ecSmrg		 "iMaxConsecutiveScreen: %d\n",
8005b261ecSmrg		 g_iNumScreens, iMaxConsecutiveScreen);
8105b261ecSmrg  if (g_iNumScreens < iMaxConsecutiveScreen)
8205b261ecSmrg    {
8305b261ecSmrg      ErrorF ("winValidateArgs - Malformed set of screen parameter(s).  "
8405b261ecSmrg	      "Screens must be specified consecutively starting with "
8505b261ecSmrg	      "screen 0.  That is, you cannot have only a screen 1, nor "
8605b261ecSmrg	      "could you have screen 0 and screen 2.  You instead must "
8705b261ecSmrg	      "have screen 0, or screen 0 and screen 1, respectively.  Of "
8805b261ecSmrg	      "you can specify as many screens as you want from 0 up to "
8905b261ecSmrg	      "%d.\n", MAXSCREENS - 1);
9005b261ecSmrg      return FALSE;
9105b261ecSmrg    }
9205b261ecSmrg
9305b261ecSmrg  /* Loop through all screens */
9405b261ecSmrg  for (i = 0; i < g_iNumScreens; ++i)
9505b261ecSmrg    {
9605b261ecSmrg      /*
9705b261ecSmrg       * Check for any combination of
9805b261ecSmrg       * -multiwindow, -mwextwm, and -rootless.
9905b261ecSmrg       */
10005b261ecSmrg      {
10105b261ecSmrg	int		iCount = 0;
10205b261ecSmrg
10305b261ecSmrg	/* Count conflicting options */
10405b261ecSmrg#ifdef XWIN_MULTIWINDOW
10505b261ecSmrg	if (g_ScreenInfo[i].fMultiWindow)
10605b261ecSmrg	  ++iCount;
10705b261ecSmrg#endif
10805b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
10905b261ecSmrg	if (g_ScreenInfo[i].fMWExtWM)
11005b261ecSmrg	  ++iCount;
11105b261ecSmrg#endif
11205b261ecSmrg	if (g_ScreenInfo[i].fRootless)
11305b261ecSmrg	  ++iCount;
11405b261ecSmrg
11505b261ecSmrg	/* Check if the first screen is without rootless and multiwindow */
11605b261ecSmrg	if (iCount == 0 && i == 0)
11705b261ecSmrg	  fHasNormalScreen0 = TRUE;
11805b261ecSmrg
11905b261ecSmrg	/* Fail if two or more conflicting options */
12005b261ecSmrg	if (iCount > 1)
12105b261ecSmrg	  {
12205b261ecSmrg	    ErrorF ("winValidateArgs - Only one of -multiwindow, -mwextwm, "
12305b261ecSmrg		    "and -rootless can be specific at a time.\n");
12405b261ecSmrg	    return FALSE;
12505b261ecSmrg	  }
12605b261ecSmrg      }
12705b261ecSmrg
12805b261ecSmrg      /* Check for -multiwindow or -mwextwm and Xdmcp */
12905b261ecSmrg      /* allow xdmcp if screen 0 is normal. */
13005b261ecSmrg      if (g_fXdmcpEnabled && !fHasNormalScreen0
13105b261ecSmrg	  && (FALSE
13205b261ecSmrg#ifdef XWIN_MULTIWINDOW
13305b261ecSmrg	      || g_ScreenInfo[i].fMultiWindow
13405b261ecSmrg#endif
13505b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
13605b261ecSmrg	      || g_ScreenInfo[i].fMWExtWM
13705b261ecSmrg#endif
13805b261ecSmrg	      )
13905b261ecSmrg	  )
14005b261ecSmrg	{
14105b261ecSmrg	  ErrorF ("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) "
14205b261ecSmrg		  "is invalid with -multiwindow or -mwextwm.\n");
14305b261ecSmrg	  return FALSE;
14405b261ecSmrg	}
14505b261ecSmrg
14605b261ecSmrg      /* Check for -multiwindow, -mwextwm, or -rootless and fullscreen */
14705b261ecSmrg      if (g_ScreenInfo[i].fFullScreen
14805b261ecSmrg	  && (FALSE
14905b261ecSmrg#ifdef XWIN_MULTIWINDOW
15005b261ecSmrg	      || g_ScreenInfo[i].fMultiWindow
15105b261ecSmrg#endif
15205b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
15305b261ecSmrg	      || g_ScreenInfo[i].fMWExtWM
15405b261ecSmrg#endif
15505b261ecSmrg	      || g_ScreenInfo[i].fRootless)
15605b261ecSmrg	  )
15705b261ecSmrg	{
15805b261ecSmrg	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
15905b261ecSmrg		  "-multiwindow, -mwextwm, or -rootless.\n");
16005b261ecSmrg	  return FALSE;
16105b261ecSmrg	}
16205b261ecSmrg
16305b261ecSmrg      /* Check for !fullscreen and any fullscreen-only parameters */
16405b261ecSmrg      if (!g_ScreenInfo[i].fFullScreen
16505b261ecSmrg	  && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_BPP
16605b261ecSmrg	      || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_REFRESH))
16705b261ecSmrg	{
16805b261ecSmrg	  ErrorF ("winValidateArgs - -refresh and -depth are only valid "
16905b261ecSmrg		  "with -fullscreen.\n");
17005b261ecSmrg	  return FALSE;
17105b261ecSmrg	}
17205b261ecSmrg
17305b261ecSmrg      /* Check for fullscreen and any non-fullscreen parameters */
17405b261ecSmrg      if (g_ScreenInfo[i].fFullScreen
17505b261ecSmrg	  && (g_ScreenInfo[i].fScrollbars
17605b261ecSmrg	      || !g_ScreenInfo[i].fDecoration
17705b261ecSmrg	      || g_ScreenInfo[i].fLessPointer))
17805b261ecSmrg	{
17905b261ecSmrg	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
18005b261ecSmrg		  "-scrollbars, -nodecoration, or -lesspointer.\n");
18105b261ecSmrg	  return FALSE;
18205b261ecSmrg	}
18305b261ecSmrg    }
18405b261ecSmrg
18505b261ecSmrg  winDebug ("winValidateArgs - Returning.\n");
18605b261ecSmrg
18705b261ecSmrg  return TRUE;
18805b261ecSmrg}
189