fix: マルチディスプレイ環境で変換候補ウィンドウがカーソルと異なるディスプレイに表示される不具合を修正#323
Open
itouuuuuuuuu wants to merge 1 commit intoazooKey:mainfrom
Open
fix: マルチディスプレイ環境で変換候補ウィンドウがカーソルと異なるディスプレイに表示される不具合を修正#323itouuuuuuuuu wants to merge 1 commit intoazooKey:mainfrom
itouuuuuuuuu wants to merge 1 commit intoazooKey:mainfrom
Conversation
window.screen は「ウィンドウが現在乗っているスクリーン」を返すため、 カーソルが別ディスプレイへ移動した直後に誤った visibleFrame を渡してしまい、 候補ウィンドウが隣ディスプレイの右端に貼り付く症状が出ていた。 - カーソル位置を含む NSScreen を引く ScreenLookup ヘルパーを追加 (包含判定は frame、フォールバックは最近接 screen → window.screen → main) - BaseCandidateViewController.resizeWindowToFitContent を ScreenLookup ベースに変更 - positionPredictionWindowRightOfCandidateWindow を候補ウィンドウ中心が乗る スクリーン基準に変更 - WindowPositioning.frameNearCursor に左端/上下のクランプを追加 (これまで右端しかクランプしていなかった) - WindowPositioningTests に副ディスプレイ/クランプ各種のケースを追加(+6 ケース) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a63afdd to
928c74f
Compare
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.
問題
Closes #322
マルチディスプレイ環境で日本語入力中にスペースを押して変換すると、変換候補ウィンドウがカーソルのあるディスプレイとは別のディスプレイに表示されることがある不具合の修正です。
原因
BaseCandidateViewController.resizeWindowToFitContent(cursorLocation:)が、window.screenから取ったvisibleFrameをWindowPositioning.frameNearCursorに渡していました。window.screenは 「ウィンドウが現在乗っているスクリーン」 を返すため、マルチディスプレイ環境でカーソルが別ディスプレイへ移動した直後は、カーソル所在のディスプレイと一致しないことがあります。その状態で
frameNearCursor内の右端クランプ:が走ると、カーソル所在ディスプレイのグローバル座標(例: 右モニターの
x=2000)と、別ディスプレイのscreenRect.maxX(例: 左モニターの1920)を比較してしまい、ウィンドウが誤ったディスプレイの右端に貼り付く症状が発生していました。positionPredictionWindowRightOfCandidateWindowもpredictionWindow.screen ?? candidatesWindow.screenを使っており、同じ理由で予測ウィンドウも候補ウィンドウに引きずられていました。なお
PromptInputWindow.adjustWindowPositionはNSScreen.screens.first(where: { NSMouseInRect(cursorLocation, $0.frame, false) })でカーソル所在のスクリーンを正しく選んでいるため、候補ウィンドウ系だけ同様のケアが抜けていた状態でした。修正内容
1.
ScreenLookupヘルパーの追加azooKeyMac/InputController/WindowPositioning+CoreGraphics.swiftにカーソル位置を含むNSScreenを引くヘルパーを追加しました。NSScreen.frame(メニューバー / Dock を含むディスプレイ全体)を使用。visibleFrameで判定するとメニューバー直下や Dock 領域付近で取りこぼすことがあるため、包含と利用領域を意図的に分離(クランプには引き続きvisibleFrameを渡す)。fallbackWindow?.screen→NSScreen.main。本ヘルパーの主目的が「window.screenがカーソル所在のディスプレイと一致しない問題を避けること」なので、fallbackWindow?.screenより最近接 screen を優先しています。2.
BaseCandidateViewController.resizeWindowToFitContentの修正window.screen参照をScreenLookup.screen(containing: cursorLocation, fallbackWindow: window)に置換。PredictionCandidatesViewControllerも同 superclass のため一括で解消されます。3.
positionPredictionWindowRightOfCandidateWindowの修正candidatesWindow.frameの中心点が乗るスクリーンをScreenLookupで能動的に判定する形に変更。*.screenプロパティの状態に依存しないようにしました。4.
WindowPositioning.frameNearCursorのクランプを 4 方向化これまで右端しかクランプしておらず、左モニター(負 origin)や縦配置で破綻する余地がありました。左端・上端・下端のクランプを追加し、ウィンドウが screenRect より大きい場合は最終的に min 側に寄せるフォールバック挙動も明示しています。
動作確認
swift test --filter WindowPositioningTests(Core パッケージ)→ 11/11 PASS(既存 5 + 新規 6)xcodebuild -scheme azooKeyMac -configuration Debug build→ BUILD SUCCEEDEDswiftlint lint変更ファイル全件 → 警告ゼロ