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(RimeWithWeasel): async keyevent processing #1433

Closed
wants to merge 1 commit into from
Closed
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
48 changes: 28 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,33 @@ 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