mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-27 04:54:15 +01:00
[util] Introduce common functions to set, get and restore display modes
This commit is contained in:
parent
66503aeaa0
commit
4e16d65bb8
@ -1,4 +1,5 @@
|
||||
#include "util_monitor.h"
|
||||
#include "util_string.h"
|
||||
|
||||
#include "./log/log.h"
|
||||
|
||||
@ -9,6 +10,67 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
BOOL SetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
DEVMODEW* pMode) {
|
||||
::MONITORINFOEXW monInfo;
|
||||
monInfo.cbSize = sizeof(monInfo);
|
||||
|
||||
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
||||
Logger::err("Failed to query monitor info");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
Logger::info(str::format("Setting display mode: ",
|
||||
pMode->dmPelsWidth, "x", pMode->dmPelsHeight, "@",
|
||||
pMode->dmDisplayFrequency));
|
||||
|
||||
LONG status = ::ChangeDisplaySettingsExW(monInfo.szDevice,
|
||||
pMode, nullptr, CDS_FULLSCREEN, nullptr);
|
||||
|
||||
if (status != DISP_CHANGE_SUCCESSFUL) {
|
||||
pMode->dmFields &= ~DM_DISPLAYFREQUENCY;
|
||||
|
||||
status = ::ChangeDisplaySettingsExW(monInfo.szDevice,
|
||||
pMode, nullptr, CDS_FULLSCREEN, nullptr);
|
||||
}
|
||||
|
||||
return status == DISP_CHANGE_SUCCESSFUL;
|
||||
}
|
||||
|
||||
|
||||
BOOL GetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
DWORD modeNum,
|
||||
DEVMODEW* pMode) {
|
||||
::MONITORINFOEXW monInfo;
|
||||
monInfo.cbSize = sizeof(monInfo);
|
||||
|
||||
if (!::GetMonitorInfoW(hMonitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
||||
Logger::err("Failed to query monitor info");
|
||||
return false;
|
||||
}
|
||||
|
||||
return ::EnumDisplaySettingsW(monInfo.szDevice, modeNum, pMode);
|
||||
}
|
||||
|
||||
|
||||
BOOL RestoreMonitorDisplayMode(
|
||||
HMONITOR hMonitor) {
|
||||
DEVMODEW devMode = { };
|
||||
devMode.dmSize = sizeof(devMode);
|
||||
|
||||
if (!GetMonitorDisplayMode(hMonitor, ENUM_REGISTRY_SETTINGS, &devMode))
|
||||
return false;
|
||||
|
||||
Logger::info(str::format("Restoring display mode: ",
|
||||
devMode.dmPelsWidth, "x", devMode.dmPelsHeight, "@",
|
||||
devMode.dmDisplayFrequency));
|
||||
|
||||
return SetMonitorDisplayMode(hMonitor, &devMode);
|
||||
}
|
||||
|
||||
|
||||
void GetWindowClientSize(
|
||||
HWND hWnd,
|
||||
UINT* pWidth,
|
||||
|
@ -10,6 +10,40 @@ namespace dxvk {
|
||||
*/
|
||||
HMONITOR GetDefaultMonitor();
|
||||
|
||||
/**
|
||||
* \brief Sets monitor display mode
|
||||
*
|
||||
* Note that \c pMode may be altered by this function.
|
||||
* \param [in] hMonitor The monitor to change
|
||||
* \param [in] pMode The desired display mode
|
||||
* \returns \c true on success
|
||||
*/
|
||||
BOOL SetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
DEVMODEW* pMode);
|
||||
|
||||
/**
|
||||
* \brief Enumerates monitor display modes
|
||||
*
|
||||
* \param [in] hMonitor The monitor to query
|
||||
* \param [in] modeNum Mode number or enum
|
||||
* \param [in] pMode The display mode
|
||||
* \returns \c true on success
|
||||
*/
|
||||
BOOL GetMonitorDisplayMode(
|
||||
HMONITOR hMonitor,
|
||||
DWORD modeNum,
|
||||
DEVMODEW* pMode);
|
||||
|
||||
/**
|
||||
* \brief Change display mode to registry settings
|
||||
*
|
||||
* \param [in] hMonitor The monitor to change
|
||||
* \returns \c true on success
|
||||
*/
|
||||
BOOL RestoreMonitorDisplayMode(
|
||||
HMONITOR hMonitor);
|
||||
|
||||
/**
|
||||
* \brief Queries window client size
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user