Skip to content

Poll Fcitx only when there is an input method to switch to - #15184

Merged
dhh merged 17 commits into
quattrofrom
fcitx-indicator-events
Oct 13, 2026
Merged

dhh merged 17 commits into
quattrofrom
fcitx-indicator-events

Conversation

@dhh

@dhh dhh commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

The bar's Fcitx reader (default/input-methods/indicator.py, started unconditionally by shell/Commons/InputMethodState.qml) made three synchronous D-Bus calls every 500 ms on every machine, including machines with only one input method. It now polls only when there is something to switch between, and otherwise waits for events.

  • Events: it reads once at startup, then again when:
    • the org.fcitx.Fcitx5 bus name gains or loses an owner (a service start or restart);
    • the profile Fcitx saves its configuration to changes. Every configuration change ends in a Save: omarchy-input-method, the Typing pickers and fcitx5-configtool all call it.
  • Finding the profile: each time the bus name appears (or changes owner), the reader locates the profile once, from the environment of the process that owns it: $FCITX_CONFIG_HOME/profile, else $XDG_CONFIG_HOME/fcitx5/profile. That means a service drop-in that moves it is followed. Gio.File.monitor_file(..., WATCH_MOVES) watches it, plus its target when the profile itself is a link into dotfiles (saves replace the target). It sees saves that rename a new file into place, and inotify resolves a linked directory when the watch is added. Known limit: if the dotfiles are relinked while Fcitx runs, the reader picks that up at Fcitx's next start (or the next shell start), and until then a single-method setup can miss an added engine. I tried following every link hop live, but it cost ~110 lines of path walking plus ~300 lines of tests for cases that rarely happen, so I dropped it.
  • Polling stays at 500 ms, unchanged, while there is something to switch between: more than one method in the current group, a lone composition engine (it still toggles, and steps aside in password fields), or more than one group. The existing 50 ms retry while a bar click waits for an input context is kept. A read that fails while the service is on the bus is retried every 2 s; a timed-out call does not change the cadence, and a timed-out group count keeps the last good reading on the bar instead of blanking it.

Why polling remains for multi-method users

I looked for a change signal first. Fcitx 5.1.23 exposes InputMethodGroupsChanged() on Controller1, but an eavesdropping dbus-monitor on the fcitx5 connection saw no signal at all for SetInputMethodGroupInfo, SetCurrentIM, Toggle, AddInputMethodGroup, SwitchInputMethodGroup, RemoveInputMethodGroup, ReloadConfig or Save. The other frontends (IBus, portal, InputContext1) signal only the client that owns an input context. The SNI addon would signal icon changes, but Omarchy disables it with --disable notificationitem so it doesn't duplicate the tray entry. With several methods, a switch made by a trigger key inside an application can only be seen by reading, so that case keeps the poll it has today.

Measurements

Standalone reader, 60 s window, all threads, voluntary + nonvoluntary context switches (the same counter as the battery audit). This machine has one method, keyboard-us.

indicator.py wakeups/s
quattro 21.2
this branch, one method 0.00
this branch, two methods (live, 20 s) 20.8 (unchanged on purpose)

Fcitx5's own wakeups fall with it, since it no longer answers three calls per tick (27/s down to 15/s here, and the 15/s includes another shell instance still running quattro's reader).

Tests

  • test/shell.d/input-indicator-test.sh runs the reader in a real GLib loop against a real profile file in one TemporaryDirectory, with Fcitx stubbed. It covers:

    • one method reads once and arms no timer; a renamed-over save with a second method starts the 500 ms poll; an in-app switch reaches the output;
    • a save while polling replaces the poll instead of starting a second chain (8 reads in 2 s before the fix, at most 5 now);
    • a failed read is retried, and a failed group count keeps the reading;
    • a save through a profile linked into dotfiles is seen;
    • the profile location comes from FCITX_CONFIG_HOME/XDG_CONFIG_HOME and from the bus owner's own environment, and the watch moves there when the name appears;
    • the group-count and lone-engine gating.

    Every behaviour was mutation-checked: reverting each fix fails the test.

  • test/shell.d/input-method-test.sh passes.

  • Live, under the desktop lock, on the final code: I replaced the running shell with this branch's (omarchy-launch-shell with OMARCHY_PATH set to the worktree) and focused a foot window. I added Hangul through SetInputMethodGroupInfo + Save: the keyboard widget appeared showing EN. fcitx5-remote -s hangul changed it to 한, and fcitx5-remote -s keyboard-us changed it back to EN. Removing Hangul and saving hid the widget. The reader showed 0 wakeups in 20 s before and after, and 416 in 20 s with two methods. The profile came back byte-identical, and the ~/omarchy shell and the Starship theme were restored.

For a human to check

  • A real CJK setup (Mozc or Hangul) behaves as before: switching with the trigger keys inside an application still updates the bar within half a second.
  • Changing the method list through fcitx5-configtool updates the bar without a shell restart.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues.

Summary

The reader polls only when input methods can switch. The latest change also watches a linked profile’s target, matching how atomic_write() saves it.

  • The Fcitx bar reader polls only when input can change silently.

Reviews (17) · Last reviewed commit: "Watch the target of a linked Fcitx profi..." · Reviewed by Greptile

Comment thread default/input-methods/indicator.py Resolved
Comment thread default/input-methods/indicator.py Resolved
Comment thread test/shell.d/input-indicator-test.sh Resolved
dhh and others added 5 commits October 12, 2026 17:24
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread default/input-methods/indicator.py Resolved
Comment thread default/input-methods/indicator.py Resolved
dhh and others added 5 commits October 12, 2026 18:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rming

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rectories

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread default/input-methods/indicator.py Resolved
dhh and others added 6 commits October 12, 2026 19:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…failed group count

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit d7abdbd into quattro Oct 13, 2026
1 check passed
@dhh
dhh deleted the fcitx-indicator-events branch October 13, 2026 12:17
@emirb emirb added this to the 4.5 milestone Oct 17, 2026
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