aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-04 17:39:11 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-12-07 19:44:11 +0000
commitb59d695b2b00157e403399af78b3128848a65e0f (patch)
treef84b9ccf330e033a108785400196e0c0ca302d63 /terminal.c
parentime: 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 'terminal.c')
-rw-r--r--terminal.c74
1 files changed, 68 insertions, 6 deletions
diff --git a/terminal.c b/terminal.c
index cfcc2040..80c162bd 100644
--- a/terminal.c
+++ b/terminal.c
@@ -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);
}
+bool
+term_ime_is_enabled(const struct terminal *term)
+{
+#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
+ return term->ime.enabled;
+#else
+ return false;
+#endif
+}
+
void
-term_reset_ime(struct terminal *term)
+term_ime_enable(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;
+ 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
}