winvalargs.c revision 05b261ec
1/*
2 *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
3 *
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
11 *
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
14 *
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 *Except as contained in this notice, the name of Harold L Hunt II
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from Harold L Hunt II.
27 *
28 * Authors:	Harold L Hunt II
29 */
30
31#ifdef HAVE_XWIN_CONFIG_H
32#include <xwin-config.h>
33#endif
34#include "win.h"
35#include "winmsg.h"
36
37
38/*
39 * References to external symbols
40 */
41
42extern int			g_iNumScreens;
43extern winScreenInfo		g_ScreenInfo[];
44extern Bool			g_fXdmcpEnabled;
45
46
47/*
48 * Prototypes
49 */
50
51Bool
52winValidateArgs (void);
53
54
55/*
56 * winValidateArgs - Look for invalid argument combinations
57 */
58
59Bool
60winValidateArgs (void)
61{
62  int		i;
63  int		iMaxConsecutiveScreen = 0;
64  BOOL		fHasNormalScreen0 = FALSE;
65
66  /*
67   * Check for a malformed set of -screen parameters.
68   * Examples of malformed parameters:
69   *	XWin -screen 1
70   *	XWin -screen 0 -screen 2
71   *	XWin -screen 1 -screen 2
72   */
73  for (i = 0; i < MAXSCREENS; i++)
74    {
75      if (g_ScreenInfo[i].fExplicitScreen)
76	iMaxConsecutiveScreen = i + 1;
77    }
78  winErrorFVerb (2, "winValidateArgs - g_iNumScreens: %d "
79		 "iMaxConsecutiveScreen: %d\n",
80		 g_iNumScreens, iMaxConsecutiveScreen);
81  if (g_iNumScreens < iMaxConsecutiveScreen)
82    {
83      ErrorF ("winValidateArgs - Malformed set of screen parameter(s).  "
84	      "Screens must be specified consecutively starting with "
85	      "screen 0.  That is, you cannot have only a screen 1, nor "
86	      "could you have screen 0 and screen 2.  You instead must "
87	      "have screen 0, or screen 0 and screen 1, respectively.  Of "
88	      "you can specify as many screens as you want from 0 up to "
89	      "%d.\n", MAXSCREENS - 1);
90      return FALSE;
91    }
92
93  /* Loop through all screens */
94  for (i = 0; i < g_iNumScreens; ++i)
95    {
96      /*
97       * Check for any combination of
98       * -multiwindow, -mwextwm, and -rootless.
99       */
100      {
101	int		iCount = 0;
102
103	/* Count conflicting options */
104#ifdef XWIN_MULTIWINDOW
105	if (g_ScreenInfo[i].fMultiWindow)
106	  ++iCount;
107#endif
108#ifdef XWIN_MULTIWINDOWEXTWM
109	if (g_ScreenInfo[i].fMWExtWM)
110	  ++iCount;
111#endif
112	if (g_ScreenInfo[i].fRootless)
113	  ++iCount;
114
115	/* Check if the first screen is without rootless and multiwindow */
116	if (iCount == 0 && i == 0)
117	  fHasNormalScreen0 = TRUE;
118
119	/* Fail if two or more conflicting options */
120	if (iCount > 1)
121	  {
122	    ErrorF ("winValidateArgs - Only one of -multiwindow, -mwextwm, "
123		    "and -rootless can be specific at a time.\n");
124	    return FALSE;
125	  }
126      }
127
128      /* Check for -multiwindow or -mwextwm and Xdmcp */
129      /* allow xdmcp if screen 0 is normal. */
130      if (g_fXdmcpEnabled && !fHasNormalScreen0
131	  && (FALSE
132#ifdef XWIN_MULTIWINDOW
133	      || g_ScreenInfo[i].fMultiWindow
134#endif
135#ifdef XWIN_MULTIWINDOWEXTWM
136	      || g_ScreenInfo[i].fMWExtWM
137#endif
138	      )
139	  )
140	{
141	  ErrorF ("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) "
142		  "is invalid with -multiwindow or -mwextwm.\n");
143	  return FALSE;
144	}
145
146      /* Check for -multiwindow, -mwextwm, or -rootless and fullscreen */
147      if (g_ScreenInfo[i].fFullScreen
148	  && (FALSE
149#ifdef XWIN_MULTIWINDOW
150	      || g_ScreenInfo[i].fMultiWindow
151#endif
152#ifdef XWIN_MULTIWINDOWEXTWM
153	      || g_ScreenInfo[i].fMWExtWM
154#endif
155	      || g_ScreenInfo[i].fRootless)
156	  )
157	{
158	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
159		  "-multiwindow, -mwextwm, or -rootless.\n");
160	  return FALSE;
161	}
162
163      /* Check for !fullscreen and any fullscreen-only parameters */
164      if (!g_ScreenInfo[i].fFullScreen
165	  && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_BPP
166	      || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_REFRESH))
167	{
168	  ErrorF ("winValidateArgs - -refresh and -depth are only valid "
169		  "with -fullscreen.\n");
170	  return FALSE;
171	}
172
173      /* Check for fullscreen and any non-fullscreen parameters */
174      if (g_ScreenInfo[i].fFullScreen
175	  && (g_ScreenInfo[i].fScrollbars
176	      || !g_ScreenInfo[i].fDecoration
177	      || g_ScreenInfo[i].fLessPointer))
178	{
179	  ErrorF ("winValidateArgs - -fullscreen is invalid with "
180		  "-scrollbars, -nodecoration, or -lesspointer.\n");
181	  return FALSE;
182	}
183    }
184
185  winDebug ("winValidateArgs - Returning.\n");
186
187  return TRUE;
188}
189