Skip to content

Commit

Permalink
feat(linux): Optimize if surrounding text is supported
Browse files Browse the repository at this point in the history
Only send fake event if client does not support surrounding text.
  • Loading branch information
ermshiperete committed Aug 29, 2022
1 parent c76f804 commit 085be9a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions linux/ibus-keyman/src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,9 @@ process_persist_action(

static gboolean
process_emit_keystroke_action(IBusKeymanEngine *keyman) {
if (((IBusEngine*)keyman)->client_capabilities & IBUS_CAP_PREFILTER) {
IBusEngine *engine = (IBusEngine *)keyman;
if ((engine->client_capabilities & IBUS_CAP_PREFILTER) &&
!(engine->client_capabilities & IBUS_CAP_SURROUNDING_TEXT)) {
keyman->commit_item->emitting_keystroke = TRUE;
} else {
if (keyman->commit_item->char_buffer != NULL) {
Expand All @@ -676,8 +678,8 @@ process_emit_keystroke_action(IBusKeymanEngine *keyman) {
return TRUE;
}

static gboolean process_invalidate_context_action(IBusEngine *engine) {
IBusKeymanEngine *keyman = (IBusKeymanEngine *)engine;
static gboolean
process_invalidate_context_action(IBusEngine *engine) {
reset_context(engine);
return TRUE;
}
Expand Down Expand Up @@ -727,7 +729,9 @@ commit_text(IBusKeymanEngine *keyman) {
static gboolean
process_end_action(IBusKeymanEngine *keyman) {
g_assert(keyman != NULL);
if (((IBusEngine *)keyman)->client_capabilities & IBUS_CAP_PREFILTER) {
IBusEngine *engine = (IBusEngine *)keyman;
if ((engine->client_capabilities & IBUS_CAP_PREFILTER) &&
!(engine->client_capabilities & IBUS_CAP_SURROUNDING_TEXT)) {
guint state = keyman->commit_item->state;
keyman->commit_item++;
if (keyman->commit_item > &keyman->commit_queue[MAX_QUEUE_SIZE-1]) {
Expand Down Expand Up @@ -836,8 +840,9 @@ ibus_keyman_engine_process_key_event(

// This keycode is a fake keycode that we send when it's time to commit the text, ensuring the
// correct output order of backspace and text.
if ((engine->client_capabilities & IBUS_CAP_PREFILTER) && keycode == KEYMAN_F24_KEYCODE_OUTPUT_SENTINEL &&
(state & IBUS_PREFILTER_MASK)) {
if ((engine->client_capabilities & IBUS_CAP_PREFILTER) &&
!(engine->client_capabilities & IBUS_CAP_SURROUNDING_TEXT) &&
keycode == KEYMAN_F24_KEYCODE_OUTPUT_SENTINEL && (state & IBUS_PREFILTER_MASK)) {
commit_text(keyman);
return TRUE;
}
Expand Down Expand Up @@ -915,7 +920,7 @@ ibus_keyman_engine_process_key_event(
const km_kbp_action_item *action_items = km_kbp_state_action_items(keyman->state, &num_action_items);

if (!process_actions(engine, action_items, num_action_items) &&
!(engine->client_capabilities & IBUS_CAP_PREFILTER)) {
(!(engine->client_capabilities & IBUS_CAP_PREFILTER) || (engine->client_capabilities & IBUS_CAP_SURROUNDING_TEXT))) {
return FALSE;
}

Expand Down

0 comments on commit 085be9a

Please sign in to comment.