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.
This commit is contained in:
Daniel Eklöf 2020-12-04 18:39:11 +01:00
parent 5c17b7f8e7
commit b59d695b2b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 122 additions and 48 deletions

View file

@ -24,6 +24,7 @@
#include "config.h"
#include "extract.h"
#include "grid.h"
#include "ime.h"
#include "quirks.h"
#include "reaper.h"
#include "render.h"
@ -1116,6 +1117,11 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.shutdown_data = shutdown_data,
.foot_exe = xstrdup(foot_exe),
.cwd = xstrdup(cwd),
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
.ime = {
.enabled = true,
},
#endif
};
for (size_t i = 0; i < 4; i++) {
@ -1403,7 +1409,7 @@ term_destroy(struct terminal *term)
tll_free(term->alt.sixel_images);
sixel_fini(term);
term_reset_ime(term);
term_ime_reset(term);
free(term->foot_exe);
free(term->cwd);
@ -1559,6 +1565,10 @@ term_reset(struct terminal *term, bool hard)
sixel_destroy(&it->item);
tll_free(term->alt.sixel_images);
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
term_ime_enable(term);
#endif
if (!hard)
return;
@ -2220,7 +2230,7 @@ term_kbd_focus_out(struct terminal *term)
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
if (term->ime.preedit.cells != NULL) {
term_reset_ime(term);
term_ime_reset(term);
render_refresh(term);
}
#endif
@ -2754,12 +2764,64 @@ term_view_to_text(const struct terminal *term, char **text, size_t *len)
return rows_to_text(term, start, end, text, len);
}
void
term_reset_ime(struct terminal *term)
bool
term_ime_is_enabled(const struct terminal *term)
{
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
free(term->ime.preedit.cells);
term->ime.preedit.cells = NULL;
term->ime.preedit.count = 0;
return term->ime.enabled;
#else
return false;
#endif
}
void
term_ime_enable(struct terminal *term)
{
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
if (term->ime.enabled)
return;
LOG_DBG("IME enabled");
term->ime.enabled = true;
term_ime_reset(term);
/* IME is per seat - enable on all seat currenly focusing us */
tll_foreach(term->wl->seats, it) {
if (it->item.kbd_focus == term)
ime_enable(&it->item);
}
#endif
}
void
term_ime_disable(struct terminal *term)
{
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
if (!term->ime.enabled)
return;
LOG_DBG("IME disabled");
term->ime.enabled = false;
term_ime_reset(term);
/* IME is per seat - disable on all seat currenly focusing us */
tll_foreach(term->wl->seats, it) {
if (it->item.kbd_focus == term)
ime_disable(&it->item);
}
#endif
}
void
term_ime_reset(struct terminal *term)
{
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
if (term->ime.preedit.cells != NULL) {
free(term->ime.preedit.cells);
term->ime.preedit.cells = NULL;
term->ime.preedit.count = 0;
}
#endif
}