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/*
386747b715Smrg * Verify all screens have been explicitly specified
3905b261ecSmrg */
406747b715Smrgstatic BOOL
416747b715SmrgisEveryScreenExplicit(void)
426747b715Smrg{
4335c4bbdfSmrg    int i;
4405b261ecSmrg
4535c4bbdfSmrg    for (i = 0; i < g_iNumScreens; i++)
4635c4bbdfSmrg        if (!g_ScreenInfo[i].fExplicitScreen)
4735c4bbdfSmrg            return FALSE;
4805b261ecSmrg
4935c4bbdfSmrg    return TRUE;
506747b715Smrg}
5105b261ecSmrg
5205b261ecSmrg/*
5305b261ecSmrg * winValidateArgs - Look for invalid argument combinations
5405b261ecSmrg */
5505b261ecSmrg
5605b261ecSmrgBool
5735c4bbdfSmrgwinValidateArgs(void)
5805b261ecSmrg{
5935c4bbdfSmrg    int i;
6035c4bbdfSmrg    BOOL fHasNormalScreen0 = FALSE;
6135c4bbdfSmrg
6235c4bbdfSmrg    /*
6335c4bbdfSmrg     * Check for a malformed set of -screen parameters.
6435c4bbdfSmrg     * Examples of malformed parameters:
6535c4bbdfSmrg     *    XWin -screen 1
6635c4bbdfSmrg     *    XWin -screen 0 -screen 2
6735c4bbdfSmrg     *    XWin -screen 1 -screen 2
6835c4bbdfSmrg     */
6935c4bbdfSmrg    if (!isEveryScreenExplicit()) {
7035c4bbdfSmrg        ErrorF("winValidateArgs - Malformed set of screen parameter(s).  "
7135c4bbdfSmrg               "Screens must be specified consecutively starting with "
7235c4bbdfSmrg               "screen 0.  That is, you cannot have only a screen 1, nor "
7335c4bbdfSmrg               "could you have screen 0 and screen 2.  You instead must "
7435c4bbdfSmrg               "have screen 0, or screen 0 and screen 1, respectively.  "
7535c4bbdfSmrg               "You can specify as many screens as you want.\n");
7635c4bbdfSmrg        return FALSE;
7705b261ecSmrg    }
7805b261ecSmrg
7935c4bbdfSmrg    /* Loop through all screens */
8035c4bbdfSmrg    for (i = 0; i < g_iNumScreens; ++i) {
8135c4bbdfSmrg        /*
8235c4bbdfSmrg         * Check for any combination of
83ed6184dfSmrg         * -multiwindow and -rootless.
8435c4bbdfSmrg         */
8535c4bbdfSmrg        {
8635c4bbdfSmrg            int iCount = 0;
8735c4bbdfSmrg
8835c4bbdfSmrg            /* Count conflicting options */
8935c4bbdfSmrg            if (g_ScreenInfo[i].fMultiWindow)
9035c4bbdfSmrg                ++iCount;
91ed6184dfSmrg
9235c4bbdfSmrg            if (g_ScreenInfo[i].fRootless)
9335c4bbdfSmrg                ++iCount;
9435c4bbdfSmrg
9535c4bbdfSmrg            /* Check if the first screen is without rootless and multiwindow */
9635c4bbdfSmrg            if (iCount == 0 && i == 0)
9735c4bbdfSmrg                fHasNormalScreen0 = TRUE;
9835c4bbdfSmrg
9935c4bbdfSmrg            /* Fail if two or more conflicting options */
10035c4bbdfSmrg            if (iCount > 1) {
101ed6184dfSmrg                ErrorF("winValidateArgs - Only one of -multiwindow "
10235c4bbdfSmrg                       "and -rootless can be specific at a time.\n");
10335c4bbdfSmrg                return FALSE;
10435c4bbdfSmrg            }
10535c4bbdfSmrg        }
10635c4bbdfSmrg
107ed6184dfSmrg        /* Check for -multiwindow and Xdmcp */
10835c4bbdfSmrg        /* allow xdmcp if screen 0 is normal. */
10935c4bbdfSmrg        if (g_fXdmcpEnabled && !fHasNormalScreen0 && (FALSE
11035c4bbdfSmrg                                                      || g_ScreenInfo[i].
11135c4bbdfSmrg                                                      fMultiWindow
1121b5d61b8Smrg
11335c4bbdfSmrg            )
11435c4bbdfSmrg            ) {
11535c4bbdfSmrg            ErrorF("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) "
116ed6184dfSmrg                   "is invalid with -multiwindow.\n");
11735c4bbdfSmrg            return FALSE;
11835c4bbdfSmrg        }
11935c4bbdfSmrg
120ed6184dfSmrg        /* Check for -multiwindow or -rootless and -fullscreen */
12135c4bbdfSmrg        if (g_ScreenInfo[i].fFullScreen && (FALSE
12235c4bbdfSmrg                                            || g_ScreenInfo[i].fMultiWindow
12335c4bbdfSmrg                                            || g_ScreenInfo[i].fRootless)
12435c4bbdfSmrg            ) {
12535c4bbdfSmrg            ErrorF("winValidateArgs - -fullscreen is invalid with "
126ed6184dfSmrg                   "-multiwindow or -rootless.\n");
12735c4bbdfSmrg            return FALSE;
12835c4bbdfSmrg        }
12935c4bbdfSmrg
130ed6184dfSmrg        /* Check for -multiwindow or -rootless and -nodecoration */
1311b5d61b8Smrg        if (!g_ScreenInfo[i].fDecoration && (FALSE
1321b5d61b8Smrg                                            || g_ScreenInfo[i].fMultiWindow
1331b5d61b8Smrg                                            || g_ScreenInfo[i].fRootless)
1341b5d61b8Smrg            ) {
1351b5d61b8Smrg            ErrorF("winValidateArgs - -nodecoration is invalid with "
136ed6184dfSmrg                   "-multiwindow or -rootless.\n");
1371b5d61b8Smrg            return FALSE;
1381b5d61b8Smrg        }
1391b5d61b8Smrg
14035c4bbdfSmrg        /* Check for !fullscreen and any fullscreen-only parameters */
14135c4bbdfSmrg        if (!g_ScreenInfo[i].fFullScreen
14235c4bbdfSmrg            && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_REFRESH
14335c4bbdfSmrg                || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_BPP)) {
14435c4bbdfSmrg            ErrorF("winValidateArgs - -refresh and -depth are only valid "
14535c4bbdfSmrg                   "with -fullscreen.\n");
14635c4bbdfSmrg            return FALSE;
14735c4bbdfSmrg        }
14835c4bbdfSmrg
14935c4bbdfSmrg        /* Check for fullscreen and any non-fullscreen parameters */
15035c4bbdfSmrg        if (g_ScreenInfo[i].fFullScreen
1511b5d61b8Smrg            && ((g_ScreenInfo[i].iResizeMode != resizeNotAllowed)
15235c4bbdfSmrg                || !g_ScreenInfo[i].fDecoration
15335c4bbdfSmrg                || g_ScreenInfo[i].fLessPointer)) {
15435c4bbdfSmrg            ErrorF("winValidateArgs - -fullscreen is invalid with "
15535c4bbdfSmrg                   "-scrollbars, -resize, -nodecoration, or -lesspointer.\n");
15635c4bbdfSmrg            return FALSE;
15735c4bbdfSmrg        }
158ed6184dfSmrg
159ed6184dfSmrg        /* Ignore -swcursor if -multiwindow -compositewm is requested */
160ed6184dfSmrg        if (g_ScreenInfo[i].fMultiWindow && g_ScreenInfo[i].fCompositeWM) {
161ed6184dfSmrg            if (g_fSoftwareCursor) {
162ed6184dfSmrg                g_fSoftwareCursor = FALSE;
163ed6184dfSmrg                winMsg(X_WARNING, "Ignoring -swcursor due to -compositewm\n");
164ed6184dfSmrg            }
165ed6184dfSmrg        }
16605b261ecSmrg    }
16705b261ecSmrg
16835c4bbdfSmrg    winDebug("winValidateArgs - Returning.\n");
16905b261ecSmrg
17035c4bbdfSmrg    return TRUE;
17105b261ecSmrg}
172