Skip to content

Commit

Permalink
Video: Fixed resolution/size issues when entering exclusive fullscree…
Browse files Browse the repository at this point in the history
…n mode
  • Loading branch information
SourMesen committed Jul 15, 2024
1 parent bdbcf4e commit 83c0c5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 4 additions & 2 deletions UI/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,13 @@ public void ToggleFullscreen()
return;
}

WindowState = WindowState.FullScreen;

Task.Run(() => {
EmuApi.SetExclusiveFullscreenMode(true, TryGetPlatformHandle()?.Handle ?? IntPtr.Zero);
_preventFullscreenToggle = false;

Dispatcher.UIThread.Post(() => {
WindowState = WindowState.FullScreen;
});
});
} else {
WindowState = WindowState.FullScreen;
Expand Down
36 changes: 33 additions & 3 deletions Windows/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height)
_screenWidth != rendererSize.Width ||
_newFullscreen != _fullscreen ||
_useSrgbTextureFormat != cfg.UseSrgbTextureFormat ||
(_fullscreen && _fullscreenRefreshRate != refreshRate)
(_fullscreen && _fullscreenRefreshRate != refreshRate) ||
(_fullscreen && (_realScreenHeight != _monitorHeight || _realScreenWidth != _monitorWidth))
);
};

Expand Down Expand Up @@ -100,8 +101,15 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height)
_screenWidth = rendererSize.Width;

if(_fullscreen) {
_realScreenHeight = _monitorHeight;
_realScreenWidth = _monitorWidth;
if(_realScreenHeight != _monitorHeight) {
_realScreenHeight = _monitorHeight;
needReset = true;
}

if(_realScreenWidth != _monitorWidth) {
_realScreenWidth = _monitorWidth;
needReset = true;
}

//Ensure the screen width/height is smaller or equal to the fullscreen resolution, no matter the requested scale
if(_monitorHeight < _screenHeight || _monitorWidth < _screenWidth) {
Expand Down Expand Up @@ -349,6 +357,28 @@ HRESULT Renderer::InitDevice()
MessageManager::Log("SetFullscreenState(false) failed - Error:" + std::to_string(hr));
return hr;
}
} else {
//Get actual monitor resolution (which might differ from the one that was requested)
HMONITOR monitor = MonitorFromWindow(_hWnd, MONITOR_DEFAULTTOPRIMARY);
MONITORINFO info = {};
info.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(monitor, &info);

uint32_t monitorWidth = info.rcMonitor.right - info.rcMonitor.left;
uint32_t monitorHeight = info.rcMonitor.bottom - info.rcMonitor.top;

if(_monitorHeight != monitorHeight || _monitorWidth != monitorWidth) {
MessageManager::Log(
"Requested resolution (" + std::to_string(_monitorWidth) + "x" + std::to_string(_monitorHeight)
+ ") is not available. Resetting to nearest match instead: " +
std::to_string(monitorWidth) + "x" + std::to_string(monitorHeight)
);
_monitorWidth = monitorWidth;
_monitorHeight = monitorHeight;

//Make UI wait until this 2nd reset is over
_resetCounter--;
}
}
}

Expand Down

0 comments on commit 83c0c5e

Please sign in to comment.