mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Windows] Add textScaleFactor support (flutter/engine#33316)
This commit is contained in:
parent
abb62f4cfe
commit
5bf7ff5530
@ -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<EventWatcherWin32>([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
|
||||
|
||||
@ -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<EventWatcherWin32> preferred_brightness_changed_watcher_{
|
||||
nullptr};
|
||||
std::unique_ptr<EventWatcherWin32> preferred_brightness_changed_watcher_;
|
||||
std::unique_ptr<EventWatcherWin32> text_scale_factor_changed_watcher_;
|
||||
|
||||
SettingsPluginWin32(const SettingsPluginWin32&) = delete;
|
||||
SettingsPluginWin32& operator=(const SettingsPluginWin32&) = delete;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user