fix(windows): 多显示器下胶囊跟随正在输入的屏幕#569
Merged
H-Chris233 merged 1 commit intoJun 1, 2026
Merged
Conversation
问题:多显示器环境下,无论在哪块屏输入,录音胶囊总是固定出现在主屏 (或胶囊窗口自己所在那块屏)。在 A 屏取消后到 B 屏输入,胶囊仍停在 A 屏。 根因:`position_capsule_bottom_center` 用 `window.current_monitor()` 决定 位置,拿到的是胶囊窗口自身所在显示器,而非用户正在输入的显示器。并且 `maybe_position_capsule_bottom_center` 的去重缓存 key 也基于同一个 current_monitor,于是「输入焦点已切到另一块屏、但胶囊还在原屏」会被误判为 「没变化」→ 跳过重新定位,胶囊被钉死在原屏。 修复: - 新增 `foreground_window_monitor()`(Win32 GetForegroundWindow → MonitorFromWindow → GetMonitorInfoW + GetDpiForMonitor),定位「正在输入的 App」所在显示器;`position_capsule_bottom_center` 在 Windows 上优先按它 (physical px + 该屏 DPI)摆放,取不到时回退 current_monitor。 - `capsule_layout_snapshot()` 让去重缓存 key 与实际定位用的显示器一致, 消除「输入切屏但不重定位」的误判。 - Cargo.toml 增加 `Win32_UI_HiDpi` feature(GetDpiForMonitor 所需)。 仅 Windows 路径改动;macOS / Linux 行为不变(仍走 current_monitor)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
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.
User description
问题
多显示器环境下,无论在哪块屏输入,录音胶囊总是固定出现在主屏(或胶囊窗口自己所在那块屏)。例如在 A 屏取消听写、再到 B 屏输入时,胶囊仍停留在 A 屏,不会跟到正在输入的 B 屏。
根因
position_capsule_bottom_center用window.current_monitor()决定位置,拿到的是胶囊窗口自身所在显示器,而不是用户正在输入的显示器。maybe_position_capsule_bottom_center的「是否需要重新定位」去重缓存 key 也基于同一个current_monitor。于是「输入焦点已经切到另一块屏、但胶囊还在原屏」会被误判为「显示器没变化」→ 跳过重新定位,胶囊被钉死在原屏。修改
foreground_window_monitor():Win32GetForegroundWindow→MonitorFromWindow(MONITOR_DEFAULTTONEAREST)→GetMonitorInfoW+GetDpiForMonitor,定位「正在输入的 App」所在显示器及其 DPI。position_capsule_bottom_center在 Windows 上优先按前台显示器(physical px + 该屏有效 DPI)摆放;Win32 取不到时回退原来的current_monitor逻辑。capsule_layout_snapshot(),让去重缓存 key 与实际定位所用的显示器保持一致,消除「输入切屏但不重定位」的误判。Cargo.toml增加Win32_UI_HiDpifeature(GetDpiForMonitor所需)。平台影响
仅改动 Windows 路径。macOS / Linux 行为完全不变(仍走
current_monitor,相关分支以#[cfg(target_os = "windows")]隔离)。验证
cargo check/ release 构建在 Windows 通过,应用启动、热键、胶囊显示正常。PR Type
Bug fix
Description
Add foreground_window_monitor() to locate active input monitor
Use it in position_capsule_bottom_center on Windows
Align caching snapshot with actual monitor used
Add Win32_UI_HiDpi Cargo feature
Diagram Walkthrough
File Walkthrough
coordinator.rs
Add capsule_layout_snapshot for correct cachingopenless-all/app/src-tauri/src/coordinator.rs
lib.rs
Add foreground_window_monitor to track input monitoropenless-all/app/src-tauri/src/lib.rs
function
Cargo.toml
Enable Win32_UI_HiDpi featureopenless-all/app/src-tauri/Cargo.toml