From abb1b32f2c6ed6b41e64e5839b5039d15a68c9ce Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 22 May 2016 18:19:58 +0200 Subject: [PATCH] Restore font smoothing settings --- DDrawCompat/CompatActivateAppHandler.cpp | 7 +++ DDrawCompat/CompatFontSmoothing.cpp | 57 ++++++++++++++++++++++++ DDrawCompat/CompatFontSmoothing.h | 21 +++++++++ DDrawCompat/DDrawCompat.vcxproj | 2 + DDrawCompat/DDrawCompat.vcxproj.filters | 6 +++ DDrawCompat/DllMain.cpp | 3 ++ 6 files changed, 96 insertions(+) create mode 100644 DDrawCompat/CompatFontSmoothing.cpp create mode 100644 DDrawCompat/CompatFontSmoothing.h diff --git a/DDrawCompat/CompatActivateAppHandler.cpp b/DDrawCompat/CompatActivateAppHandler.cpp index 371a4a7..8e44d8b 100644 --- a/DDrawCompat/CompatActivateAppHandler.cpp +++ b/DDrawCompat/CompatActivateAppHandler.cpp @@ -2,6 +2,7 @@ #include "CompatDirectDraw.h" #include "CompatDirectDrawSurface.h" #include "CompatDisplayMode.h" +#include "CompatFontSmoothing.h" #include "CompatGdi.h" #include "CompatPrimarySurface.h" #include "CompatPtr.h" @@ -16,6 +17,7 @@ namespace CompatWeakPtr g_fullScreenDirectDraw = nullptr; HWND g_fullScreenCooperativeWindow = nullptr; DWORD g_fullScreenCooperativeFlags = 0; + CompatFontSmoothing::SystemSettings g_fontSmoothingSettings = {}; HHOOK g_callWndProcHook = nullptr; void handleActivateApp(bool isActivated); @@ -42,6 +44,8 @@ namespace CompatDirectDrawSurface::fixSurfacePtrs(*primary); CompatGdi::invalidate(nullptr); } + + CompatFontSmoothing::setSystemSettings(g_fontSmoothingSettings); } void deactivateApp(CompatRef dd) @@ -53,6 +57,9 @@ namespace { ShowWindow(g_fullScreenCooperativeWindow, SW_SHOWMINNOACTIVE); } + + g_fontSmoothingSettings = CompatFontSmoothing::getSystemSettings(); + CompatFontSmoothing::setSystemSettings(CompatFontSmoothing::g_origSystemSettings); } LRESULT CALLBACK callWndProc(int nCode, WPARAM wParam, LPARAM lParam) diff --git a/DDrawCompat/CompatFontSmoothing.cpp b/DDrawCompat/CompatFontSmoothing.cpp new file mode 100644 index 0000000..0e092f1 --- /dev/null +++ b/DDrawCompat/CompatFontSmoothing.cpp @@ -0,0 +1,57 @@ +#define WIN32_LEAN_AND_MEAN + +#include + +#include "CompatFontSmoothing.h" + +namespace CompatFontSmoothing +{ + SystemSettings g_origSystemSettings = {}; + + bool SystemSettings::operator==(const SystemSettings& rhs) const + { + return isEnabled == rhs.isEnabled && + type == rhs.type && + contrast == rhs.contrast && + orientation == rhs.orientation; + } + + bool SystemSettings::operator!=(const SystemSettings& rhs) const + { + return !(*this == rhs); + } + + SystemSettings getSystemSettings() + { + SystemSettings settings = {}; + SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &settings.isEnabled, 0); + SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &settings.type, 0); + SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &settings.contrast, 0); + SystemParametersInfo(SPI_GETFONTSMOOTHINGORIENTATION, 0, &settings.orientation, 0); + return settings; + } + + void setSystemSettings(const SystemSettings& settings) + { + if (settings != getSystemSettings()) + { + setSystemSettingsForced(settings); + } + } + + void setSystemSettingsForced(const SystemSettings& settings) + { + SystemParametersInfo(SPI_SETFONTSMOOTHING, settings.isEnabled, nullptr, 0); + SystemParametersInfo(SPI_SETFONTSMOOTHINGTYPE, 0, + reinterpret_cast(settings.type), 0); + SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, + reinterpret_cast(settings.contrast), 0); + SystemParametersInfo(SPI_SETFONTSMOOTHINGORIENTATION, 0, + reinterpret_cast(settings.orientation), 0); + + const char* regKey = "FontSmoothing"; + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETFONTSMOOTHING, + reinterpret_cast(regKey), SMTO_BLOCK, 100, nullptr); + RedrawWindow(nullptr, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN); + } +} diff --git a/DDrawCompat/CompatFontSmoothing.h b/DDrawCompat/CompatFontSmoothing.h new file mode 100644 index 0000000..a416f71 --- /dev/null +++ b/DDrawCompat/CompatFontSmoothing.h @@ -0,0 +1,21 @@ +#pragma once + +namespace CompatFontSmoothing +{ + struct SystemSettings + { + BOOL isEnabled; + UINT type; + UINT contrast; + UINT orientation; + + bool operator==(const SystemSettings& rhs) const; + bool operator!=(const SystemSettings& rhs) const; + }; + + extern SystemSettings g_origSystemSettings; + + SystemSettings getSystemSettings(); + void setSystemSettings(const SystemSettings& settings); + void setSystemSettingsForced(const SystemSettings& settings); +} diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index e46fe32..ff1c001 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -147,6 +147,7 @@ + @@ -189,6 +190,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 523595d..9afef54 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -129,6 +129,9 @@ Header Files + + Header Files + @@ -212,6 +215,9 @@ Source Files + + Source Files + diff --git a/DDrawCompat/DllMain.cpp b/DDrawCompat/DllMain.cpp index b22a592..d8835fa 100644 --- a/DDrawCompat/DllMain.cpp +++ b/DDrawCompat/DllMain.cpp @@ -9,6 +9,7 @@ #include "CompatDirectDraw.h" #include "CompatDirectDrawSurface.h" #include "CompatDirectDrawPalette.h" +#include "CompatFontSmoothing.h" #include "CompatGdi.h" #include "CompatRegistry.h" #include "CompatPtr.h" @@ -183,6 +184,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/) SetProcessPriorityBoost(GetCurrentProcess(), disablePriorityBoost); SetProcessAffinityMask(GetCurrentProcess(), 1); SetThemeAppProperties(0); + CompatFontSmoothing::g_origSystemSettings = CompatFontSmoothing::getSystemSettings(); Time::init(); if (Compat::origProcs.SetAppCompatData) @@ -204,6 +206,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/) Compat::unhookAllFunctions(); FreeLibrary(g_origDInputModule); FreeLibrary(g_origDDrawModule); + CompatFontSmoothing::setSystemSettingsForced(CompatFontSmoothing::g_origSystemSettings); Compat::Log() << "DDrawCompat detached successfully"; }