diff --git a/engine/src/flutter/shell/platform/windows/settings_plugin_win32.cc b/engine/src/flutter/shell/platform/windows/settings_plugin_win32.cc index 0da7e2ac5b0..9355dab5662 100644 --- a/engine/src/flutter/shell/platform/windows/settings_plugin_win32.cc +++ b/engine/src/flutter/shell/platform/windows/settings_plugin_win32.cc @@ -12,6 +12,10 @@ namespace { constexpr wchar_t kGetPreferredBrightnessRegKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; constexpr wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; + +constexpr wchar_t kGetTextScaleFactorRegKey[] = + L"Software\\Microsoft\\Accessibility"; +constexpr wchar_t kGetTextScaleFactorRegValue[] = L"TextScaleFactor"; } // namespace // static @@ -26,21 +30,28 @@ SettingsPluginWin32::SettingsPluginWin32(BinaryMessenger* messenger, : SettingsPlugin(messenger, task_runner) { RegOpenKeyEx(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, RRF_RT_REG_DWORD, KEY_NOTIFY, &preferred_brightness_reg_hkey_); + RegOpenKeyEx(HKEY_CURRENT_USER, kGetTextScaleFactorRegKey, RRF_RT_REG_DWORD, + KEY_NOTIFY, &text_scale_factor_reg_hkey_); } SettingsPluginWin32::~SettingsPluginWin32() { StopWatching(); RegCloseKey(preferred_brightness_reg_hkey_); + RegCloseKey(text_scale_factor_reg_hkey_); } void SettingsPluginWin32::StartWatching() { - if (preferred_brightness_reg_hkey_ != NULL) { + if (preferred_brightness_reg_hkey_ != nullptr) { WatchPreferredBrightnessChanged(); } + if (text_scale_factor_reg_hkey_ != nullptr) { + WatchTextScaleFactorChanged(); + } } void SettingsPluginWin32::StopWatching() { preferred_brightness_changed_watcher_ = nullptr; + text_scale_factor_changed_watcher_ = nullptr; } bool SettingsPluginWin32::GetAlwaysUse24HourFormat() { @@ -48,7 +59,18 @@ bool SettingsPluginWin32::GetAlwaysUse24HourFormat() { } float SettingsPluginWin32::GetTextScaleFactor() { - return 1.0; + DWORD text_scale_factor; + DWORD text_scale_factor_size = sizeof(text_scale_factor); + LONG result = RegGetValue( + HKEY_CURRENT_USER, kGetTextScaleFactorRegKey, kGetTextScaleFactorRegValue, + RRF_RT_REG_DWORD, nullptr, &text_scale_factor, &text_scale_factor_size); + + if (result == 0) { + return text_scale_factor / 100.0; + } else { + // The current OS does not have text scale factor. + return 1.0; + } } SettingsPlugin::PlatformBrightness @@ -83,4 +105,18 @@ void SettingsPluginWin32::WatchPreferredBrightnessChanged() { preferred_brightness_changed_watcher_->GetHandle(), TRUE); } +void SettingsPluginWin32::WatchTextScaleFactorChanged() { + text_scale_factor_changed_watcher_ = + std::make_unique([this]() { + task_runner_->PostTask([this]() { + SendSettings(); + WatchTextScaleFactorChanged(); + }); + }); + + RegNotifyChangeKeyValue( + text_scale_factor_reg_hkey_, FALSE, REG_NOTIFY_CHANGE_LAST_SET, + text_scale_factor_changed_watcher_->GetHandle(), TRUE); +} + } // namespace flutter diff --git a/engine/src/flutter/shell/platform/windows/settings_plugin_win32.h b/engine/src/flutter/shell/platform/windows/settings_plugin_win32.h index a5d2b30cfb1..5d66a169b06 100644 --- a/engine/src/flutter/shell/platform/windows/settings_plugin_win32.h +++ b/engine/src/flutter/shell/platform/windows/settings_plugin_win32.h @@ -39,11 +39,13 @@ class SettingsPluginWin32 : public SettingsPlugin { private: void WatchPreferredBrightnessChanged(); + void WatchTextScaleFactorChanged(); - HKEY preferred_brightness_reg_hkey_ = NULL; + HKEY preferred_brightness_reg_hkey_ = nullptr; + HKEY text_scale_factor_reg_hkey_ = nullptr; - std::unique_ptr preferred_brightness_changed_watcher_{ - nullptr}; + std::unique_ptr preferred_brightness_changed_watcher_; + std::unique_ptr text_scale_factor_changed_watcher_; SettingsPluginWin32(const SettingsPluginWin32&) = delete; SettingsPluginWin32& operator=(const SettingsPluginWin32&) = delete;