Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GUID_COMPARTMENT_KEYBOARD_OPENCLOSE actions configurable. #1364

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions WeaselSetup/WeaselSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 21 additions & 6 deletions WeaselTSF/Compartment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <functional>
#include "ResponseParser.h"
#include "CandidateList.h"
#include "LanguageBar.h"

STDAPI CCompartmentEventSink::QueryInterface(REFIID riid,
_Outptr_ void** ppvObj) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion WeaselTSF/KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions WeaselTSF/LanguageBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions WeaselTSF/WeaselTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions WeaselTSF/WeaselTSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,5 @@ class WeaselTSF : public ITfTextInputProcessorEx,
TfGuidAtom _gaDisplayAttributeInput;
BOOL _async_edit = false;
BOOL _committed = false;
BOOL _isToOpenClose = false;
};