|
10 | 10 | #include <filesystem>
|
11 | 11 | #include <map>
|
12 | 12 | #include <regex>
|
| 13 | +#include <future> |
13 | 14 | #include <rime_api.h>
|
14 | 15 |
|
15 | 16 | #define TRANSPARENT_COLOR 0x00000000
|
@@ -322,26 +323,29 @@ BOOL RimeWithWeaselHandler::ProcessKeyEvent(KeyEvent keyEvent,
|
322 | 323 | << ", mask = " << keyEvent.mask << ", ipc_id = " << ipc_id;
|
323 | 324 | if (m_disabled)
|
324 | 325 | return FALSE;
|
325 |
| - RimeSessionId session_id = to_session_id(ipc_id); |
326 |
| - Bool handled = rime_api->process_key(session_id, keyEvent.keycode, |
327 |
| - expand_ibus_modifier(keyEvent.mask)); |
328 |
| - if (!handled) { |
329 |
| - bool isVimBackInCommandMode = |
330 |
| - (keyEvent.keycode == ibus::Keycode::Escape) || |
331 |
| - ((keyEvent.mask & (1 << 2)) && |
332 |
| - (keyEvent.keycode == ibus::Keycode::XK_c || |
333 |
| - keyEvent.keycode == ibus::Keycode::XK_C || |
334 |
| - keyEvent.keycode == ibus::Keycode::XK_bracketleft)); |
335 |
| - if (isVimBackInCommandMode && |
336 |
| - rime_api->get_option(session_id, "vim_mode") && |
337 |
| - !rime_api->get_option(session_id, "ascii_mode")) { |
338 |
| - rime_api->set_option(session_id, "ascii_mode", True); |
| 326 | + auto handled = std::async(std::launch::async, [this](WeaselSessionId &&ipc, KeyEvent &&event, EatLine &&eat) -> Bool { |
| 327 | + RimeSessionId session_id = to_session_id(ipc); |
| 328 | + Bool result = rime_api->process_key(session, event.keycode, |
| 329 | + expand_ibus_modifier(event.mask)); |
| 330 | + if (!result) { |
| 331 | + bool isVimBackInCommandMode = |
| 332 | + (keyEvent.keycode == ibus::Keycode::Escape) || |
| 333 | + ((keyEvent.mask & (1 << 2)) && |
| 334 | + (keyEvent.keycode == ibus::Keycode::XK_c || |
| 335 | + keyEvent.keycode == ibus::Keycode::XK_C || |
| 336 | + keyEvent.keycode == ibus::Keycode::XK_bracketleft)); |
| 337 | + if (isVimBackInCommandMode && |
| 338 | + rime_api->get_option(session_id, "vim_mode") && |
| 339 | + !rime_api->get_option(session_id, "ascii_mode")) { |
| 340 | + rime_api->set_option(session_id, "ascii_mode", True); |
| 341 | + } |
339 | 342 | }
|
340 |
| - } |
341 |
| - _Respond(ipc_id, eat); |
342 |
| - _UpdateUI(ipc_id); |
343 |
| - m_active_session = ipc_id; |
344 |
| - return (BOOL)handled; |
| 343 | + _Respond(ipc, eat); |
| 344 | + _UpdateUI(ipc); |
| 345 | + m_active_session = ipc; |
| 346 | + return result; |
| 347 | + }, ipc_id, keyEvent, eat); |
| 348 | + return (BOOL)handled.valid(); |
345 | 349 | }
|
346 | 350 |
|
347 | 351 | void RimeWithWeaselHandler::CommitComposition(WeaselSessionId ipc_id) {
|
|
0 commit comments