diff --git a/src/Composition/CompositionProcessorEngine.cpp b/src/Composition/CompositionProcessorEngine.cpp index 2d50806f..652720c1 100644 --- a/src/Composition/CompositionProcessorEngine.cpp +++ b/src/Composition/CompositionProcessorEngine.cpp @@ -1,4 +1,4 @@ -#include "Private.h" +#include "Private.h" #include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include "TfInputProcessorProfile.h" @@ -97,9 +97,9 @@ BOOL CMetasequoiaIME::_AddTextProcessorEngine() // //---------------------------------------------------------------------------- -CCompositionProcessorEngine::CCompositionProcessorEngine() -{ - _langid = 0xffff; +CCompositionProcessorEngine::CCompositionProcessorEngine() +{ + _langid = 0xffff; _guidProfile = GUID_NULL; _tfClientId = TF_CLIENTID_NULL; @@ -113,11 +113,11 @@ CCompositionProcessorEngine::CCompositionProcessorEngine() _pCompartmentDoubleSingleByteEventSink = nullptr; _pCompartmentPunctuationEventSink = nullptr; - _hasWildcardIncludedInKeystrokeBuffer = FALSE; - - _isWildcard = FALSE; - _isDisableWildcardAtFirst = FALSE; - _isKeystrokeSort = FALSE; + _hasWildcardIncludedInKeystrokeBuffer = FALSE; + + _isWildcard = FALSE; + _isDisableWildcardAtFirst = FALSE; + _isKeystrokeSort = FALSE; _candidateListPhraseModifier = 0; @@ -132,9 +132,9 @@ CCompositionProcessorEngine::CCompositionProcessorEngine() // //---------------------------------------------------------------------------- -CCompositionProcessorEngine::~CCompositionProcessorEngine() -{ - if (_pLanguageBar_IMEMode) +CCompositionProcessorEngine::~CCompositionProcessorEngine() +{ + if (_pLanguageBar_IMEMode) { _pLanguageBar_IMEMode->CleanUp(); _pLanguageBar_IMEMode->Release(); @@ -183,7 +183,7 @@ CCompositionProcessorEngine::~CCompositionProcessorEngine() _pCompartmentPunctuationEventSink = nullptr; } -} +} //+--------------------------------------------------------------------------- // @@ -218,12 +218,12 @@ BOOL CCompositionProcessorEngine::SetupLanguageProfile(LANGID langid, REFGUID gu SetupPreserved(pThreadMgr, tfClientId); InitializeMetasequoiaIMECompartment(pThreadMgr, tfClientId); - SetupPunctuationPair(); - SetupLanguageBar(pThreadMgr, tfClientId, isSecureMode); - SetupKeystroke(); - SetupConfiguration(); - -Exit: + SetupPunctuationPair(); + SetupLanguageBar(pThreadMgr, tfClientId, isSecureMode); + SetupKeystroke(); + SetupConfiguration(); + +Exit: return ret; } @@ -376,17 +376,17 @@ void CCompositionProcessorEngine::GetReadingStrings(_Inout_ CMetasequoiaImeArray // //---------------------------------------------------------------------------- -void CCompositionProcessorEngine::GetCandidateList(_Inout_ CMetasequoiaImeArray *pCandidateList, - BOOL isIncrementalWordSearch, BOOL isWildcardSearch) -{ - isIncrementalWordSearch; - isWildcardSearch; - - // - // Candidate generation now lives in the IPC server. TSF keeps a minimal - // local mirror so selection/page bookkeeping still works. - // - const std::wstring keystrokeStr(_keystrokeBuffer.Get(), _keystrokeBuffer.GetLength()); +void CCompositionProcessorEngine::GetCandidateList(_Inout_ CMetasequoiaImeArray *pCandidateList, + BOOL isIncrementalWordSearch, BOOL isWildcardSearch) +{ + isIncrementalWordSearch; + isWildcardSearch; + + // + // Candidate generation now lives in the IPC server. TSF keeps a minimal + // local mirror so selection/page bookkeeping still works. + // + const std::wstring keystrokeStr(_keystrokeBuffer.Get(), _keystrokeBuffer.GetLength()); CCandidateListItem *pLI = nullptr; pLI = pCandidateList->Append(); if (pLI) @@ -402,11 +402,11 @@ void CCompositionProcessorEngine::GetCandidateList(_Inout_ CMetasequoiaImeArray< startItemString.Set(pLI->_ItemString.Get(), 1); endItemString.Set(pLI->_ItemString.Get() + pLI->_ItemString.GetLength() - 1, 1); - - index++; - } - return; -} + + index++; + } + return; +} //+--------------------------------------------------------------------------- // @@ -445,54 +445,54 @@ BOOL CCompositionProcessorEngine::IsPunctuation(WCHAR wch) if (pPuncNestPair->_punctuation_end._Code == wch) { return TRUE; - } - } - return FALSE; -} - -namespace -{ -bool IsCommitWithFirstCandidatePunctuationInCandidateMode(UINT uCode, WCHAR wch, CANDIDATE_MODE candidateMode) -{ - if (candidateMode == CANDIDATE_NONE) - { - return false; - } - - // Candidate paging keys must keep their navigation semantics even if the - // corresponding character is also listed in CommitWithFirstCandPunc. - switch (uCode) - { - case VK_PRIOR: - case VK_NEXT: - case VK_OEM_MINUS: - case VK_OEM_PLUS: - case VK_SUBTRACT: - case VK_ADD: - case VK_HOME: - case VK_END: - case VK_TAB: - return false; - default: - break; - } - - return wch != 0 && Global::CommitWithFirstCandPunc.count(wch) > 0; -} - -bool IsManualPinyinSeparatorInComposition(WCHAR wch, BOOL fComposing, CANDIDATE_MODE candidateMode, DWORD_PTR keystrokeLength) -{ - if (wch != L'\'') - { - return false; - } - if (keystrokeLength == 0) - { - return false; - } - return fComposing || candidateMode != CANDIDATE_NONE; -} -} + } + } + return FALSE; +} + +namespace +{ +bool IsCommitWithFirstCandidatePunctuationInCandidateMode(UINT uCode, WCHAR wch, CANDIDATE_MODE candidateMode) +{ + if (candidateMode == CANDIDATE_NONE) + { + return false; + } + + // Candidate paging keys must keep their navigation semantics even if the + // corresponding character is also listed in CommitWithFirstCandPunc. + switch (uCode) + { + case VK_PRIOR: + case VK_NEXT: + case VK_OEM_MINUS: + case VK_OEM_PLUS: + case VK_SUBTRACT: + case VK_ADD: + case VK_HOME: + case VK_END: + case VK_TAB: + return false; + default: + break; + } + + return wch != 0 && Global::CommitWithFirstCandPunc.count(wch) > 0; +} + +bool IsManualPinyinSeparatorInComposition(WCHAR wch, BOOL fComposing, CANDIDATE_MODE candidateMode, DWORD_PTR keystrokeLength) +{ + if (wch != L'\'') + { + return false; + } + if (keystrokeLength == 0) + { + return false; + } + return fComposing || candidateMode != CANDIDATE_NONE; +} +} //+--------------------------------------------------------------------------- // @@ -1016,12 +1016,12 @@ BOOL CCompositionProcessorEngine::GetDoubleSingleByteMode(_In_ ITfThreadMgr *pTh // //---------------------------------------------------------------------------- -void CCompositionProcessorEngine::SetupConfiguration() -{ - _isWildcard = TRUE; - _isDisableWildcardAtFirst = TRUE; - _isKeystrokeSort = TRUE; - _candidateWndWidth = CAND_WIDTH; +void CCompositionProcessorEngine::SetupConfiguration() +{ + _isWildcard = TRUE; + _isDisableWildcardAtFirst = TRUE; + _isKeystrokeSort = TRUE; + _candidateWndWidth = CAND_WIDTH; SetInitialCandidateListRange(); @@ -1131,9 +1131,9 @@ BOOL CCompositionProcessorEngine::InitLanguageBar(_In_ CLangBarItemButton *pLang return FALSE; } -//+--------------------------------------------------------------------------- -// -// SetupPunctuationPair +//+--------------------------------------------------------------------------- +// +// SetupPunctuationPair // //---------------------------------------------------------------------------- @@ -1690,53 +1690,50 @@ void CCompositionProcessorEngine::SetDefaultCandidateTextFont() // If engine need this virtual key code, returns true. Otherwise returns false. //---------------------------------------------------------------------------- -BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // - UINT uCode, // +BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // + UINT uCode, // _In_reads_(1) WCHAR *pwch, // BOOL fComposing, // CANDIDATE_MODE candidateMode, // BOOL hasCandidateWithWildcard, // _Out_opt_ _KEYSTROKE_STATE *pKeyState // -) -{ - if (pKeyState) - { - pKeyState->Category = CATEGORY_NONE; +) +{ + if (pKeyState) + { + pKeyState->Category = CATEGORY_NONE; pKeyState->Function = FUNCTION_NONE; } - if (candidateMode == CANDIDATE_ORIGINAL) - { - fComposing = FALSE; - } - - if (IsManualPinyinSeparatorInComposition(pwch ? *pwch : 0, fComposing, candidateMode, _keystrokeBuffer.GetLength())) - { - if (pKeyState) - { - pKeyState->Category = CATEGORY_COMPOSING; - pKeyState->Function = FUNCTION_INPUT; - } - return TRUE; - } - - if (IsCommitWithFirstCandidatePunctuationInCandidateMode(uCode, pwch ? *pwch : 0, candidateMode)) - { - if (pKeyState) - { - pKeyState->Category = CATEGORY_COMPOSING; - pKeyState->Function = FUNCTION_PUNCTUATION; - } - return TRUE; - } - - if (fComposing || candidateMode == CANDIDATE_INCREMENTAL || candidateMode == CANDIDATE_NONE) - { - if (IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_NONE)) // 26 basic English chars - { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: Basic 26 chars key pressed."); -#endif + if (candidateMode == CANDIDATE_ORIGINAL) + { + fComposing = FALSE; + } + + if (IsManualPinyinSeparatorInComposition(pwch ? *pwch : 0, fComposing, candidateMode, _keystrokeBuffer.GetLength())) + { + if (pKeyState) + { + pKeyState->Category = CATEGORY_COMPOSING; + pKeyState->Function = FUNCTION_INPUT; + } + return TRUE; + } + + if (IsCommitWithFirstCandidatePunctuationInCandidateMode(uCode, pwch ? *pwch : 0, candidateMode)) + { + if (pKeyState) + { + pKeyState->Category = CATEGORY_COMPOSING; + pKeyState->Function = FUNCTION_PUNCTUATION; + } + return TRUE; + } + + if (fComposing || candidateMode == CANDIDATE_INCREMENTAL || candidateMode == CANDIDATE_NONE) + { + if (IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_NONE)) // 26 basic English chars + { return TRUE; } else if ((IsWildcard() && IsWildcardChar(*pwch) && !IsDisableWildcardAtFirst()) || @@ -1764,13 +1761,13 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // } } - if (candidateMode == CANDIDATE_ORIGINAL) - { - BOOL isRetCode = TRUE; - if (IsVirtualKeyKeystrokeCandidate(uCode, pKeyState, candidateMode, &isRetCode, &_KeystrokeCandidate)) - { - return isRetCode; - } + if (candidateMode == CANDIDATE_ORIGINAL) + { + BOOL isRetCode = TRUE; + if (IsVirtualKeyKeystrokeCandidate(uCode, pKeyState, candidateMode, &isRetCode, &_KeystrokeCandidate)) + { + return isRetCode; + } if (hasCandidateWithWildcard) { @@ -1781,13 +1778,13 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // } } - // Candidate list could not handle key. We can try to restart the composition. - if (IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_INPUT)) - { - if (candidateMode == CANDIDATE_ORIGINAL) - { - if (pKeyState) - { + // Candidate list could not handle key. We can try to restart the composition. + if (IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_INPUT)) + { + if (candidateMode == CANDIDATE_ORIGINAL) + { + if (pKeyState) + { pKeyState->Category = CATEGORY_CANDIDATE; pKeyState->Function = FUNCTION_FINALIZE_CANDIDATELIST_AND_INPUT; } @@ -1797,19 +1794,19 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // } // CANDIDATE_INCREMENTAL should process Keystroke.Candidate virtual keys. - else if (candidateMode == CANDIDATE_INCREMENTAL) - { - BOOL isRetCode = TRUE; - if (IsVirtualKeyKeystrokeCandidate(uCode, pKeyState, candidateMode, &isRetCode, &_KeystrokeCandidate)) - { - return isRetCode; - } - } - - if (!fComposing && candidateMode != CANDIDATE_ORIGINAL) - { - if (IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_INPUT)) - { + else if (candidateMode == CANDIDATE_INCREMENTAL) + { + BOOL isRetCode = TRUE; + if (IsVirtualKeyKeystrokeCandidate(uCode, pKeyState, candidateMode, &isRetCode, &_KeystrokeCandidate)) + { + return isRetCode; + } + } + + if (!fComposing && candidateMode != CANDIDATE_ORIGINAL) + { + if (IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_INPUT)) + { return TRUE; } } @@ -1958,9 +1955,6 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // case VK_RETURN: // Do something when user press return key -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: VK_RETURN pressed."); -#endif if (pKeyState) { pKeyState->Category = CATEGORY_CANDIDATE; @@ -2005,13 +1999,13 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // pKeyState->Function = FUNCTION_MOVE_PAGE_UP; } return TRUE; - case VK_OEM_MINUS: - if (pKeyState) - { - pKeyState->Category = CATEGORY_CANDIDATE; - pKeyState->Function = FUNCTION_MOVE_PAGE_UP; - } - return TRUE; + case VK_OEM_MINUS: + if (pKeyState) + { + pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Function = FUNCTION_MOVE_PAGE_UP; + } + return TRUE; case VK_NEXT: if (pKeyState) { @@ -2019,13 +2013,13 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; } return TRUE; - case VK_OEM_PLUS: - if (pKeyState) - { - pKeyState->Category = CATEGORY_CANDIDATE; - pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; - } - return TRUE; + case VK_OEM_PLUS: + if (pKeyState) + { + pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; + } + return TRUE; case VK_TAB: if (pKeyState) { @@ -2080,9 +2074,9 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // } } - if (candidateMode == CANDIDATE_ORIGINAL) - { - switch (uCode) + if (candidateMode == CANDIDATE_ORIGINAL) + { + switch (uCode) { case VK_UP: if (pKeyState) @@ -2105,13 +2099,13 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // pKeyState->Function = FUNCTION_MOVE_PAGE_UP; } return TRUE; - case VK_OEM_MINUS: - if (pKeyState) - { - pKeyState->Category = CATEGORY_CANDIDATE; - pKeyState->Function = FUNCTION_MOVE_PAGE_UP; - } - return TRUE; + case VK_OEM_MINUS: + if (pKeyState) + { + pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Function = FUNCTION_MOVE_PAGE_UP; + } + return TRUE; case VK_NEXT: if (pKeyState) { @@ -2119,13 +2113,13 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; } return TRUE; - case VK_OEM_PLUS: - if (pKeyState) - { - pKeyState->Category = CATEGORY_CANDIDATE; - pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; - } - return TRUE; + case VK_OEM_PLUS: + if (pKeyState) + { + pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; + } + return TRUE; case VK_TAB: if (pKeyState) { @@ -2177,15 +2171,15 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // } return TRUE; - case VK_ESCAPE: - if (pKeyState) - { - pKeyState->Category = CATEGORY_CANDIDATE; - pKeyState->Function = FUNCTION_CANCEL; - } - return TRUE; - } - } + case VK_ESCAPE: + if (pKeyState) + { + pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Function = FUNCTION_CANCEL; + } + return TRUE; + } + } // // Check whether the keystroke is number(for selecting candidate) and is in the range @@ -2199,19 +2193,16 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed( // return FALSE; } - if (*pwch && !IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_NONE)) - { - if (pKeyState) - { - pKeyState->Category = CATEGORY_INVOKE_COMPOSITION_EDIT_SESSION; - pKeyState->Function = FUNCTION_FINALIZE_TEXTSTORE; - } - return FALSE; - } + if (*pwch && !IsVirtualKeyKeystrokeComposition(uCode, pKeyState, FUNCTION_NONE)) + { + if (pKeyState) + { + pKeyState->Category = CATEGORY_INVOKE_COMPOSITION_EDIT_SESSION; + pKeyState->Function = FUNCTION_FINALIZE_TEXTSTORE; + } + return FALSE; + } -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: Unknown keystroke."); -#endif return FALSE; } @@ -2227,12 +2218,7 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeComposition( // KEYSTROKE_FUNCTION function // ) { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: Fany Here: IsVirtualKeyKeystrokeComposition 26."); - std::wstring modifiers = fmt::format(L"[msime]: Global Modifiers: {}", Global::ModifiersValue); - OutputDebugString(modifiers.c_str()); -#endif - if (pKeyState == nullptr) + if (pKeyState == nullptr) { return FALSE; } @@ -2296,7 +2282,7 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeCandidate( *pfRetCode = TRUE; if (pKeyState) { - pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Category = CATEGORY_CANDIDATE; pKeyState->Function = pKeystroke->Function; } @@ -2326,17 +2312,14 @@ BOOL CCompositionProcessorEngine::IsKeystrokeRange(UINT uCode, _Out_ _KEYSTROKE_ if (_candidateListIndexRange.IsRange(uCode)) { - if (candidateMode != CANDIDATE_NONE) - { - pKeyState->Category = CATEGORY_CANDIDATE; - pKeyState->Function = FUNCTION_SELECT_BY_NUMBER; + if (candidateMode != CANDIDATE_NONE) + { + pKeyState->Category = CATEGORY_CANDIDATE; + pKeyState->Function = FUNCTION_SELECT_BY_NUMBER; return TRUE; } else if (GetVirtualKeyLength() > 0) { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: GetVirtualKeyLength() > 0"); -#endif pKeyState->Category = CATEGORY_CANDIDATE; pKeyState->Function = FUNCTION_SELECT_BY_NUMBER; return TRUE; diff --git a/src/Edit/GetTextExtentEditSession.cpp b/src/Edit/GetTextExtentEditSession.cpp index ec2a7d00..c5d45763 100644 --- a/src/Edit/GetTextExtentEditSession.cpp +++ b/src/Edit/GetTextExtentEditSession.cpp @@ -46,10 +46,7 @@ STDAPI CGetTextExtentEditSession::DoEditSession(TfEditCookie ec) if (SUCCEEDED(hr)) { -#ifdef FANY_DEBUG - // TODO: Log rc position -#endif - Global::Point[0] = rc.left * Global::DpiScale; + Global::Point[0] = rc.left * Global::DpiScale; Global::Point[1] = rc.bottom * Global::DpiScale; if (Global::current_process_name == Global::ZEN_BROWSER) { diff --git a/src/FanyLog/FanyLog.h b/src/FanyLog/FanyLog.h index f75538f9..6f70f09b 100644 --- a/src/FanyLog/FanyLog.h +++ b/src/FanyLog/FanyLog.h @@ -1,14 +1 @@ #pragma once - -#include -#include -#include - -template // -void DebugLog(std::wstring format_str, Args &&...args) -{ -#ifdef FANY_DEBUG - auto msg = fmt::format(format_str, std::forward(args)...); - OutputDebugString(msg.c_str()); -#endif -} \ No newline at end of file diff --git a/src/IME/MetasequoiaIME.cpp b/src/IME/MetasequoiaIME.cpp index 7428ee16..8d7dfc78 100644 --- a/src/IME/MetasequoiaIME.cpp +++ b/src/IME/MetasequoiaIME.cpp @@ -18,13 +18,6 @@ #include "Utils/FanyUtils.h" #include "../Utils/PerfTimer.h" -#ifdef FANY_IPC_DEBUG -#define FANY_IPC_LOG_RAW(message) OutputDebugString(message) -#define FANY_IPC_LOGF(...) OutputDebugString(fmt::format(__VA_ARGS__).c_str()) -#else -#define FANY_IPC_LOG_RAW(message) ((void)0) -#define FANY_IPC_LOGF(...) ((void)0) -#endif #pragma comment(lib, "Shcore.lib") @@ -61,12 +54,6 @@ class CPunctuationCommitEditSession : public CEditSessionBase QueryPerformanceCounter(&nowQpc); const double queueElapsedMs = static_cast(nowQpc.QuadPart - _requestStartQpc.QuadPart) * 1000.0 / static_cast(freq.QuadPart); - OutputDebugString( - fmt::format(L"[msime-punc] DirectPunctuationEditSession DoEditSession keycode={} wch={} queue_ms={:.3f} " - L"do_ms={:.3f} hr=0x{:08X}", - _code, static_cast(_wch), queueElapsedMs, timer.ElapsedMs(), - static_cast(hr)) - .c_str()); return hr; } @@ -240,12 +227,6 @@ HRESULT CMetasequoiaIME::_RequestDirectPunctuationEditSession(_In_ ITfContext *p PerfTimer requestTimer; HRESULT requestHr = pContext->RequestEditSession(_tfClientId, pEditSession, TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &editSessionHr); - OutputDebugString( - fmt::format(L"[msime-punc] DirectPunctuationEditSession RequestEditSession keycode={} wch={} request_ms={:.3f} " - L"request_hr=0x{:08X} session_hr=0x{:08X}", - code, static_cast(wch), requestTimer.ElapsedMs(), static_cast(requestHr), - static_cast(editSessionHr)) - .c_str()); pEditSession->Release(); return requestHr; } @@ -430,9 +411,6 @@ STDAPI CMetasequoiaIME::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClient _tfClientId = tfClientId; _dwActivateFlags = dwFlags; -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: CMetasequoiaIME::ActivateEx"); -#endif /* std::wstring processName = FanyUtils::GetCurrentProcessName(); if (Global::VSCodeSeries.find(processName) != Global::VSCodeSeries.end()) @@ -532,9 +510,6 @@ STDAPI CMetasequoiaIME::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClient if (awareness == DPI_AWARENESS_UNAWARE) { -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: awareness == DPI_AWARENESS_UNAWARE").c_str()); -#endif /* 宿主是非感知程序,需要反向缩放 */ DPI_AWARENESS_CONTEXT oldCtx = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); HMONITOR hMon = MonitorFromWindow(hwndTarget, MONITOR_DEFAULTTONEAREST); @@ -542,16 +517,9 @@ STDAPI CMetasequoiaIME::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClient GetDpiForMonitor(hMon, MDT_EFFECTIVE_DPI, &dpiX, &dpiY); SetThreadDpiAwarenessContext(oldCtx); Global::DpiScale = dpiX / 96.0; -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: Global::DpiScale: {}", Global::DpiScale).c_str()); -#endif } } -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: CMetasequoiaIME::ActivateEx"); -#endif - return S_OK; ExitError: @@ -587,9 +555,6 @@ STDAPI CMetasequoiaIME::Deactivate() { // 向 server 端发送一个输入法真的切换到了别的输入法的消息 // 只有接收到这个消息,才可以隐藏 ftb -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: Truely deactivate IME and switch to another.").c_str()); -#endif SendIMEDeactivationEventToUIProcessViaNamedPipe(); } @@ -615,10 +580,6 @@ STDAPI CMetasequoiaIME::Deactivate() // TODO: 去掉共享内存,只保留命名管道 // CloseNamedpipe(); -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: CMetasequoiaIME::Deactivate"); -#endif - if (_pCompositionProcessorEngine) { delete _pCompositionProcessorEngine; @@ -742,9 +703,6 @@ 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) { @@ -753,9 +711,6 @@ 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) { @@ -764,9 +719,6 @@ 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) { @@ -775,9 +727,6 @@ 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) { @@ -786,9 +735,6 @@ 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) { @@ -797,9 +743,6 @@ 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); @@ -824,70 +767,41 @@ 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 - FANY_IPC_LOG_RAW(L"[msime]: [ipc] WM_ConnectNamedpipe: start reconnect-all sequence"); KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; SetTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE, CONNECT_NAMEDPIPE_RETRY_INTERVAL_MS, nullptr); break; } case WM_DisconnectNamedpipe: { -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: WM_DisconnectNamedpipe.").c_str()); -#endif - FANY_IPC_LOG_RAW(L"[msime]: [ipc] WM_DisconnectNamedpipe: deactivating current pipe client"); KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); KillTimer(hWnd, TIMER_CONNECT_TO_TSF_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; @@ -896,10 +810,6 @@ 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 - FANY_IPC_LOG_RAW(L"[msime]: [ipc] WM_ConnectToTsfNamedpipe: start reconnect-to-tsf sequence"); KillTimer(hWnd, TIMER_CONNECT_TO_TSF_NAMEDPIPE); g_connectToTsfNamedpipeRetryCount = 0; // Keep old behavior: wait once before first connect try, but do it asynchronously. @@ -912,33 +822,23 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar // 如果用户已经切换走了,就不用继续重试 if (!Global::g_connected) { - FANY_IPC_LOG_RAW(L"[msime]: [ipc] reconnect-all aborted because threadmgr is disconnected"); KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; break; } -#ifdef FANY_DEBUG - OutputDebugString( - fmt::format(L"[msime]: Retry connect all named pipes: {}", g_connectAllNamedpipeRetryCount).c_str()); -#endif if (ConnectToAllNamedpipe()) { pIME->_hToTsfWorkerThreadPipe = GetToTsfWorkerThreadNamedpipe(); KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; - FANY_IPC_LOG_RAW(L"[msime]: [ipc] reconnect-all succeeded"); SendClientActivatedEventToServerViaNamedPipe(); -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: Yes Connected to named pipe :)").c_str()); -#endif break; } g_connectAllNamedpipeRetryCount++; if (g_connectAllNamedpipeRetryCount >= CONNECT_ALL_NAMEDPIPE_MAX_RETRY) { - FANY_IPC_LOG_RAW(L"[msime]: [ipc] reconnect-all reached max retry count"); KillTimer(hWnd, TIMER_CONNECT_ALL_NAMEDPIPE); g_connectAllNamedpipeRetryCount = 0; } @@ -947,23 +847,16 @@ 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); g_connectToTsfNamedpipeRetryCount = 0; - FANY_IPC_LOG_RAW(L"[msime]: [ipc] reconnect-to-tsf succeeded"); break; } g_connectToTsfNamedpipeRetryCount++; if (g_connectToTsfNamedpipeRetryCount >= CONNECT_TO_TSF_NAMEDPIPE_MAX_RETRY) { - FANY_IPC_LOG_RAW(L"[msime]: [ipc] reconnect-to-tsf reached max retry count"); KillTimer(hWnd, TIMER_CONNECT_TO_TSF_NAMEDPIPE); g_connectToTsfNamedpipeRetryCount = 0; } @@ -1049,10 +942,6 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar if (useDirectPunctuationSession) { pIME->_RequestDirectPunctuationEditSession(pContext, code, wch); - OutputDebugString( - fmt::format(L"[msime-punc] WM_AsyncPunctuationCommit direct keycode={} wch={} total_ms={:.3f}", - code, static_cast(wch), timer.ElapsedMs()) - .c_str()); } else { @@ -1060,10 +949,6 @@ LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND hWnd, UINT message, WPARAM wPar KeystrokeState.Category = CATEGORY_COMPOSING; KeystrokeState.Function = FUNCTION_PUNCTUATION; pIME->_InvokeKeyHandler(pContext, code, wch, 0, KeystrokeState); - OutputDebugString( - fmt::format(L"[msime-punc] WM_AsyncPunctuationCommit invoke keycode={} wch={} total_ms={:.3f}", - code, static_cast(wch), timer.ElapsedMs()) - .c_str()); } pContext->Release(); } diff --git a/src/IME/MetasequoiaIMEBaseStructure.h b/src/IME/MetasequoiaIMEBaseStructure.h index 5b8ad1fd..9a9cf524 100644 --- a/src/IME/MetasequoiaIMEBaseStructure.h +++ b/src/IME/MetasequoiaIMEBaseStructure.h @@ -5,7 +5,6 @@ #include "assert.h" #include -using std::cout; using std::endl; //--------------------------------------------------------------------- @@ -20,13 +19,13 @@ template struct _DEFINED_KEYWORD //--------------------------------------------------------------------- // enum //--------------------------------------------------------------------- -enum KEYSTROKE_CATEGORY -{ - CATEGORY_NONE = 0, - CATEGORY_COMPOSING, - CATEGORY_CANDIDATE, - CATEGORY_INVOKE_COMPOSITION_EDIT_SESSION -}; +enum KEYSTROKE_CATEGORY +{ + CATEGORY_NONE = 0, + CATEGORY_COMPOSING, + CATEGORY_CANDIDATE, + CATEGORY_INVOKE_COMPOSITION_EDIT_SESSION +}; enum KEYSTROKE_FUNCTION { @@ -63,12 +62,12 @@ enum KEYSTROKE_FUNCTION //--------------------------------------------------------------------- // candidate list //--------------------------------------------------------------------- -enum CANDIDATE_MODE -{ - CANDIDATE_NONE = 0, - CANDIDATE_ORIGINAL, - CANDIDATE_INCREMENTAL -}; +enum CANDIDATE_MODE +{ + CANDIDATE_NONE = 0, + CANDIDATE_ORIGINAL, + CANDIDATE_INCREMENTAL +}; //--------------------------------------------------------------------- // structure diff --git a/src/IPC/Ipc.cpp b/src/IPC/Ipc.cpp index 1229fb87..48fa5c0e 100644 --- a/src/IPC/Ipc.cpp +++ b/src/IPC/Ipc.cpp @@ -10,15 +10,6 @@ #include "MetasequoiaIME.h" #include -#ifdef FANY_IPC_DEBUG -#define FANY_IPC_LOG_RAW(message) OutputDebugString(message) -#define FANY_IPC_LOGW(message) OutputDebugString((message).c_str()) -#define FANY_IPC_LOGF(...) OutputDebugString(fmt::format(__VA_ARGS__).c_str()) -#else -#define FANY_IPC_LOG_RAW(message) ((void)0) -#define FANY_IPC_LOGW(message) ((void)0) -#define FANY_IPC_LOGF(...) ((void)0) -#endif static HANDLE hMapFile = nullptr; static void *pBuf; @@ -56,70 +47,14 @@ uint64_t GetPipeClientId() return clientId; } -void LogCreateFileFailure(const wchar_t *pipeName) -{ - FANY_IPC_LOGF(L"[msime]: [ipc] CreateFile failed: pipe={}, gle={}", pipeName, GetLastError()); -} -void LogCreateFileSuccess(const wchar_t *pipeName) -{ - FANY_IPC_LOGF(L"[msime]: [ipc] CreateFile connected: pipe={}", pipeName); -} -void LogWriteFailure(const wchar_t *pipeName, DWORD bytesWritten, DWORD expectedBytes) -{ - FANY_IPC_LOGF(L"[msime]: [ipc] WriteFile failed: pipe={}, gle={}, bytes_written={}, expected_bytes={}", pipeName, - GetLastError(), bytesWritten, expectedBytes); -} -void LogReadFailure(const wchar_t *pipeName, DWORD bytesRead) -{ - FANY_IPC_LOGF(L"[msime]: [ipc] ReadFile failed or empty: pipe={}, gle={}, bytes_read={}", pipeName, - GetLastError(), bytesRead); -} -void LogPeekFailure(const wchar_t *pipeName) -{ - FANY_IPC_LOGF(L"[msime]: [ipc] PeekNamedPipe failed: pipe={}, gle={}", pipeName, GetLastError()); -} -void LogServerPipeReadFallback(const wchar_t *reason, const wchar_t *fallbackText, double elapsedMs, int timeoutMs, - DWORD gle, DWORD bytesAvailable, int peekFailureCount) -{ - OutputDebugString(fmt::format(L"[msime]: [ipc] server-pipe fallback: reason={}, fallback={}, elapsed_ms={:.3f}, " - L"timeout_ms={}, gle={}, bytes_available={}, peek_failures={}, client_id={}, " - L"event_type={}, keycode={}, wch={}, modifiers={}, pinyin_length={}", - reason, fallbackText, elapsedMs, timeoutMs, gle, bytesAvailable, peekFailureCount, - GetPipeClientId(), namedpipeData.event_type, namedpipeData.keycode, - static_cast(namedpipeData.wch), namedpipeData.modifiers_down, - namedpipeData.pinyin_length) - .c_str()); -} -void LogServerPipeWaitStart(int timeoutMs) -{ - OutputDebugString(fmt::format(L"[msime]: [ipc] server-pipe wait start: timeout_ms={}, client_id={}, event_type={}, " - L"keycode={}, wch={}, modifiers={}, pinyin_length={}", - timeoutMs, GetPipeClientId(), namedpipeData.event_type, namedpipeData.keycode, - static_cast(namedpipeData.wch), namedpipeData.modifiers_down, - namedpipeData.pinyin_length) - .c_str()); -} -void LogServerPipeWaitResult(UINT msgType, const WCHAR *candidateString, double elapsedMs) -{ - OutputDebugString(fmt::format(L"[msime]: [ipc] server-pipe wait result: msg_type={}, candidate={}, elapsed_ms={:.3f}, " - L"client_id={}, event_type={}, keycode={}, wch={}", - msgType, candidateString ? candidateString : L"", elapsedMs, GetPipeClientId(), - namedpipeData.event_type, namedpipeData.keycode, - static_cast(namedpipeData.wch)) - .c_str()); -} -void LogAuxMessage(const std::wstring &message) -{ - FANY_IPC_LOGF(L"[msime]: [ipc] SendToAuxNamedpipe: {}", message); -} void ClosePipeHandleIfValid(HANDLE &hPipeHandle) { @@ -168,16 +103,12 @@ bool TryOpenClientPipe(HANDLE &hPipeHandle, const wchar_t *pipeName, UINT pipeRo if (openedPipe == INVALID_HANDLE_VALUE) { - LogCreateFileFailure(pipeName); return false; } hPipeHandle = openedPipe; - LogCreateFileSuccess(pipeName); if (!WritePipeHello(hPipeHandle, pipeRole)) { - LogWriteFailure(pipeName, 0, pipeRole == FanyImePipeRole::Main ? sizeof(FanyImeNamedpipeData) - : sizeof(FanyImePipeHello)); ClosePipeHandleIfValid(hPipeHandle); return false; } @@ -566,11 +497,7 @@ void SendToNamedpipe() if (!ret || bytesWritten != sizeof(namedpipeData)) { /* Error handling: 必须将 hPipe 置为无效,否则将留下脏句柄,导致有些情况下无法再次连接 */ - LogWriteFailure(FANY_IME_NAMED_PIPE, bytesWritten, sizeof(namedpipeData)); ClosePipeHandleIfValid(hPipe); -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: SendToNamedpipe failed eventually01.").c_str()); -#endif for (int i = 0; i < 10; ++i) { Sleep(10); @@ -582,15 +509,10 @@ void SendToNamedpipe() if (hPipe == INVALID_HANDLE_VALUE) { - LogCreateFileFailure(FANY_IME_NAMED_PIPE); -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: SendToNamedpipe failed eventually02.").c_str()); -#endif return; } else { - LogCreateFileSuccess(FANY_IME_NAMED_PIPE); } namedpipeData.client_id = GetPipeClientId(); @@ -605,10 +527,6 @@ void SendToNamedpipe() if (!ret || bytesWritten != sizeof(namedpipeData)) { - LogWriteFailure(FANY_IME_NAMED_PIPE, bytesWritten, sizeof(namedpipeData)); -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: SendToNamedpipe failed eventually03.").c_str()); -#endif } return; @@ -657,7 +575,6 @@ void ClearNamedpipeDataIfExists(bool force) { if (!peekOk) { - LogPeekFailure(FANY_IME_TO_TSF_NAMED_PIPE); } break; // no more data or pipe error } @@ -672,7 +589,6 @@ void ClearNamedpipeDataIfExists(bool force) if (!readOk || bytesRead == 0) { - LogReadFailure(FANY_IME_TO_TSF_NAMED_PIPE, bytesRead); break; } clearedCount++; @@ -692,7 +608,6 @@ struct FanyImeNamedpipeDataToTsf *TryReadDataFromServerPipeWithTimeout() { std::pair ret = {0, L""}; int timeoutMs = 50; // Default timeout 50ms - LogServerPipeWaitStart(timeoutMs); if (!hFromServerPipe || hFromServerPipe == INVALID_HANDLE_VALUE) // Try to reconnect { @@ -701,8 +616,6 @@ struct FanyImeNamedpipeDataToTsf *TryReadDataFromServerPipeWithTimeout() namedpipeDataFromServer.msg_type = Global::DataFromServerMsgType::Normal; // wcscpy_s(namedpipeDataFromServer.candidate_string, L"PipeOpenError"); wcscpy_s(namedpipeDataFromServer.candidate_string, L"X"); - LogServerPipeReadFallback(L"open_to_tsf_pipe_failed", namedpipeDataFromServer.candidate_string, 0.0, - timeoutMs, GetLastError(), 0, 0); return &namedpipeDataFromServer; } } @@ -719,12 +632,6 @@ struct FanyImeNamedpipeDataToTsf *TryReadDataFromServerPipeWithTimeout() while (true) { // TODO: Do not log -#ifdef FANY_DEBUG - QueryPerformanceCounter(&nowCounter); - OutputDebugString( - fmt::format(L"[msime]: current waited: {:.3f}", GetElapsedMilliseconds(startCounter, nowCounter, frequency)) - .c_str()); -#endif BOOL peekOk = PeekNamedPipe(hFromServerPipe, nullptr, 0, nullptr, &bytesAvailable, nullptr); if (!peekOk) { @@ -734,14 +641,6 @@ struct FanyImeNamedpipeDataToTsf *TryReadDataFromServerPipeWithTimeout() else if (bytesAvailable > 0) { auto ret = ReadDataFromServerViaNamedPipe(); -#ifdef FANY_DEBUG - QueryPerformanceCounter(&nowCounter); - OutputDebugString( - fmt::format(L"[msime]: PeekNamedPipe: {:.3f}", GetElapsedMilliseconds(startCounter, nowCounter, frequency)) - .c_str()); -#endif - LogServerPipeWaitResult(ret->msg_type, ret->candidate_string, - GetElapsedMilliseconds(startCounter, nowCounter, frequency)); return ret; } @@ -763,9 +662,6 @@ struct FanyImeNamedpipeDataToTsf *TryReadDataFromServerPipeWithTimeout() // Pipe timeout error wcscpy_s(namedpipeDataFromServer.candidate_string, L"T"); const wchar_t *reason = peekFailureCount > 0 ? L"peek_failed_until_timeout" : L"timeout_no_data"; - LogServerPipeReadFallback(reason, namedpipeDataFromServer.candidate_string, - GetElapsedMilliseconds(startCounter, nowCounter, frequency), timeoutMs, lastPeekError, - bytesAvailable, peekFailureCount); return &namedpipeDataFromServer; } @@ -785,8 +681,6 @@ struct FanyImeNamedpipeDataToTsf *ReadDataFromServerViaNamedPipe() namedpipeDataFromServer.msg_type = 0; // wcscpy_s(namedpipeDataFromServer.candidate_string, L"PipeOpenError"); wcscpy_s(namedpipeDataFromServer.candidate_string, L"X"); - LogServerPipeReadFallback(L"read_open_to_tsf_pipe_failed", namedpipeDataFromServer.candidate_string, 0.0, - 0, GetLastError(), 0, 0); return &namedpipeDataFromServer; } } @@ -801,22 +695,15 @@ struct FanyImeNamedpipeDataToTsf *ReadDataFromServerViaNamedPipe() ); if (!readResult || bytesRead == 0) // Disconnected or error { - LogReadFailure(FANY_IME_TO_TSF_NAMED_PIPE, bytesRead); ClosePipeHandleIfValid(hFromServerPipe); } else { -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: ReadDataFromServerViaNamedPipe: {}", // - namedpipeDataFromServer.candidate_string) - .c_str()); -#endif return &namedpipeDataFromServer; } namedpipeDataFromServer.msg_type = 0; wcscpy_s(namedpipeDataFromServer.candidate_string, L"ReadDataError"); - LogServerPipeReadFallback(L"read_failed", namedpipeDataFromServer.candidate_string, 0.0, 0, GetLastError(), 0, 0); return &namedpipeDataFromServer; } @@ -852,13 +739,8 @@ 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 - LogCreateFileFailure(FANY_IME_AUX_NAMED_PIPE); return; } - LogAuxMessage(pipeData); DWORD bytesWritten = 0; BOOL ret = WriteFile( // hAuxPipe, // @@ -869,7 +751,6 @@ void SendToAuxNamedpipe(std::wstring pipeData) ); if (!ret || bytesWritten != pipeData.length() * sizeof(wchar_t)) { - LogWriteFailure(FANY_IME_AUX_NAMED_PIPE, bytesWritten, pipeData.length() * sizeof(wchar_t)); } CloseHandle(hAuxPipe); } diff --git a/src/Key/KeyEventSink.cpp b/src/Key/KeyEventSink.cpp index 9dc17735..040f854f 100644 --- a/src/Key/KeyEventSink.cpp +++ b/src/Key/KeyEventSink.cpp @@ -169,10 +169,6 @@ BOOL CMetasequoiaIME::_IsKeyEaten( // } } -#ifdef FANY_DEBUG - DebugLog(L"IsPunctuation _candidateMode: {}, isPunctuation: {}", (int)_candidateMode, isPunctuation); -#endif - // // Punctuation // @@ -436,13 +432,6 @@ STDAPI CMetasequoiaIME::OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lP _QueuePendingPunctuationCommitText(punctuationCommitText.c_str()); } PostMessage(_msgWndHandle, WM_AsyncPunctuationCommit, code, static_cast(wch)); - OutputDebugString( - fmt::format( - L"[msime-punc] OnKeyDown async-punctuation queue keycode={} wch={} with_candidate={} " - L"elapsed_ms={:.3f}", - code, static_cast(wch), shouldFinalizeFirstCandidateWithPunctuation ? 1 : 0, - asyncPuncTimer.ElapsedMs()) - .c_str()); return S_OK; } @@ -486,10 +475,6 @@ STDAPI CMetasequoiaIME::OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lP if (isPunctuationKey) { - OutputDebugString( - fmt::format(L"[msime-punc] OnKeyDown end keycode={} eaten={} total_ms={:.3f}", code, *pIsEaten ? 1 : 0, - onKeyDownTimer.ElapsedMs()) - .c_str()); } return S_OK; } @@ -535,11 +520,6 @@ STDAPI CMetasequoiaIME::OnKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lPar UINT code = 0; *pIsEaten = _IsKeyEaten(pContext, (UINT)wParam, &code, &wch, &KeystrokeState); -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: ITfKeyEventSink::OnKeyUp"); - OutputDebugString(fmt::format(L"[msime]: Global::PureShiftKeyUp: {}", Global::PureShiftKeyUp).c_str()); -#endif - // if (code == VK_SHIFT) // { // if (Global::PureShiftKeyUp) diff --git a/src/Key/KeyHandler.cpp b/src/Key/KeyHandler.cpp index beb23437..97cc9902 100644 --- a/src/Key/KeyHandler.cpp +++ b/src/Key/KeyHandler.cpp @@ -77,9 +77,6 @@ VOID CMetasequoiaIME::_DeleteCandidateList(BOOL isForce, _In_opt_ ITfContext *pC double endCandidateElapsedMs = 0; if (_pCandidateListUIPresenter) { -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: create_word: dispose window?").c_str()); -#endif PerfTimer endCandidateTimer; CCandidateListUIPresenter *pPresenter = _pCandidateListUIPresenter; _pCandidateListUIPresenter = nullptr; @@ -177,10 +174,6 @@ 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)) { @@ -257,9 +250,6 @@ HRESULT CMetasequoiaIME::_HandleCompositionInput(TfEditCookie ec, _In_ ITfContex } } -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: AddVirtualKey Here."); -#endif // Add virtual key to composition processor engine pCompositionProcessorEngine->AddVirtualKey(wch); g_toggleImeFallbackBuffer.push_back(wch); @@ -296,12 +286,6 @@ HRESULT CMetasequoiaIME::_HandleCompositionInputWorker(_In_ CCompositionProcesso if (readingStrings.Count()) { -#ifdef FANY_DEBUG - // TODO: Log reading strings - OutputDebugString(fmt::format(L"[msime]: create_word count: {}", readingStrings.Count()).c_str()); - std::wstring readingStr = readingStrings.GetAt(0)->ToWString(); - OutputDebugString(fmt::format(L"[msime]: create_word: {}", readingStr).c_str()); -#endif } /* 一般来说,readingStrings 数组中只有一个元素,这个元素就是当前输入的拼音 */ @@ -309,9 +293,6 @@ HRESULT CMetasequoiaIME::_HandleCompositionInputWorker(_In_ CCompositionProcesso double addComposingElapsedMs = 0; for (UINT index = 0; index < readingStrings.Count(); index++) { -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: create_word here test!!!").c_str()); -#endif CStringRange curReadingStr; std::wstring readingStr = readingStrings.GetAt(0)->ToWString(); @@ -841,13 +822,6 @@ HRESULT CMetasequoiaIME::_HandleCompositionPunctuation(TfEditCookie ec, _In_ ITf PerfTimer completeTimer; _HandleCompleteCommitFirst(ec, pContext); double completeElapsedMs = completeTimer.ElapsedMs(); - OutputDebugString( - fmt::format( - L"[msime-punc] HandleCompositionPunctuation composed keycode={} wch={} pipe_ms={:.3f} " - L"insert_ms={:.3f} complete_ms={:.3f} total_ms={:.3f}", - Global::Keycode, static_cast(wch), pipeReadElapsedMs, insertElapsedMs, - completeElapsedMs, timer.ElapsedMs()) - .c_str()); } else { @@ -862,13 +836,6 @@ HRESULT CMetasequoiaIME::_HandleCompositionPunctuation(TfEditCookie ec, _In_ ITf PerfTimer completeTimer; _HandleComplete(ec, pContext); double completeElapsedMs = completeTimer.ElapsedMs(); - OutputDebugString( - fmt::format( - L"[msime-punc] HandleCompositionPunctuation plain keycode={} wch={} pipe_ms={:.3f} " - L"addchar_ms={:.3f} complete_ms={:.3f} total_ms={:.3f}", - Global::Keycode, static_cast(wch), pipeReadElapsedMs, addCharElapsedMs, - completeElapsedMs, timer.ElapsedMs()) - .c_str()); } diff --git a/src/Key/KeyStateCategory.cpp b/src/Key/KeyStateCategory.cpp index 5877db90..0a2cec06 100644 --- a/src/Key/KeyStateCategory.cpp +++ b/src/Key/KeyStateCategory.cpp @@ -36,11 +36,11 @@ CKeyStateCategory *CKeyStateCategoryFactory::MakeKeyStateCategory(KEYSTROKE_CATE pKeyState = new (std::nothrow) CKeyStateComposing(pTextService); break; - case CATEGORY_CANDIDATE: - pKeyState = new (std::nothrow) CKeyStateCandidate(pTextService); - break; - - default: + case CATEGORY_CANDIDATE: + pKeyState = new (std::nothrow) CKeyStateCandidate(pTextService); + break; + + default: pKeyState = new (std::nothrow) CKeyStateNull(pTextService); break; } @@ -87,10 +87,7 @@ HRESULT CKeyStateCategory::KeyStateHandler(KEYSTROKE_FUNCTION function, KeyHandl case FUNCTION_FINALIZE_CANDIDATELIST: return HandleKeyFinalizeCandidatelist(dto); case FUNCTION_FINALIZE_CANDIDATELISTForVKReturn: -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: Use VK_RETURN to commit original keystroke string."); -#endif - return HandleKeyFinalizeCandidatelistForVKReturn(dto); + return HandleKeyFinalizeCandidatelistForVKReturn(dto); case FUNCTION_CONVERT: { return HandleKeyConvert(dto); @@ -280,10 +277,7 @@ HRESULT CKeyStateComposing::HandleKeyConvert(KeyHandlerEditSessionDTO dto) { if (Global::Keycode == VK_SPACE) { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: HandleKeyConvert in CKeyStateComposing"); -#endif - return _pTextService->_HandleCandidateFinalize(dto.ec, dto.pContext); + return _pTextService->_HandleCandidateFinalize(dto.ec, dto.pContext); } // VK_SPACE return _pTextService->_HandleCompositionConvert(dto.ec, dto.pContext, FALSE); @@ -340,10 +334,7 @@ HRESULT CKeyStateCandidate::HandleKeyFinalizeCandidatelist(KeyHandlerEditSession // _HandleCandidateInput HRESULT CKeyStateCandidate::HandleKeyFinalizeCandidatelistForVKReturn(KeyHandlerEditSessionDTO dto) { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: Will commit original keystroke string."); -#endif - return _pTextService->_HandleCandidateFinalizeForVKReturn(dto.ec, dto.pContext); + return _pTextService->_HandleCandidateFinalizeForVKReturn(dto.ec, dto.pContext); } // HandleKeyFinalizeCandidatelistAndInput @@ -358,10 +349,7 @@ HRESULT CKeyStateCandidate::HandleKeyConvert(KeyHandlerEditSessionDTO dto) { if (Global::Keycode == VK_SPACE) { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: HandleKeyConvert in CKeyStateCandidate"); -#endif - return _pTextService->_HandleCandidateFinalize(dto.ec, dto.pContext); + return _pTextService->_HandleCandidateFinalize(dto.ec, dto.pContext); } // Send candidate string to client when pressing VK_SPACE return _pTextService->_HandleCandidateConvert(dto.ec, dto.pContext); @@ -382,10 +370,7 @@ HRESULT CKeyStateCandidate::HandleKeyArrow(KeyHandlerEditSessionDTO dto) //_HandleCandidateSelectByNumber HRESULT CKeyStateCandidate::HandleKeySelectByNumber(KeyHandlerEditSessionDTO dto) { -#ifdef FANY_DEBUG - OutputDebugString(L"[msime]: HandleKeySelectByNumber in CKeyStateCandidate"); -#endif - // return _pTextService->_HandleCandidateSelectByNumber(dto.ec, dto.pContext, dto.code); + // return _pTextService->_HandleCandidateSelectByNumber(dto.ec, dto.pContext, dto.code); return _pTextService->_HandleCandidateFinalize(dto.ec, dto.pContext); } diff --git a/src/LanguageBar/LanguageBar.cpp b/src/LanguageBar/LanguageBar.cpp index 1570c85d..ff269ff7 100644 --- a/src/LanguageBar/LanguageBar.cpp +++ b/src/LanguageBar/LanguageBar.cpp @@ -374,16 +374,7 @@ 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(L"[msime]: right click of lang bar item"); -#endif - SendLangbarRightClickEventToUIProcess(prcArea); + SendLangbarRightClickEventToUIProcess(prcArea); return S_OK; } diff --git a/src/Tf/TfTextLayoutSink.cpp b/src/Tf/TfTextLayoutSink.cpp index f03289e6..6af70277 100644 --- a/src/Tf/TfTextLayoutSink.cpp +++ b/src/Tf/TfTextLayoutSink.cpp @@ -97,10 +97,7 @@ STDAPI CTfTextLayoutSink::OnLayoutChange(_In_ ITfContext *pContext, TfLayoutCode switch (lcode) { case TF_LC_CREATE: { -#ifdef FANY_DEBUG - // TODO: Log TF_LC_CREATE is triggered -#endif - } + } case TF_LC_CHANGE: { CGetTextExtentEditSession *pEditSession = nullptr; pEditSession = new (std::nothrow) @@ -111,10 +108,7 @@ STDAPI CTfTextLayoutSink::OnLayoutChange(_In_ ITfContext *pContext, TfLayoutCode PerfTimer requestTimer; pContext->RequestEditSession(_pTextService->_GetClientId(), pEditSession, TF_ES_SYNC | TF_ES_READ, &hr); requestEditSessionElapsedMs = requestTimer.ElapsedMs(); -#ifdef FANY_DEBUG - // TODO: Log TF_LC_CHANGE is triggered and edit session is started -#endif - pEditSession->Release(); + pEditSession->Release(); } } break; @@ -244,17 +238,10 @@ HRESULT CTfTextLayoutSink::_GetTextExt(_Out_ RECT *lpRect) if (FAILED(hr = pContextView->GetTextExt(_tfEditCookie, _pRangeComposition, lpRect, &isClipped))) { -#ifdef FANY_DEBUG - // TODO: Log GetTextExt failed -#endif - // Set default value to make sure the window is hidden by moving it out of the screen + // Set default value to make sure the window is hidden by moving it out of the screen lpRect->left = 0; lpRect->bottom = Global::INVALID_Y; } -#ifdef FANY_DEBUG - // TODO: Log lpRect position -#endif - pContextView->Release(); diff --git a/src/Thread/ThreadFocusSink.cpp b/src/Thread/ThreadFocusSink.cpp index 75fcee43..fcf07106 100644 --- a/src/Thread/ThreadFocusSink.cpp +++ b/src/Thread/ThreadFocusSink.cpp @@ -11,14 +11,11 @@ // //---------------------------------------------------------------------------- -STDAPI CMetasequoiaIME::OnSetThreadFocus() -{ -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: CMetasequoiaIME::OnSetThreadFocus").c_str()); -#endif - PostMessage(_msgWndHandle, WM_ThreadFocus, 0, 0); - if (_pCandidateListUIPresenter) - { +STDAPI CMetasequoiaIME::OnSetThreadFocus() +{ + PostMessage(_msgWndHandle, WM_ThreadFocus, 0, 0); + if (_pCandidateListUIPresenter) + { ITfDocumentMgr *pCandidateListDocumentMgr = nullptr; ITfContext *pTfContext = _pCandidateListUIPresenter->_GetContextDocument(); @@ -41,13 +38,10 @@ STDAPI CMetasequoiaIME::OnSetThreadFocus() // //---------------------------------------------------------------------------- -STDAPI CMetasequoiaIME::OnKillThreadFocus() -{ -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: CMetasequoiaIME::OnKillThreadFocus").c_str()); -#endif - if (_pCandidateListUIPresenter) - { +STDAPI CMetasequoiaIME::OnKillThreadFocus() +{ + if (_pCandidateListUIPresenter) + { ITfDocumentMgr *pCandidateListDocumentMgr = nullptr; ITfContext *pTfContext = _pCandidateListUIPresenter->_GetContextDocument(); diff --git a/src/UI/CandidateListUIPresenter.cpp b/src/UI/CandidateListUIPresenter.cpp index dcff1ebf..adb15823 100644 --- a/src/UI/CandidateListUIPresenter.cpp +++ b/src/UI/CandidateListUIPresenter.cpp @@ -52,10 +52,6 @@ HRESULT CMetasequoiaIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfConte std::wstring pendingCommitCandidate = _TakePendingCommitCandidate(); -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: create_word, keystrokeBuffer: {}", keyStrokebuffer.ToWString()).c_str()); -#endif - // _pCandidateListUIPresenter would be null in uwp/metro apps if (nullptr == _pCandidateListUIPresenter) { @@ -118,9 +114,6 @@ HRESULT CMetasequoiaIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfConte else if (serverMsgType == Global::DataFromServerMsgType::Normal) // 只有正常情况下才会上屏 { GlobalIme::word_for_creating_word = L""; -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"[msime]: create_word, normal???").c_str()); -#endif candidateString.Set(serverCandidateString.c_str(), serverCandidateString.length()); PerfTimer insertTextTimer; hr = _InsertTextToComposition(ec, pContext, &candidateString); @@ -142,11 +135,6 @@ HRESULT CMetasequoiaIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfConte { std::wstring remainingRawInput = data.substr(0, separator); std::wstring curWord = data.substr(separator + 1); -#ifdef FANY_DEBUG - OutputDebugString( - fmt::format(L"[msime]: create_word, remainingRawInput: {}, curWord: {}", remainingRawInput, curWord) - .c_str()); -#endif GlobalIme::word_for_creating_word = curWord; CCompositionProcessorEngine *pCompositionProcessorEngine = nullptr; pCompositionProcessorEngine = _pCompositionProcessorEngine; @@ -175,10 +163,6 @@ HRESULT CMetasequoiaIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfConte _HandleCancel(ec, pContext); } } -#ifdef FANY_DEBUG - OutputDebugString( - fmt::format(L"[msime]: create_word: current word part {}", GlobalIme::word_for_creating_word).c_str()); -#endif return hr; } } @@ -211,11 +195,6 @@ HRESULT CMetasequoiaIME::_HandleCandidateFinalizeForVKReturn(TfEditCookie ec, _I // goto NoPresenter; } -#ifdef FANY_DEBUG - std::wstring msg(candidateString.Get(), candidateLen); - OutputDebugString(fmt::format(L"[msime]: {}", msg).c_str()); -#endif - if (candidateLen) { hr = _AddComposingAndChar(ec, pContext, &candidateString); diff --git a/src/Utils/FanyUtils.cpp b/src/Utils/FanyUtils.cpp index 6ad70452..186cb78d 100644 --- a/src/Utils/FanyUtils.cpp +++ b/src/Utils/FanyUtils.cpp @@ -32,9 +32,6 @@ 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 } } } @@ -82,4 +79,4 @@ string::size_type count_utf8_chars(const string &str) { return utf8::distance(str.begin(), str.end()); } -} // namespace FanyUtils \ No newline at end of file +} // namespace FanyUtils