feat(macos): set-input-source and input-source-is#2033
Conversation
jtroo
left a comment
There was a problem hiding this comment.
To start, this is not something I like to see:
This code was written entirely by Codex and needs careful maintainer review.
The bar for contributions must be higher than this. There is no LLM policy defined in kanata but the one by Oxide looks like a reasonable one, if not too lengthy for the scope of this project. A relevant snippet:
Wherever LLM-generated code is used, it becomes the responsibility of the engineer. As part of this process of taking responsibility, self-review becomes essential: LLM-generated code should not be reviewed by others if the responsible engineer has not themselves reviewed it.
Onto the code itself, this PR does not look like something that feels worth the maintenance burden and is hyper-specific on the use case.
There are two separate design ideas here that could be worth exploring more but not worth pushing in their current use-case-constrained implementation further:
- A more expressive alternative to
push-msgwith a synchronous request-response semantics andfork/switch-like evaluation based on the return value, to help support this input-source-helper integration better - more power
switchconditionals, such as evaluating the results of TCP requests (similar to above) or ofcmdexecutions
Describe your changes. Use imperative present tense.
Add native macOS input-source support.
(set-input-source "...")to switch the current macOS keyboard input source by exact input source ID.(input-source-is "...")forswitchconditions that check the current macOS keyboard input source by exact ID.kanata-input-source-helperLaunchAgent so input-source operations run in the logged-in Aqua user session.This code was written entirely by Codex and needs careful maintainer review.
One practical use case for this is deterministic language selection on macOS via tap dance.
For example:
This is different from sending the system “next input source” shortcut, because that shortcut is stateful and depends on the current macOS source ordering. With
set-input-source, the mapping is exact and deterministic.I’m already using this pattern in my own Kanata config:
https://github.com/alenkimov/moonlander_msklc/blob/835fdf1c10b238c9f0c5733ff90ef4ec0768adab/MacOS/kanata.kbd#L19
Relevant part:
us->(set-input-source "com.apple.keylayout.US")+(layer-switch us)ru->(set-input-source "com.apple.keylayout.RussianWin")+(layer-switch ru)toggle-lang->(tap-dance-eager 250 (@us @ru))Checklist
Manual/testing notes:
cargo check.cargo fmt --all -- --check.cargo test -p kanata-parser parse_macos_input_source_support -- --nocapture.com.apple.keylayout.USandcom.apple.keylayout.RussianWin.