Add a menu bar item to toggle Caps Lock directly#25
Open
otiai10 wants to merge 3 commits into
Open
Conversation
Lets Capsomnia flip the actual system Caps Lock modifier-lock state (LED included) instead of only reading it, so a future trigger other than the physical key can drive the same polling-based sleep logic.
Keyboards that remap the physical Caps Lock key (e.g. to Control) had no way to flip Capsomnia's trigger. The new menu item flips the real state via CapsLockController, and the existing 250ms poll picks it up exactly like a physical key press.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
物理 Caps Lock キーを Ctrl 等にリマップしているユーザーは、Capsomnia が読み取る実際の Caps Lock 状態を切り替える手段がなかった。メニューバーには表示・言語などの設定項目はあるが、状態そのものを書き換える項目は無かった。
目的
Caps Lock キーをリマップしているユーザーも、メニューバーから直接 Caps Lock 状態を切り替えられるようにし、Capsomnia 既存のスリープ抑止フローをそのまま使えるようにする。
方針
物理キー入力を模倣する代わりに、IOKit の HIDSystem 経由で実際の Caps Lock modifier-lock 状態(LED含む)を書き換える。これにより、既存の 250ms ポーリング(
applyCurrentCapsLockState)が新しい状態を物理キー押下と同じものとして検知し、apply()以降の既存ロジックを一切変更せずに済む。設計
Sources/Capsomnia/SystemServices.swiftCapsLockControllerを追加。純粋関数toggledState(current:)と、IOKit HIDSystem 経由で実際の状態を書き換えるset(_:)Sources/Capsomnia/CapsomniaApp.swifttoggleCapsLock()を実行Sources/Capsomnia/AppConstants.swiftREADME.md/README.ja.md/CHANGELOG.md受入条件
swift test --filter CapsLockControllerTestsでtoggledStateの true/false 反転が pass するswift build -c releaseが成功するgrep -q "Toggle Caps Lock" README.mdとgrep -q "Caps Lockを切り替え" README.ja.mdが成功する評価観点
IOServiceOpen/IOServiceClose/IOObjectRelease)にリークが無いか