Repository navigation
stoa-predict: popup at the text cursor with arrow-key navigation (Wayland input method) - #208
Merged
Merged
Conversation
The suggestions now sit in a popup next to the text cursor, and the arrow keys work: Down/Up enter the popup, Left/Right move, Enter or Tab accepts, Esc dismisses. Neither is possible from a shell panel, which cannot see another app's caret nor take keys without stealing focus, so the daemon is now an input method (input-method-v2, as fcitx): - the compositor places its popup surface at the caret (cairo + Pango into shm buffers, Stoa palette); - a keyboard grab sees each key; keys it does not use are forwarded through its virtual keyboard, which niri and sway route past the grab; - the word before the cursor comes from text-input surrounding text, or from the keys themselves in terminals, which send none; - the choice is committed with commit_string (+ delete_surrounding_text, or BackSpaces looked up in the current keymap for terminals). That also fixes emoji, which never went in: wtype refused non-ASCII without a UTF-8 locale and dropped a lone keystroke 9 times in 15. evdev and the input group are no longer needed for prediction. The Noctalia plugin keeps only its service (start/stop/notify); the panel is gone. Brave and Obsidian get --enable-wayland-ime --wayland-text-input-version=3 so Chromium talks to the input method. SIGTERM keeps its default action: a Python handler never runs while libwayland sits in poll(), which left the daemon alive on toggle-off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CrdbH4MCHhLKimzdRSzXZp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Text prediction becomes a Wayland input method (
input-method-v2, the protocol fcitx uses). This answers three requests:Why an input method: a shell panel can't see another app's caret, and it can't take arrow keys without stealing focus. An input method gets both from the compositor.
How it works (
scripts/stoa-predict.py)StoaCustom.jsonif present). It follows the output scale and shows a↓hint until the popup is entered.src/handlers/virtual_keyboard.rssays so explicitly, and fcitx relies on the same path.surrounding_text. In terminals, which send none, it comes from the keys themselves via xkbcommon (ctypes, no extra package), so abnt2 and ç work.commit_string, preceded bydelete_surrounding_text. In terminals it is preceded by BackSpaces, using the keycode looked up in the current keymap. Case follows what was typed (Stoi→Stoical).~/.cachefrom XMLs shipped inscripts/stoa-predict-protocols/(MIT, from wlroots). No Arch package installs these two protocols.Why the emojis never went in
Two causes in the old
wtypepath, both reproduced and measured:wtyperefuses any non-ASCII input (Failed to deencode input argv);wtypecreates its keyboard dropped it 9 times out of 15.commit_stringavoids both.Plumbing
panel.luauis gone, andplugin_apidrops back to 9.stoa-predict.sh:toggle | start | stop | run | kill.killwaits for the old instance to disconnect, because the compositor refuses a second input method while the first is still connected.post-installswapspython-evdevforpython-pywayland python-cairo python-gobject. Theinputgroup stays, relabelled:libinput-gesturesneeds it, prediction no longer does..desktop) and Obsidian (~/.config/obsidian/user-flags.conf): get--enable-wayland-ime --wayland-text-input-version=3, so Chromium talks to the input method.Bugs caught while testing
poll()(it restarts on EINTR). The daemon survived toggle-off, and the next start was refused. Now SIGTERM keeps its default action; the compositor cleans up on disconnect.sys.exit(): the "another input method is running" path kept running. Fatal exits now useos._exit.Verification
Headless sway 1.10 (built here, since sway 1.9 doesn't draw IME popups), with a GTK4 text view, foot, and a test virtual keyboard carrying a full br/abnt2 keymap:
the Stoi→ ↓ → Enter givesthe Stoical.Fir→ ↓ ← Enter givesFir🔥.go stoi→ ↓ Enter gives 4×DEL +stoic.stoa-predict toggle→ service → daemon, typing into GTK and foot. Toggling off leaves no daemon, and text then goes in plain.tests/run.sh18 passed;ruff,luac5.4, shellcheck andnoctalia plugins lintare clean.Not tested here: niri and Hyprland themselves, which don't run headless. niri's source supports the IME popup (
PopupKind::InputMethod) and the grab passthrough. A real Brave/Obsidian has not been tried either.Generated by Claude Code