r_monitor is now latched, auto-updated and is used in every vid_restart call

fixed glConfig.vidWidth/Height when r_mode is set to use desktop res
This commit is contained in:
myT 2017-05-17 07:41:25 +02:00
parent 94541565b5
commit 8e2aafbdfd
6 changed files with 34 additions and 31 deletions

View File

@ -29,10 +29,10 @@ add: command history saving with con_history (default: 0)
chg: replaced id's Huffman codec code with something both simpler and much faster
add: improved multi-monitor support and added r_monitor to select the start-up monitor
add: improved multi-monitor support and added r_monitor to select the monitor
r_monitor is the 1-based index of the monitor to use
r_monitor 0 (default) = start-up on the primary monitor
r_monitor N = start-up on monitor number N
r_monitor 0 (default) = use the primary monitor
r_monitor N = use monitor number N
fix: fixed the start-up console window staying visible when starting in full-screen

View File

@ -37,7 +37,7 @@ typedef struct
HDC hDC;
HGLRC hGLRC;
HINSTANCE hinstOpenGL;
int desktopWidth, desktopHeight, desktopBPP;
int desktopBPP;
qbool cdsFullscreen;
qbool pixelFormatSet;
int nPendingPF;

View File

@ -471,7 +471,6 @@ static qbool GLW_CreateWindow( int width, int height, int colorbits )
const int w = r.right - r.left;
const int h = r.bottom - r.top;
WIN_GetStartUpMonitorIndex();
const RECT monRect = g_wv.monitorRects[g_wv.monitor];
int dx = 0;
@ -549,14 +548,14 @@ static qbool GLW_SetMode( qbool cdsFullscreen )
{
HDC hDC = GetDC( GetDesktopWindow() );
glw_state.desktopBPP = GetDeviceCaps( hDC, BITSPIXEL );
glw_state.desktopWidth = GetDeviceCaps( hDC, HORZRES );
glw_state.desktopHeight = GetDeviceCaps( hDC, VERTRES );
ReleaseDC( GetDesktopWindow(), hDC );
glInfo.isFullscreen = cdsFullscreen;
WIN_UpdateMonitorIndexFromCvar();
if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect ) ) {
glConfig.vidWidth = glw_state.desktopWidth;
glConfig.vidHeight = glw_state.desktopHeight;
const RECT monRect = g_wv.monitorRects[g_wv.monitor];
glConfig.vidWidth = monRect.right - monRect.left;
glConfig.vidHeight = monRect.bottom - monRect.top;
glConfig.windowAspect = (float)glConfig.vidWidth / glConfig.vidHeight;
cdsFullscreen = qfalse;
}

View File

@ -40,8 +40,8 @@ qbool IN_ProcessMessage( UINT msg, WPARAM wParam, LPARAM lParam ); // returns tr
void IN_Frame();
void IN_Shutdown();
void WIN_GetStartUpMonitorIndex();
void WIN_GetMonitorIndexFromMainWindow();
void WIN_UpdateMonitorIndexFromCvar();
void WIN_UpdateMonitorIndexFromMainWindow();
void WIN_UpdateResolution( int width, int height );
void SNDDMA_Activate();
@ -68,9 +68,9 @@ typedef struct
RECT monitorRects[MAX_MONITOR_COUNT];
HMONITOR hMonitors[MAX_MONITOR_COUNT];
int monitor; // index of the monitor currently used for display
int primaryMonitor;
int monitor; // 0-based index of the monitor currently used for display
int primaryMonitor; // 0-based index of the primary monitor
int monitorCount;
} WinVars_t;
extern WinVars_t g_wv;
extern WinVars_t g_wv;

View File

@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <VersionHelpers.h>
WinVars_t g_wv;
WinVars_t g_wv;
static qbool win_timePeriodActive = qfalse;
@ -552,8 +552,6 @@ void Sys_Init()
// save out a couple things in rom cvars for the renderer to access
Cvar_Get( "win_hinstance", va("%i", (int)g_wv.hInstance), CVAR_ROM );
//Cvar_Set( "username", Sys_GetCurrentUser() );
}
@ -578,7 +576,7 @@ static BOOL CALLBACK WIN_MonitorEnumCallback( HMONITOR hMonitor, HDC hdcMonitor,
}
static void WIN_GetMonitorList()
static void WIN_InitMonitorList()
{
EnumDisplayMonitors( NULL, NULL, &WIN_MonitorEnumCallback, 0 );
@ -596,17 +594,11 @@ static void WIN_GetMonitorList()
}
void WIN_GetStartUpMonitorIndex()
void WIN_UpdateMonitorIndexFromCvar()
{
static qbool called = qfalse;
if ( called )
return;
called = qtrue;
// r_monitor is the 1-based monitor index the user asks for
const int monitor = Cvar_Get( "r_monitor", "0", CVAR_ARCHIVE )->integer;
// r_monitor is the 1-based monitor index, 0 means primary monitor
// use Cvar_Get to enforce the latched change, if any
const int monitor = Cvar_Get( "r_monitor", "0", CVAR_ARCHIVE | CVAR_LATCH )->integer;
if ( monitor <= 0 || monitor > g_wv.monitorCount )
{
g_wv.monitor = g_wv.primaryMonitor;
@ -617,7 +609,7 @@ void WIN_GetStartUpMonitorIndex()
}
void WIN_GetMonitorIndexFromMainWindow()
void WIN_UpdateMonitorIndexFromMainWindow()
{
const HMONITOR hMonitor = MonitorFromWindow( g_wv.hWnd, MONITOR_DEFAULTTONEAREST );
for ( int i = 0; i < g_wv.monitorCount; i++ )
@ -628,6 +620,17 @@ void WIN_GetMonitorIndexFromMainWindow()
break;
}
}
// if r_monitor is 0 and we're already on the primary monitor,
// don't change the cvar to a non-zero number
if ( Cvar_VariableIntegerValue( "r_monitor" ) == 0 &&
g_wv.monitor == g_wv.primaryMonitor )
{
return;
}
// use the function to apply the change properly
Cvar_Set( "r_monitor", va( "%d", g_wv.monitor + 1 ) );
}
@ -642,7 +645,7 @@ int WINAPI WinMainImpl( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCm
g_wv.hInstance = hInstance;
WIN_GetMonitorList();
WIN_InitMonitorList();
// done before Com/Sys_Init since we need this for error output
Sys_CreateConsole();

View File

@ -245,6 +245,7 @@ LRESULT CALLBACK MainWndProc (
vid_xpos = Cvar_Get( "vid_xpos", "3", CVAR_ARCHIVE );
vid_ypos = Cvar_Get( "vid_ypos", "22", CVAR_ARCHIVE );
r_fullscreen = Cvar_Get( "r_fullscreen", "1", CVAR_ARCHIVE | CVAR_LATCH );
Cvar_Get( "r_monitor", "0", CVAR_ARCHIVE | CVAR_LATCH ); // 1-based monitor index, 0 means primary
if ( r_fullscreen->integer )
WIN_DisableAltTab();
@ -273,7 +274,7 @@ LRESULT CALLBACK MainWndProc (
{
if (!r_fullscreen->integer )
{
WIN_GetMonitorIndexFromMainWindow();
WIN_UpdateMonitorIndexFromMainWindow();
RECT r;
r.left = 0;