From ffc0709ce3c8cf75a5425c46e18b9705d66b0c3e Mon Sep 17 00:00:00 2001 From: fanlumaster <1730976608@qq.com> Date: Sat, 14 Mar 2026 00:44:14 +0800 Subject: [PATCH] wrap log with macros --- .clangd | 2 +- CMakeLists.txt | 6 +-- .../CompositionProcessorEngine.cpp | 2 +- src/IME/MetasequoiaIME.cpp | 44 ++++++++++++++++++- src/IPC/Ipc.cpp | 12 ++++- src/Key/KeyHandler.cpp | 2 + src/LanguageBar/LanguageBar.cpp | 9 ++-- src/Thread/ThreadFocusSink.cpp | 4 ++ src/UI/CandidateListUIPresenter.cpp | 3 +- src/Utils/FanyUtils.cpp | 2 + 10 files changed, 72 insertions(+), 14 deletions(-) diff --git a/.clangd b/.clangd index 475137f3..cc010f2c 100644 --- a/.clangd +++ b/.clangd @@ -4,7 +4,7 @@ CompileFlags: # Macros -DUNICODE, -D_UNICODE, - # -DFANY_DEBUG, + -DFANY_DEBUG, # Project src include paths "-IC:/Users/sonnycalcr/EDisk/CppCodes/IMECodes/MetasequoiaImeTsf/src", "-IC:/Users/sonnycalcr/EDisk/CppCodes/IMECodes/MetasequoiaImeTsf/src/Candidate", diff --git a/CMakeLists.txt b/CMakeLists.txt index d5fbd496..d67cdbed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,9 @@ add_definitions( # For utf8cpp, make it use C++11 and later add_compile_options(/Zc:__cplusplus) -# add_definitions( -# /DFANY_DEBUG=1 -# ) +add_definitions( + /DFANY_DEBUG=1 +) # fmt find_package(fmt CONFIG REQUIRED) diff --git a/src/Composition/CompositionProcessorEngine.cpp b/src/Composition/CompositionProcessorEngine.cpp index bf26b189..9bf132e0 100644 --- a/src/Composition/CompositionProcessorEngine.cpp +++ b/src/Composition/CompositionProcessorEngine.cpp @@ -1452,7 +1452,7 @@ HRESULT CCompositionProcessorEngine::CompartmentCallback(_In_ void *pv, REFGUID { CompartmentPunctuation._SetCompartmentBOOL(FALSE); } - + // SendIMESwitchEventToUIProcessViaNamedPipe(isOpen ? 1 : 0); PostMessage(Global::msgWndHandle, WM_UpdateIMEStatus, (WPARAM)(isOpen ? 1 : 0), 0); diff --git a/src/IME/MetasequoiaIME.cpp b/src/IME/MetasequoiaIME.cpp index 43e463b0..e40a2aba 100644 --- a/src/IME/MetasequoiaIME.cpp +++ b/src/IME/MetasequoiaIME.cpp @@ -412,9 +412,11 @@ STDAPI CMetasequoiaIME::Deactivate() hrProfile = pProfileMgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &profile); if (SUCCEEDED(hrProfile) && !IsEqualCLSID(profile.clsid, Global::MetasequoiaIMECLSID)) { - // 向 server 端发送一个输入法真的切换到了别的输入法的消息 - // 只有接收到这个消息,才可以隐藏 ftb +// 向 server 端发送一个输入法真的切换到了别的输入法的消息 +// 只有接收到这个消息,才可以隐藏 ftb +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Truely deactivate IME and switch to another.").c_str()); +#endif SendIMEDeactivationEventToUIProcessViaNamedPipe(); } @@ -556,7 +558,9 @@ void CMetasequoiaIME::IpcWorkerThread(CMetasequoiaIME *pIME) WM_CheckGlobalCompartment, // Global::DataToTsfWorkerThreadMsgType::SwitchToEnglish, // 0); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to English").c_str()); +#endif } else if (buf.msg_type == Global::DataToTsfWorkerThreadMsgType::SwitchToChinese) { @@ -565,7 +569,9 @@ void CMetasequoiaIME::IpcWorkerThread(CMetasequoiaIME *pIME) WM_CheckGlobalCompartment, // Global::DataToTsfWorkerThreadMsgType::SwitchToChinese, // 0); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to Chinese").c_str()); +#endif } else if (buf.msg_type == Global::DataToTsfWorkerThreadMsgType::SwitchToPuncEn) { @@ -574,7 +580,9 @@ void CMetasequoiaIME::IpcWorkerThread(CMetasequoiaIME *pIME) WM_CheckGlobalCompartment, // Global::DataToTsfWorkerThreadMsgType::SwitchToPuncEn, // 0); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to Punc En").c_str()); +#endif } else if (buf.msg_type == Global::DataToTsfWorkerThreadMsgType::SwitchToPuncCn) { @@ -583,7 +591,9 @@ void CMetasequoiaIME::IpcWorkerThread(CMetasequoiaIME *pIME) WM_CheckGlobalCompartment, // Global::DataToTsfWorkerThreadMsgType::SwitchToPuncCn, // 0); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to Punc Cn").c_str()); +#endif } else if (buf.msg_type == Global::DataToTsfWorkerThreadMsgType::SwitchToFullwidth) { @@ -592,7 +602,9 @@ void CMetasequoiaIME::IpcWorkerThread(CMetasequoiaIME *pIME) WM_CheckGlobalCompartment, // Global::DataToTsfWorkerThreadMsgType::SwitchToFullwidth, // 0); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to Fullwidth").c_str()); +#endif } else if (buf.msg_type == Global::DataToTsfWorkerThreadMsgType::SwitchToHalfwidth) { @@ -601,7 +613,9 @@ void CMetasequoiaIME::IpcWorkerThread(CMetasequoiaIME *pIME) WM_CheckGlobalCompartment, // Global::DataToTsfWorkerThreadMsgType::SwitchToHalfwidth, // 0); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to Halfwidth").c_str()); +#endif } } Sleep(100); @@ -626,43 +640,59 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar case WM_CheckGlobalCompartment: { if (wParam == Global::DataToTsfWorkerThreadMsgType::SwitchToEnglish) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Wnd Switch to English").c_str()); +#endif pIME->GetCompositionProcessorEngine()->SetIMEMode(pIME->_GetThreadMgr(), pIME->_GetClientId(), FALSE); } else if (wParam == Global::DataToTsfWorkerThreadMsgType::SwitchToChinese) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Wnd Switch to Chinese").c_str()); +#endif pIME->GetCompositionProcessorEngine()->SetIMEMode(pIME->_GetThreadMgr(), pIME->_GetClientId(), TRUE); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Switch to Chinese").c_str()); +#endif } else if (wParam == Global::DataToTsfWorkerThreadMsgType::SwitchToPuncEn) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Wnd Switch to Punc En").c_str()); +#endif pIME->GetCompositionProcessorEngine()->SetPunctuationMode(pIME->_GetThreadMgr(), pIME->_GetClientId(), FALSE); } else if (wParam == Global::DataToTsfWorkerThreadMsgType::SwitchToPuncCn) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Wnd Switch to Punc Cn").c_str()); +#endif pIME->GetCompositionProcessorEngine()->SetPunctuationMode(pIME->_GetThreadMgr(), pIME->_GetClientId(), TRUE); } else if (wParam == Global::DataToTsfWorkerThreadMsgType::SwitchToFullwidth) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Wnd Switch to Fullwidth").c_str()); +#endif pIME->GetCompositionProcessorEngine()->SetDoubleSingleByteMode(pIME->_GetThreadMgr(), pIME->_GetClientId(), TRUE); } else if (wParam == Global::DataToTsfWorkerThreadMsgType::SwitchToHalfwidth) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Wnd Switch to Halfwidth").c_str()); +#endif pIME->GetCompositionProcessorEngine()->SetDoubleSingleByteMode(pIME->_GetThreadMgr(), pIME->_GetClientId(), FALSE); } break; } case WM_ConnectNamedpipe: { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Try to connect named pipe via WM_ConnectNamedpipe").c_str()); +#endif KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; SendToAuxNamedpipe(L"kill"); @@ -671,7 +701,9 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar break; } case WM_DisconnectNamedpipe: { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: WM_DisconnectNamedpipe.").c_str()); +#endif KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); KillTimer(hWnd, TIMER_CONNECT_TO_TSF_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; @@ -680,7 +712,9 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar break; } case WM_ConnectToTsfNamedpipe: { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Try to Connect to TSF named pipe").c_str()); +#endif KillTimer(hWnd, TIMER_CONNECT_TO_TSF_NAMEDPIPE); g_connectToTsfNamedpipeRetryCount = 0; // Keep old behavior: wait once before first connect try, but do it asynchronously. @@ -698,13 +732,17 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar break; } +#ifdef FANY_DEBUG OutputDebugString( fmt::format(L"[msime]: Retry connect all named pipes: {}", g_connectAllNamedpipeRetryCount).c_str()); +#endif if (ConnectToAllNamedpipe()) { KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: Yes Connected to named pipe :)").c_str()); +#endif break; } @@ -719,9 +757,11 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar if (wParam == TIMER_CONNECT_TO_TSF_NAMEDPIPE) { +#ifdef FANY_DEBUG OutputDebugString( fmt::format(L"[msime]: Retry connect to tsf named pipe: {}", g_connectToTsfNamedpipeRetryCount) .c_str()); +#endif if (ConnectToTsfNamedpipe()) { KillTimer(hWnd, TIMER_CONNECT_TO_TSF_NAMEDPIPE); diff --git a/src/IPC/Ipc.cpp b/src/IPC/Ipc.cpp index cf9e676d..dbc80ba9 100644 --- a/src/IPC/Ipc.cpp +++ b/src/IPC/Ipc.cpp @@ -470,7 +470,9 @@ void SendToNamedpipe() // Global::hToTsfWorkerThreadPipe = INVALID_HANDLE_VALUE; /* 向 Server 端发送 kill 同时重置两个管道的 connect */ SendToAuxNamedpipe(L"kill"); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: SendToNamedpipe failed eventually01.").c_str()); +#endif // } // @@ -497,8 +499,10 @@ void SendToNamedpipe() if (hPipe == INVALID_HANDLE_VALUE) { - // TODO: Log +// TODO: Log +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: SendToNamedpipe failed eventually02.").c_str()); +#endif return; } else @@ -517,8 +521,10 @@ void SendToNamedpipe() if (!ret || bytesWritten != sizeof(namedpipeData)) { - // TODO: Error handling +// TODO: Error handling +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: SendToNamedpipe failed eventually03.").c_str()); +#endif } return; @@ -755,7 +761,9 @@ void SendToAuxNamedpipe(std::wstring pipeData) } if (!hAuxPipe || hAuxPipe == INVALID_HANDLE_VALUE) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: SendToAuxNamedpipe: PipeOpenError: {}", pipeData).c_str()); +#endif return; } DWORD bytesWritten = 0; diff --git a/src/Key/KeyHandler.cpp b/src/Key/KeyHandler.cpp index cc004c20..d4055bf5 100644 --- a/src/Key/KeyHandler.cpp +++ b/src/Key/KeyHandler.cpp @@ -124,7 +124,9 @@ HRESULT CMetasequoiaIME::_HandleToogleIMEMode(TfEditCookie ec, _In_ ITfContext * commitString.assign(keyStrokebuffer.Get(), keyStrokebuffer.GetLength()); CStringRange commitStringRange; commitStringRange.Set(commitString.c_str(), commitString.length()); +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: commitString: {}", commitString).c_str()); +#endif HRESULT hr = _AddCharAndFinalize(ec, pContext, &commitStringRange); if (FAILED(hr)) diff --git a/src/LanguageBar/LanguageBar.cpp b/src/LanguageBar/LanguageBar.cpp index 583a6487..1570c85d 100644 --- a/src/LanguageBar/LanguageBar.cpp +++ b/src/LanguageBar/LanguageBar.cpp @@ -375,9 +375,12 @@ STDAPI CLangBarItemButton::OnClick(TfLBIClick click, POINT pt, _In_ const RECT * if (click == TF_LBI_CLK_RIGHT) { #ifdef FANY_DEBUG - OutputDebugString( - fmt::format(L"[msime]: \nprcArea: ({}, {}, {}, {})", prcArea->left, prcArea->top, prcArea->right, prcArea->bottom) - .c_str()); + OutputDebugString(fmt::format(L"[msime]: \nprcArea: ({}, {}, {}, {})", // + prcArea->left, // + prcArea->top, // + prcArea->right, // + prcArea->bottom) + .c_str()); OutputDebugString(L"[msime]: right click of lang bar item"); #endif SendLangbarRightClickEventToUIProcess(prcArea); diff --git a/src/Thread/ThreadFocusSink.cpp b/src/Thread/ThreadFocusSink.cpp index 23af0b4d..75fcee43 100644 --- a/src/Thread/ThreadFocusSink.cpp +++ b/src/Thread/ThreadFocusSink.cpp @@ -13,7 +13,9 @@ STDAPI CMetasequoiaIME::OnSetThreadFocus() { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: CMetasequoiaIME::OnSetThreadFocus").c_str()); +#endif PostMessage(_msgWndHandle, WM_ThreadFocus, 0, 0); if (_pCandidateListUIPresenter) { @@ -41,7 +43,9 @@ STDAPI CMetasequoiaIME::OnSetThreadFocus() STDAPI CMetasequoiaIME::OnKillThreadFocus() { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: CMetasequoiaIME::OnKillThreadFocus").c_str()); +#endif if (_pCandidateListUIPresenter) { ITfDocumentMgr *pCandidateListDocumentMgr = nullptr; diff --git a/src/UI/CandidateListUIPresenter.cpp b/src/UI/CandidateListUIPresenter.cpp index 49272877..aeff9c1b 100644 --- a/src/UI/CandidateListUIPresenter.cpp +++ b/src/UI/CandidateListUIPresenter.cpp @@ -130,8 +130,7 @@ HRESULT CMetasequoiaIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfConte } #ifdef FANY_DEBUG OutputDebugString( - fmt::format(L"[msime]: create_word: current word part {}", GlobalIme::word_for_creating_word) - .c_str()); + fmt::format(L"[msime]: create_word: current word part {}", GlobalIme::word_for_creating_word).c_str()); #endif return hr; } diff --git a/src/Utils/FanyUtils.cpp b/src/Utils/FanyUtils.cpp index 0014886a..6ad70452 100644 --- a/src/Utils/FanyUtils.cpp +++ b/src/Utils/FanyUtils.cpp @@ -32,7 +32,9 @@ void SendKeys(std::wstring pinyin) UINT sent = SendInput(2, in, sizeof(INPUT)); if (sent != 2) { +#ifdef FANY_DEBUG OutputDebugString(fmt::format(L"[msime]: SendKeys failed.").c_str()); +#endif } } }