Skip to content

app: [Wayland] add IME support - #177

Draft
bigwolfeman wants to merge 1 commit into
gioui:mainfrom
bigwolfeman:app-wayland-ime
Draft

app: [Wayland] add IME support#177
bigwolfeman wants to merge 1 commit into
gioui:mainfrom
bigwolfeman:app-wayland-ime

Conversation

@bigwolfeman

@bigwolfeman bigwolfeman commented Aug 12, 2026

Copy link
Copy Markdown

Summary

  • bind text-input-v3 for each Wayland seat
  • apply preedit, commit, and surrounding-text deletion as atomic done transactions
  • synchronize protocol serials and convert between Gio rune offsets and UTF-8 byte offsets
  • report surrounding text, cursor bounds, and content purpose to the input method

Related discussion:
https://lists.sr.ht/~eliasnaur/gio/%3C87tsyhhjkm.fsf@inet.name%3E

Testing

  • go test ./app -run '^TestTextInput' -count=1
  • go test ./app -count=1
  • go build ./app
  • live Pinyin composition with Mango and fcitx5, including preedit, candidate commit, selection replacement, cancellation, rapid repeated composition, and focus restoration
  • live input-method-v2 deletion across the multibyte text é🙂, followed by a commit in the same transaction

@bigwolfeman
bigwolfeman force-pushed the app-wayland-ime branch 2 times, most recently from 864e4fc to 3a32a4d Compare August 12, 2026 04:31
Comment thread app/os_wayland.go Outdated
Comment on lines +115 to +123
imFocus *window
imSerial uint32
imActive bool
imDirty bool
imExternal bool
imHint key.InputHint
pending textInputUpdate
sent textInputSnapshot
sentValid bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a bit of state to keep in the driver. I haven't looked closely at the changes (and the PR is in draft), but my impression is that some of this should be subsumed by the general IM machinery in ime.go and ime_test.go. In short, drivers are meant to be minimal because they're plural and hard to test. Even if some machinery is required just for one platform, it's usually better to implement that in general purpose Go to make it hackable and testable everywhere.

Wayland currently handles text input as key events, so input methods
cannot provide preedit text, commits, or surrounding-text edits.

Bind text-input-v3 for each seat and apply its preedit, commit, and
deletion events atomically on done. Report surrounding text, cursor
bounds, and content purpose with UTF-8 byte offsets as required by the
protocol.

Add tests for transaction ordering, serial synchronization, nullable
events, UTF-8 deletion ranges, and the 4000-byte surrounding-text limit.

Related discussion:
https://lists.sr.ht/~eliasnaur/gio/%3C87tsyhhjkm.fsf@inet.name%3E

Signed-off-by: bigwolfe <15391393+bigwolfeman@users.noreply.github.com>
@bigwolfeman

Copy link
Copy Markdown
Author

Changed based on your input. Created imState to maintain the state that is not necessarily Wayland unique. Driver is kept as minimal as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants