Skip to content

Commit

Permalink
feat(RimeWithWeasel): async keyevent processing
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Nov 19, 2024
1 parent 0ef3154 commit e893f67
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <filesystem>
#include <map>
#include <regex>
#include <future>
#include <rime_api.h>

#define TRANSPARENT_COLOR 0x00000000
Expand Down Expand Up @@ -322,26 +323,32 @@ BOOL RimeWithWeaselHandler::ProcessKeyEvent(KeyEvent keyEvent,
<< ", mask = " << keyEvent.mask << ", ipc_id = " << ipc_id;
if (m_disabled)
return FALSE;
RimeSessionId session_id = to_session_id(ipc_id);
Bool handled = rime_api->process_key(session_id, keyEvent.keycode,
expand_ibus_modifier(keyEvent.mask));
if (!handled) {
bool isVimBackInCommandMode =
(keyEvent.keycode == ibus::Keycode::Escape) ||
((keyEvent.mask & (1 << 2)) &&
(keyEvent.keycode == ibus::Keycode::XK_c ||
keyEvent.keycode == ibus::Keycode::XK_C ||
keyEvent.keycode == ibus::Keycode::XK_bracketleft));
if (isVimBackInCommandMode &&
rime_api->get_option(session_id, "vim_mode") &&
!rime_api->get_option(session_id, "ascii_mode")) {
rime_api->set_option(session_id, "ascii_mode", True);
}
}
_Respond(ipc_id, eat);
_UpdateUI(ipc_id);
m_active_session = ipc_id;
return (BOOL)handled;
auto handled = std::async(
std::launch::async,
[this](WeaselSessionId&& ipc_id, KeyEvent&& keyEvent, EatLine&& eat) -> Bool {
RimeSessionId session_id = to_session_id(ipc_id);
Bool result = rime_api->process_key(session_id, keyEvent.keycode,
expand_ibus_modifier(keyEvent.mask));
if (!result) {
bool isVimBackInCommandMode =
(keyEvent.keycode == ibus::Keycode::Escape) ||
((keyEvent.mask & (1 << 2)) &&
(keyEvent.keycode == ibus::Keycode::XK_c ||
keyEvent.keycode == ibus::Keycode::XK_C ||
keyEvent.keycode == ibus::Keycode::XK_bracketleft));
if (isVimBackInCommandMode &&
rime_api->get_option(session_id, "vim_mode") &&
!rime_api->get_option(session_id, "ascii_mode")) {
rime_api->set_option(session_id, "ascii_mode", True);
}
}
_Respond(ipc_id, eat);
_UpdateUI(ipc_id);
m_active_session = ipc_id;
return result;
},
ipc_id, keyEvent, eat);
return (BOOL)handled.valid();
}

void RimeWithWeaselHandler::CommitComposition(WeaselSessionId ipc_id) {
Expand Down

0 comments on commit e893f67

Please sign in to comment.