From 194ca31cc3572497cf11feb0114a17828d3ad498 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sun, 30 Mar 2025 14:02:37 +0100 Subject: [PATCH] Add an API for passing pre-edit text to terminal; call from GTK The terminal code doesn't yet do anything with the text other than feed it to a debugging printf. The call uses UTF-8 and expects the terminal to copy the string because that's compatible with gtk_im_context_get_preedit_string(). --- putty.h | 1 + terminal/terminal.c | 10 ++++++++++ unix/window.c | 2 ++ 3 files changed, 13 insertions(+) diff --git a/putty.h b/putty.h index dbd85298..ce39d680 100644 --- a/putty.h +++ b/putty.h @@ -2044,6 +2044,7 @@ void term_notify_palette_changed(Terminal *term); void term_notify_window_pos(Terminal *term, int x, int y); void term_notify_window_size_pixels(Terminal *term, int x, int y); void term_palette_override(Terminal *term, unsigned osc4_index, rgb rgb); +void term_set_preedit_text(Terminal *term, char *preedit_text); typedef enum SmallKeypadKey { SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN, diff --git a/terminal/terminal.c b/terminal/terminal.c index 4d1d4f5b..3aac6960 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -8106,3 +8106,13 @@ void term_notify_window_size_pixels(Terminal *term, int x, int y) term->winpixsize_x = x; term->winpixsize_y = y; } + +/* + * Set the pre-edit text as required by an input method. preedit_text + * is expected to be in UTF-8. It's NULL if no pre-edit text is + * required. It's owned by the caller and must not be freed here. + */ +void term_set_preedit_text(Terminal *term, char *preedit_text) +{ + debug("Pre-edit: %s\n", preedit_text); +} diff --git a/unix/window.c b/unix/window.c index a6cd7eec..95916913 100644 --- a/unix/window.c +++ b/unix/window.c @@ -2150,6 +2150,7 @@ void input_method_preedit_changed_event(GtkIMContext *imc, gpointer data) string_string, (int)cursor_pos); sfree(string_string); #endif + term_set_preedit_text(inst->term, preedit_string); g_free(preedit_string); } @@ -2160,6 +2161,7 @@ void input_method_preedit_end_event(GtkIMContext *imc, gpointer data) #ifdef KEY_EVENT_DIAGNOSTICS debug(" - IM preedit-end event\n"); #endif + term_set_preedit_text(inst->term, NULL); } #endif