Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform Per-Monitor DPI v2 protocol in Windows #831

Open
yukawa opened this issue Oct 21, 2023 · 0 comments
Open

Conform Per-Monitor DPI v2 protocol in Windows #831

yukawa opened this issue Oct 21, 2023 · 0 comments

Comments

@yukawa
Copy link
Collaborator

yukawa commented Oct 21, 2023

Description

Currently Mozc binaries fall into System DPI Awareness category in Windows.

We'd like to make them run under Per-Monitor v2 Awareness mode.

Version or commit-id

af20906

Environment

  • OS: Windows 11 22H2

Additional Context

src/gui/tool/mozc_tool.exe.manifest

<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>

Needs PerMonitorV2 declaration.

      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>

Also, it'd be safer to switch to Qt 6.6 or later version, which contains qt/qtbase@5e0d9a0.


src/renderer/win32/mozc_renderer.exe.manifest

<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>

Needs PerMonitorV2 declaration.

      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>

src/renderer/win32/indicator_window.cc

double GetDPIScaling() {
CDC desktop_dc(::GetDC(nullptr));
const int dpi_x = desktop_dc.GetDeviceCaps(LOGPIXELSX);
return static_cast<double>(dpi_x) / kDefaultDPI;
}

We can no longer assume this is a runtime constant.

BEGIN_MSG_MAP_EX(WindowImpl)
MSG_WM_CREATE(OnCreate)
MSG_WM_TIMER(OnTimer)
MSG_WM_SETTINGCHANGE(OnSettingChange)
END_MSG_MAP()

We also need to handle WM_DPICHANGED.


src/renderer/win32/candidate_window.h

BEGIN_MSG_MAP_EX(CandidateWindow)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_ERASEBKGND(OnEraseBkgnd)
MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
MSG_WM_LBUTTONDOWN(OnLButtonDown)
MSG_WM_LBUTTONUP(OnLButtonUp)
MSG_WM_MOUSEMOVE(OnMouseMove)
MSG_WM_SETTINGCHANGE(OnSettingChange)
MSG_WM_PAINT(OnPaint)
MSG_WM_PRINTCLIENT(OnPrintClient)
END_MSG_MAP()

We also need to handle WM_DPICHANGED.


src/renderer/win32/candidate_window.cc

double scale_factor_x = 1.0;
double scale_factor_y = 1.0;
RendererStyleHandler::GetDPIScalingFactor(&scale_factor_x, &scale_factor_y);
double image_scale_factor = 1.0;
if (scale_factor_x < 1.125 || scale_factor_y < 1.125) {
footer_logo_.Attach(LoadBitmapFromResource(::GetModuleHandle(nullptr),
IDB_FOOTER_LOGO_COLOR_100));
image_scale_factor = 1.0;
} else if (scale_factor_x < 1.375 || scale_factor_y < 1.375) {
footer_logo_.Attach(LoadBitmapFromResource(::GetModuleHandle(nullptr),
IDB_FOOTER_LOGO_COLOR_125));
image_scale_factor = 1.25;
} else if (scale_factor_x < 1.75 || scale_factor_y < 1.75) {
footer_logo_.Attach(LoadBitmapFromResource(::GetModuleHandle(nullptr),
IDB_FOOTER_LOGO_COLOR_150));
image_scale_factor = 1.5;
} else {
footer_logo_.Attach(LoadBitmapFromResource(::GetModuleHandle(nullptr),
IDB_FOOTER_LOGO_COLOR_200));
image_scale_factor = 2.0;
}
// If DPI is not default value, re-calculate the size based on the DPI.
if (!footer_logo_.IsNull()) {
CSize size;
footer_logo_.GetSize(size);
size.cx *= (scale_factor_x / image_scale_factor);
size.cy *= (scale_factor_y / image_scale_factor);
footer_logo_display_size_ = Size(size.cx, size.cy);
}
indicator_width_ = kIndicatorWidthInDefaultDPI * scale_factor_x;

scale_factor_x and scale_factor_y are no longer the runtime constants. We need to re-calculate these values every time WM_DPICHANGED is received.


src/win32/tip/tip_lang_bar_menu.cc

LoadIconFromResource should use GetSystemMetricsForDpi with primary display's DPI no matter which display is used to show the application, because the IME mode icon is shown only on the primary display.

HICON LoadIconFromResource(HINSTANCE instance, UINT icon_id) {
const auto icon_size = ::GetSystemMetrics(SM_CYSMICON);
// Replace some text icons with on-the-fly image drawn with MS-Gothic.
const auto &icon_text = GetIconStringIfNecessary(icon_id);
if (!icon_text.empty()) {
const COLORREF text_color = ::GetSysColor(COLOR_WINDOWTEXT);
return TextIcon::CreateMonochromeIcon(icon_size, icon_size, icon_text,
kTextIconFont, text_color);
}
return static_cast<HICON>(::LoadImage(instance, MAKEINTRESOURCE(icon_id),
IMAGE_ICON, icon_size, icon_size,
LR_CREATEDIBSECTION));
}

hiroyuki-komatsu pushed a commit that referenced this issue Oct 23, 2023
This is a minimum change to place candidate windows around the cursor
location even under Per-Monitor DPI mode in Windows.

Note that there are still known issues that 'mozc_render' continues
using the initial DPI.  Watch #831 for such remaining issues.

Closes #832.

PiperOrigin-RevId: 575633393
hiroyuki-komatsu pushed a commit that referenced this issue Oct 23, 2023
With this commit macOS and Windows builds switch to Qt 6.6.0 [1], which
contains an important commit for Per-Monitor DPI support in Windows [2]
as discussed in #831.

Note that '-no-feature-systemsemaphore' needs to be removed as otherwise
the build fails in macOS.

 [1]: https://code.qt.io/cgit/qt/qtreleasenotes.git/about/qt/6.6.0/release-note.md
 [2]: qt/qtbase@5e0d9a0

PiperOrigin-RevId: 575700086
hiroyuki-komatsu pushed a commit that referenced this issue Oct 23, 2023
This is part of our on-going effort to make Mozc binaries comply with
Per Monitor DPI V2 protocol in Windows (#831).

With this commit, 'mozc_renderer' process starts running under
Per Monitor DPI V2 mode, and Qt 6.6 also correctly recognizes it at run
time [1].

 [1]: qt/qtbase@5e0d9a0

PiperOrigin-RevId: 575708085
coooooooozy pushed a commit to coooooooozy/mozc that referenced this issue Nov 26, 2023
This is a minimum change to place candidate windows around the cursor
location even under Per-Monitor DPI mode in Windows.

Note that there are still known issues that 'mozc_render' continues
using the initial DPI.  Watch google#831 for such remaining issues.

Closes google#832.

PiperOrigin-RevId: 575633393
coooooooozy pushed a commit to coooooooozy/mozc that referenced this issue Nov 26, 2023
With this commit macOS and Windows builds switch to Qt 6.6.0 [1], which
contains an important commit for Per-Monitor DPI support in Windows [2]
as discussed in google#831.

Note that '-no-feature-systemsemaphore' needs to be removed as otherwise
the build fails in macOS.

 [1]: https://code.qt.io/cgit/qt/qtreleasenotes.git/about/qt/6.6.0/release-note.md
 [2]: qt/qtbase@5e0d9a0

PiperOrigin-RevId: 575700086
coooooooozy pushed a commit to coooooooozy/mozc that referenced this issue Nov 26, 2023
This is part of our on-going effort to make Mozc binaries comply with
Per Monitor DPI V2 protocol in Windows (google#831).

With this commit, 'mozc_renderer' process starts running under
Per Monitor DPI V2 mode, and Qt 6.6 also correctly recognizes it at run
time [1].

 [1]: qt/qtbase@5e0d9a0

PiperOrigin-RevId: 575708085
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant