From cc36bc4c642cb8edad8192089bd07dc7405349a5 Mon Sep 17 00:00:00 2001 From: OddTurtleHead <355182507+OddTurtleHead@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:37:46 +0800 Subject: [PATCH] fix: return floating host controls home only after a screen change Live re-test of a1c8329 on open-voice-surface desktop: toasts no longer pull the application-library launcher back, but opening the audio-settings modal did. Its backdrop hid "Share accompaniment", the default bottom-right corner looked free, the launcher went home, and right after Esc it still covered the button. 854a488's return-home rule is meant for a stale spot picked for the previous screen, so apply it only within the screen-change window (home <-> voice page, skin switch); on the same screen a free-looking default corner may just be hidden for a moment. The ts3-classic home-return case still passes (it goes through screenChanged()). Browser fixture: modal dialog over the corner (fails on a1c8329 and 854a488). --- docs/SKIN_DEVELOPMENT.md | 2 +- web/src/services/host-floating-placement.ts | 11 +++++++--- .../fixtures/host-floating-transient.html | 20 ++++++++++++++++--- web/test/host-chrome-recovery.test.mjs | 8 ++++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/docs/SKIN_DEVELOPMENT.md b/docs/SKIN_DEVELOPMENT.md index c3af6a9..219b624 100644 --- a/docs/SKIN_DEVELOPMENT.md +++ b/docs/SKIN_DEVELOPMENT.md @@ -492,7 +492,7 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 **这不是编译期限制。** `skin.css` 校验器不会因为是否声明 `slots` 而改变,也不会生成额外的隐藏或定位规则;停靠完全由宿主运行时完成。胶囊位于顶层,会挡住它下面的一切,因此宿主还会检查胶囊的占位(按观察到的最大尺寸计算,紧凑模式展开后的宽度也算在内)是否压到了可见的受保护控件(`PROTECTED_PART_IDS`,例如 `voice.audio-dock.microphone`、`voice.audio-dock.output`、`home.footer.clear`、`voice.connection-status.reconnect`);锚点的祖先容器(如包住专用锚点的 `voice.audio-dock`)不算,锚点自身只有在它是或包含可交互控件时才算。压到时同样回退。示例 `host-chrome-demo` 因此把胶囊靠 `start` 对齐在音频栏左侧的说明文字上,避开右侧的麦克风/输出按钮。锚点一旦不可用,胶囊立即回到默认左下角(仍在闭合 Shadow DOM 和顶层,皮肤无法遮挡或隐藏)。为避免闪烁,回退后需要连续 2 次检查都通过才会重新停靠;停靠期间约每 400 ms 复查一次,浮动态保持原来的 1 s 节奏。窗口缩放、滚动和锚点/胶囊尺寸变化都会触发复查。 -**浮动位置的运行时避让。** 没有停靠(未声明 `slots`,或锚点回退)时,恢复胶囊默认在左下角;宿主约每 400 ms(以及每次点击后约 150 ms)检查一次它是否盖住了皮肤里可见、处于最上层的可交互控件(按钮、链接、输入框、`[tabindex]` 自定义按钮、iframe 等;禁用的“发送”按钮也算,透明度为 0 的不算;受保护部件权重最高,其次是打开的对话框/底部弹层里的控件;只因位于皮肤根 `app` 之内的普通按钮不算受保护)。盖住时,胶囊会换到左下、右下、左上、右上、左中、右中、底部居中、顶部居中里遮挡最少的位置,但不会换到鼠标最后所在的位置或当前聚焦的控件上;只有收起能至少让出一个控件时,才收成只显示 ◈ 的紧凑形态(悬停、聚焦或点按展开)。鼠标悬停(触屏上不算残留的悬停)或焦点在胶囊内时不会移动。为避免闪动:遮挡要持续约 250 ms 才移动,两次移动至少相隔 1 s,10 s 内移动超过 6 次就停在默认角落 10 s(期间若默认角落盖住了控件,最多再挪开一次,之后保持不动);判断某个控件是否被盖住时会“看穿”短暂出现的提示条(`app.toast`)和另一个宿主浮动控件,提示条暂时挡住的控件仍按存在计算,不会因此把那个角落误判为空闲;默认角落重新空出来(且当前位置也不遮挡、鼠标不在那里)时,会按同样的节奏回到默认角落,免得为上一屏选的位置盖住下一屏新出现的控件;进入或离开语音页、切换皮肤时,宿主会在约 1.5 s 内跳过确认等待和最短间隔、连续复查几次,让胶囊尽快换到新页面合适的位置(通常就是重新空出来的默认角落)。位置计算和 CSS 一样计入 `env(safe-area-inset-*)`(刘海屏、底部手势条)。宿主自带的应用库悬浮按钮(皮肤没有提供 `voice.plugin-launcher` 挂载点时出现在右下角)使用同一套避让,两者也互相避开。这同样只是运行时行为,不新增任何 `skin.css` 编译期限制;皮肤作者无需为它做任何事,但如果希望胶囊固定在设计好的位置,仍建议用 `slots` 停靠。 +**浮动位置的运行时避让。** 没有停靠(未声明 `slots`,或锚点回退)时,恢复胶囊默认在左下角;宿主约每 400 ms(以及每次点击后约 150 ms)检查一次它是否盖住了皮肤里可见、处于最上层的可交互控件(按钮、链接、输入框、`[tabindex]` 自定义按钮、iframe 等;禁用的“发送”按钮也算,透明度为 0 的不算;受保护部件权重最高,其次是打开的对话框/底部弹层里的控件;只因位于皮肤根 `app` 之内的普通按钮不算受保护)。盖住时,胶囊会换到左下、右下、左上、右上、左中、右中、底部居中、顶部居中里遮挡最少的位置,但不会换到鼠标最后所在的位置或当前聚焦的控件上;只有收起能至少让出一个控件时,才收成只显示 ◈ 的紧凑形态(悬停、聚焦或点按展开)。鼠标悬停(触屏上不算残留的悬停)或焦点在胶囊内时不会移动。为避免闪动:遮挡要持续约 250 ms 才移动,两次移动至少相隔 1 s,10 s 内移动超过 6 次就停在默认角落 10 s(期间若默认角落盖住了控件,最多再挪开一次,之后保持不动);判断某个控件是否被盖住时会“看穿”短暂出现的提示条(`app.toast`)和另一个宿主浮动控件,提示条暂时挡住的控件仍按存在计算,不会因此把那个角落误判为空闲;同一页面内,当前位置不遮挡时不会为了回到默认角落而移动(默认角落“看起来空”可能只是被模态对话框的遮罩或提示条暂时挡住);进入或离开语音页、切换皮肤时,宿主会在约 1.5 s 内跳过确认等待和最短间隔、连续复查几次,并在默认角落和当前位置都空闲(鼠标也不在那里)时回到默认角落,免得为上一屏选的位置盖住下一屏新出现的控件。位置计算和 CSS 一样计入 `env(safe-area-inset-*)`(刘海屏、底部手势条)。宿主自带的应用库悬浮按钮(皮肤没有提供 `voice.plugin-launcher` 挂载点时出现在右下角)使用同一套避让,两者也互相避开。这同样只是运行时行为,不新增任何 `skin.css` 编译期限制;皮肤作者无需为它做任何事,但如果希望胶囊固定在设计好的位置,仍建议用 `slots` 停靠。 **样式令牌**:皮肤可在皮肤根(`:root`)、锚点或锚点的祖先上设置下列普通 `--skin-*` 变量;宿主从锚点(存在时)或活动皮肤根的计算样式读取、校验,再写入闭合 Shadow DOM 内部的宿主变量。没有声明 `slots` 的皮肤也能用这些令牌给浮动态胶囊换肤;锚点仍在 DOM 中时,停靠态和浮动态都会继续使用这些令牌;锚点被移除或隐藏时,宿主读取皮肤根上可继承的值,否则使用默认值。每个 `--skin-recovery-*` 都有全局回退 `--skin-host-<同名>`,`--skin-recovery-*` 优先;只有颜色对比度不达标时整组颜色才回退到宿主默认值。声明了插槽但没写颜色令牌时,胶囊使用不透明的宿主默认色(白底),而不是无插槽时的半透明底。 diff --git a/web/src/services/host-floating-placement.ts b/web/src/services/host-floating-placement.ts index 16c436f..b8e649a 100644 --- a/web/src/services/host-floating-placement.ts +++ b/web/src/services/host-floating-placement.ts @@ -160,6 +160,9 @@ export interface FloatingChoice { * order. When `home` (the default corner) is given and both it and `current` * are free, go back home: a spot picked for one screen must not linger over * controls that appear on the next one (e.g. after leaving the voice page). + * The binding passes `home` only right after a screen change: on the same + * screen a free-looking default corner may just be hidden for a moment (a + * modal dialog's backdrop, a toast) and going back there would cover it. * `moveObstacles` (the user's pointer and focused control) only count against * positions the control would move to, so it never jumps under the cursor or * onto the field being typed in. @@ -452,7 +455,11 @@ export function bindFloatingAvoidance(options: FloatingAvoidanceOptions): Floati const rect = focused.getBoundingClientRect(); if (rect.width > 0 && rect.height > 0) moveObstacles.push({ rect: toRect(rect), weight: FLOATING_WEIGHT_POINTER }); } - const full = chooseFloatingPosition({ current: position, size, viewport, margins, obstacles, moveObstacles, home: defaultPosition }); + const now = Date.now(); + const urgent = now < urgentUntil; + // Return home only after a screen change (see chooseFloatingPosition). + const home = urgent ? defaultPosition : undefined; + const full = chooseFloatingPosition({ current: position, size, viewport, margins, obstacles, moveObstacles, home }); let next = full; let nextCompact = false; if (full.score > 0 && small && small.width > 0 && small.height > 0) { @@ -466,7 +473,6 @@ export function bindFloatingAvoidance(options: FloatingAvoidanceOptions): Floati pendingSince = 0; return; } - const now = Date.now(); const frozen = now < frozenUntil; if (frozen) { // Frozen at the default corner: hold still, except one escape per @@ -476,7 +482,6 @@ export function bindFloatingAvoidance(options: FloatingAvoidanceOptions): Floati const parkedScore = floatingScore(parked, obstacles); if (frozenEscaped || !(parkedScore > 0 && next.score < parkedScore - 1e-6)) return; } - const urgent = now < urgentUntil; if (!urgent && !pendingSince) { pendingSince = now; scheduleConfirm(HOST_FLOATING_MOVE_CONFIRM_MS); diff --git a/web/test/fixtures/host-floating-transient.html b/web/test/fixtures/host-floating-transient.html index 462cadd..6f5301a 100644 --- a/web/test/fixtures/host-floating-transient.html +++ b/web/test/fixtures/host-floating-transient.html @@ -57,8 +57,9 @@ try { const accompaniment = document.getElementById("accompaniment"); // A. A toast keeps passing over the accompaniment button (every mic/output - // toggle shows one). The launcher must not take the "free" default corner - // while the toast hides the button, and must never end up covering it. + // toggle shows one), then a modal dialog hides it. The launcher must not + // take the "free" default corner while the button is hidden, and must never + // end up covering it. { const { lib, binding } = makeLauncher(); binding.revalidate(); await sleep(1400); binding.revalidate(); await sleep(50); @@ -77,7 +78,20 @@ try { } } await sleep(1500); - results.push({ name: "toast-transient", settled, positions: [...positions], coveredSamples, samples, final: binding.position, finalCovered: coveredByLib(accompaniment) }); + // A modal dialog (audio settings) opens over everything: its backdrop + // hides the accompaniment button, so the default corner looks free. On the + // same screen that is no reason to go back there. + const modalPositions = new Set(); + document.body.insertAdjacentHTML("beforeend", '
' + + ''); + for (let i = 0; i < 20; i++) { binding.revalidate(); modalPositions.add(binding.position); await sleep(100); } + document.getElementById("backdrop").remove(); + document.getElementById("settings").remove(); + binding.revalidate(); + await sleep(100); + const afterModal = { positions: [...modalPositions], position: binding.position, accompanimentCovered: coveredByLib(accompaniment) }; + results.push({ name: "toast-transient", afterModal, settled, positions: [...positions], coveredSamples, samples, final: binding.position, finalCovered: coveredByLib(accompaniment) }); binding.dispose(); lib.remove(); } diff --git a/web/test/host-chrome-recovery.test.mjs b/web/test/host-chrome-recovery.test.mjs index 554eefc..4ba197d 100644 --- a/web/test/host-chrome-recovery.test.mjs +++ b/web/test/host-chrome-recovery.test.mjs @@ -396,13 +396,17 @@ test("floating host controls see through toasts and still step off a control whi const byName = Object.fromEntries(payload.results.map((result) => [result.name, result])); t.diagnostic(JSON.stringify(payload.results)); - // open-voice-surface desktop: toasts passing over "Share accompaniment" no - // longer make the default bottom-right corner look free. + // open-voice-surface desktop: toasts passing over "Share accompaniment" (or + // the audio-settings modal) no longer make the default corner look free. const toast = byName["toast-transient"]; assert.notEqual(toast.settled, "bottom-right", JSON.stringify(toast)); assert.ok(!toast.positions.includes("bottom-right"), JSON.stringify(toast)); assert.equal(toast.coveredSamples, 0, JSON.stringify(toast)); assert.equal(toast.finalCovered, false, JSON.stringify(toast)); + // Same screen, modal backdrop over the corner: no return home, so the + // button is usable the moment the dialog closes. + assert.ok(!toast.afterModal.positions.includes("bottom-right"), JSON.stringify(toast)); + assert.equal(toast.afterModal.accompanimentCovered, false, JSON.stringify(toast)); // Parked at the default corner by the flap freeze on top of a control: one // escape about 1 s after the freeze (inside the 3 s pin), then still for the rest of it.