Skip to content

fix(macos): 补发 IME_ACTIVATED,让切回输入法时重置中文 - #260

Open
Kovisun wants to merge 1 commit into
huanfeng:mainfrom
Kovisun:fix/macos-ime-activated
Open

Kovisun wants to merge 1 commit into
huanfeng:mainfrom
Kovisun:fix/macos-ime-activated

Conversation

@Kovisun

@Kovisun Kovisun commented Oct 27, 2026 •

Copy link
Copy Markdown

变更说明

macOS IMKit 端只发 FocusGained / FocusLost,服务端的 handle_ime_activated 从未被调用。因此 input.default.remember_last_state = false 的「每次激活重置中英」在 macOS 上不生效:从清风切到 ABC 再切回,仍保持切走前的英文状态。

本 PR 在 InputController.activateServer 里,于 sendFocusGained() 之后补发一帧 IME_ACTIVATED(复用同一个 clientToken),让服务端走与 Windows 相同的 apply_initial_mode(..., reset_aux = true)。remember_last_state = false 时会重置为 input.default.chinese_mode,同时重置全角/标点。IME_ACTIVATED 是异步命令、服务端不回 ack,因此只 send 不 readFrame。

同时新增 BinaryCodec.encodeTokenFrame(8 字节 clientToken 载荷)及对应帧 roundtrip 测试。

只改 macOS Swift 客户端,没有 Rust / Windows 改动。

变更类型

  • Bug 修复
  • 新功能
  • 重构 / 代码优化
  • 文档更新
  • 构建 / CI 相关
  • 其他(请说明)

相关 Issue

Related: #9(Windows 端同类问题已修复;这个 PR 补齐 macOS 的激活重置路径)

测试情况

  • 已在 Windows 10/11 上测试
  • 已在 macOS 上测试(整包运行)
  • 已测试相关输入方案(五笔/拼音/混输)
  • .\scripts\dev.ps1 ci 通过(fmt 检查 + clippy + 测试)

补充:

  • cd wind_macos && swift build 通过(Swift 6.3.3 / macOS 26)。
  • swift test 未能在提交者环境跑完:当前机器只有 Command Line Tools,没有完整 Xcode,XCTest 模块不可用。测试文件已随 PR 提交,在完整 Xcode 环境可运行。
  • 提交者环境没有 Rust 工具链,因此没有构建完整 .app / .pkg 做端到端验证;改动仅在 Swift IMKit 客户端,逻辑路径已按服务端现有协议核对。

检查清单

  • Rust 代码已用 cargo fmt 格式化(本 PR 无 Rust 改动)
  • 提交信息遵循 Conventional Commits 规范
  • 修改了 crate 对外接口/文件结构时,已同步更新对应 AGENTS.md(本 PR 未改对外接口,N/A)
  • 已阅读贡献指南
  • 首次贡献已签署 CLA(等待 CLA Assistant 发起后签署)

行为说明

macOS 的 activateServer 不只发生在「从别的输入法切回清风」时,切换文本框也会调用。因此本改动的效果是:每个新的输入上下文都会按 input.default 的初始模式重置(remember_last_state = false 时即中文)。

这与 Windows 上 IME_ACTIVATED 的语义一致,也是 input.default.remember_last_state 文档里写的「每次激活重置」。如果维护者希望只在「输入源切换」时重置、而应用内换文本框保持现状,需要额外区分 macOS 的 TIS 输入源切换通知和普通 activateServer;本 PR 先按现有跨平台语义做最小修复,愿意根据维护者的意见调整。

macOS IMKit only sent FocusGained/FocusLost, so the core's
handle_ime_activated never ran. With `input.default.remember_last_state = false`,
switching away to another input source and back kept the previous English state
instead of resetting to `input.default.chinese_mode`.

Send IME_ACTIVATED with the same clientToken after FocusGained. The command is
async (no ack), so it is sent without readFrame. Add an 8-byte token frame codec
helper and a frame roundtrip test.

Verified: `cd wind_macos && swift build` (Swift 6.3.3 / macOS 26).
Not run: `swift test` (XCTest unavailable in this Command Line Tools-only env).
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Kovisun

Kovisun commented Oct 27, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@Kovisun

Kovisun commented Oct 27, 2026

Copy link
Copy Markdown
Author

recheck

github-actions Bot added a commit that referenced this pull request Oct 27, 2026

This branch has not been deployed

No deployments
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.

1 participant