From 97af71e9cfc24722bd658bb0181db74ca09b2995 Mon Sep 17 00:00:00 2001 From: fanlumaster <1730976608@qq.com> Date: Fri, 16 Jan 2026 22:47:37 +0800 Subject: [PATCH] feat: Synchronize floating toolbar status via IPC --- server/src/defines/defines.h | 3 ++- server/src/ipc/event_listener.cpp | 20 ++++++++++++++++++ server/src/webview2/windows_webview2.cpp | 27 ++++++++++++------------ server/src/webview2/windows_webview2.h | 2 +- server/src/window/ime_windows.cpp | 11 ++++++++-- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/server/src/defines/defines.h b/server/src/defines/defines.h index 27306d51..203e1b45 100644 --- a/server/src/defines/defines.h +++ b/server/src/defines/defines.h @@ -14,4 +14,5 @@ inline const UINT WM_LANGBAR_RIGHTCLICK = WM_USER + 102; inline const UINT WM_IMEACTIVATE = WM_USER + 103; inline const UINT WM_IMEDEACTIVATE = WM_USER + 104; inline const UINT WM_IMESWITCH = WM_USER + 105; -inline const UINT WM_PUNCSWITCH = WM_USER + 106; \ No newline at end of file +inline const UINT WM_PUNCSWITCH = WM_USER + 106; +inline const UINT UPDATE_FTB_STATUS = WM_USER + 107; \ No newline at end of file diff --git a/server/src/ipc/event_listener.cpp b/server/src/ipc/event_listener.cpp index 8a45c08a..20eb2b21 100644 --- a/server/src/ipc/event_listener.cpp +++ b/server/src/ipc/event_listener.cpp @@ -469,6 +469,26 @@ void AuxPipeEventListenerLoopThread() { PostMessage(::global_hwnd, WM_IMEDEACTIVATE, 0, 0); } + else if (boost::starts_with(message, L"ftbStatus")) + { + std::wstring ftbStatus = message.substr(9); + if (ftbStatus == L"11") // 中中 + { + PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 3, 0); + } + else if (ftbStatus == L"00") // 英英 + { + PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 0, 0); + } + else if (ftbStatus == L"10") // 中英 + { + PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 2, 0); + } + else if (ftbStatus == L"01") // 英中 + { + PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 1, 0); + } + } } } else diff --git a/server/src/webview2/windows_webview2.cpp b/server/src/webview2/windows_webview2.cpp index 2c5edf68..0cbd81ed 100644 --- a/server/src/webview2/windows_webview2.cpp +++ b/server/src/webview2/windows_webview2.cpp @@ -988,38 +988,37 @@ void UpdateFtbCnEnState(ComPtr webview, int cnEnState) * * @param webview * @param cnEnState 1: 中文, 0: 英文 + * @param puncState 1: 中文标点, 0: 英文标点 */ -void UpdateFtbCnEnAndPuncState(ComPtr webview, int cnEnState) +void UpdateFtbCnEnAndPuncState(ComPtr webview, int cnEnState, int puncState) { if (webview == nullptr) { return; } - + std::wstring script; + script.reserve(256); if (cnEnState == 1) { - std::wstring script; - script.reserve(256); - script.append(L"document.getElementById('cn').style.display = 'flex';"); script.append(L"document.getElementById('en').style.display = 'none';"); - script.append(L"document.getElementById('puncCn').style.display = 'flex';"); - script.append(L"document.getElementById('puncEn').style.display = 'none';"); - - webview->ExecuteScript(script.c_str(), nullptr); } else if (cnEnState == 0) { - std::wstring script; - script.reserve(256); - script.append(L"document.getElementById('cn').style.display = 'none';"); script.append(L"document.getElementById('en').style.display = 'flex';"); + } + if (puncState == 1) + { + script.append(L"document.getElementById('puncCn').style.display = 'flex';"); + script.append(L"document.getElementById('puncEn').style.display = 'none';"); + } + else if (puncState == 0) + { script.append(L"document.getElementById('puncCn').style.display = 'none';"); script.append(L"document.getElementById('puncEn').style.display = 'flex';"); - - webview->ExecuteScript(script.c_str(), nullptr); } + webview->ExecuteScript(script.c_str(), nullptr); } /** diff --git a/server/src/webview2/windows_webview2.h b/server/src/webview2/windows_webview2.h index e96832f2..b7923f5b 100644 --- a/server/src/webview2/windows_webview2.h +++ b/server/src/webview2/windows_webview2.h @@ -83,5 +83,5 @@ inline std::wstring HTMLStringFtbWnd = LR"()"; void InitWebviewFtbWnd(HWND hwnd); void UpdateFtbCnEnState(ComPtr webview, int cnEnState); -void UpdateFtbCnEnAndPuncState(ComPtr webview, int cnEnState); +void UpdateFtbCnEnAndPuncState(ComPtr webview, int cnEnState, int puncState); void UpdateFtbPuncState(ComPtr webview, int puncState); diff --git a/server/src/window/ime_windows.cpp b/server/src/window/ime_windows.cpp index a5dc330b..e7c2a013 100644 --- a/server/src/window/ime_windows.cpp +++ b/server/src/window/ime_windows.cpp @@ -394,12 +394,12 @@ LRESULT CALLBACK WndProcCandWindow(HWND hwnd, UINT message, WPARAM wParam, LPARA if (wParam == 0) // 此时是英文状态 { /* 更新 floating toolbar 的中英文状态为英文,同时更新标点的全角和半角状态 */ - UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 0); + UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 0, 0); } else // 此时是中文状态 { /* 更新 floating toolbar 的中英文状态为中文,同时更新标点的全角和半角状态 */ - UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 1); + UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 1, 1); } return 0; } @@ -626,6 +626,13 @@ LRESULT CALLBACK WndProcFtbWindow(HWND hwnd, UINT message, WPARAM wParam, LPARAM static int s_check_cnt = 0; switch (message) { + case UPDATE_FTB_STATUS: { + int cnEnState = (wParam >> 1) & 0x1; + int puncState = wParam & 0x1; + UpdateFtbCnEnAndPuncState(::webviewFtbWnd, cnEnState, puncState); + break; + } + case WM_TIMER: { if (wParam == TIMER_ID_MOVE_WEBVIEW_FTB) {