diff --git a/src/Composition/CompositionProcessorEngine.cpp b/src/Composition/CompositionProcessorEngine.cpp index 6d20db28..6290a197 100644 --- a/src/Composition/CompositionProcessorEngine.cpp +++ b/src/Composition/CompositionProcessorEngine.cpp @@ -1041,6 +1041,21 @@ void CCompositionProcessorEngine::SetIMEMode(_In_ ITfThreadMgr *pThreadMgr, TfCl } } +/** + * @brief 获取当前 IME 的状态 + * + * @param pThreadMgr + * @param tfClientId + * @return BOOL True: 中文输入法打开, False: 中文输入法关闭 + */ +BOOL CCompositionProcessorEngine::GetIMEMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId) +{ + BOOL isOpen = FALSE; + CCompartment CompartmentKeyboardOpen(pThreadMgr, tfClientId, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); + CompartmentKeyboardOpen._GetCompartmentBOOL(isOpen); + return isOpen; +} + //+--------------------------------------------------------------------------- // // SetPunctuationMode @@ -1058,6 +1073,21 @@ void CCompositionProcessorEngine::SetPunctuationMode(_In_ ITfThreadMgr *pThreadM } } +/** + * @brief 获取当前标点符号模式 + * + * @param pThreadMgr + * @param tfClientId + * @return BOOL True: 中文标点符号打开, False: 中文标点符号关闭 + */ +BOOL CCompositionProcessorEngine::GetPunctuationMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId) +{ + BOOL isOpen = FALSE; + CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); + CompartmentPunctuation._GetCompartmentBOOL(isOpen); + return isOpen; +} + //+--------------------------------------------------------------------------- // // SetupConfiguration diff --git a/src/Composition/CompositionProcessorEngine.h b/src/Composition/CompositionProcessorEngine.h index 2d47eab0..41193c89 100644 --- a/src/Composition/CompositionProcessorEngine.h +++ b/src/Composition/CompositionProcessorEngine.h @@ -67,7 +67,9 @@ class CCompositionProcessorEngine // Toggle IME Mode void ToggleIMEMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); void SetIMEMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId, BOOL bOpen); + BOOL CCompositionProcessorEngine::GetIMEMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); void SetPunctuationMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId, BOOL bOpen); + BOOL GetPunctuationMode(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); // Punctuation BOOL IsPunctuation(WCHAR wch); diff --git a/src/IME/MetasequoiaIME.cpp b/src/IME/MetasequoiaIME.cpp index 35604455..2deac1de 100644 --- a/src/IME/MetasequoiaIME.cpp +++ b/src/IME/MetasequoiaIME.cpp @@ -616,6 +616,13 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar SendIMEActivationEventToUIProcessViaNamedPipe(); break; } + case WM_ThreadFocus: { + /* 通知 server 端更新一下 ftb 中英和标点的状态 */ + SendIMEStatusEventToUIProcessViaNamedPipe( // + pIME->GetCompositionProcessorEngine()->GetIMEMode(pIME->_GetThreadMgr(), pIME->_GetClientId()), // + pIME->GetCompositionProcessorEngine()->GetPunctuationMode(pIME->_GetThreadMgr(), pIME->_GetClientId())); + break; + } default: return DefWindowProc(hWnd, message, wParam, lParam); } diff --git a/src/IME/MetasequoiaIME.h b/src/IME/MetasequoiaIME.h index 4d56bddd..88492a7f 100644 --- a/src/IME/MetasequoiaIME.h +++ b/src/IME/MetasequoiaIME.h @@ -14,6 +14,7 @@ const DWORD WM_ConnectNamedpipe = WM_USER + 1; const DWORD WM_DisconnectNamedpipe = WM_USER + 2; const DWORD WM_ConnectToTsfNamedpipe = WM_USER + 3; const DWORD WM_IMEActivation = WM_USER + 4; +const DWORD WM_ThreadFocus = WM_USER + 5; LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND wndHandle, UINT uMsg, WPARAM wParam, LPARAM lParam); class CMetasequoiaIME : public ITfTextInputProcessorEx, diff --git a/src/IPC/Ipc.cpp b/src/IPC/Ipc.cpp index b0107377..44adf4e4 100644 --- a/src/IPC/Ipc.cpp +++ b/src/IPC/Ipc.cpp @@ -941,6 +941,36 @@ int SendIMEActivationEventToUIProcessViaNamedPipe() return 0; } +/** + * @brief Send IME status to UI process via named pipe + * + * @param kbdIsOpen + * @param puncIsOpen + * @return int + */ +int SendIMEStatusEventToUIProcessViaNamedPipe(bool kbdIsOpen, bool puncIsOpen) +{ + std::wstring status = L"ftbStatus"; + if (kbdIsOpen) + { + status += L"1"; + } + else + { + status += L"0"; + } + if (puncIsOpen) + { + status += L"1"; + } + else + { + status += L"0"; + } + SendToAuxNamedpipe(status); + return 0; +} + int SendIMEDeactivationEventToUIProcessViaNamedPipe() { SendToAuxNamedpipe(L"IMEDeactivation"); diff --git a/src/IPC/Ipc.h b/src/IPC/Ipc.h index 3726fe2e..f13836ec 100644 --- a/src/IPC/Ipc.h +++ b/src/IPC/Ipc.h @@ -117,6 +117,7 @@ int SendMoveCandidateWndEventToUIProcess(); int SendLangbarRightClickEventToUIProcess(const RECT *prcArea); int SendIMEActivationEventToUIProcessViaNamedPipe(); int SendIMEDeactivationEventToUIProcessViaNamedPipe(); +int SendIMEStatusEventToUIProcessViaNamedPipe(bool kbdIsOpen, bool puncIsOpen); int SendIMESwitchEventToUIProcessViaNamedPipe(UINT uImeStatus); int SendPuncSwitchEventToUIProcessViaNamedPipe(BOOL isPunc); diff --git a/src/Thread/ThreadFocusSink.cpp b/src/Thread/ThreadFocusSink.cpp index 783e3dfc..7a357b5d 100644 --- a/src/Thread/ThreadFocusSink.cpp +++ b/src/Thread/ThreadFocusSink.cpp @@ -13,6 +13,8 @@ STDAPI CMetasequoiaIME::OnSetThreadFocus() { + OutputDebugString(fmt::format(L"CMetasequoiaIME::OnSetThreadFocus").c_str()); + PostMessage(_msgWndHandle, WM_ThreadFocus, 0, 0); if (_pCandidateListUIPresenter) { ITfDocumentMgr *pCandidateListDocumentMgr = nullptr; @@ -39,6 +41,7 @@ STDAPI CMetasequoiaIME::OnSetThreadFocus() STDAPI CMetasequoiaIME::OnKillThreadFocus() { + OutputDebugString(fmt::format(L"CMetasequoiaIME::OnKillThreadFocus").c_str()); if (_pCandidateListUIPresenter) { ITfDocumentMgr *pCandidateListDocumentMgr = nullptr;