diff --git a/WeaselSetup/WeaselSetup.cpp b/WeaselSetup/WeaselSetup.cpp index bef216a7c..259af11f7 100644 --- a/WeaselSetup/WeaselSetup.cpp +++ b/WeaselSetup/WeaselSetup.cpp @@ -161,6 +161,14 @@ static int Run(LPTSTR lpCmdLine) { L"CheckForUpdates", L"0", REG_SZ); } + if (!wcscmp(L"/toggleime", lpCmdLine)) { + return SetRegKeyValue(HKEY_CURRENT_USER, L"Software\\Rime\\weasel", + L"ToggleImeOnOpenClose", L"yes", REG_SZ); + } + if (!wcscmp(L"/toggleascii", lpCmdLine)) { + return SetRegKeyValue(HKEY_CURRENT_USER, L"Software\\Rime\\weasel", + L"ToggleImeOnOpenClose", L"no", REG_SZ); + } if (!wcscmp(L"/testing", lpCmdLine)) { return SetRegKeyValue(HKEY_CURRENT_USER, L"Software\\Rime\\weasel", L"UpdateChannel", L"testing", REG_SZ); diff --git a/WeaselTSF/Compartment.cpp b/WeaselTSF/Compartment.cpp index a3b6a25a2..a45e0d1f9 100644 --- a/WeaselTSF/Compartment.cpp +++ b/WeaselTSF/Compartment.cpp @@ -5,6 +5,7 @@ #include #include "ResponseParser.h" #include "CandidateList.h" +#include "LanguageBar.h" STDAPI CCompartmentEventSink::QueryInterface(REFIID riid, _Outptr_ void** ppvObj) { @@ -242,13 +243,27 @@ void WeaselTSF::_UninitCompartment() { HRESULT WeaselTSF::_HandleCompartment(REFGUID guidCompartment) { if (IsEqualGUID(guidCompartment, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE)) { - BOOL isOpen = _IsKeyboardOpen(); - // clear composition when close keyboard - if (!isOpen && _pEditSessionContext) { - m_client.ClearComposition(); - _EndComposition(_pEditSessionContext, true); + if (_isToOpenClose) { + BOOL isOpen = _IsKeyboardOpen(); + // clear composition when close keyboard + if (!isOpen && _pEditSessionContext) { + m_client.ClearComposition(); + _EndComposition(_pEditSessionContext, true); + } + _EnableLanguageBar(isOpen); + _UpdateLanguageBar(_status); + } else { + _status.ascii_mode = !_status.ascii_mode; + _SetKeyboardOpen(true); + if (_pLangBarButton && _pLangBarButton->IsLangBarDisabled()) + _EnableLanguageBar(true); + _HandleLangBarMenuSelect(_status.ascii_mode + ? ID_WEASELTRAY_ENABLE_ASCII + : ID_WEASELTRAY_DISABLE_ASCII); + if (_pEditSessionContext) + m_client.ClearComposition(); + _UpdateLanguageBar(_status); } - _EnableLanguageBar(isOpen); } else if (IsEqualGUID(guidCompartment, GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION)) { BOOL isOpen = _IsKeyboardOpen(); diff --git a/WeaselTSF/KeyEventSink.cpp b/WeaselTSF/KeyEventSink.cpp index 55dde4f98..e0d431410 100644 --- a/WeaselTSF/KeyEventSink.cpp +++ b/WeaselTSF/KeyEventSink.cpp @@ -9,7 +9,9 @@ static BOOL prevfEaten = FALSE; static int keyCountToSimulate = 0; void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten) { - if (!_IsKeyboardOpen() || _IsKeyboardDisabled()) { + // when _IsKeyboardDisabled don't eat the key, + // when keyboard closable and keyboard closed, don't eat the key + if ((_isToOpenClose && !_IsKeyboardOpen()) || _IsKeyboardDisabled()) { *pfEaten = FALSE; return; } diff --git a/WeaselTSF/LanguageBar.h b/WeaselTSF/LanguageBar.h index 667eab3fd..2c0513ab3 100644 --- a/WeaselTSF/LanguageBar.h +++ b/WeaselTSF/LanguageBar.h @@ -30,6 +30,7 @@ class CLangBarItemButton : public ITfLangBarItemButton, public ITfSource { /* ITfSource */ STDMETHODIMP AdviseSink(REFIID riid, IUnknown* punk, DWORD* pdwCookie); STDMETHODIMP UnadviseSink(DWORD dwCookie); + BOOL IsLangBarDisabled() { return (_status & TF_LBI_STATUS_DISABLED); } void UpdateWeaselStatus(weasel::Status stat); void SetLangbarStatus(DWORD dwStatus, BOOL fSet); diff --git a/WeaselTSF/WeaselTSF.cpp b/WeaselTSF/WeaselTSF.cpp index 0564ebdc1..236e3daf8 100644 --- a/WeaselTSF/WeaselTSF.cpp +++ b/WeaselTSF/WeaselTSF.cpp @@ -171,6 +171,10 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr* pThreadMgr, } STDMETHODIMP WeaselTSF::OnSetThreadFocus() { + std::wstring _ToggleImeOnOpenClose{}; + RegGetStringValue(HKEY_CURRENT_USER, L"Software\\Rime\\weasel", + L"ToggleImeOnOpenClose", _ToggleImeOnOpenClose); + _isToOpenClose = (_ToggleImeOnOpenClose == L"yes"); if (m_client.Echo()) { m_client.ProcessKeyEvent(0); weasel::ResponseParser parser(NULL, NULL, &_status, NULL, &_cand->style()); diff --git a/WeaselTSF/WeaselTSF.h b/WeaselTSF/WeaselTSF.h index 12ae30d17..696d3cce4 100644 --- a/WeaselTSF/WeaselTSF.h +++ b/WeaselTSF/WeaselTSF.h @@ -232,4 +232,5 @@ class WeaselTSF : public ITfTextInputProcessorEx, TfGuidAtom _gaDisplayAttributeInput; BOOL _async_edit = false; BOOL _committed = false; + BOOL _isToOpenClose = false; };