Skip to content

Commit

Permalink
Fix window locations under Per-Monitor DPI in Windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yukawa authored and coooooooozy committed Nov 25, 2023
1 parent 408ce37 commit 4af9688
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/renderer/win32/candidate_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ void CandidateWindow::OnDestroy() {
::PostQuitMessage(0);
}

void CandidateWindow::OnDpiChanged(UINT dpiX, UINT dpiY, RECT *rect) {
metrics_changed_ = true;
}

BOOL CandidateWindow::OnEraseBkgnd(CDCHandle dc) {
// We do not have to erase background
// because all pixels in client area will be drawn in the DoPaint method.
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/win32/candidate_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CandidateWindow : public ATL::CWindowImpl<CandidateWindow, ATL::CWindow,
BEGIN_MSG_MAP_EX(CandidateWindow)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_DPICHANGED(OnDpiChanged)
MSG_WM_ERASEBKGND(OnEraseBkgnd)
MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
MSG_WM_LBUTTONDOWN(OnLButtonDown)
Expand All @@ -93,6 +94,7 @@ class CandidateWindow : public ATL::CWindowImpl<CandidateWindow, ATL::CWindow,
~CandidateWindow();
LRESULT OnCreate(LPCREATESTRUCT create_struct);
void OnDestroy();
void OnDpiChanged(UINT dpiX, UINT dpiY, RECT *rect);
BOOL OnEraseBkgnd(WTL::CDCHandle dc);
void OnGetMinMaxInfo(MINMAXINFO *min_max_info);
void OnLButtonDown(UINT nFlags, CPoint point);
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/win32/infolist_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ void InfolistWindow::OnDestroy() {
::PostQuitMessage(0);
}

void InfolistWindow::OnDpiChanged(UINT dpiX, UINT dpiY, RECT *rect) {
metrics_changed_ = true;
}

BOOL InfolistWindow::OnEraseBkgnd(CDCHandle dc) {
// We do not have to erase background
// because all pixels in client area will be drawn in the DoPaint method.
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/win32/infolist_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class InfolistWindow : public ATL::CWindowImpl<InfolistWindow, ATL::CWindow,

BEGIN_MSG_MAP_EX(InfolistWindow)
MSG_WM_DESTROY(OnDestroy)
MSG_WM_DPICHANGED(OnDpiChanged)
MSG_WM_ERASEBKGND(OnEraseBkgnd)
MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
MSG_WM_SETTINGCHANGE(OnSettingChange)
Expand All @@ -83,6 +84,7 @@ class InfolistWindow : public ATL::CWindowImpl<InfolistWindow, ATL::CWindow,
InfolistWindow &operator=(const InfolistWindow &) = delete;
~InfolistWindow();
void OnDestroy();
void OnDpiChanged(UINT dpiX, UINT dpiY, RECT *rect);
BOOL OnEraseBkgnd(WTL::CDCHandle dc);
void OnGetMinMaxInfo(MINMAXINFO *min_max_info);
void OnPaint(WTL::CDCHandle dc);
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/win32/mozc_renderer.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
PerMonitorV2
</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

0 comments on commit 4af9688

Please sign in to comment.