fix(floating-windows): 浮窗跟随鼠标所在的屏,多显示器下不再被钉死在主屏 - #1028
Open
bigsongeth wants to merge 1 commit into
Open
Conversation
接了外接屏时,Less Computer 的全屏彩虹描边(跑马灯)、Less Computer 聊天浮窗和 QA 浮窗都只出现在主屏上,胶囊却在你正在用的那块屏 —— 两边分家。 原因是这三个浮窗选屏时问的是「我自己现在在哪块屏」(window.current_monitor)。 它们都是懒创建 + 常驻隐藏的窗口:隐藏时停在上一次出现的屏,而这辈子第一次出现 就在系统默认(主)屏,于是每次 show 都算出主屏、又铺回主屏,永久钉死。 胶囊自己踩过并修好过同一个坑 —— 改成跟随鼠标光标所在的屏(capsule_target_monitor 的注释写着「不能用窗口自己的 current_monitor」),这三个浮窗漏掉了。这里抽出共用的 floating_window_monitor_frame,让浮窗和胶囊看同一块屏;非 macOS 没有这条 CGEvent/AX 通路,仍走 current_monitor,行为不变。 顺带把选屏的纯逻辑抽成 pick_monitor_for_anchor_point 并补单测:光标在哪块屏就选 哪块、落在所有屏之外时退到最近的屏。 注:QA 浮窗只在首次 show 时定位(之后有意保留用户拖动后的位置),所以这条对它只 影响第一次出现的位置。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
这个 PR 解决什么
接了外接屏之后,在外接屏上用 Less Computer:胶囊正确地出现在外接屏,但全屏彩虹描边(跑马灯)点亮的却是主屏的边缘,Less Computer 聊天浮窗也留在主屏。胶囊和浮窗各在一块屏上,视线要来回跳。
QA 浮窗有同样的毛病,只是它只在首次出现时定位,所以不那么显眼。
为什么会这样
这三个浮窗选屏时问的是「我自己现在在哪块屏」(
window.current_monitor())。它们都是懒创建 + 常驻隐藏的窗口:隐藏时停在上一次出现的位置,而它们这辈子第一次出现就在系统默认(主)屏 —— 于是每次显示都算出主屏、又铺回主屏,被永久钉死。
这个坑胶囊自己踩过并且修好了,
capsule_target_monitor()的注释写得很清楚:胶囊当时改成了跟随鼠标光标所在的屏,这三个浮窗漏掉了同一次修复。
改了什么
抽出共用的
floating_window_monitor_frame(),让浮窗和胶囊问同一个信号:capsule_target_monitor)current_monitor(),行为不变三个调用点全部换过去:glow 描边、Less Computer 面板、QA 浮窗。
实现细节与刻意没做的事
pick_monitor_for_anchor_point()(不依赖 Tauri / AppKit),补了 3 个单测:光标在哪块屏就选哪块、落在所有屏之外时退到最近的屏、没有屏时返回None。primary_monitor()兜底,QA / Less Computer 面板仍是「取不到就不动」。本次只换选屏信号。LogicalMonitorFrame逻辑坐标换算,Retina 下不会把窗口铺成两倍。QA_WINDOW_POSITIONED,之后有意保留用户拖动后的位置),所以这条改动对它只影响第一次出现的位置。要不要让 QA 每次都跟随光标是个产品取舍,本 PR 不动。验证
cargo test --lib:1172 passed / 0 failed(含新增的 3 个用例)🤖 Generated with Claude Code