winvalargs.c revision 6747b715
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;
436747b715Smrgextern winScreenInfo *		g_ScreenInfo;
4405b261ecSmrgextern Bool			g_fXdmcpEnabled;
4505b261ecSmrg
4605b261ecSmrg
4705b261ecSmrg/*
486747b715Smrg * Verify all screens have been explicitly specified
4905b261ecSmrg */
506747b715Smrgstatic BOOL
516747b715SmrgisEveryScreenExplicit(void)
526747b715Smrg{
536747b715Smrg  int i;
5405b261ecSmrg
556747b715Smrg  for (i = 0; i < g_iNumScreens; i++)
566747b715Smrg    if (!g_ScreenInfo[i].fExplicitScreen)
576747b715Smrg      return FALSE;
5805b261ecSmrg
596747b715Smrg  return TRUE;
606747b715Smrg}
6105b261ecSmrg
6205b261ecSmrg/*
6305b261ecSmrg * winValidateArgs - Look for invalid argument combinations
6405b261ecSmrg */
6505b261ecSmrg
6605b261ecSmrgBool
6705b261ecSmrgwinValidateArgs (void)
6805b261ecSmrg{
6905b261ecSmrg  int		i;
7005b261ecSmrg  int		iMaxConsecutiveScreen = 0;
7105b261ecSmrg  BOOL		fHasNormalScreen0 = FALSE;
726747b715Smrg  BOOL		fImplicitScreenFound = FALSE;
7305b261ecSmrg
7405b261ecSmrg  /*
7505b261ecSmrg   * Check for a malformed set of -screen parameters.
7605b261ecSmrg   * Examples of malformed parameters:
7705b261ecSmrg   *	XWin -screen 1
7805b261ecSmrg   *	XWin -screen 0 -screen 2
7905b261ecSmrg   *	XWin -screen 1 -screen 2
8005b261ecSmrg   */
816747b715Smrg  if (!isEveryScreenExplicit())
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 "
876747b715Smrg	      "have screen 0, or screen 0 and screen 1, respectively.  "
886747b715Smrg	      "You can specify as many screens as you want.\n");
8905b261ecSmrg      return FALSE;
9005b261ecSmrg    }
9105b261ecSmrg
9205b261ecSmrg  /* Loop through all screens */
9305b261ecSmrg  for (i = 0; i < g_iNumScreens; ++i)
9405b261ecSmrg    {
9505b261ecSmrg      /*
9605b261ecSmrg       * Check for any combination of
9705b261ecSmrg       * -multiwindow, -mwextwm, and -rootless.
9805b261ecSmrg       */
9905b261ecSmrg      {
10005b261ecSmrg	int		iCount = 0;
10105b261ecSmrg
10205b261ecSmrg	/* Count conflicting options */
10305b261ecSmrg#ifdef XWIN_MULTIWINDOW
10405b261ecSmrg	if (g_ScreenInfo[i].fMultiWindow)
10505b261ecSmrg	  ++iCount;
10605b261ecSmrg#endif
10705b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
10805b261ecSmrg	if (g_ScreenInfo[i].fMWExtWM)
10905b261ecSmrg	  ++iCount;
11005b261ecSmrg#endif
11105b261ecSmrg	if (g_ScreenInfo[i].fRootless)
11205b261ecSmrg	  ++iCount;
11305b261ecSmrg
11405b261ecSmrg	/* Check if the first screen is without rootless and multiwindow */
11505b261ecSmrg	if (iCount == 0 && i == 0)
11605b261ecSmrg	  fHasNormalScreen0 = TRUE;
11705b261ecSmrg
11805b261ecSmrg	/* Fail if two or more conflicting options */
11905b261ecSmrg	if (iCount > 1)
12005b261ecSmrg	  {
12105b261ecSmrg	    ErrorF ("winValidateArgs - Only one of -multiwindow, -mwextwm, "
12205b261ecSmrg		    "and -rootless can be specific at a time.\n");
12305b261ecSmrg	    return FALSE;
12405b261ecSmrg	  }
12505b261ecSmrg      }
12605b261ecSmrg
12705b261ecSmrg      /* Check for -multiwindow or -mwextwm and Xdmcp */
12805b261ecSmrg      /* allow xdmcp if screen 0 is normal. */
12905b261ecSmrg      if (g_fXdmcpEnabled && !fHasNormalScreen0
13005b261ecSmrg	  && (FALSE
13105b261ecSmrg#ifdef XWIN_MULTIWINDOW
13205b261ecSmrg	      || g_ScreenInfo[i].fMultiWindow
13305b261ecSmrg#endif
13405b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
13505b261ecSmrg	      || g_ScreenInfo[i].fMWExtWM
13605b261ecSmrg#endif
13705b261ecSmrg	      )
13805b261ecSmrg	  )
13905b261ecSmrg	{
14005b261ecSmrg	  ErrorF ("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) "
14105b261ecSmrg		  "is invalid with -multiwindow or -mwextwm.\n");
14205b261ecSmrg	  return FALSE;
14305b261ecSmrg	}
14405b261ecSmrg
14505b261ecSmrg      /* Check for -multiwindow, -mwextwm, or -rootless and fullscreen */
14605b261ecSmrg      if (g_ScreenInfo[i].fFullScreen
14705b261ecSmrg	  && (FALSE
14805b261ecSmrg#ifdef XWIN_MULTIWINDOW
14905b261ecSmrg	      || g_ScreenInfo[i].fMultiWindow
15005b261ecSmrg#endif
15105b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
15205b261ecSmrg	      || g_ScreenInfo[i].fMWExtWM
15305b261ecSmrg#endif
15405b261ecSmrg	      || g_ScreenInfo[i].fRootless)
15505b261ecSmrg	  )
15605b261ecSmrg	{
15705b261ecSmrg	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
15805b261ecSmrg		  "-multiwindow, -mwextwm, or -rootless.\n");
15905b261ecSmrg	  return FALSE;
16005b261ecSmrg	}
16105b261ecSmrg
16205b261ecSmrg      /* Check for !fullscreen and any fullscreen-only parameters */
16305b261ecSmrg      if (!g_ScreenInfo[i].fFullScreen
16405b261ecSmrg	  && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_BPP
16505b261ecSmrg	      || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_REFRESH))
16605b261ecSmrg	{
16705b261ecSmrg	  ErrorF ("winValidateArgs - -refresh and -depth are only valid "
16805b261ecSmrg		  "with -fullscreen.\n");
16905b261ecSmrg	  return FALSE;
17005b261ecSmrg	}
17105b261ecSmrg
17205b261ecSmrg      /* Check for fullscreen and any non-fullscreen parameters */
17305b261ecSmrg      if (g_ScreenInfo[i].fFullScreen
17405b261ecSmrg	  && (g_ScreenInfo[i].fScrollbars
17505b261ecSmrg	      || !g_ScreenInfo[i].fDecoration
17605b261ecSmrg	      || g_ScreenInfo[i].fLessPointer))
17705b261ecSmrg	{
17805b261ecSmrg	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
17905b261ecSmrg		  "-scrollbars, -nodecoration, or -lesspointer.\n");
18005b261ecSmrg	  return FALSE;
18105b261ecSmrg	}
18205b261ecSmrg    }
18305b261ecSmrg
18405b261ecSmrg  winDebug ("winValidateArgs - Returning.\n");
18505b261ecSmrg
18605b261ecSmrg  return TRUE;
18705b261ecSmrg}
188