mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-15 08:21:03 -04:00
ime: make IME compile-time optional
This commit is contained in:
parent
8c3d48c5cd
commit
05083110c3
9 changed files with 103 additions and 29 deletions
63
ime.c
63
ime.c
|
|
@ -1,5 +1,7 @@
|
||||||
#include "ime.h"
|
#include "ime.h"
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "text-input-unstable-v3.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);
|
zwp_text_input_v3_commit(seat->wl_text_input);
|
||||||
seat->ime.serial++;
|
seat->ime.serial++;
|
||||||
|
|
||||||
free(seat->ime.preedit.pending.text);
|
ime_reset(seat);
|
||||||
seat->ime.preedit.pending.text = NULL;
|
|
||||||
|
|
||||||
free(seat->ime.commit.pending.text);
|
|
||||||
seat->ime.commit.pending.text = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -82,10 +80,13 @@ preedit_string(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
|
|
||||||
struct seat *seat = data;
|
struct seat *seat = data;
|
||||||
|
|
||||||
free(seat->ime.preedit.pending.text);
|
ime_reset_preedit(seat);
|
||||||
seat->ime.preedit.pending.text = text != NULL ? xstrdup(text) : NULL;
|
|
||||||
seat->ime.preedit.pending.cursor_begin = cursor_begin;
|
if (text != NULL) {
|
||||||
seat->ime.preedit.pending.cursor_end = cursor_end;
|
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
|
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);
|
LOG_DBG("commit: text=%s", text);
|
||||||
|
|
||||||
struct seat *seat = data;
|
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
|
static void
|
||||||
|
|
@ -142,9 +146,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
|
|
||||||
/* 1. Delete existing pre-edit text */
|
/* 1. Delete existing pre-edit text */
|
||||||
if (term->ime.preedit.cells != NULL) {
|
if (term->ime.preedit.cells != NULL) {
|
||||||
free(term->ime.preedit.cells);
|
term_reset_ime(term);
|
||||||
term->ime.preedit.cells = NULL;
|
|
||||||
term->ime.preedit.count = 0;
|
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,9 +164,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
|
||||||
term,
|
term,
|
||||||
seat->ime.commit.pending.text,
|
seat->ime.commit.pending.text,
|
||||||
strlen(seat->ime.commit.pending.text));
|
strlen(seat->ime.commit.pending.text));
|
||||||
|
ime_reset_commit(seat);
|
||||||
free(seat->ime.commit.pending.text);
|
|
||||||
seat->ime.commit.pending.text = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 4. Calculate surrounding text to send - not supported */
|
/* 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);
|
render_refresh(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ime_reset_preedit(seat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ime_reset_preedit(struct seat *seat)
|
||||||
|
{
|
||||||
free(seat->ime.preedit.pending.text);
|
free(seat->ime.preedit.pending.text);
|
||||||
seat->ime.preedit.pending.text = NULL;
|
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 = {
|
const struct zwp_text_input_v3_listener text_input_listener = {
|
||||||
.enter = &enter,
|
.enter = &enter,
|
||||||
.leave = &leave,
|
.leave = &leave,
|
||||||
|
|
@ -304,3 +325,11 @@ const struct zwp_text_input_v3_listener text_input_listener = {
|
||||||
.delete_surrounding_text = &delete_surrounding_text,
|
.delete_surrounding_text = &delete_surrounding_text,
|
||||||
.done = &done,
|
.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
|
||||||
|
|
|
||||||
10
ime.h
10
ime.h
|
|
@ -1,5 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
|
|
||||||
#include "text-input-unstable-v3.h"
|
#include "text-input-unstable-v3.h"
|
||||||
|
|
||||||
extern const struct zwp_text_input_v3_listener text_input_listener;
|
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);
|
||||||
|
|
|
||||||
15
meson.build
15
meson.build
|
|
@ -17,6 +17,9 @@ add_project_arguments(
|
||||||
(is_debug_build
|
(is_debug_build
|
||||||
? ['-D_DEBUG']
|
? ['-D_DEBUG']
|
||||||
: [cc.get_supported_arguments('-fno-asynchronous-unwind-tables')]) +
|
: [cc.get_supported_arguments('-fno-asynchronous-unwind-tables')]) +
|
||||||
|
(get_option('ime')
|
||||||
|
? ['-DFOOT_IME_ENABLED=1']
|
||||||
|
: []) +
|
||||||
cc.get_supported_arguments(
|
cc.get_supported_arguments(
|
||||||
['-pedantic',
|
['-pedantic',
|
||||||
'-fstrict-aliasing',
|
'-fstrict-aliasing',
|
||||||
|
|
@ -198,9 +201,9 @@ subdir('completions')
|
||||||
subdir('doc')
|
subdir('doc')
|
||||||
subdir('icons')
|
subdir('icons')
|
||||||
|
|
||||||
# summary(
|
summary(
|
||||||
# {
|
{
|
||||||
# '<feature>': false,
|
'IME': get_option('ime'),
|
||||||
# },
|
},
|
||||||
# bool_yn: true
|
bool_yn: true
|
||||||
# )
|
)
|
||||||
|
|
|
||||||
1
meson_options.txt
Normal file
1
meson_options.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
option('ime', type: 'boolean', value: true, description: 'IME (Input Method Editor) support')
|
||||||
3
render.c
3
render.c
|
|
@ -1025,6 +1025,8 @@ static void
|
||||||
render_ime_preedit(struct terminal *term, struct buffer *buf,
|
render_ime_preedit(struct terminal *term, struct buffer *buf,
|
||||||
struct coord cursor)
|
struct coord cursor)
|
||||||
{
|
{
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
|
|
||||||
if (likely(term->ime.preedit.cells == NULL))
|
if (likely(term->ime.preedit.cells == NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -1112,6 +1114,7 @@ render_ime_preedit(struct terminal *term, struct buffer *buf,
|
||||||
term->margins.top + row_idx * term->cell_height,
|
term->margins.top + row_idx * term->cell_height,
|
||||||
term->width - term->margins.left - term->margins.right,
|
term->width - term->margins.left - term->margins.right,
|
||||||
1 * term->cell_height);
|
1 * term->cell_height);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
18
terminal.c
18
terminal.c
|
|
@ -1403,7 +1403,7 @@ term_destroy(struct terminal *term)
|
||||||
tll_free(term->alt.sixel_images);
|
tll_free(term->alt.sixel_images);
|
||||||
sixel_fini(term);
|
sixel_fini(term);
|
||||||
|
|
||||||
free(term->ime.preedit.cells);
|
term_reset_ime(term);
|
||||||
|
|
||||||
free(term->foot_exe);
|
free(term->foot_exe);
|
||||||
free(term->cwd);
|
free(term->cwd);
|
||||||
|
|
@ -2218,12 +2218,12 @@ term_kbd_focus_out(struct terminal *term)
|
||||||
if (it->item.kbd_focus == term)
|
if (it->item.kbd_focus == term)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
if (term->ime.preedit.cells != NULL) {
|
if (term->ime.preedit.cells != NULL) {
|
||||||
free(term->ime.preedit.cells);
|
term_reset_ime(term);
|
||||||
term->ime.preedit.cells = NULL;
|
|
||||||
term->ime.preedit.count = 0;
|
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
term->kbd_focus = false;
|
term->kbd_focus = false;
|
||||||
cursor_refresh(term);
|
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);
|
int end = grid_row_absolute_in_view(term->grid, term->rows - 1);
|
||||||
return rows_to_text(term, start, end, text, len);
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,7 @@ struct terminal {
|
||||||
unsigned max_height; /* Maximum image height, in pixels */
|
unsigned max_height; /* Maximum image height, in pixels */
|
||||||
} sixel;
|
} sixel;
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
struct {
|
struct {
|
||||||
struct {
|
struct {
|
||||||
struct cell *cells;
|
struct cell *cells;
|
||||||
|
|
@ -482,6 +483,7 @@ struct terminal {
|
||||||
} cursor;
|
} cursor;
|
||||||
} preedit;
|
} preedit;
|
||||||
} ime;
|
} ime;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool quit;
|
bool quit;
|
||||||
bool is_shutting_down;
|
bool is_shutting_down;
|
||||||
|
|
@ -605,3 +607,5 @@ bool term_scrollback_to_text(
|
||||||
const struct terminal *term, char **text, size_t *len);
|
const struct terminal *term, char **text, size_t *len);
|
||||||
bool term_view_to_text(
|
bool term_view_to_text(
|
||||||
const struct terminal *term, char **text, size_t *len);
|
const struct terminal *term, char **text, size_t *len);
|
||||||
|
|
||||||
|
void term_reset_ime(struct terminal *term);
|
||||||
|
|
|
||||||
14
wayland.c
14
wayland.c
|
|
@ -116,6 +116,7 @@ seat_add_primary_selection(struct seat *seat)
|
||||||
static void
|
static void
|
||||||
seat_add_text_input(struct seat *seat)
|
seat_add_text_input(struct seat *seat)
|
||||||
{
|
{
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
if (seat->wayl->text_input_manager == NULL)
|
if (seat->wayl->text_input_manager == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -128,6 +129,7 @@ seat_add_text_input(struct seat *seat)
|
||||||
|
|
||||||
seat->wl_text_input = text_input;
|
seat->wl_text_input = text_input;
|
||||||
zwp_text_input_v3_add_listener(text_input, &text_input_listener, seat);
|
zwp_text_input_v3_add_listener(text_input, &text_input_listener, seat);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -184,15 +186,18 @@ seat_destroy(struct seat *seat)
|
||||||
wl_keyboard_release(seat->wl_keyboard);
|
wl_keyboard_release(seat->wl_keyboard);
|
||||||
if (seat->wl_pointer != NULL)
|
if (seat->wl_pointer != NULL)
|
||||||
wl_pointer_release(seat->wl_pointer);
|
wl_pointer_release(seat->wl_pointer);
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
if (seat->wl_text_input != NULL)
|
if (seat->wl_text_input != NULL)
|
||||||
zwp_text_input_v3_destroy(seat->wl_text_input);
|
zwp_text_input_v3_destroy(seat->wl_text_input);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (seat->wl_seat != NULL)
|
if (seat->wl_seat != NULL)
|
||||||
wl_seat_release(seat->wl_seat);
|
wl_seat_release(seat->wl_seat);
|
||||||
|
|
||||||
|
ime_reset(seat);
|
||||||
free(seat->clipboard.text);
|
free(seat->clipboard.text);
|
||||||
free(seat->primary.text);
|
free(seat->primary.text);
|
||||||
free(seat->ime.preedit.pending.text);
|
|
||||||
free(seat->ime.commit.pending.text);
|
|
||||||
free(seat->name);
|
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) {
|
else if (strcmp(interface, zwp_text_input_manager_v3_interface.name) == 0) {
|
||||||
const uint32_t required = 1;
|
const uint32_t required = 1;
|
||||||
if (!verify_iface_version(interface, version, required))
|
if (!verify_iface_version(interface, version, required))
|
||||||
|
|
@ -931,6 +937,7 @@ handle_global(void *data, struct wl_registry *registry,
|
||||||
tll_foreach(wayl->seats, it)
|
tll_foreach(wayl->seats, it)
|
||||||
seat_add_text_input(&it->item);
|
seat_add_text_input(&it->item);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -1190,8 +1197,11 @@ wayl_destroy(struct wayland *wayl)
|
||||||
seat_destroy(&it->item);
|
seat_destroy(&it->item);
|
||||||
tll_free(wayl->seats);
|
tll_free(wayl->seats);
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
if (wayl->text_input_manager != NULL)
|
if (wayl->text_input_manager != NULL)
|
||||||
zwp_text_input_manager_v3_destroy(wayl->text_input_manager);
|
zwp_text_input_manager_v3_destroy(wayl->text_input_manager);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (wayl->xdg_output_manager != NULL)
|
if (wayl->xdg_output_manager != NULL)
|
||||||
zxdg_output_manager_v1_destroy(wayl->xdg_output_manager);
|
zxdg_output_manager_v1_destroy(wayl->xdg_output_manager);
|
||||||
if (wayl->shell != NULL)
|
if (wayl->shell != NULL)
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,7 @@ struct seat {
|
||||||
struct wl_clipboard clipboard;
|
struct wl_clipboard clipboard;
|
||||||
struct wl_primary primary;
|
struct wl_primary primary;
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
/* Input Method Editor */
|
/* Input Method Editor */
|
||||||
struct zwp_text_input_v3 *wl_text_input;
|
struct zwp_text_input_v3 *wl_text_input;
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -250,6 +251,7 @@ struct seat {
|
||||||
|
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
} ime;
|
} ime;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
enum csd_surface {
|
enum csd_surface {
|
||||||
|
|
@ -404,7 +406,9 @@ struct wayland {
|
||||||
struct wp_presentation *presentation;
|
struct wp_presentation *presentation;
|
||||||
uint32_t presentation_clock_id;
|
uint32_t presentation_clock_id;
|
||||||
|
|
||||||
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
struct zwp_text_input_manager_v3 *text_input_manager;
|
struct zwp_text_input_manager_v3 *text_input_manager;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool have_argb8888;
|
bool have_argb8888;
|
||||||
tll(struct monitor) monitors; /* All available outputs */
|
tll(struct monitor) monitors; /* All available outputs */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue