Skip to content

Fix Cocoa modifier recovery and duplicate control input - #48

Merged
levovix0 merged 2 commits into
levovix0:masterfrom
elcritch:fix/cocoa-stuck-modifiers
Aug 29, 2026
Merged

Fix Cocoa modifier recovery and duplicate control input#48
levovix0 merged 2 commits into
levovix0:masterfrom
elcritch:fix/cocoa-stuck-modifiers

Conversation

@elcritch

@elcritch elcritch commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • derive Cocoa modifier key transitions from the current CoreGraphics per-key state instead of toggling cached state
  • clear the modifier snapshot before emitting synthesized focus-loss releases
  • keep Control and Command key chords out of the Cocoa text-input context so one physical chord cannot emit both key and text events
  • recover correctly when an app regains focus while a modifier is already held, such as during Cmd-Tab

Regression sequences

When the app became key while Command was held, refreshModifiers restored the generic modifier mask but the pressed-key set remained empty. The following Command release was therefore toggled into the pressed set as a new press, leaving Command stuck for later key events.

Cocoa also routed Control-letter chords through both the key event callback and NSTextInputClient. Terminal consumers therefore received control bytes such as Control-B and Control-F twice.

Verification

  • nim c --hints:off tests/t_multiwindow.nim
  • nim c --hints:off tests/t_event_loop.nim
  • downstream NimKit Bash input regression suite

@elcritch
elcritch force-pushed the fix/cocoa-stuck-modifiers branch from 8320080 to c59af94 Compare August 28, 2026 02:38
@elcritch elcritch changed the title Fix stuck Cocoa modifier state after focus changes Fix Cocoa modifier recovery and duplicate control input Aug 28, 2026
@levovix0
levovix0 merged commit 96ca695 into levovix0:master Aug 29, 2026
3 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