Skip to content

fix(windows): 多显示器下胶囊跟随正在输入的屏幕#569

Merged
H-Chris233 merged 1 commit into
Open-Less:betafrom
katanumahotori:fix/capsule-follow-input-monitor
Jun 1, 2026
Merged

fix(windows): 多显示器下胶囊跟随正在输入的屏幕#569
H-Chris233 merged 1 commit into
Open-Less:betafrom
katanumahotori:fix/capsule-follow-input-monitor

Conversation

@katanumahotori
Copy link
Copy Markdown
Contributor

@katanumahotori katanumahotori commented Jun 1, 2026

User description

问题

多显示器环境下,无论在哪块屏输入,录音胶囊总是固定出现在主屏(或胶囊窗口自己所在那块屏)。例如在 A 屏取消听写、再到 B 屏输入时,胶囊仍停留在 A 屏,不会跟到正在输入的 B 屏。

根因

  • position_capsule_bottom_centerwindow.current_monitor() 决定位置,拿到的是胶囊窗口自身所在显示器,而不是用户正在输入的显示器。
  • 同时 maybe_position_capsule_bottom_center 的「是否需要重新定位」去重缓存 key 也基于同一个 current_monitor。于是「输入焦点已经切到另一块屏、但胶囊还在原屏」会被误判为「显示器没变化」→ 跳过重新定位,胶囊被钉死在原屏。

修改

  • 新增 foreground_window_monitor():Win32 GetForegroundWindowMonitorFromWindow(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_HiDpi feature(GetDpiForMonitor 所需)。

平台影响

仅改动 Windows 路径。macOS / Linux 行为完全不变(仍走 current_monitor,相关分支以 #[cfg(target_os = "windows")] 隔离)。

验证

  • cargo check / release 构建在 Windows 通过,应用启动、热键、胶囊显示正常。
  • 该问题来自三显示器环境的实测反馈(胶囊不跟随输入屏)。

由 fork 维护者在日文环境使用中发现并修复;如对命名 / 注释口径有偏好可直接指出。


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

flowchart LR
  A["Foreground window"] --> B["Get monitor via MonitorFromWindow"]
  B --> C["ForegroundMonitor (rect + DPI)"]
  C --> D["position_capsule_bottom_center uses ForegroundMonitor"]
  D --> E["Capsule placed on active monitor"]
Loading

File Walkthrough

Relevant files
Enhancement
coordinator.rs
Add capsule_layout_snapshot for correct caching                   

openless-all/app/src-tauri/src/coordinator.rs

  • Refactored caching logic into capsule_layout_snapshot()
  • Snapshot now uses foreground_window_monitor on Windows
  • Ensures re-position decision uses correct monitor key
+38/-7   
lib.rs
Add foreground_window_monitor to track input monitor         

openless-all/app/src-tauri/src/lib.rs

  • Added ForegroundMonitor struct and foreground_window_monitor()
    function
  • Modified position_capsule_bottom_center to use it on Windows
  • Falls back to current_monitor if unavailable
+77/-2   
Dependencies
Cargo.toml
Enable Win32_UI_HiDpi feature                                                       

openless-all/app/src-tauri/Cargo.toml

  • Added Win32_UI_HiDpi feature for GetDpiForMonitor
+1/-0     

问题:多显示器环境下,无论在哪块屏输入,录音胶囊总是固定出现在主屏
(或胶囊窗口自己所在那块屏)。在 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>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@H-Chris233 H-Chris233 merged commit 137c175 into Open-Less:beta Jun 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants