winvalargs.c revision 35c4bbdf
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
8335c4bbdfSmrg         * -multiwindow, -mwextwm, and -rootless.
8435c4bbdfSmrg         */
8535c4bbdfSmrg        {
8635c4bbdfSmrg            int iCount = 0;
8735c4bbdfSmrg
8835c4bbdfSmrg            /* Count conflicting options */
8905b261ecSmrg#ifdef XWIN_MULTIWINDOW
9035c4bbdfSmrg            if (g_ScreenInfo[i].fMultiWindow)
9135c4bbdfSmrg                ++iCount;
9205b261ecSmrg#endif
9305b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
9435c4bbdfSmrg            if (g_ScreenInfo[i].fMWExtWM)
9535c4bbdfSmrg                ++iCount;
9605b261ecSmrg#endif
9735c4bbdfSmrg            if (g_ScreenInfo[i].fRootless)
9835c4bbdfSmrg                ++iCount;
9935c4bbdfSmrg
10035c4bbdfSmrg            /* Check if the first screen is without rootless and multiwindow */
10135c4bbdfSmrg            if (iCount == 0 && i == 0)
10235c4bbdfSmrg                fHasNormalScreen0 = TRUE;
10335c4bbdfSmrg
10435c4bbdfSmrg            /* Fail if two or more conflicting options */
10535c4bbdfSmrg            if (iCount > 1) {
10635c4bbdfSmrg                ErrorF("winValidateArgs - Only one of -multiwindow, -mwextwm, "
10735c4bbdfSmrg                       "and -rootless can be specific at a time.\n");
10835c4bbdfSmrg                return FALSE;
10935c4bbdfSmrg            }
11035c4bbdfSmrg        }
11135c4bbdfSmrg
11235c4bbdfSmrg        /* Check for -multiwindow or -mwextwm and Xdmcp */
11335c4bbdfSmrg        /* allow xdmcp if screen 0 is normal. */
11435c4bbdfSmrg        if (g_fXdmcpEnabled && !fHasNormalScreen0 && (FALSE
11505b261ecSmrg#ifdef XWIN_MULTIWINDOW
11635c4bbdfSmrg                                                      || g_ScreenInfo[i].
11735c4bbdfSmrg                                                      fMultiWindow
11805b261ecSmrg#endif
11905b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
12035c4bbdfSmrg                                                      || g_ScreenInfo[i].
12135c4bbdfSmrg                                                      fMWExtWM
12205b261ecSmrg#endif
12335c4bbdfSmrg            )
12435c4bbdfSmrg            ) {
12535c4bbdfSmrg            ErrorF("winValidateArgs - Xdmcp (-query, -broadcast, or -indirect) "
12635c4bbdfSmrg                   "is invalid with -multiwindow or -mwextwm.\n");
12735c4bbdfSmrg            return FALSE;
12835c4bbdfSmrg        }
12935c4bbdfSmrg
13035c4bbdfSmrg        /* Check for -multiwindow, -mwextwm, or -rootless and fullscreen */
13135c4bbdfSmrg        if (g_ScreenInfo[i].fFullScreen && (FALSE
13205b261ecSmrg#ifdef XWIN_MULTIWINDOW
13335c4bbdfSmrg                                            || g_ScreenInfo[i].fMultiWindow
13405b261ecSmrg#endif
13505b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM
13635c4bbdfSmrg                                            || g_ScreenInfo[i].fMWExtWM
13705b261ecSmrg#endif
13835c4bbdfSmrg                                            || g_ScreenInfo[i].fRootless)
13935c4bbdfSmrg            ) {
14035c4bbdfSmrg            ErrorF("winValidateArgs - -fullscreen is invalid with "
14135c4bbdfSmrg                   "-multiwindow, -mwextwm, or -rootless.\n");
14235c4bbdfSmrg            return FALSE;
14335c4bbdfSmrg        }
14435c4bbdfSmrg
14535c4bbdfSmrg        /* Check for !fullscreen and any fullscreen-only parameters */
14635c4bbdfSmrg        if (!g_ScreenInfo[i].fFullScreen
14735c4bbdfSmrg            && (g_ScreenInfo[i].dwRefreshRate != WIN_DEFAULT_REFRESH
14835c4bbdfSmrg                || g_ScreenInfo[i].dwBPP != WIN_DEFAULT_BPP)) {
14935c4bbdfSmrg            ErrorF("winValidateArgs - -refresh and -depth are only valid "
15035c4bbdfSmrg                   "with -fullscreen.\n");
15135c4bbdfSmrg            return FALSE;
15235c4bbdfSmrg        }
15335c4bbdfSmrg
15435c4bbdfSmrg        /* Check for fullscreen and any non-fullscreen parameters */
15535c4bbdfSmrg        if (g_ScreenInfo[i].fFullScreen
15635c4bbdfSmrg            && ((g_ScreenInfo[i].iResizeMode != notAllowed)
15735c4bbdfSmrg                || !g_ScreenInfo[i].fDecoration
15835c4bbdfSmrg                || g_ScreenInfo[i].fLessPointer)) {
15935c4bbdfSmrg            ErrorF("winValidateArgs - -fullscreen is invalid with "
16035c4bbdfSmrg                   "-scrollbars, -resize, -nodecoration, or -lesspointer.\n");
16135c4bbdfSmrg            return FALSE;
16235c4bbdfSmrg        }
16305b261ecSmrg    }
16405b261ecSmrg
16535c4bbdfSmrg    winDebug("winValidateArgs - Returning.\n");
16605b261ecSmrg
16735c4bbdfSmrg    return TRUE;
16805b261ecSmrg}
169