Skip to content

Commit 786c51d

Browse files
committed
feat: new parameter hide_ime_mode_icon: {bool} in weasel.yaml to determine if to hide TSF language bar icon.
1 parent bf4853d commit 786c51d

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

RimeWithWeasel/RimeWithWeasel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef enum { COLOR_ABGR = 0, COLOR_ARGB, COLOR_RGBA } ColorFormat;
2929
#define TRIMHEAD_REGEX std::regex("0x", std::regex::icase)
3030
#endif
3131
using namespace weasel;
32+
static bool hide_ime_mode_icon = false;
3233

3334
static RimeApi* rime_api;
3435
WeaselSessionId _GenerateNewWeaselSessionId(SessionStatusMap sm, DWORD pid) {
@@ -927,6 +928,8 @@ bool RimeWithWeaselHandler::_Respond(WeaselSessionId ipc_id, EatLine eat) {
927928

928929
// style
929930
if (!session_status.__synced) {
931+
messages.push_back(std::string("config.hide_ime_mode_icon=") +
932+
std::to_string((int)hide_ime_mode_icon) + "\n");
930933
std::wstringstream ss;
931934
boost::archive::text_woarchive oa(ss);
932935
oa << session_status.style;
@@ -1150,6 +1153,7 @@ static void _UpdateUIStyle(RimeConfig* config, UI* ui, bool initialize) {
11501153
_RimeGetIntStr(config, "style/font_point", style.font_point);
11511154
if (style.font_point <= 0)
11521155
style.font_point = 12;
1156+
_RimeGetBool(config, "hide_ime_mode_icon", initialize, hide_ime_mode_icon);
11531157
_RimeGetIntStr(config, "style/label_font_point", style.label_font_point,
11541158
"style/font_point", 0, _abs);
11551159
_RimeGetIntStr(config, "style/comment_font_point", style.comment_font_point,

WeaselIPC/Configurator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ void Configurator::Store(Deserializer::KeyType const& key,
1919
bool bool_value = (!value.empty() && value != L"0");
2020
if (key[1] == L"inline_preedit") {
2121
m_pTarget->p_config->inline_preedit = bool_value;
22+
return;
23+
}
24+
25+
if (key[1] == L"hide_ime_mode_icon") {
26+
m_pTarget->p_config->hide_ime_mode_icon = bool_value;
27+
return;
2228
}
2329
}

WeaselTSF/EditSession.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ STDAPI WeaselTSF::DoEditSession(TfEditCookie ec) {
1313

1414
bool ok = m_client.GetResponseData(std::ref(parser));
1515

16+
if (config.hide_ime_mode_icon != _config.hide_ime_mode_icon) {
17+
_config = config;
18+
_UninitLanguageBar();
19+
_InitLanguageBar();
20+
}
1621
_UpdateLanguageBar(_status);
1722

1823
if (ok) {

WeaselTSF/LanguageBar.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,18 @@ BOOL WeaselTSF::_InitLanguageBar() {
374374
if (_pThreadMgr->QueryInterface(&pLangBarItemMgr) != S_OK)
375375
return FALSE;
376376

377-
if ((_pLangBarButton = new CLangBarItemButton(this, GUID_LBI_INPUTMODE,
378-
_cand->style())) == NULL)
377+
const GUID langBarGuid =
378+
_config.hide_ime_mode_icon ? GUID_NULL : GUID_LBI_INPUTMODE;
379+
if ((_pLangBarButton =
380+
new CLangBarItemButton(this, langBarGuid, _cand->style())) == NULL)
379381
return FALSE;
380382

381383
if (pLangBarItemMgr->AddItem(_pLangBarButton) != S_OK) {
382384
_pLangBarButton = NULL;
383385
return FALSE;
384386
}
385387

386-
_pLangBarButton->Show(TRUE);
388+
_pLangBarButton->Show(!_config.hide_ime_mode_icon);
387389
fRet = TRUE;
388390

389391
return fRet;

WeaselTSF/WeaselTSF.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ STDAPI WeaselTSF::Deactivate() {
119119
return S_OK;
120120
}
121121

122+
static void fake_key() {
123+
INPUT inputs[2];
124+
inputs[0].type = INPUT_KEYBOARD;
125+
inputs[0].ki = {VK_SELECT, 0, 0, 0, 0};
126+
inputs[1].type = INPUT_KEYBOARD;
127+
inputs[1].ki = {VK_SELECT, 0, KEYEVENTF_KEYUP, 0, 0};
128+
::SendInput(sizeof(inputs) / sizeof(INPUT), inputs, sizeof(INPUT));
129+
}
130+
122131
STDAPI WeaselTSF::ActivateEx(ITfThreadMgr* pThreadMgr,
123132
TfClientId tfClientId,
124133
DWORD dwFlags) {
@@ -148,6 +157,7 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr* pThreadMgr,
148157
if (!_InitPreservedKey())
149158
goto ExitError;
150159

160+
fake_key();
151161
if (!_InitLanguageBar())
152162
goto ExitError;
153163

@@ -175,10 +185,12 @@ STDMETHODIMP WeaselTSF::OnSetThreadFocus() {
175185
_isToOpenClose = (_ToggleImeOnOpenClose == L"yes");
176186
if (m_client.Echo()) {
177187
m_client.ProcessKeyEvent(0);
178-
weasel::ResponseParser parser(NULL, NULL, &_status, NULL, &_cand->style());
188+
weasel::ResponseParser parser(NULL, NULL, &_status, &_config,
189+
&_cand->style());
179190
bool ok = m_client.GetResponseData(std::ref(parser));
180191
if (ok)
181192
_UpdateLanguageBar(_status);
193+
_ShowLanguageBar(!_config.hide_ime_mode_icon);
182194
}
183195
return S_OK;
184196
}

WeaselTSF/WeaselTSF.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class WeaselTSF : public ITfTextInputProcessorEx,
227227

228228
/* IME status */
229229
weasel::Status _status;
230+
weasel::Config _config;
230231

231232
// guidatom for the display attibute.
232233
TfGuidAtom _gaDisplayAttributeInput;

include/WeaselIPCData.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,13 @@ struct Status {
187187

188188
// 用於向前端告知設置信息
189189
struct Config {
190-
Config() : inline_preedit(false) {}
191-
void reset() { inline_preedit = false; }
190+
Config() : inline_preedit(false), hide_ime_mode_icon(false) {}
191+
void reset() {
192+
inline_preedit = false;
193+
hide_ime_mode_icon = false;
194+
}
192195
bool inline_preedit;
196+
bool hide_ime_mode_icon;
193197
};
194198

195199
struct UIStyle {
@@ -532,5 +536,10 @@ void serialize(Archive& ar, weasel::TextRange& s, const unsigned int version) {
532536
ar & s.end;
533537
ar & s.cursor;
534538
}
539+
template <typename Archive>
540+
void serialize(Archive& ar, weasel::Config& s, const unsigned int version) {
541+
ar & s.inline_preedit;
542+
ar & s.hide_ime_mode_icon;
543+
}
535544
} // namespace serialization
536545
} // namespace boost

0 commit comments

Comments
 (0)