mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Added DisplayRefreshRate setting
This commit is contained in:
parent
0d85ab5dc6
commit
408ccee3d8
@ -7,6 +7,7 @@ namespace Config
|
||||
Settings::CpuAffinity cpuAffinity;
|
||||
Settings::DesktopColorDepth desktopColorDepth;
|
||||
Settings::DisplayFilter displayFilter;
|
||||
Settings::DisplayRefreshRate displayRefreshRate;
|
||||
Settings::DisplayResolution displayResolution;
|
||||
Settings::RenderColorDepth renderColorDepth;
|
||||
Settings::ResolutionScale resolutionScale;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <Config/Settings/CpuAffinity.h>
|
||||
#include <Config/Settings/DesktopColorDepth.h>
|
||||
#include <Config/Settings/DisplayFilter.h>
|
||||
#include <Config/Settings/DisplayRefreshRate.h>
|
||||
#include <Config/Settings/DisplayResolution.h>
|
||||
#include <Config/Settings/RenderColorDepth.h>
|
||||
#include <Config/Settings/ResolutionScale.h>
|
||||
@ -22,6 +23,7 @@ namespace Config
|
||||
extern Settings::CpuAffinity cpuAffinity;
|
||||
extern Settings::DesktopColorDepth desktopColorDepth;
|
||||
extern Settings::DisplayFilter displayFilter;
|
||||
extern Settings::DisplayRefreshRate displayRefreshRate;
|
||||
extern Settings::DisplayResolution displayResolution;
|
||||
extern Settings::RenderColorDepth renderColorDepth;
|
||||
extern Settings::ResolutionScale resolutionScale;
|
||||
|
36
DDrawCompat/Config/Settings/DisplayRefreshRate.cpp
Normal file
36
DDrawCompat/Config/Settings/DisplayRefreshRate.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <Config/Settings/DisplayRefreshRate.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
DisplayRefreshRate::DisplayRefreshRate()
|
||||
: MappedSetting("DisplayRefreshRate", "app", { {"app", APP}, {"desktop", DESKTOP} })
|
||||
{
|
||||
}
|
||||
|
||||
std::string DisplayRefreshRate::getValueStr() const
|
||||
{
|
||||
try
|
||||
{
|
||||
return MappedSetting::getValueStr();
|
||||
}
|
||||
catch (const ParsingError&)
|
||||
{
|
||||
return std::to_string(m_value);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayRefreshRate::setValue(const std::string& value)
|
||||
{
|
||||
try
|
||||
{
|
||||
MappedSetting::setValue(value);
|
||||
}
|
||||
catch (const ParsingError&)
|
||||
{
|
||||
m_value = Parser::parseInt(value, 1, MAXINT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
DDrawCompat/Config/Settings/DisplayRefreshRate.h
Normal file
22
DDrawCompat/Config/Settings/DisplayRefreshRate.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <Config/MappedSetting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
class DisplayRefreshRate : public MappedSetting<int>
|
||||
{
|
||||
public:
|
||||
static const int APP = 0;
|
||||
static const int DESKTOP = -1;
|
||||
|
||||
DisplayRefreshRate();
|
||||
|
||||
protected:
|
||||
std::string getValueStr() const override;
|
||||
void setValue(const std::string& value) override;
|
||||
};
|
||||
}
|
||||
}
|
@ -220,6 +220,7 @@
|
||||
<ClInclude Include="Config\Settings\CpuAffinity.h" />
|
||||
<ClInclude Include="Config\Settings\DesktopColorDepth.h" />
|
||||
<ClInclude Include="Config\Settings\DisplayFilter.h" />
|
||||
<ClInclude Include="Config\Settings\DisplayRefreshRate.h" />
|
||||
<ClInclude Include="Config\Settings\DisplayResolution.h" />
|
||||
<ClInclude Include="Config\Settings\RenderColorDepth.h" />
|
||||
<ClInclude Include="Config\Settings\ResolutionScale.h" />
|
||||
@ -343,6 +344,7 @@
|
||||
<ClCompile Include="Config\Settings\Antialiasing.cpp" />
|
||||
<ClCompile Include="Config\Settings\CpuAffinity.cpp" />
|
||||
<ClCompile Include="Config\Settings\DisplayFilter.cpp" />
|
||||
<ClCompile Include="Config\Settings\DisplayRefreshRate.cpp" />
|
||||
<ClCompile Include="Config\Settings\DisplayResolution.cpp" />
|
||||
<ClCompile Include="Config\Settings\ResolutionScale.cpp" />
|
||||
<ClCompile Include="Config\Settings\SupportedResolutions.cpp" />
|
||||
|
@ -516,6 +516,9 @@
|
||||
<ClInclude Include="Gdi\GuiThread.h">
|
||||
<Filter>Header Files\Gdi</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\Settings\DisplayRefreshRate.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Gdi\Gdi.cpp">
|
||||
@ -815,6 +818,9 @@
|
||||
<ClCompile Include="Gdi\GuiThread.cpp">
|
||||
<Filter>Source Files\Gdi</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Config\Settings\DisplayRefreshRate.cpp">
|
||||
<Filter>Source Files\Config\Settings</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="DDrawCompat.rc">
|
||||
|
@ -63,6 +63,9 @@ namespace
|
||||
BOOL WINAPI dwm8And16BitIsShimAppliedCallOut();
|
||||
BOOL WINAPI seComHookInterface(CLSID* clsid, GUID* iid, DWORD unk1, DWORD unk2);
|
||||
|
||||
template <typename Char>
|
||||
DWORD getConfiguredRefreshRate(const Char* deviceName);
|
||||
|
||||
template <typename Char>
|
||||
SIZE getConfiguredResolution(const Char* deviceName);
|
||||
|
||||
@ -125,6 +128,11 @@ namespace
|
||||
targetDevMode.dmFields |= DM_PELSHEIGHT;
|
||||
targetDevMode.dmPelsHeight = currDevMode.dmPelsHeight;
|
||||
}
|
||||
if (!(targetDevMode.dmFields & DM_DISPLAYFREQUENCY))
|
||||
{
|
||||
targetDevMode.dmFields |= DM_DISPLAYFREQUENCY;
|
||||
targetDevMode.dmDisplayFrequency = currDevMode.dmDisplayFrequency;
|
||||
}
|
||||
|
||||
emulatedResolution = makeSize(targetDevMode.dmPelsWidth, targetDevMode.dmPelsHeight);
|
||||
auto supportedDisplayModeMap(getSupportedDisplayModeMap(lpszDeviceName, 0));
|
||||
@ -137,23 +145,31 @@ namespace
|
||||
return DISP_CHANGE_BADMODE;
|
||||
}
|
||||
|
||||
DevMode<Char> dm = targetDevMode;
|
||||
SIZE resolutionOverride = getConfiguredResolution(lpszDeviceName);
|
||||
if (0 != resolutionOverride.cx)
|
||||
{
|
||||
DevMode<Char> dm = {};
|
||||
dm.dmSize = sizeof(dm);
|
||||
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
|
||||
dm.dmPelsWidth = resolutionOverride.cx;
|
||||
dm.dmPelsHeight = resolutionOverride.cy;
|
||||
}
|
||||
|
||||
DWORD refreshRateOverride = getConfiguredRefreshRate(lpszDeviceName);
|
||||
if (0 != refreshRateOverride)
|
||||
{
|
||||
dm.dmDisplayFrequency = refreshRateOverride;
|
||||
}
|
||||
|
||||
if (0 != resolutionOverride.cx || 0 != refreshRateOverride)
|
||||
{
|
||||
LONG result = origChangeDisplaySettingsEx(lpszDeviceName, &dm, nullptr, CDS_TEST, nullptr);
|
||||
if (DISP_CHANGE_SUCCESSFUL == result)
|
||||
{
|
||||
targetDevMode.dmPelsWidth = resolutionOverride.cx;
|
||||
targetDevMode.dmPelsHeight = resolutionOverride.cy;
|
||||
targetDevMode = dm;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ONCE("Failed to apply setting: DisplayResolution = " << dm.dmPelsWidth << 'x' << dm.dmPelsHeight);
|
||||
LOG_ONCE("Failed to apply custom display mode: "
|
||||
<< dm.dmPelsWidth << 'x' << dm.dmPelsHeight << '@' << dm.dmDisplayFrequency);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -352,6 +368,22 @@ namespace
|
||||
return CALL_ORIG_FUNC(GdiEntry13)() + g_displaySettingsUniquenessBias;
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
DWORD getConfiguredRefreshRate(const Char* deviceName)
|
||||
{
|
||||
auto refreshRate = Config::displayRefreshRate.get();
|
||||
if (Config::Settings::DisplayRefreshRate::DESKTOP == refreshRate)
|
||||
{
|
||||
DevMode<Char> dm = {};
|
||||
dm.dmSize = sizeof(dm);
|
||||
if (origEnumDisplaySettingsEx(deviceName, ENUM_REGISTRY_SETTINGS, &dm, 0))
|
||||
{
|
||||
refreshRate = dm.dmDisplayFrequency;
|
||||
}
|
||||
}
|
||||
return refreshRate;
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
SIZE getConfiguredResolution(const Char* deviceName)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user