From 148bb1ff136ee225aaa93ff9b40700feb81503c5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 10 Oct 2020 22:14:35 +0200 Subject: ime: wip: add text-input object to seat --- meson.build | 2 ++ 1 file changed, 2 insertions(+) (limited to 'meson.build') diff --git a/meson.build b/meson.build index 6b9a8c4d..1aa018a9 100644 --- a/meson.build +++ b/meson.build @@ -78,6 +78,7 @@ foreach prot : [ wayland_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml', wayland_protocols_datadir + '/unstable/primary-selection/primary-selection-unstable-v1.xml', wayland_protocols_datadir + '/stable/presentation-time/presentation-time.xml', + wayland_protocols_datadir + '/unstable/text-input/text-input-unstable-v3.xml', ] wl_proto_headers += custom_target( @@ -147,6 +148,7 @@ executable( 'commands.c', 'commands.h', 'extract.c', 'extract.h', 'fdm.c', 'fdm.h', + 'ime.c', 'ime.h', 'input.c', 'input.h', 'main.c', 'quirks.c', 'quirks.h', -- cgit v1.3 From 05083110c3fad046ccf0838a364150b8d2bab888 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 3 Dec 2020 18:36:56 +0100 Subject: ime: make IME compile-time optional --- ime.c | 63 ++++++++++++++++++++++++++++++++++++++++--------------- ime.h | 10 +++++++++ meson.build | 15 +++++++------ meson_options.txt | 1 + render.c | 3 +++ terminal.c | 18 ++++++++++++---- terminal.h | 4 ++++ wayland.c | 14 +++++++++++-- wayland.h | 4 ++++ 9 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 meson_options.txt (limited to 'meson.build') diff --git a/ime.c b/ime.c index 787985cf..ccdbb098 100644 --- a/ime.c +++ b/ime.c @@ -1,5 +1,7 @@ #include "ime.h" +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED + #include #include "text-input-unstable-v3.h" @@ -67,11 +69,7 @@ leave(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, zwp_text_input_v3_commit(seat->wl_text_input); seat->ime.serial++; - free(seat->ime.preedit.pending.text); - seat->ime.preedit.pending.text = NULL; - - free(seat->ime.commit.pending.text); - seat->ime.commit.pending.text = NULL; + ime_reset(seat); } static void @@ -82,10 +80,13 @@ preedit_string(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, struct seat *seat = data; - free(seat->ime.preedit.pending.text); - seat->ime.preedit.pending.text = text != NULL ? xstrdup(text) : NULL; - seat->ime.preedit.pending.cursor_begin = cursor_begin; - seat->ime.preedit.pending.cursor_end = cursor_end; + ime_reset_preedit(seat); + + if (text != NULL) { + seat->ime.preedit.pending.text = xstrdup(text); + seat->ime.preedit.pending.cursor_begin = cursor_begin; + seat->ime.preedit.pending.cursor_end = cursor_end; + } } static void @@ -95,8 +96,11 @@ commit_string(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, LOG_DBG("commit: text=%s", text); struct seat *seat = data; - free(seat->ime.commit.pending.text); - seat->ime.commit.pending.text = text != NULL ? xstrdup(text) : NULL; + + ime_reset_commit(seat); + + if (text != NULL) + seat->ime.commit.pending.text = xstrdup(text); } static void @@ -142,9 +146,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) { - free(term->ime.preedit.cells); - term->ime.preedit.cells = NULL; - term->ime.preedit.count = 0; + term_reset_ime(term); render_refresh(term); } @@ -162,9 +164,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, term, seat->ime.commit.pending.text, strlen(seat->ime.commit.pending.text)); - - free(seat->ime.commit.pending.text); - seat->ime.commit.pending.text = NULL; + ime_reset_commit(seat); } /* 4. Calculate surrounding text to send - not supported */ @@ -292,10 +292,31 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, render_refresh(term); } + ime_reset_preedit(seat); +} + +void +ime_reset_preedit(struct seat *seat) +{ free(seat->ime.preedit.pending.text); seat->ime.preedit.pending.text = NULL; } +void +ime_reset_commit(struct seat *seat) +{ + free(seat->ime.commit.pending.text); + seat->ime.commit.pending.text = NULL; +} + +void +ime_reset(struct seat *seat) +{ + ime_reset_preedit(seat); + ime_reset_commit(seat); +} + + const struct zwp_text_input_v3_listener text_input_listener = { .enter = &enter, .leave = &leave, @@ -304,3 +325,11 @@ const struct zwp_text_input_v3_listener text_input_listener = { .delete_surrounding_text = &delete_surrounding_text, .done = &done, }; + +#else /* !FOOT_IME_ENABLED */ + +void ime_reset_preedit(struct seat *seat) {} +void ime_reset_commit(struct seat *seat) {} +void ime_reset(struct seat *seat) {} + +#endif diff --git a/ime.h b/ime.h index d1ce7ff0..d5c96534 100644 --- a/ime.h +++ b/ime.h @@ -1,5 +1,15 @@ #pragma once +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED + #include "text-input-unstable-v3.h" extern const struct zwp_text_input_v3_listener text_input_listener; + +#endif /* FOOT_IME_ENABLED */ + +struct seat; + +void ime_reset_preedit(struct seat *seat); +void ime_reset_commit(struct seat *seat); +void ime_reset(struct seat *seat); diff --git a/meson.build b/meson.build index 1aa018a9..6e04ba8b 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,9 @@ add_project_arguments( (is_debug_build ? ['-D_DEBUG'] : [cc.get_supported_arguments('-fno-asynchronous-unwind-tables')]) + + (get_option('ime') + ? ['-DFOOT_IME_ENABLED=1'] + : []) + cc.get_supported_arguments( ['-pedantic', '-fstrict-aliasing', @@ -198,9 +201,9 @@ subdir('completions') subdir('doc') subdir('icons') -# summary( -# { -# '': false, -# }, -# bool_yn: true -# ) +summary( + { + 'IME': get_option('ime'), + }, + bool_yn: true +) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..fc3c1b0f --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('ime', type: 'boolean', value: true, description: 'IME (Input Method Editor) support') diff --git a/render.c b/render.c index 88a47d47..3e7ed96a 100644 --- a/render.c +++ b/render.c @@ -1025,6 +1025,8 @@ static void render_ime_preedit(struct terminal *term, struct buffer *buf, struct coord cursor) { +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED + if (likely(term->ime.preedit.cells == NULL)) return; @@ -1112,6 +1114,7 @@ render_ime_preedit(struct terminal *term, struct buffer *buf, term->margins.top + row_idx * term->cell_height, term->width - term->margins.left - term->margins.right, 1 * term->cell_height); +#endif } static void diff --git a/terminal.c b/terminal.c index d08d8658..cfcc2040 100644 --- a/terminal.c +++ b/terminal.c @@ -1403,7 +1403,7 @@ term_destroy(struct terminal *term) tll_free(term->alt.sixel_images); sixel_fini(term); - free(term->ime.preedit.cells); + term_reset_ime(term); free(term->foot_exe); free(term->cwd); @@ -2218,12 +2218,12 @@ term_kbd_focus_out(struct terminal *term) if (it->item.kbd_focus == term) return; +#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; + term_reset_ime(term); render_refresh(term); } +#endif term->kbd_focus = false; cursor_refresh(term); @@ -2753,3 +2753,13 @@ term_view_to_text(const struct terminal *term, char **text, size_t *len) int end = grid_row_absolute_in_view(term->grid, term->rows - 1); return rows_to_text(term, start, end, text, len); } + +void +term_reset_ime(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; +#endif +} diff --git a/terminal.h b/terminal.h index b8339d8d..bbe7df25 100644 --- a/terminal.h +++ b/terminal.h @@ -470,6 +470,7 @@ struct terminal { unsigned max_height; /* Maximum image height, in pixels */ } sixel; +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED struct { struct { struct cell *cells; @@ -482,6 +483,7 @@ struct terminal { } cursor; } preedit; } ime; +#endif bool quit; bool is_shutting_down; @@ -605,3 +607,5 @@ bool term_scrollback_to_text( const struct terminal *term, char **text, size_t *len); bool term_view_to_text( const struct terminal *term, char **text, size_t *len); + +void term_reset_ime(struct terminal *term); diff --git a/wayland.c b/wayland.c index c0a9c512..c8cb2c9c 100644 --- a/wayland.c +++ b/wayland.c @@ -116,6 +116,7 @@ seat_add_primary_selection(struct seat *seat) static void seat_add_text_input(struct seat *seat) { +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED if (seat->wayl->text_input_manager == NULL) return; @@ -128,6 +129,7 @@ seat_add_text_input(struct seat *seat) seat->wl_text_input = text_input; zwp_text_input_v3_add_listener(text_input, &text_input_listener, seat); +#endif } static void @@ -184,15 +186,18 @@ seat_destroy(struct seat *seat) wl_keyboard_release(seat->wl_keyboard); if (seat->wl_pointer != NULL) wl_pointer_release(seat->wl_pointer); + +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED if (seat->wl_text_input != NULL) zwp_text_input_v3_destroy(seat->wl_text_input); +#endif + if (seat->wl_seat != NULL) wl_seat_release(seat->wl_seat); + ime_reset(seat); free(seat->clipboard.text); free(seat->primary.text); - free(seat->ime.preedit.pending.text); - free(seat->ime.commit.pending.text); free(seat->name); } @@ -920,6 +925,7 @@ handle_global(void *data, struct wl_registry *registry, } } +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED else if (strcmp(interface, zwp_text_input_manager_v3_interface.name) == 0) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) @@ -931,6 +937,7 @@ handle_global(void *data, struct wl_registry *registry, tll_foreach(wayl->seats, it) seat_add_text_input(&it->item); } +#endif } static void @@ -1190,8 +1197,11 @@ wayl_destroy(struct wayland *wayl) seat_destroy(&it->item); tll_free(wayl->seats); +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED if (wayl->text_input_manager != NULL) zwp_text_input_manager_v3_destroy(wayl->text_input_manager); +#endif + if (wayl->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); if (wayl->shell != NULL) diff --git a/wayland.h b/wayland.h index 51a6fad1..f275c69c 100644 --- a/wayland.h +++ b/wayland.h @@ -224,6 +224,7 @@ struct seat { struct wl_clipboard clipboard; struct wl_primary primary; +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED /* Input Method Editor */ struct zwp_text_input_v3 *wl_text_input; struct { @@ -250,6 +251,7 @@ struct seat { uint32_t serial; } ime; +#endif }; enum csd_surface { @@ -404,7 +406,9 @@ struct wayland { struct wp_presentation *presentation; uint32_t presentation_clock_id; +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED struct zwp_text_input_manager_v3 *text_input_manager; +#endif bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ -- cgit v1.3 From 77bc7c8b2c61c9eb166fa0050be0b53270475e97 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 4 Dec 2020 18:57:49 +0100 Subject: features: include compile-time enable/disable state of features when printing version --- client.c | 12 +++++++++++- foot-features.h | 12 ++++++++++++ main.c | 14 ++++++++++++-- meson.build | 2 ++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 foot-features.h (limited to 'meson.build') diff --git a/client.c b/client.c index 9887c514..58a500eb 100644 --- a/client.c +++ b/client.c @@ -16,6 +16,7 @@ #define LOG_ENABLE_DBG 0 #include "log.h" #include "client-protocol.h" +#include "foot-features.h" #include "version.h" #include "xmalloc.h" @@ -27,6 +28,15 @@ sig_handler(int signo) aborted = 1; } +static const char * +version_and_features(void) +{ + static char buf[256]; + snprintf(buf, sizeof(buf), "version: %s %cime", + FOOT_VERSION, feature_ime() ? '+' : '-'); + return buf; +} + static void print_usage(const char *prog_name) { @@ -155,7 +165,7 @@ main(int argc, char *const *argv) break; case 'v': - printf("footclient version %s\n", FOOT_VERSION); + printf("footclient %s\n", version_and_features()); return EXIT_SUCCESS; case 'h': diff --git a/foot-features.h b/foot-features.h new file mode 100644 index 00000000..8da22f6c --- /dev/null +++ b/foot-features.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +static inline bool feature_ime(void) +{ +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED + return true; +#else + return false; +#endif +} diff --git a/main.c b/main.c index ab595d22..59ac9b61 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,7 @@ #include "log.h" #include "config.h" +#include "foot-features.h" #include "fdm.h" #include "reaper.h" #include "render.h" @@ -39,6 +40,15 @@ sig_handler(int signo) aborted = 1; } +static const char * +version_and_features(void) +{ + static char buf[256]; + snprintf(buf, sizeof(buf), "version: %s %cime", + FOOT_VERSION, feature_ime() ? '+' : '-'); + return buf; +} + static void print_usage(const char *prog_name) { @@ -325,7 +335,7 @@ main(int argc, char *const *argv) break; case 'v': - printf("foot version %s\n", FOOT_VERSION); + printf("foot %s\n", version_and_features()); return EXIT_SUCCESS; case 'h': @@ -343,7 +353,7 @@ main(int argc, char *const *argv) argc -= optind; argv += optind; - LOG_INFO("version: %s", FOOT_VERSION); + LOG_INFO("%s", version_and_features()); { struct utsname name; diff --git a/meson.build b/meson.build index 6e04ba8b..36c5807e 100644 --- a/meson.build +++ b/meson.build @@ -151,6 +151,7 @@ executable( 'commands.c', 'commands.h', 'extract.c', 'extract.h', 'fdm.c', 'fdm.h', + 'foot-features.h', 'ime.c', 'ime.h', 'input.c', 'input.h', 'main.c', @@ -174,6 +175,7 @@ executable( executable( 'footclient', 'client.c', 'client-protocol.h', + 'foot-features.h', 'log.c', 'log.h', 'macros.h', 'xmalloc.c', 'xmalloc.h', -- cgit v1.3