Skip to content

Commit

Permalink
feat: Caps_Lock binding available
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Jul 4, 2024
1 parent 964456e commit 9bb4b7f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions WeaselTSF/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ void WeaselTSF::_AbortComposition(bool clear) {
if (_IsComposing()) {
_EndComposition(_pEditSessionContext, clear);
}
_committed = TRUE;
_cand->Destroy();
}

Expand Down
3 changes: 3 additions & 0 deletions WeaselTSF/EditSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ STDAPI WeaselTSF::DoEditSession(TfEditCookie ec) {
}
_InsertText(_pEditSessionContext, commit);
_EndComposition(_pEditSessionContext, false);
_committed = TRUE;
} else {
_committed = FALSE;
}
if (_status.composing && !_IsComposing()) {
_StartComposition(_pEditSessionContext,
Expand Down
30 changes: 29 additions & 1 deletion WeaselTSF/KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "KeyEvent.h"
#include "CandidateList.h"

static weasel::KeyEvent prevKeyEvent;
static BOOL prevfEaten = FALSE;
static int keyCountToSimulate = 0;

void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten) {
if (!_IsKeyboardOpen() || _IsKeyboardDisabled()) {
*pfEaten = FALSE;
Expand All @@ -28,7 +32,31 @@ void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten) {
else if (ke.keycode == ibus::Down)
ke.keycode = ibus::Up;
}
*pfEaten = (BOOL)m_client.ProcessKeyEvent(ke);
if (!keyCountToSimulate)
*pfEaten = (BOOL)m_client.ProcessKeyEvent(ke);

if (ke.keycode == ibus::Caps_Lock) {
if (prevKeyEvent.keycode == ibus::Caps_Lock && prevfEaten == TRUE &&
(ke.mask & ibus::RELEASE_MASK) && (!keyCountToSimulate)) {
if ((GetKeyState(VK_CAPITAL) & 0x01)) {
if (_committed || (!*pfEaten && _status.composing)) {
keyCountToSimulate = 2;
INPUT inputs[2];
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki = {VK_CAPITAL, 0, 0, 0, 0};
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki = {VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0, 0};
::SendInput(sizeof(inputs) / sizeof(INPUT), inputs, sizeof(INPUT));
}
}
*pfEaten = TRUE;
}
if (keyCountToSimulate)
keyCountToSimulate--;
}

prevfEaten = *pfEaten;
prevKeyEvent = ke;
}
}

Expand Down
1 change: 1 addition & 0 deletions WeaselTSF/WeaselTSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@ class WeaselTSF : public ITfTextInputProcessorEx,
// guidatom for the display attibute.
TfGuidAtom _gaDisplayAttributeInput;
BOOL _async_edit = false;
BOOL _committed = false;
};

0 comments on commit 9bb4b7f

Please sign in to comment.