Skip to content

feat: 快捷菜单长按触发键支持区分左右 - #14

Closed
miantiao-me wants to merge 1 commit into
zoolapp:mainfrom
miantiao-me:feat/hold-key-left-right
Closed

miantiao-me wants to merge 1 commit into
zoolapp:mainfrom
miantiao-me:feat/hold-key-left-right

Conversation

@miantiao-me

Copy link
Copy Markdown
Contributor

需求

长按呼出快捷菜单的修饰键支持区分左右:Option / Control / Command 各提供「左右均可 / 仅左 / 仅右」+ 关闭,共 10 个选项。例如可只用右 ⌥ 触发,左 ⌥ 保留普通按键用途。

旧的 features.json 配置值("option"、"control"、"command")语义保持「任意侧」,零迁移。

实现

macOS flagsChanged 事件的 modifierFlags rawValue 本身携带设备相关位(NX_DEVICELALTKEYMASK 等),原实现主动剥离了它。本 PR 恢复这一信息用于长按判定,librime 仍收设备无关 flags:

  • ModifierHold.Key 增加 6 个分侧 case;判定改为 flags & relevantMask 匹配「通用位 + 侧位」——分侧键要求侧位恰好等于目标侧;任意侧键接受单侧或无侧位(兼容虚拟键盘/远程桌面),两侧同按视为两个键不触发
  • AIMEInputController.flagsChanged 分两层取 flags;新增仅设备位变化不进 librime 的守卫(与旧去重行为等价);activate 用同一快照初始化两份状态
  • 修复要点:withoutHoldKey 在对侧仍按住时保留通用位,使该侧 ⌥+数字不被当成普通菜单键;吞掉长按 release 时 cancelModifierTap() 清掉 librime ascii_composer 的 tap 锁存,防残留对侧 release 误切中英;右 Control 设备位按 IOLLEvent.h 实为 1<<13(1<<7 是 ALPHASHIFT_STATELESS)
  • 设置页 Picker 10 项分组展示
  • CHANGELOG 双语条目

验证

  • swift test:12/12 ModifierHold + 全量回归通过(新增分侧武装/对侧加入/分侧释放/通用位保留/rawValue 兼容 5 个测试)
  • xcodebuild Debug:BUILD SUCCEEDED
  • 已实机安装 dev 版可手动验证

兼容性

  • 旧配置零迁移
  • 已知边界:旧实现允许同一修饰键两侧同按时触发,现在明确拒绝(语义:独按一枚物理键);虚拟键盘/远程桌面等无设备位的事件源下,分侧选项不触发(宁可不触发)

Option, Control and Command can each open the quick menu on the left or
right key only, leaving the other side for normal use; "either side"
keeps the previous behavior. Existing features.json values ("option",
"control", "command") decode unchanged, so no config migration.

Detection now reads the unmasked modifierFlags raw value: the
device-dependent bits (NX_DEVICELALTKEYMASK and friends) tell the sides
apart, while librime still receives device-independent flags. A second
guard keeps side-only transitions (left ⌥ held, right ⌥ joins) out of
librime, exactly as the old dedup did.

- ModifierHold.Key grows 6 sided cases; a hold counts when the masked
  flags equal generic-flag+side for a sided key, or generic-flag plus at
  most one side bit for an unsided key
- withoutHoldKey keeps the generic flag while the opposite side is still
  down, so ⌥+digit on that side isn't read as a plain menu key
- Swallowing the hold-key release clears librime's ascii_composer tap
  latch via cancelModifierTap, so a surviving opposite-side release
  can't toggle Chinese/English
- Settings picker offers either/left/right per key ×3 + off
- Tests cover sided arming, opposite-side join, sided release filtering,
  generic-flag preservation and rawValue compatibility
foru17 added a commit that referenced this pull request Oct 10, 2026
…ctuation, 以词定字 vs [ ] paging, left/right hold key

Fixes #10, #11, #13. Includes #14 by @miantiao-me.

Co-Authored-By: 面条 <[email protected]>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@foru17

foru17 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

感谢贡献!已经合进 0.1.8 发布(公开仓库的提交 b4d69d5 由导出流程生成,署名里带上了你)。本机实测「只用右 ⌥」长按呼出菜单、左 ⌥ 不触发,工作正常。

评审时记下的几处小改进,后续我们来补:consumeRelease 里未使用的 target 绑定、设置页 10 个选项分组、docs/rime-config-reference.md 补左右选项说明、降级到旧版时 features.json 的兜底。

因为公开仓库由私有仓库导出,这个 PR 无法直接合并,我先关闭它。

@foru17 foru17 closed this Oct 10, 2026
wangsizhu0504 pushed a commit to wangsizhu0504/kime that referenced this pull request Oct 12, 2026
…ctuation, 以词定字 vs [ ] paging, left/right hold key

Fixes zoolapp#10, zoolapp#11, zoolapp#13. Includes zoolapp#14 by @miantiao-me.

Co-Authored-By: 面条 <[email protected]>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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