Skip to content

Commit

Permalink
fix: candidate window performance becomes bad when typing in 2nd high…
Browse files Browse the repository at this point in the history
… resolution monitor with higher dpi. (rime#1262)

* fix: candidate window performance becomes bad when typing in 2nd high
resolution monitor with higher dpi.

* perf: less object recreation when reset text format by dpi change or style change

* chore: initialize m_inputPos

---------

Co-authored-by: Yiming Sun <[email protected]>
  • Loading branch information
2 people authored and wxyzh committed May 27, 2024
1 parent 449faef commit 53860a6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "WeaselPanel.h"

#include <utility>
Expand Down Expand Up @@ -58,6 +58,7 @@ WeaselPanel::WeaselPanel(weasel::UI& ui)
m_ostyle(ui.ostyle()),
m_candidateCount(0),
m_current_zhung_icon(),
m_inputPos(CRect()),
m_sticky(false),
dpi(96),
hide_candidates(false),
Expand All @@ -77,6 +78,11 @@ WeaselPanel::WeaselPanel(weasel::UI& ui)
// for gdi+ drawings, initialization
GdiplusStartup(&_m_gdiplusToken, &_m_gdiplusStartupInput, NULL);

HMONITOR hMonitor = MonitorFromRect(m_inputPos, MONITOR_DEFAULTTONEAREST);
UINT dpiX = 96, dpiY = 96;
if (hMonitor)
GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
dpi = dpiX;
_InitFontRes();
m_ostyle = m_style;
}
Expand Down Expand Up @@ -170,8 +176,10 @@ void WeaselPanel::_InitFontRes(bool forced) {
// if style changed, or dpi changed, or pDWR NULL, re-initialize directwrite
// resources
if (forced || (pDWR == NULL) || (m_ostyle != m_style) || (dpiX != dpi)) {
pDWR.reset();
pDWR = std::make_shared<DirectWriteResources>(m_style, dpiX);
if (pDWR)
pDWR->InitResources(m_style, dpiX);
else
pDWR = std::make_shared<DirectWriteResources>(m_style, dpiX);
pDWR->pRenderTarget->SetTextAntialiasMode(
(D2D1_TEXT_ANTIALIAS_MODE)m_style.antialias_mode);
}
Expand Down Expand Up @@ -1055,7 +1063,6 @@ LRESULT WeaselPanel::OnCreate(UINT uMsg,
BOOL& bHandled) {
m_mouse_entry = false;
m_hoverIndex = -1;
GetWindowRect(&m_inputPos);
Refresh();
return TRUE;
}
Expand Down

0 comments on commit 53860a6

Please sign in to comment.