diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-12-04 17:39:11 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-12-07 19:44:11 +0000 |
| commit | b59d695b2b00157e403399af78b3128848a65e0f (patch) | |
| tree | f84b9ccf330e033a108785400196e0c0ca302d63 /ime.c | |
| parent | ime: expand cursor cell-end across multi-cell characters (diff) | |
ime: add functions to enable/disable IME, simplify code that enables IME
We may want to be able to enable/disable IME run-time, even though we
have received an ‘enter’ IME event.
This enables us to do that.
Also add functions to enable/disable IME on a per-terminal instance
basis.
A terminal may have multiple seats focusing it, and enabling/disabling
IME in a terminal instance enables/disables IME on all those seats.
Finally, the code to enable IME is simplified; the *only* surface that
can ever receive ‘enter’ IME events is the main grid. All other
surfaces are sub-surfaces, without their own keyboard focus.
Diffstat (limited to 'ime.c')
| -rw-r--r-- | ime.c | 82 |
1 files changed, 42 insertions, 40 deletions
@@ -20,43 +20,16 @@ enter(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, struct wl_surface *surface) { struct seat *seat = data; - LOG_DBG("enter: seat=%s", seat->name); - - assert(seat->kbd_focus != NULL); - - switch (term_surface_kind(seat->kbd_focus, surface)) { - case TERM_SURF_GRID: - zwp_text_input_v3_enable(seat->wl_text_input); - zwp_text_input_v3_set_content_type( - seat->wl_text_input, - ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE, - ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TERMINAL); - /* TODO: set cursor rectangle */ - zwp_text_input_v3_set_cursor_rectangle(seat->wl_text_input, 0, 0, 15, 15); - break; + LOG_DBG("enter: seat=%s", seat->name); - case TERM_SURF_SEARCH: - /* TODO */ - /* FALLTHROUGH */ + /* The main grid is the *only* input-receiving surface we have */ + /* TODO: can we receive text_input::enter() _before_ keyboard_enter()? */ + struct terminal UNUSED *term = seat->kbd_focus; + assert(term != NULL); + assert(term_surface_kind(term, surface) == TERM_SURF_GRID); - case TERM_SURF_NONE: - case TERM_SURF_SCROLLBACK_INDICATOR: - case TERM_SURF_RENDER_TIMER: - case TERM_SURF_TITLE: - case TERM_SURF_BORDER_LEFT: - case TERM_SURF_BORDER_RIGHT: - case TERM_SURF_BORDER_TOP: - case TERM_SURF_BORDER_BOTTOM: - case TERM_SURF_BUTTON_MINIMIZE: - case TERM_SURF_BUTTON_MAXIMIZE: - case TERM_SURF_BUTTON_CLOSE: - zwp_text_input_v3_disable(seat->wl_text_input); - break; - } - - zwp_text_input_v3_commit(seat->wl_text_input); - seat->ime.serial++; + ime_enable(seat); } static void @@ -65,11 +38,7 @@ leave(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, { struct seat *seat = data; LOG_DBG("leave: seat=%s", seat->name); - zwp_text_input_v3_disable(seat->wl_text_input); - zwp_text_input_v3_commit(seat->wl_text_input); - seat->ime.serial++; - - ime_reset(seat); + ime_disable(seat); } static void @@ -146,7 +115,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, /* 1. Delete existing pre-edit text */ if (term->ime.preedit.cells != NULL) { - term_reset_ime(term); + term_ime_reset(term); render_refresh(term); } @@ -337,6 +306,36 @@ ime_reset(struct seat *seat) ime_reset_commit(seat); } +void +ime_enable(struct seat *seat) +{ + struct terminal *term = seat->kbd_focus; + assert(term != NULL); + + if (!term->ime.enabled) + return; + + ime_reset(seat); + + zwp_text_input_v3_enable(seat->wl_text_input); + zwp_text_input_v3_set_content_type( + seat->wl_text_input, + ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE, + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TERMINAL); + + zwp_text_input_v3_commit(seat->wl_text_input); + seat->ime.serial++; +} + +void +ime_disable(struct seat *seat) +{ + ime_reset(seat); + + zwp_text_input_v3_disable(seat->wl_text_input); + zwp_text_input_v3_commit(seat->wl_text_input); + seat->ime.serial++; +} const struct zwp_text_input_v3_listener text_input_listener = { .enter = &enter, @@ -349,6 +348,9 @@ const struct zwp_text_input_v3_listener text_input_listener = { #else /* !FOOT_IME_ENABLED */ +void ime_enable(struct seat *seat) {} +void ime_disable(struct seat *seat) {} + void ime_reset_preedit(struct seat *seat) {} void ime_reset_commit(struct seat *seat) {} void ime_reset(struct seat *seat) {} |
