Skip to content

Commit 7f03090

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 c127fa7 commit 7f03090

File tree

7 files changed

+47
-6
lines changed

7 files changed

+47
-6
lines changed

RimeWithWeasel/RimeWithWeasel.cpp

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

3132
static RimeApi* rime_api;
3233
WeaselSessionId _GenerateNewWeaselSessionId(SessionStatusMap sm, DWORD pid) {
@@ -888,6 +889,8 @@ bool RimeWithWeaselHandler::_Respond(WeaselSessionId ipc_id, EatLine eat) {
888889

889890
// style
890891
if (!session_status.__synced) {
892+
messages.push_back(std::string("config.hide_ime_mode_icon=") +
893+
std::to_string((int)hide_ime_mode_icon) + "\n");
891894
std::wstringstream ss;
892895
boost::archive::text_woarchive oa(ss);
893896
oa << session_status.style;
@@ -1112,6 +1115,7 @@ static void _UpdateUIStyle(RimeConfig* config, UI* ui, bool initialize) {
11121115
_RimeGetIntStr(config, "style/font_point", style.font_point);
11131116
if (style.font_point <= 0)
11141117
style.font_point = 12;
1118+
_RimeGetBool(config, "hide_ime_mode_icon", initialize, hide_ime_mode_icon);
11151119
_RimeGetIntStr(config, "style/label_font_point", style.label_font_point,
11161120
"style/font_point", 0, _abs);
11171121
_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
@@ -377,16 +377,18 @@ BOOL WeaselTSF::_InitLanguageBar() {
377377
if (_pThreadMgr->QueryInterface(&pLangBarItemMgr) != S_OK)
378378
return FALSE;
379379

380-
if ((_pLangBarButton = new CLangBarItemButton(this, GUID_LBI_INPUTMODE,
381-
_cand->style())) == NULL)
380+
const GUID langBarGuid =
381+
_config.hide_ime_mode_icon ? GUID_NULL : GUID_LBI_INPUTMODE;
382+
if ((_pLangBarButton =
383+
new CLangBarItemButton(this, langBarGuid, _cand->style())) == NULL)
382384
return FALSE;
383385

384386
if (pLangBarItemMgr->AddItem(_pLangBarButton) != S_OK) {
385387
_pLangBarButton = NULL;
386388
return FALSE;
387389
}
388390

389-
_pLangBarButton->Show(TRUE);
391+
_pLangBarButton->Show(!_config.hide_ime_mode_icon);
390392
fRet = TRUE;
391393

392394
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ 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+
}
195+
// inline preedit switch
192196
bool inline_preedit;
197+
// hide tsf mode icon switch
198+
bool hide_ime_mode_icon;
193199
};
194200

195201
struct UIStyle {
@@ -532,5 +538,10 @@ void serialize(Archive& ar, weasel::TextRange& s, const unsigned int version) {
532538
ar & s.end;
533539
ar & s.cursor;
534540
}
541+
template <typename Archive>
542+
void serialize(Archive& ar, weasel::Config& s, const unsigned int version) {
543+
ar & s.inline_preedit;
544+
ar & s.hide_ime_mode_icon;
545+
}
535546
} // namespace serialization
536547
} // namespace boost

0 commit comments

Comments
 (0)