aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-03 17:36:56 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-12-07 19:44:10 +0000
commit05083110c3fad046ccf0838a364150b8d2bab888 (patch)
tree5b77e2b5b87226b0e6dbc81273d9db955b8a1ef8
parentime: render pre-edit text (diff)
ime: make IME compile-time optional
-rw-r--r--ime.c63
-rw-r--r--ime.h10
-rw-r--r--meson.build15
-rw-r--r--meson_options.txt1
-rw-r--r--render.c3
-rw-r--r--terminal.c18
-rw-r--r--terminal.h4
-rw-r--r--wayland.c14
-rw-r--r--wayland.h4
9 files changed, 103 insertions, 29 deletions
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 <string.h>
#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(
-# {
-# '<feature>': 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 */