Fix a bug that font size may be smaller than normal after toggling theming.
For example, the following steps will change the system metrics to incorrect values. 1. Open winecfg, and set DPI to 192. Do not restart winecfg. 2. Change the theme to Light. UXTHEME_BackupSystemMetrics() backs up system metrics in 96 DPI because the current DPI is still 96. 3. Restart winecfg and turn off theming. UXTHEME_RestoreSystemMetrics() restores system metrics in 192 DPI because the current DPI is 192. So system metrics will be scaled to 1/2 of the original size.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=37592 Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/uxtheme/msstyles.c | 4 ++++ dlls/uxtheme/system.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c index efabd06f7c0..7356f6ea354 100644 --- a/dlls/uxtheme/msstyles.c +++ b/dlls/uxtheme/msstyles.c @@ -838,12 +838,16 @@ static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state) { + DPI_AWARENESS_CONTEXT old_context; + if (state->metricsDirty) { + old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE); SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics), &state->metrics, 0); SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (state->iconTitleFont), &state->iconTitleFont, 0); + SetThreadDpiAwarenessContext(old_context); } }
diff --git a/dlls/uxtheme/system.c b/dlls/uxtheme/system.c index ca0dd228b2c..a467fc8b157 100644 --- a/dlls/uxtheme/system.c +++ b/dlls/uxtheme/system.c @@ -278,9 +278,12 @@ static void save_sys_colors (HKEY baseKey) * is deactivated */ static void UXTHEME_BackupSystemMetrics(void) { + DPI_AWARENESS_CONTEXT old_context; HKEY hKey; const struct BackupSysParam* bsp = backupSysParams;
+ old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE); + if (RegCreateKeyExW( HKEY_CURRENT_USER, szThemeManager, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0) == ERROR_SUCCESS) @@ -317,14 +320,19 @@ static void UXTHEME_BackupSystemMetrics(void)
RegCloseKey (hKey); } + + SetThreadDpiAwarenessContext(old_context); }
/* Read back old settings after a theme was deactivated */ static void UXTHEME_RestoreSystemMetrics(void) { + DPI_AWARENESS_CONTEXT old_context; HKEY hKey; const struct BackupSysParam* bsp = backupSysParams;
+ old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE); + if (RegOpenKeyExW (HKEY_CURRENT_USER, szThemeManager, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { @@ -404,6 +412,8 @@ static void UXTHEME_RestoreSystemMetrics(void)
RegCloseKey (hKey); } + + SetThreadDpiAwarenessContext(old_context); }
/* Make system settings persistent, so they're in effect even w/o uxtheme