diff --git a/RimeWithWeasel/RimeWithWeasel.cpp b/RimeWithWeasel/RimeWithWeasel.cpp index 1c1b64fb3..b4d986a31 100644 --- a/RimeWithWeasel/RimeWithWeasel.cpp +++ b/RimeWithWeasel/RimeWithWeasel.cpp @@ -27,6 +27,7 @@ typedef enum { COLOR_ABGR = 0, COLOR_ARGB, COLOR_RGBA } ColorFormat; #define TRIMHEAD_REGEX std::regex("0x", std::regex::icase) #endif using namespace weasel; +static bool hide_ime_mode_icon = false; static RimeApi* rime_api; WeaselSessionId _GenerateNewWeaselSessionId(SessionStatusMap sm, DWORD pid) { @@ -888,6 +889,8 @@ bool RimeWithWeaselHandler::_Respond(WeaselSessionId ipc_id, EatLine eat) { // style if (!session_status.__synced) { + messages.push_back(std::string("config.hide_ime_mode_icon=") + + std::to_string((int)hide_ime_mode_icon) + "\n"); std::wstringstream ss; boost::archive::text_woarchive oa(ss); oa << session_status.style; @@ -1112,6 +1115,7 @@ static void _UpdateUIStyle(RimeConfig* config, UI* ui, bool initialize) { _RimeGetIntStr(config, "style/font_point", style.font_point); if (style.font_point <= 0) style.font_point = 12; + _RimeGetBool(config, "hide_ime_mode_icon", initialize, hide_ime_mode_icon); _RimeGetIntStr(config, "style/label_font_point", style.label_font_point, "style/font_point", 0, _abs); _RimeGetIntStr(config, "style/comment_font_point", style.comment_font_point, diff --git a/WeaselIPC/Configurator.cpp b/WeaselIPC/Configurator.cpp index a16c4fa22..1a0404973 100644 --- a/WeaselIPC/Configurator.cpp +++ b/WeaselIPC/Configurator.cpp @@ -19,5 +19,11 @@ void Configurator::Store(Deserializer::KeyType const& key, bool bool_value = (!value.empty() && value != L"0"); if (key[1] == L"inline_preedit") { m_pTarget->p_config->inline_preedit = bool_value; + return; + } + + if (key[1] == L"hide_ime_mode_icon") { + m_pTarget->p_config->hide_ime_mode_icon = bool_value; + return; } } diff --git a/WeaselTSF/EditSession.cpp b/WeaselTSF/EditSession.cpp index 8f4d50367..031aff320 100644 --- a/WeaselTSF/EditSession.cpp +++ b/WeaselTSF/EditSession.cpp @@ -13,6 +13,11 @@ STDAPI WeaselTSF::DoEditSession(TfEditCookie ec) { bool ok = m_client.GetResponseData(std::ref(parser)); + if (config.hide_ime_mode_icon != _config.hide_ime_mode_icon) { + _config = config; + _UninitLanguageBar(); + _InitLanguageBar(); + } _UpdateLanguageBar(_status); if (ok) { diff --git a/WeaselTSF/LanguageBar.cpp b/WeaselTSF/LanguageBar.cpp index a03b6159c..61dbe1519 100644 --- a/WeaselTSF/LanguageBar.cpp +++ b/WeaselTSF/LanguageBar.cpp @@ -377,8 +377,10 @@ BOOL WeaselTSF::_InitLanguageBar() { if (_pThreadMgr->QueryInterface(&pLangBarItemMgr) != S_OK) return FALSE; - if ((_pLangBarButton = new CLangBarItemButton(this, GUID_LBI_INPUTMODE, - _cand->style())) == NULL) + const GUID langBarGuid = + _config.hide_ime_mode_icon ? GUID_NULL : GUID_LBI_INPUTMODE; + if ((_pLangBarButton = + new CLangBarItemButton(this, langBarGuid, _cand->style())) == NULL) return FALSE; if (pLangBarItemMgr->AddItem(_pLangBarButton) != S_OK) { @@ -386,7 +388,7 @@ BOOL WeaselTSF::_InitLanguageBar() { return FALSE; } - _pLangBarButton->Show(TRUE); + _pLangBarButton->Show(!_config.hide_ime_mode_icon); fRet = TRUE; return fRet; diff --git a/WeaselTSF/WeaselTSF.cpp b/WeaselTSF/WeaselTSF.cpp index 590d3b8f2..4d274ff78 100644 --- a/WeaselTSF/WeaselTSF.cpp +++ b/WeaselTSF/WeaselTSF.cpp @@ -119,6 +119,15 @@ STDAPI WeaselTSF::Deactivate() { return S_OK; } +static void fake_key() { + INPUT inputs[2]; + inputs[0].type = INPUT_KEYBOARD; + inputs[0].ki = {VK_SELECT, 0, 0, 0, 0}; + inputs[1].type = INPUT_KEYBOARD; + inputs[1].ki = {VK_SELECT, 0, KEYEVENTF_KEYUP, 0, 0}; + ::SendInput(sizeof(inputs) / sizeof(INPUT), inputs, sizeof(INPUT)); +} + STDAPI WeaselTSF::ActivateEx(ITfThreadMgr* pThreadMgr, TfClientId tfClientId, DWORD dwFlags) { @@ -148,6 +157,7 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr* pThreadMgr, if (!_InitPreservedKey()) goto ExitError; + fake_key(); if (!_InitLanguageBar()) goto ExitError; @@ -175,10 +185,12 @@ STDMETHODIMP WeaselTSF::OnSetThreadFocus() { _isToOpenClose = (_ToggleImeOnOpenClose == L"yes"); if (m_client.Echo()) { m_client.ProcessKeyEvent(0); - weasel::ResponseParser parser(NULL, NULL, &_status, NULL, &_cand->style()); + weasel::ResponseParser parser(NULL, NULL, &_status, &_config, + &_cand->style()); bool ok = m_client.GetResponseData(std::ref(parser)); if (ok) _UpdateLanguageBar(_status); + _ShowLanguageBar(!_config.hide_ime_mode_icon); } return S_OK; } diff --git a/WeaselTSF/WeaselTSF.h b/WeaselTSF/WeaselTSF.h index 696d3cce4..41c2a7b31 100644 --- a/WeaselTSF/WeaselTSF.h +++ b/WeaselTSF/WeaselTSF.h @@ -227,6 +227,7 @@ class WeaselTSF : public ITfTextInputProcessorEx, /* IME status */ weasel::Status _status; + weasel::Config _config; // guidatom for the display attibute. TfGuidAtom _gaDisplayAttributeInput; diff --git a/include/WeaselIPCData.h b/include/WeaselIPCData.h index 09f22f91c..ef20f8850 100644 --- a/include/WeaselIPCData.h +++ b/include/WeaselIPCData.h @@ -187,9 +187,15 @@ struct Status { // 用於向前端告知設置信息 struct Config { - Config() : inline_preedit(false) {} - void reset() { inline_preedit = false; } + Config() : inline_preedit(false), hide_ime_mode_icon(false) {} + void reset() { + inline_preedit = false; + hide_ime_mode_icon = false; + } + // inline preedit switch bool inline_preedit; + // hide tsf mode icon switch + bool hide_ime_mode_icon; }; struct UIStyle { @@ -532,5 +538,10 @@ void serialize(Archive& ar, weasel::TextRange& s, const unsigned int version) { ar & s.end; ar & s.cursor; } +template +void serialize(Archive& ar, weasel::Config& s, const unsigned int version) { + ar & s.inline_preedit; + ar & s.hide_ime_mode_icon; +} } // namespace serialization } // namespace boost