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 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 is the 1-based index of the monitor to use
r_monitor 0 (default) = start-up on the primary monitor r_monitor 0 (default) = use the primary monitor
r_monitor N = start-up on monitor number N r_monitor N = use monitor number N
fix: fixed the start-up console window staying visible when starting in full-screen fix: fixed the start-up console window staying visible when starting in full-screen

View file

@ -37,7 +37,7 @@ typedef struct
HDC hDC; HDC hDC;
HGLRC hGLRC; HGLRC hGLRC;
HINSTANCE hinstOpenGL; HINSTANCE hinstOpenGL;
int desktopWidth, desktopHeight, desktopBPP; int desktopBPP;
qbool cdsFullscreen; qbool cdsFullscreen;
qbool pixelFormatSet; qbool pixelFormatSet;
int nPendingPF; 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 w = r.right - r.left;
const int h = r.bottom - r.top; const int h = r.bottom - r.top;
WIN_GetStartUpMonitorIndex();
const RECT monRect = g_wv.monitorRects[g_wv.monitor]; const RECT monRect = g_wv.monitorRects[g_wv.monitor];
int dx = 0; int dx = 0;
@ -549,14 +548,14 @@ static qbool GLW_SetMode( qbool cdsFullscreen )
{ {
HDC hDC = GetDC( GetDesktopWindow() ); HDC hDC = GetDC( GetDesktopWindow() );
glw_state.desktopBPP = GetDeviceCaps( hDC, BITSPIXEL ); glw_state.desktopBPP = GetDeviceCaps( hDC, BITSPIXEL );
glw_state.desktopWidth = GetDeviceCaps( hDC, HORZRES );
glw_state.desktopHeight = GetDeviceCaps( hDC, VERTRES );
ReleaseDC( GetDesktopWindow(), hDC ); ReleaseDC( GetDesktopWindow(), hDC );
glInfo.isFullscreen = cdsFullscreen; glInfo.isFullscreen = cdsFullscreen;
WIN_UpdateMonitorIndexFromCvar();
if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect ) ) { if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect ) ) {
glConfig.vidWidth = glw_state.desktopWidth; const RECT monRect = g_wv.monitorRects[g_wv.monitor];
glConfig.vidHeight = glw_state.desktopHeight; glConfig.vidWidth = monRect.right - monRect.left;
glConfig.vidHeight = monRect.bottom - monRect.top;
glConfig.windowAspect = (float)glConfig.vidWidth / glConfig.vidHeight; glConfig.windowAspect = (float)glConfig.vidWidth / glConfig.vidHeight;
cdsFullscreen = qfalse; cdsFullscreen = qfalse;
} }

View file

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

View file

@ -552,8 +552,6 @@ void Sys_Init()
// save out a couple things in rom cvars for the renderer to access // 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_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 ); EnumDisplayMonitors( NULL, NULL, &WIN_MonitorEnumCallback, 0 );
@ -596,17 +594,11 @@ static void WIN_GetMonitorList()
} }
void WIN_GetStartUpMonitorIndex() void WIN_UpdateMonitorIndexFromCvar()
{ {
static qbool called = qfalse; // r_monitor is the 1-based monitor index, 0 means primary monitor
// use Cvar_Get to enforce the latched change, if any
if ( called ) const int monitor = Cvar_Get( "r_monitor", "0", CVAR_ARCHIVE | CVAR_LATCH )->integer;
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;
if ( monitor <= 0 || monitor > g_wv.monitorCount ) if ( monitor <= 0 || monitor > g_wv.monitorCount )
{ {
g_wv.monitor = g_wv.primaryMonitor; 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 ); const HMONITOR hMonitor = MonitorFromWindow( g_wv.hWnd, MONITOR_DEFAULTTONEAREST );
for ( int i = 0; i < g_wv.monitorCount; i++ ) for ( int i = 0; i < g_wv.monitorCount; i++ )
@ -628,6 +620,17 @@ void WIN_GetMonitorIndexFromMainWindow()
break; 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; g_wv.hInstance = hInstance;
WIN_GetMonitorList(); WIN_InitMonitorList();
// done before Com/Sys_Init since we need this for error output // done before Com/Sys_Init since we need this for error output
Sys_CreateConsole(); Sys_CreateConsole();

View file

@ -245,6 +245,7 @@ LRESULT CALLBACK MainWndProc (
vid_xpos = Cvar_Get( "vid_xpos", "3", CVAR_ARCHIVE ); vid_xpos = Cvar_Get( "vid_xpos", "3", CVAR_ARCHIVE );
vid_ypos = Cvar_Get( "vid_ypos", "22", CVAR_ARCHIVE ); vid_ypos = Cvar_Get( "vid_ypos", "22", CVAR_ARCHIVE );
r_fullscreen = Cvar_Get( "r_fullscreen", "1", CVAR_ARCHIVE | CVAR_LATCH ); 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 ) if ( r_fullscreen->integer )
WIN_DisableAltTab(); WIN_DisableAltTab();
@ -273,7 +274,7 @@ LRESULT CALLBACK MainWndProc (
{ {
if (!r_fullscreen->integer ) if (!r_fullscreen->integer )
{ {
WIN_GetMonitorIndexFromMainWindow(); WIN_UpdateMonitorIndexFromMainWindow();
RECT r; RECT r;
r.left = 0; r.left = 0;