Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bazel/win32/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ bzl_library(
deps = ["//:build_defs_bzl"],
)

mozc_win32_lib(
name = "advapi32",
)

mozc_win32_lib(
name = "aux_ulib",
)
Expand Down
1 change: 1 addition & 0 deletions src/renderer/win32/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ mozc_cc_library(
tags = MOZC_TAGS.WIN_ONLY,
target_compatible_with = ["@platforms//os:windows"],
deps = [
"//bazel/win32:advapi32",
"//bazel/win32:shcore",
"//bazel/win32:user32",
"//protocol:renderer_cc_proto",
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/win32/candidate_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <memory>
#include <sstream>
#include <string>
#include <string_view>

#include "absl/log/check.h"
#include "absl/log/log.h"
Expand Down Expand Up @@ -424,7 +425,14 @@ void CandidateWindow::DoPaint(HDC dc) {
DrawFrame(dc);
}

void CandidateWindow::OnSettingChange(UINT uFlags, LPCTSTR /*lpszSection*/) {
void CandidateWindow::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) {
// Windows broadcasts "ImmersiveColorSet" when the light/dark mode changes.
if (lpszSection != nullptr &&
std::wstring_view(lpszSection) == L"ImmersiveColorSet") {
UpdateDpiDependentResources();
metrics_changed_ = true;
return;
}
// Since TextRenderer uses dialog font to render,
// we monitor font-related parameters to know when the font style is changed.
switch (uFlags) {
Expand Down
20 changes: 17 additions & 3 deletions src/renderer/win32/infolist_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <cstdint>
#include <string>
#include <string_view>

#include "base/coordinates.h"
#include "base/vlog.h"
Expand Down Expand Up @@ -250,6 +251,12 @@ Size InfolistWindow::DoPaintRow(HDC dc, int row, int ypos) {
ypos + title_rect.size.height + infostyle.row_rect_padding() +
desc_rect.size.height + infostyle.row_rect_padding());

// Use the candidate background so that the dark theme is applied too.
const RendererStyle::RGBAColor& background =
style_->candidate_style().background_color();
const COLORREF default_background_color =
RGB(background.r(), background.g(), background.b());

if (usages.has_focused_index() && (row == usages.focused_index())) {
const CRect selected_rect(
infostyle.window_border(), ypos,
Expand All @@ -272,15 +279,15 @@ Size InfolistWindow::DoPaintRow(HDC dc, int row, int ypos) {
title_style.background_color().g(),
title_style.background_color().b()));
} else {
FillSolidRect(dc, &title_back_crect, RGB(255, 255, 255));
FillSolidRect(dc, &title_back_crect, default_background_color);
}
if (desc_style.has_background_color()) {
FillSolidRect(dc, &desc_back_crect,
RGB(title_style.background_color().r(),
title_style.background_color().g(),
title_style.background_color().b()));
} else {
FillSolidRect(dc, &desc_back_crect, RGB(255, 255, 255));
FillSolidRect(dc, &desc_back_crect, default_background_color);
}
}

Expand All @@ -291,7 +298,14 @@ Size InfolistWindow::DoPaintRow(HDC dc, int row, int ypos) {
return Size(0, row_height);
}

void InfolistWindow::OnSettingChange(UINT uFlags, LPCTSTR /*lpszSection*/) {
void InfolistWindow::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) {
// Windows broadcasts "ImmersiveColorSet" when the light/dark mode changes.
if (lpszSection != nullptr &&
std::wstring_view(lpszSection) == L"ImmersiveColorSet") {
*style_ = GetScaledRendererStyle(dpi_);
metrics_changed_ = true;
return;
}
// Since TextRenderer uses dialog font to render,
// we monitor font-related parameters to know when the font style is changed.
switch (uFlags) {
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/win32/win32_dpi_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ void ScaleTextStyle(RendererStyle::TextStyle* text_style, double scale_factor) {
text_style->set_right_padding(text_style->right_padding() * scale_factor);
}

RendererStyleHandler::ColorTheme GetSystemColorTheme() {
// Windows exposes the "app mode" (light/dark) setting in this registry value.
// 0 means dark mode. The value may be missing on older Windows.
DWORD apps_use_light_theme = 1;
DWORD size = sizeof(apps_use_light_theme);
const LSTATUS result = ::RegGetValueW(
HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
L"AppsUseLightTheme", RRF_RT_REG_DWORD, nullptr, &apps_use_light_theme,
&size);
if (result == ERROR_SUCCESS && apps_use_light_theme == 0) {
return RendererStyleHandler::ColorTheme::kDark;
}
return RendererStyleHandler::ColorTheme::kLight;
}

} // namespace

double GetDPIScalingFactor(uint32_t dpi) {
Expand All @@ -68,7 +84,8 @@ uint32_t GetDpiForPoint(int x, int y) {
::mozc::renderer::RendererStyle GetScaledRendererStyle(uint32_t dpi) {
const double scale_factor = GetDPIScalingFactor(dpi);

RendererStyle style = RendererStyleHandler::GetRendererStyle();
RendererStyle style =
RendererStyleHandler::GetRendererStyle(GetSystemColorTheme());

// style.window_border is non-scalable.
style.set_scrollbar_width(style.scrollbar_width() * scale_factor);
Expand Down
Loading