Skip to content

Commit

Permalink
Fix issues with Borderless mode and High DPI resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
MadDeCoDeR committed Jan 6, 2023
1 parent cd522b1 commit 8cc3f2f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion neo/d3xp/menus/MenuScreen_Shell_SystemOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/
#pragma hdrstop

#include "precompiled.h"
#pragma hdrstop
#include "../Game_local.h"

const static int NUM_SYSTEM_OPTIONS_OPTIONS = 8;
Expand Down
24 changes: 24 additions & 0 deletions neo/renderer/RenderSystem_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,30 @@ void R_VidRestart_f( const idCmdArgs& args )

// set the mode without re-initializing the context
R_SetNewMode( false );
// GK: Borderless Mode resolution fixup.
// While we are in exclusive fullscreen we can control the monitor resolution alongside with the game's resolution.
// But in borderless we are limited to the System's resolution and without any DPI awareness System.
// So in that case after the game have exited the exclusive fullscreen mode check again if the game's resolution is bigger than the System's,
// if so then switch to the System's resolution in order to avoid the game's screen from being out of bounds.
if (r_fullscreen.GetInteger() == -1) {
idList<vidMode_t> modeList;
R_GetModeListForDisplay(0, modeList);
int maxW, maxH, maxHz;
R_GetScreenResolution(0, maxW, maxH, maxHz);
common->Printf("Max Width: %i, Max Height: %i\n", maxW, maxH);
if (r_customWidth.GetInteger() > maxW && r_customHeight.GetInteger() > maxH) {
for (int i = 0; i < modeList.Num(); i++) {
if (modeList[i].width == maxW && modeList[i].height == maxH) {
r_vidMode.SetInteger(i);
break;
}
}
r_customWidth.SetInteger(maxW);
r_customHeight.SetInteger(maxH);
}
cvarSystem->SetModifiedFlags(CVAR_ARCHIVE);
R_SetNewMode(false);
}
}

/*
Expand Down
11 changes: 9 additions & 2 deletions neo/sys/win32/win_glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,18 @@ bool R_GetModeListForDisplay( const unsigned requestedDisplayNum, idList<vidMode
}
unsigned previousWidth = 0;
unsigned previousHeight = 0;
int maxW, maxH, maxHz;
R_GetScreenResolution(displayNum - 1, maxW, maxH, maxHz);
for( int modeNum = 0 ; ; modeNum++ )
{
if( !EnumDisplaySettings( device.DeviceName, modeNum, &devmode ) )
{
break;
}

if (r_fullscreen.GetInteger() < 0 && devmode.dmPelsWidth > (uint)maxW && devmode.dmPelsHeight > (uint)maxH) {
continue;
}

if( devmode.dmBitsPerPel != 32 )
{
Expand Down Expand Up @@ -1508,14 +1514,15 @@ bool GLimp_Init( glimpParms_t parms )
parms.multiSamples, parms.stereo, parms.fullScreen );
#endif

// GK: High DPI Awareness setup. 2 different methods are used depending on what the client's OS can support, System-wide DPI Awareness (Win7,Win8 & 8.1) and PerMonitor v2 (Win10 or later) (Microsoft's recomended)
HMODULE hShell = LoadLibrary("user32.dll");
if (hShell) {
if (hShell) { // Win10 or later
SetProcessDPIAwarenessContext_t SetProcessDpiAwarenessContext = (SetProcessDPIAwarenessContext_t)GetProcAddress(hShell, "SetProcessDpiAwarenessContext");
if (SetProcessDpiAwarenessContext) {

SetProcessDpiAwarenessContext((BFA_DPI_AWARENESS_CONTEXT)-4); //DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
}
} else {
} else { // Win7, Win8 & 8.1
SetProcessDPIAware();
}

Expand Down

0 comments on commit 8cc3f2f

Please sign in to comment.