Skip to content
Draft
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
18 changes: 18 additions & 0 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ bool WeaselPanel::IsCountingDown() const {
}

void WeaselPanel::ShowWindow(int nCmdShow) {
if (nCmdShow != SW_HIDE)
::KillTimer(m_hWnd, SHOW_DEFER_TIMER);
::ShowWindow(m_hWnd, nCmdShow);
if (m_pD2D) {
if (nCmdShow != SW_HIDE) {
Expand All @@ -158,6 +160,22 @@ void WeaselPanel::ShowWindow(int nCmdShow) {
}
}

void WeaselPanel::ShowDeferred(UINT ms) {
if (!m_hWnd)
return;
::KillTimer(m_hWnd, SHOW_DEFER_TIMER);
::SetTimer(m_hWnd, SHOW_DEFER_TIMER, ms, &WeaselPanel::OnShowDeferred);
}

VOID CALLBACK WeaselPanel::OnShowDeferred(HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime) {
::KillTimer(hwnd, idEvent);
// 兜底:个别宿主始终拿不到光标矩形时,也要把候选窗显示出来
::ShowWindow(hwnd, SW_SHOWNA);
}

void WeaselPanel::DestroyWindow() {
// clear timers before releasing window resources
_ClearTimers();
Expand Down
7 changes: 7 additions & 0 deletions WeaselUI/WeaselPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class WeaselPanel {

BOOL IsWindow() const;
void ShowWindow(int nCmdShow);
// 首次显示前若还没拿到本次输入的光标位置,延迟到位置到达或超时后再显示
void ShowDeferred(UINT ms);
static VOID CALLBACK OnShowDeferred(HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime);
void DestroyWindow();
// release all resources associated with this panel (window + shared devices)
void ReleaseAllResources();
Expand All @@ -34,6 +40,7 @@ class WeaselPanel {

static const int AUTOREV_TIMER = 20241209;
static const int AUTOHIDE_TIMER = 20241107;
static const UINT_PTR SHOW_DEFER_TIMER = 20250101;

HWND hwnd() const;

Expand Down
20 changes: 20 additions & 0 deletions WeaselUI/WeaselUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace weasel {
class UIImpl {
public:
WeaselPanel panel;
// 本次输入是否已经收到过有效的光标位置(见 UI::UpdateInputPosition)
bool has_position = false;
bool pending_show = false;
UIImpl(UI& ui) : panel(ui) {}
~UIImpl() {}
bool IsShown() const {
Expand All @@ -23,11 +26,22 @@ class UIImpl {
void Show() {
if (!panel.IsWindow())
return;
// TSF 侧的光标位置是异步取回的(WeaselTSF/Composition.cpp 里
// RequestEditSession(TF_ES_ASYNCDONTCARE)),若此处立刻显示,
// 候选窗会先画在上一段输入的位置再跳过去。先挂起,等位置到达后
// 由 UI::UpdateInputPosition 触发显示;ShowDeferred 负责超时兜底。
if (!has_position) {
pending_show = true;
panel.ShowDeferred(80);
return;
}
panel.ShowWindow(SW_SHOWNA);
}
void Hide() {
if (!panel.IsWindow())
return;
pending_show = false;
has_position = false;
panel.ShowWindow(SW_HIDE);
}
void ShowWithTimeout(size_t millisec) { panel.ShowWithTimeout(millisec); }
Expand All @@ -50,6 +64,12 @@ BOOL UI::IsShown() const {
void UI::UpdateInputPosition(RECT const& rc) {
if (pimpl_ && pimpl_->panel.IsWindow()) {
pimpl_->panel.MoveTo(rc);
pimpl_->has_position = true;
if (pimpl_->pending_show) {
// 位置已就绪,补上之前被挂起的显示
pimpl_->pending_show = false;
pimpl_->panel.ShowWindow(SW_SHOWNA);
}
}
}
void UI::Update(const Context& ctx, const Status& status) {
Expand Down