Skip to content

Add macOS input source switching#291

Merged
unsecretised merged 2 commits into
MystikoLab:masterfrom
tingkai-c:input-source-switching
Jul 11, 2026
Merged

Add macOS input source switching#291
unsecretised merged 2 commits into
MystikoLab:masterfrom
tingkai-c:input-source-switching

Conversation

@tingkai-c

@tingkai-c tingkai-c commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add config-only macOS input source switching when RustCast opens
  • Restore the previous input source when RustCast closes
  • Document the new config fields and feature

Testing

  • cargo fmt
  • git diff --check
  • cargo test (46 passed)
  • Manually verified switching from Zhuyin to ABC on RustCast open and restoring Zhuyin on close

@unsecretised

Copy link
Copy Markdown
Collaborator

Hi @tingkai-c

Thank you for contributing to Rustcast. Could you share a few details about this implementation and also if AI was used in the implementation of this feature?

@tingkai-c

Copy link
Copy Markdown
Contributor Author

Hi @unsecretised, thanks for taking a look.

Implementation details:

This adds two optional config fields:

  • input_source_on_open: macOS input source ID to switch to when RustCast opens, for example com.apple.keylayout.ABC.
  • restore_input_source_on_close: restores the previously active input source when RustCast closes.

The switching is implemented in the macOS platform layer using Text Input Source APIs from Carbon:

  • TISCopyCurrentKeyboardInputSource
  • TISCreateInputSourceList
  • TISGetInputSourceProperty
  • TISSelectInputSource

RustCast captures the current input source in Message::OpenWindow, switches to the configured source if present, and restores the captured source in Message::HideWindow. If switching fails, it logs the error and keeps RustCast usable.

The configured source must be enabled in macOS Keyboard settings. I used enabled input sources only so disabled IDs fail cleanly instead of selecting unavailable sources.

Testing:

  • cargo fmt
  • git diff --check
  • cargo test passed locally
  • Manually verified switching from Zhuyin to ABC on RustCast open, then restoring Zhuyin on close.

AI usage:

Yes, AI assistance was used while developing this PR. I used it as a coding/review aid for repository exploration, implementation drafting, and validation steps. I reviewed the changes manually, tested the behavior locally on macOS.

@unsecretised

Copy link
Copy Markdown
Collaborator

Hi there. Could you elaborate more on what parts were coded with AI? It seems to be that the PR was 100% AI generated and just verified that it works by a human.

As per the contributing guidelines, we don't support 100% AI PRs, as their quality is still not up to the standard I would wish them to be. If I'm wrong about the AI Usage, then please close this PR (I will assume its 100% AI generated if there's no response for the next 1 week and close this PR)

If it isn't 100% AI generated, please share details such as where you used AI, what models, and why you had to use AI.

@unsecretised unsecretised left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Idk how much AI you used but i decided to review this PR either way.

Its a decent implementation, but I don't see the need for this, and also you're missing the ability to customise this from the settings page.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use objc2 wherever possible (i know objc2-carbon doesn't expose sufficient APIs but things like the data types should minimally be objc2)

@unsecretised unsecretised marked this pull request as draft July 10, 2026 10:01
@tingkai-c

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing.

The need for this comes from my daily workflow. I used this behavior every day in Raycast: when I’m typing in Zhuyin or another non-Latin input method, I want the launcher to always open in a predictable Latin input source so app search and commands work immediately. Without this, I have to manually switch input sources before using RustCast.

For the Settings page, I agree. I think the UX should be:

  • Add a toggle to enable/disable automatic input source switching.
  • If enabled, show/enable a dropdown of available macOS input sources.
  • Store the selected source in config.
  • Keep restoring the previous input source when RustCast closes.

I’ll also update the implementation to use objc2/objc2_core_foundation types where practical, while keeping raw FFI only for the Carbon Text Input Source APIs that are not exposed by objc2-carbon.

On AI usage: AI was used only for repository exploration and implementation drafting. I reviewed the code, tested it locally on macOS, and debugged the input-source behavior. I’m using OpenAI GPT-5.5 high.

If there are coding style rules that I should follow beyond CONTRIBUTING.md, please kindly tell me or point me to where they are documented.

@tingkai-c tingkai-c force-pushed the input-source-switching branch from 90b6608 to a55b898 Compare July 11, 2026 01:33
@tingkai-c

Copy link
Copy Markdown
Contributor Author

Pushed an update addressing the review feedback:

  • Added Settings page controls: a toggle for input source switching and a dropdown of enabled macOS input sources when enabled.
  • Updated the input source helper to expose enabled input sources for the dropdown.
  • Switched Core Foundation handling toward objc2_core_foundation types (CFArray, CFString, CFRetained) while keeping raw FFI for the Carbon TIS APIs.
  • Updated config docs to mention Settings page support.
  • Rebasing onto latest master cleared the PR behind state.

Checks:

  • cargo fmt
  • git diff --check
  • cargo test passed locally
  • GitHub CI is green

@unsecretised unsecretised marked this pull request as ready for review July 11, 2026 01:41

@unsecretised unsecretised left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good to me

@unsecretised unsecretised merged commit df2a2f5 into MystikoLab:master Jul 11, 2026
2 checks passed
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