wayland: implement text-input-unstable-v3 for IME support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Adds IME input method support (fcitx5, ibus, etc.) using the text-input-unstable-v3 Wayland protocol, following the approach used by foot and rofi. Closes #615
authored by Mark Stosberg · committed by Daniel Eklöf · parent b320e2f · Browse files · 8 files·+492 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+492 added−12 removed
- other:+492 added−12 removed
Provenance
- Commit
43caf1d- Tree
47996cf- Author
Mark Stosberg <mark@stosberg.com>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
b320e2f
8 files changed+492 added−12 removed
modified:doc/fuzzel.1.scd+5 added
641 unmodified lines642 643 Fuzzel uses the localized strings from the .desktop files by644 default. To disable this, run fuzzel with *LC_MESSAGES=C*.645 646+# IME647+648+Fuzzel supports input method editors (IME) via the649+*text-input-unstable-v3* Wayland protocol.650+651 # FONT FORMAT652 653 The font is specified in FontConfig syntax. That is, a colon-separated654 list of font name and font options.35 unmodified linesmodified:CHANGELOG.md+3 added
36 unmodified lines37 ### Added38 39 * `--override` command line option, allowing you to override **all**40 options available in `fuzzel.ini` ([#759][759]).41+* IME support, via the `text-input-unstable-v3` Wayland protocol42+ ([#615][614]).43 44 [759]: https://codeberg.org/dnkl/fuzzel/issues/75945+[615]: https://codeberg.org/dnkl/fuzzel/issues/61546 47 48 ### Changed49 1173 unmodified linesmodified:meson.build+1 added
151 unmodified lines152 wayland_protocols_datadir + '/staging/fractional-scale/fractional-scale-v1.xml',153 wayland_protocols_datadir / 'unstable/primary-selection/primary-selection-unstable-v1.xml',154 wayland_protocols_datadir / 'staging/color-management/color-management-v1.xml',155 wayland_protocols_datadir / 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml',156+ wayland_protocols_datadir / 'unstable/text-input/text-input-unstable-v3.xml',157 ]158 159 foreach prot : wl_proto_xml160 wl_proto_headers += custom_target(118 unmodified linesmodified:README.md+2 added-1 removed
53 unmodified lines545556575859596061626364100 unmodified lines53 unmodified lines- Optimized for performance- Zsh and Fish completions- Support for true fractional scaling- Wayland native- IME support via the _text-input-unstable-v3_ protocol
For details, see [`man fuzzel`](./doc/fuzzel.1.scd) and [`man fuzzel.ini`](./doc/fuzzel.ini.5.scd)For details, see [`man fuzzel`](./doc/fuzzel.1.scd)
## Requirements
### Runtime100 unmodified linesmodified:render.c+118 added-9 removed
99 unmodified lines100 unsigned message_height;101 102 unsigned input_glyph_offset; /* At which glyph to start rendering input */103 104+ /* Set during render_prompt; used by IME for cursor rectangle */105 struct {106+ int x, y, w, h; /* buffer pixel coordinates */107+ } cursor_rect;108+109+ struct {110 uint16_t count;111 sem_t start;112 sem_t done;113 mtx_t lock;633 unmodified lines747 else if (message_run != render->message_text_run)748 fcft_text_run_destroy(message_run);749 }750 751+static void752+update_cursor_rect(struct render *render, int x, int y)753+{754+ struct fcft_font *font = render->font;755+ const int height = min(font->ascent + font->descent, render->row_height);756+ render->cursor_rect.x = x;757+ render->cursor_rect.y = y + font->descent - height;758+ render->cursor_rect.w = font->underline.thickness;759+ render->cursor_rect.h = height;760+}761+762+/*763+ * Render preedit text at the cursor position, following foot's approach:764+ * - All preedit glyphs are rendered with an underline.765+ * - A bar cursor is placed at the glyph index given by preedit_cursor766+ * (-1 means the cursor is hidden).767+ * Returns the new x position after all preedit glyphs.768+ */769+static int770+render_preedit_at_cursor(const struct render *render, struct buffer *buf,771+ int x, int y, int max_x,772+ const char32_t *preedit, size_t preedit_len,773+ int32_t preedit_cursor,774+ enum fcft_subpixel subpixel)775+{776+ struct fcft_font *font = render->font;777+ const int ul_y = y - font->underline.position;778+ const int ul_h = font->underline.thickness;779+780+ char32_t prev = 0;781+782+ for (size_t i = 0; i < preedit_len; i++) {783+ /* Cursor bar before this glyph */784+ if (preedit_cursor >= 0 && (int32_t)i == preedit_cursor)785+ render_cursor(render, x, y, buf->pix[0]);786+787+ const struct fcft_glyph *glyph =788+ fcft_rasterize_char_utf32(font, preedit[i], subpixel);789+790+ if (glyph == NULL) {791+ prev = 0;792+ continue;793+ }794+795+ long x_kern = 0;796+ if (prev != 0)797+ fcft_kerning(font, prev, preedit[i], &x_kern, NULL);798+ x += x_kern;799+800+ const int pixels_needed = max(glyph->x + glyph->width, glyph->advance.x);801+ if (x + pixels_needed > max_x)802+ break;803+804+ const int glyph_start_x = x;805+806+ render_glyph(buf->pix[0], glyph, x, y, &render->pix_input_color);807+ x += glyph->advance.x;808+ x += pt_or_px_as_pixels(render, &render->conf->letter_spacing);809+810+ /* Underline below the preedit glyph */811+ pixman_image_fill_rectangles(812+ PIXMAN_OP_SRC, buf->pix[0], &render->pix_input_color,813+ 1, &(pixman_rectangle16_t){814+ glyph_start_x,815+ ul_y,816+ x - glyph_start_x,817+ ul_h});818+819+ prev = preedit[i];820+ }821+822+ /* Cursor bar after all preedit glyphs */823+ if (preedit_cursor < 0 || preedit_cursor >= (int32_t)preedit_len)824+ render_cursor(render, x, y, buf->pix[0]);825+826+ return x;827+}828+829 void830 render_prompt(struct render *render, struct buffer *buf,748- const struct prompt *prompt, const struct matches *matches)831+ const struct prompt *prompt, const struct matches *matches,832+ const char32_t *preedit, int32_t preedit_cursor)833 {834 struct fcft_font *font = render->font;835 assert(font != NULL);836 4 unmodified lines841 const size_t cursor_location = prompt_cursor(prompt);842 843 const char32_t *ptext = prompt_text(prompt);844 size_t text_len = c32len(ptext);845+ /* Suppress placeholder while IME preedit is active */846+ const bool have_preedit = preedit != NULL && preedit[0] != U'\0';761- bool use_placeholder = text_len == 0;847+ bool use_placeholder = text_len == 0 && !have_preedit;848 849 const enum fcft_subpixel subpixel =850 (render->conf->colors.background.a == 1. &&851 render->conf->colors.selection.a == 1.)117 unmodified lines969 input_glyphs, input_kerning, x, max_x);970 971 /* Cursor, if right after the prompt. In all other cases, the972 * cursor will be rendered by the loop below */887- if (cursor_location == render->input_glyph_offset888- || (conf->password_mode.enabled &&889- conf->password_mode.character == U'\0'))890- {891- render_cursor(render, x, y, buf->pix[0]);973+ const bool is_hidden_pwd =974+ conf->password_mode.enabled && conf->password_mode.character == U'\0';975+ if (cursor_location == render->input_glyph_offset || is_hidden_pwd) {976+ update_cursor_rect(render, x, y);977+ if (have_preedit && !is_hidden_pwd) {978+ x = render_preedit_at_cursor(979+ render, buf, x, y, max_x,980+ preedit, c32len(preedit), preedit_cursor, subpixel);981+ } else {982+ render_cursor(render, x, y, buf->pix[0]);983+ }984 }985 986 if (input_run != NULL && !(conf->password_mode.enabled && !use_placeholder)) {987 /* We only shape the placeholder string */60 unmodified lines1048 x += glyph->advance.x;1049 x += pt_or_px_as_pixels(render, &render->conf->letter_spacing);1050 1051 /* Cursor */960- if (cursor_location > 0 && cursor_location - 1 == i)961- render_cursor(render, x, y, buf->pix[0]);1052+ if (cursor_location > 0 && cursor_location - 1 == i) {1053+ update_cursor_rect(render, x, y);1054+ if (have_preedit) {1055+ x = render_preedit_at_cursor(1056+ render, buf, x, y, max_x,1057+ preedit, c32len(preedit), preedit_cursor, subpixel);1058+ } else {1059+ render_cursor(render, x, y, buf->pix[0]);1060+ }1061+ }1062 1063 prev = glyph->cp;1064 }1065 }1211 unmodified lines2277 return row;2278 }2279 2280 void2281+render_get_cursor_rect(const struct render *render, int *x, int *y, int *w, int *h)2282+{2283+ *x = render->cursor_rect.x;2284+ *y = render->cursor_rect.y;2285+ *w = render->cursor_rect.w;2286+ *h = render->cursor_rect.h;2287+}2288+2289+void2290 render_flush_text_run_cache(struct render *render)2291 {2292 fcft_text_run_destroy(render->prompt_text_run);2293 fcft_text_run_destroy(render->message_text_run);5 unmodified linesmodified:render.h+5 added-1 removed
29 unmodified lines30 void render_message(struct render *render, struct buffer *buf);31 32 void render_prompt(33 struct render *render, struct buffer *buf,34- const struct prompt *prompt, const struct matches *matches);34+ const struct prompt *prompt, const struct matches *matches,35+ const char32_t *preedit, int32_t preedit_cursor);36 37+void render_get_cursor_rect(38+ const struct render *render, int *x, int *y, int *w, int *h);39+40 void render_match_list(41 struct render *render, struct buffer *buf,42 const struct prompt *prompt, const struct matches *matches);43 5 unmodified linesmodified:wayland.c+342 added-1 removed
29 unmodified lines30 #include <cursor-shape-v1.h>31 #include <fractional-scale-v1.h>32 #include <primary-selection-unstable-v1.h>33 #include <single-pixel-buffer-v1.h>34+#include <text-input-unstable-v3.h>35 #include <viewporter.h>36 #include <wlr-layer-shell-unstable-v1.h>37 #include <xdg-activation-v1.h>38 #include <xdg-output-unstable-v1.h>156 unmodified lines195 bool have_primaries_srgb;196 } color_management;197 198 struct wp_single_pixel_buffer_manager_v1 *single_pixel_manager;199+ struct zwp_text_input_manager_v3 *text_input_manager;200 201+ /* Active preedit text (displayed inline in the prompt) */202+ struct {203+ char32_t *text; /* NULL when no preedit is active */204+ int32_t cursor; /* glyph index for cursor (-1 = hidden) */205+ } preedit;206+207 tll(struct monitor) monitors;208 const struct monitor *monitor;209 210 tll(struct seat) seats;100 unmodified lines311 312 if (seat->wl_seat != NULL)313 wl_seat_release(seat->wl_seat);314 315+ if (seat->text_input != NULL)316+ zwp_text_input_v3_destroy(seat->text_input);317+ free(seat->ime.preedit_pending.text);318+ free(seat->ime.commit_pending);319+320 free(seat->clipboard.text);321 free(seat->primary.text);322 free(seat->name);323 }1189 unmodified lines1513 .shape = wl_touch_shape,1514 .orientation = wl_touch_orientation,1515 };1516 1517+/*---------------------------------------------------------------------------1518+ * text-input-unstable-v3 listener1519+ *---------------------------------------------------------------------------*/1520+1521+/*1522+ * Convert a UTF-8 byte offset within a preedit string to the corresponding1523+ * char32_t (glyph) index. Returns the glyph count if byte_offset is at or1524+ * beyond the end of the string.1525+ */1526+static int32_t1527+byte_offset_to_glyph_idx(const char *text, size_t byte_len, int32_t byte_offset)1528+{1529+ if (byte_offset < 0)1530+ return -1;1531+1532+ int32_t glyph_idx = 0;1533+ size_t byte_idx = 0;1534+1535+ while (byte_idx < byte_len) {1536+ if ((int32_t)byte_idx == byte_offset)1537+ return glyph_idx;1538+1539+ int n = mblen(&text[byte_idx], byte_len - byte_idx);1540+ if (n <= 0)1541+ break;1542+1543+ byte_idx += n;1544+ glyph_idx++;1545+ }1546+1547+ /* byte_offset at or past end of string */1548+ return glyph_idx;1549+}1550+1551 static void1552+text_input_enter(void *data, struct zwp_text_input_v3 *text_input,1553+ struct wl_surface *surface)1554+{1555+ struct seat *seat = data;1556+ struct wayland *wayl = seat->wayl;1557+1558+ LOG_DBG("text_input enter");1559+1560+ /* Reset any stale pending state */1561+ free(seat->ime.preedit_pending.text);1562+ seat->ime.preedit_pending.text = NULL;1563+ free(seat->ime.commit_pending);1564+ seat->ime.commit_pending = NULL;1565+1566+ zwp_text_input_v3_enable(text_input);1567+ zwp_text_input_v3_set_content_type(1568+ text_input,1569+ ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE,1570+ ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL);1571+1572+ /* Send current cursor rect to position the IME popup */1573+ int cx, cy, cw, ch;1574+ render_get_cursor_rect(wayl->render, &cx, &cy, &cw, &ch);1575+ const float scale = wayl->scale;1576+ zwp_text_input_v3_set_cursor_rectangle(1577+ text_input,1578+ (int)(cx / scale), (int)(cy / scale),1579+ (int)(cw / scale), (int)(ch / scale));1580+1581+ zwp_text_input_v3_commit(text_input);1582+ seat->ime.serial++;1583+1584+ /* Record what we just sent */1585+ seat->ime.cursor_rect.x = (int)(cx / scale);1586+ seat->ime.cursor_rect.y = (int)(cy / scale);1587+ seat->ime.cursor_rect.w = (int)(cw / scale);1588+ seat->ime.cursor_rect.h = (int)(ch / scale);1589+}1590+1591+static void1592+text_input_leave(void *data, struct zwp_text_input_v3 *text_input,1593+ struct wl_surface *surface)1594+{1595+ struct seat *seat = data;1596+ struct wayland *wayl = seat->wayl;1597+1598+ LOG_DBG("text_input leave");1599+1600+ free(seat->ime.preedit_pending.text);1601+ seat->ime.preedit_pending.text = NULL;1602+ free(seat->ime.commit_pending);1603+ seat->ime.commit_pending = NULL;1604+1605+ /* Clear any active preedit */1606+ if (wayl->preedit.text != NULL) {1607+ free(wayl->preedit.text);1608+ wayl->preedit.text = NULL;1609+ wayl->preedit.cursor = -1;1610+ wayl_refresh(wayl);1611+ }1612+1613+ zwp_text_input_v3_disable(text_input);1614+ zwp_text_input_v3_commit(text_input);1615+ seat->ime.serial++;1616+}1617+1618+static void1619+text_input_preedit_string(void *data, struct zwp_text_input_v3 *text_input,1620+ const char *text, int32_t cursor_begin, int32_t cursor_end)1621+{1622+ struct seat *seat = data;1623+1624+ LOG_DBG("preedit_string: text=%s begin=%d end=%d",1625+ text ? text : "(null)", cursor_begin, cursor_end);1626+1627+ free(seat->ime.preedit_pending.text);1628+ seat->ime.preedit_pending.text = text ? xstrdup(text) : NULL;1629+ seat->ime.preedit_pending.cursor_begin = cursor_begin;1630+ seat->ime.preedit_pending.cursor_end = cursor_end;1631+}1632+1633+static void1634+text_input_commit_string(void *data, struct zwp_text_input_v3 *text_input,1635+ const char *text)1636+{1637+ struct seat *seat = data;1638+1639+ LOG_DBG("commit_string: text=%s", text ? text : "(null)");1640+1641+ free(seat->ime.commit_pending);1642+ seat->ime.commit_pending = text ? xstrdup(text) : NULL;1643+}1644+1645+static void1646+text_input_delete_surrounding_text(void *data,1647+ struct zwp_text_input_v3 *text_input,1648+ uint32_t before_length,1649+ uint32_t after_length)1650+{1651+ /*1652+ * We never call set_surrounding_text(), so the compositor should1653+ * never request deletion of surrounding text. Log it anyway.1654+ */1655+ LOG_DBG("delete_surrounding_text: before=%u after=%u (ignored)",1656+ before_length, after_length);1657+}1658+1659+static void1660+text_input_done(void *data, struct zwp_text_input_v3 *text_input,1661+ uint32_t serial)1662+{1663+ struct seat *seat = data;1664+ struct wayland *wayl = seat->wayl;1665+1666+ LOG_DBG("done: serial=%u (expected=%u)", serial, seat->ime.serial);1667+1668+ /*1669+ * Ignore stale events. The serial we track is the number of1670+ * commit() calls we have made; the compositor echoes it back.1671+ */1672+ if (seat->ime.serial != serial) {1673+ LOG_DBG("IME serial mismatch, discarding");1674+ free(seat->ime.preedit_pending.text);1675+ seat->ime.preedit_pending.text = NULL;1676+ free(seat->ime.commit_pending);1677+ seat->ime.commit_pending = NULL;1678+ return;1679+ }1680+1681+ bool refresh = false;1682+1683+ /*1684+ * Apply protocol events in the required order:1685+ * 1. Replace existing preedit with cursor.1686+ * 2. Delete surrounding text (not implemented).1687+ * 3. Insert commit string.1688+ * 4. Calculate new surrounding text (not implemented).1689+ * 5. Insert new preedit text at cursor.1690+ * 6. Place cursor inside preedit.1691+ */1692+1693+ /* 1. Clear existing preedit */1694+ if (wayl->preedit.text != NULL) {1695+ free(wayl->preedit.text);1696+ wayl->preedit.text = NULL;1697+ wayl->preedit.cursor = -1;1698+ refresh = true;1699+ }1700+1701+ /* 3. Insert commit string into the prompt */1702+ bool did_commit = false;1703+ if (seat->ime.commit_pending != NULL) {1704+ const char *text = seat->ime.commit_pending;1705+ prompt_insert_chars(wayl->prompt, text, strlen(text));1706+ free(seat->ime.commit_pending);1707+ seat->ime.commit_pending = NULL;1708+ matches_update_incremental(wayl->matches);1709+ matches_selected_set(wayl->matches, 0);1710+ did_commit = true;1711+ refresh = true;1712+ }1713+1714+ /* 5 & 6. Activate new preedit and compute cursor position */1715+ if (seat->ime.preedit_pending.text != NULL &&1716+ seat->ime.preedit_pending.text[0] != '\0')1717+ {1718+ const char *preedit_utf8 = seat->ime.preedit_pending.text;1719+ const size_t byte_len = strlen(preedit_utf8);1720+1721+ char32_t *preedit_c32 = ambstoc32(preedit_utf8);1722+ if (preedit_c32 != NULL) {1723+ wayl->preedit.text = preedit_c32;1724+1725+ const int32_t cb = seat->ime.preedit_pending.cursor_begin;1726+ const int32_t ce = seat->ime.preedit_pending.cursor_end;1727+1728+ if (cb < 0 || ce < 0) {1729+ /* Compositor requests hidden cursor within preedit */1730+ wayl->preedit.cursor = -1;1731+ } else {1732+ /* Map the byte offset to a glyph (char32_t) index */1733+ wayl->preedit.cursor =1734+ byte_offset_to_glyph_idx(preedit_utf8, byte_len, cb);1735+ }1736+ }1737+ free(seat->ime.preedit_pending.text);1738+ seat->ime.preedit_pending.text = NULL;1739+ refresh = true;1740+ } else {1741+ free(seat->ime.preedit_pending.text);1742+ seat->ime.preedit_pending.text = NULL;1743+ }1744+1745+ if (refresh) {1746+ wayl_refresh(wayl);1747+ if (did_commit)1748+ check_auto_select(seat, true);1749+ }1750+}1751+1752+static const struct zwp_text_input_v3_listener text_input_listener = {1753+ .enter = text_input_enter,1754+ .leave = text_input_leave,1755+ .preedit_string = text_input_preedit_string,1756+ .commit_string = text_input_commit_string,1757+ .delete_surrounding_text= text_input_delete_surrounding_text,1758+ .done = text_input_done,1759+};1760+1761+static void1762+seat_add_text_input(struct seat *seat)1763+{1764+ struct wayland *wayl = seat->wayl;1765+1766+ if (wayl->text_input_manager == NULL)1767+ return;1768+ if (seat->text_input != NULL)1769+ return;1770+1771+ seat->text_input = zwp_text_input_manager_v3_get_text_input(1772+ wayl->text_input_manager, seat->wl_seat);1773+ if (seat->text_input == NULL) {1774+ LOG_ERR("failed to create text_input object");1775+ return;1776+ }1777+ zwp_text_input_v3_add_listener(1778+ seat->text_input, &text_input_listener, seat);1779+}1780+1781+static void1782 seat_handle_capabilities(void *data, struct wl_seat *wl_seat,1783 enum wl_seat_capability caps)1784 {1785 struct seat *seat = data;2 unmodified lines1788 if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {1789 if (seat->wl_keyboard == NULL) {1790 seat->wl_keyboard = wl_seat_get_keyboard(wl_seat);1791 wl_keyboard_add_listener(seat->wl_keyboard, &keyboard_listener, seat);1792+ seat_add_text_input(seat);1793 }1794 } else {1795 if (seat->wl_keyboard != NULL) {1796 wl_keyboard_release(seat->wl_keyboard);1797 seat->wl_keyboard = NULL;1798 }1799+ if (seat->text_input != NULL) {1800+ zwp_text_input_v3_destroy(seat->text_input);1801+ seat->text_input = NULL;1802+ }1803 }1804 1805 if (caps & WL_SEAT_CAPABILITY_POINTER) {1806 if (seat->wl_pointer == NULL) {831 unmodified lines2638 wayl->registry, name,2639 &wp_single_pixel_buffer_manager_v1_interface, required);2640 }2641 2642+ else if (strcmp(interface, zwp_text_input_manager_v3_interface.name) == 0) {2643+ const uint32_t required = 1;2644+ if (!verify_iface_version(interface, version, required))2645+ return;2646+2647+ wayl->text_input_manager = wl_registry_bind(2648+ wayl->registry, name,2649+ &zwp_text_input_manager_v3_interface, required);2650+2651+ /* Late-bind: create text_input for seats already registered */2652+ tll_foreach(wayl->seats, it)2653+ seat_add_text_input(&it->item);2654+ }2655+2656 }2657 2658 static void2659 monitor_destroy(struct monitor *mon)219 unmodified lines2879 goto done;2880 }2881 2882 struct buffer *buf = shm_get_buffer(wayl->chain, wayl->width, wayl->height, true);2883+ bool did_render_prompt = false;2884 2885 pixman_region32_t clip;2886 pixman_region32_init_rect(&clip, 0, 0, buf->width, buf->height);2887 pixman_image_set_clip_region32(buf->pix[0], &clip);17 unmodified lines2905 /* Window content */2906 matches_lock(wayl->matches);2907 render_message(wayl->render, buf);2908 if (!wayl->conf->hide_prompt) {2612- render_prompt(wayl->render, buf, wayl->prompt, wayl->matches);2909+ render_prompt(wayl->render, buf, wayl->prompt, wayl->matches,2910+ wayl->preedit.text, wayl->preedit.cursor);2911+ did_render_prompt = true;2912 }2913 if (wayl->hide_when_prompt_empty) {2914 if (prompt_text(wayl->prompt)[0] != '\0') {2915 wayl->hide_when_prompt_empty = false;14 unmodified lines2930 commit:2931 /* No pending frames - render immediately */2932 assert(!wayl->need_refresh);2933 commit_buffer(wayl, buf, false);2934+2935+ /*2936+ * After rendering, send an updated cursor rectangle to any active2937+ * text_input so the IME popup tracks the cursor position.2938+ * Only send when the cursor rect has actually changed to avoid2939+ * generating spurious serial increments.2940+ */2941+ if (did_render_prompt) {2942+ int cx, cy, cw, ch;2943+ render_get_cursor_rect(wayl->render, &cx, &cy, &cw, &ch);2944+ const float scale = wayl->scale;2945+ const int sx = (int)(cx / scale);2946+ const int sy = (int)(cy / scale);2947+ const int sw = (int)(cw / scale);2948+ const int sh = (int)(ch / scale);2949+2950+ tll_foreach(wayl->seats, it) {2951+ struct seat *seat = &it->item;2952+ if (seat->text_input == NULL)2953+ continue;2954+ if (sx == seat->ime.cursor_rect.x &&2955+ sy == seat->ime.cursor_rect.y &&2956+ sw == seat->ime.cursor_rect.w &&2957+ sh == seat->ime.cursor_rect.h)2958+ continue;2959+ zwp_text_input_v3_set_cursor_rectangle(2960+ seat->text_input, sx, sy, sw, sh);2961+ zwp_text_input_v3_commit(seat->text_input);2962+ seat->ime.serial++;2963+ seat->ime.cursor_rect.x = sx;2964+ seat->ime.cursor_rect.y = sy;2965+ seat->ime.cursor_rect.w = sw;2966+ seat->ime.cursor_rect.h = sh;2967+ }2968+ }2969+2970 done:2971 2972 time_finish(2973 start_frame, NULL, "%sframe rendered",421 unmodified lines3395 tll_foreach(wayl->monitors, it)3396 monitor_destroy(&it->item);3397 tll_free(wayl->monitors);3398 3399+ free(wayl->preedit.text);3400+ wayl->preedit.text = NULL;3401+3402+ if (wayl->text_input_manager != NULL)3403+ zwp_text_input_manager_v3_destroy(wayl->text_input_manager);3404+3405 if (wayl->single_pixel_manager != NULL)3406 wp_single_pixel_buffer_manager_v1_destroy(wayl->single_pixel_manager);3407 if (wayl->color_management_surface != NULL)3408 wp_color_management_surface_v1_destroy(wayl->color_management_surface);135 unmodified linesmodified:wayland.h+16 added
1 unmodified line2 3 #include <stdbool.h>4 #include <stdint.h>5 6+struct zwp_text_input_v3; /* text-input-unstable-v3 */7+8 #include <fcft/fcft.h>9 10 #include "clipboard.h"11 #include "config.h"70 unmodified lines82 83 bool is_pasting;84 struct wl_clipboard clipboard;85 struct wl_primary primary;86+87+ struct zwp_text_input_v3 *text_input;88+ struct {89+ uint32_t serial; /* incremented on each commit() */90+ struct {91+ char *text; /* pending preedit UTF-8, NULL if none */92+ int32_t cursor_begin; /* byte offset within preedit */93+ int32_t cursor_end; /* byte offset within preedit */94+ } preedit_pending;95+ char *commit_pending; /* pending commit UTF-8, NULL if none */96+ struct {97+ int x, y, w, h; /* last sent cursor rect (surface coords) */98+ } cursor_rect;99+ } ime;100 };101 102 103 typedef void (*font_reloaded_t)(25 unmodified lines