Esempio n. 1
0
/*
===================
GLW_ChangeDislaySettingsIfNeeded

Optionally ChangeDisplaySettings to get a different fullscreen resolution.
Default uses the full desktop resolution.
===================
*/
static bool GLW_ChangeDislaySettingsIfNeeded( glimpParms_t parms ) {
    // If we had previously changed the display settings on a different monitor,
    // go back to standard.
    if ( win32.cdsFullscreen != 0 && win32.cdsFullscreen != parms.fullScreen ) {
        win32.cdsFullscreen = 0;
        ChangeDisplaySettings( 0, 0 );
        Sys_Sleep( 1000 ); // Give the driver some time to think about this change
    }

    // 0 is dragable mode on desktop, -1 is borderless window on desktop
    if ( parms.fullScreen <= 0 ) {
        return true;
    }

    // if we are already in the right resolution, don't do a ChangeDisplaySettings
    int x, y, width, height, displayHz;

    if ( !GetDisplayCoordinates( parms.fullScreen - 1, x, y, width, height, displayHz ) ) {
        return false;
    }
    if ( width == parms.width && height == parms.height && ( displayHz == parms.displayHz || parms.displayHz == 0 ) ) {
        return true;
    }

    DEVMODE dm = {};

    dm.dmSize = sizeof( dm );

    dm.dmPelsWidth  = parms.width;
    dm.dmPelsHeight = parms.height;
    dm.dmBitsPerPel = 32;
    dm.dmFields     = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
    if ( parms.displayHz != 0 ) {
        dm.dmDisplayFrequency = parms.displayHz;
        dm.dmFields |= DM_DISPLAYFREQUENCY;
    }

    common->Printf( "...calling CDS: " );

    const char * const deviceName = GetDisplayName( parms.fullScreen - 1 );

    int		cdsRet;
    if ( ( cdsRet = ChangeDisplaySettingsEx(
                        deviceName,
                        &dm,
                        NULL,
                        CDS_FULLSCREEN,
                        NULL) ) == DISP_CHANGE_SUCCESSFUL ) {
        common->Printf( "ok\n" );
        win32.cdsFullscreen = parms.fullScreen;
        return true;
    }

    common->Printf( "^3failed^0, " );
    PrintCDSError( cdsRet );
    return false;
}
Esempio n. 2
0
/*
====================
GLW_GetWindowDimensions
====================
*/
static bool GLW_GetWindowDimensions( const glimpParms_t parms, int& x, int& y, int& w, int& h )
{
	//
	// compute width and height
	//
	if( parms.fullScreen != 0 )
	{
		if( parms.fullScreen == -1 )
		{
			// borderless window at specific location, as for spanning
			// multiple monitor outputs
			x = parms.x;
			y = parms.y;
			w = parms.width;
			h = parms.height;
		}
		else
		{
			// get the current monitor position and size on the desktop, assuming
			// any required ChangeDisplaySettings has already been done
			int displayHz = 0;
			if( !GetDisplayCoordinates( parms.fullScreen - 1, x, y, w, h, displayHz ) )
			{
				return false;
			}
		}
	}
	else
	{
		RECT	r;
		
		// adjust width and height for window border
		r.bottom = parms.height;
		r.left = 0;
		r.top = 0;
		r.right = parms.width;
		
		AdjustWindowRect( &r, WINDOW_STYLE | WS_SYSMENU, FALSE );
		
		w = r.right - r.left;
		h = r.bottom - r.top;
		
		x = parms.x;
		y = parms.y;
	}
	
	return true;
}