merge #992: 桌面壳兜底入口避开标题栏左侧系统按钮(红绿灯)

This commit is contained in:
Menghuan1918 committed 2026-10-26 15:26:46 +08:00
commit fd8a09d96b
2 files changed
+75 -11

No files matched your search

+14 -10
View File
@@ -134,22 +134,26 @@ function slotOccupiedByRect(cx: number, cy: number): boolean {
* 因此这里从锚点左侧起逐像素左移,取**最近的一个真的空着**的槽位。走查是**有界**的:
* 最多 {@link MAX_RETREAT_STEPS} 步(400px)——真实的宿主编簇只有几个 28px 按钮,退过
* 400px 说明整排都被占着,而每一步都要采样 5 个点做命中测试,不封顶的走查(旧值 400 步)
* 会把一次 tick 变成上千次命中测试。到达上限仍未找到空位就接受当前槽位;一直退到
* 视口左缘(`left <= 4`)仍被占时停在最左(宁可贴边,也不叠在宿主控件上)。
* 会把一次 tick 变成上千次命中测试。走查有两条下限:macOS 桌面壳的标题栏左侧是系统窗口
* 按钮(红绿灯,约 88px),原生控件不会出现在命中测试栈里,所以那条下限必须显式保留;
* 若下限之上仍无空位,接受与宿主内容重叠——空白会话没有别的底部工作台 opener,宁可叠
* 内容也不叠系统控件、更不能把唯一入口藏掉。
* @returns 视口坐标下的 top/left。
*/
function measure(): { top: number; left: number } {
const anchor = document.querySelector('[data-sidebar-right-expand], [data-sidebar-right-toggle]')
if (anchor === null) return { top: 8, left: window.innerWidth - BUTTON_SIZE - GAP - 8 }
const rect = anchor.getBoundingClientRect()
const top = Math.max(4, rect.top + (rect.height - BUTTON_SIZE) / 2)
let left = Math.max(4, rect.left - GAP - BUTTON_SIZE)
for (let step = 0; step < MAX_RETREAT_STEPS; step++) {
if (slotFree(left, top)) break
const rect = anchor?.getBoundingClientRect()
const top = rect === undefined ? 8 : Math.max(4, rect.top + (rect.height - BUTTON_SIZE) / 2)
let left = rect === undefined ? window.innerWidth - BUTTON_SIZE - GAP - 8 : rect.left - GAP - BUTTON_SIZE
// 复用宿主 preload 的平台属性;原生红绿灯不会出现在 elementsFromPoint 中。
// 48px 高度 / 88px 左侧留白与宿主 AppFrame / fullscreen dock strip 的几何一致。
const root = document.documentElement
const minLeft = root.dataset.platform === 'darwin' && !root.hasAttribute('data-fullscreen') && top < 48 ? 88 : 4
for (let step = 0; step < MAX_RETREAT_STEPS && left >= minLeft; step++) {
if (slotFree(left, top)) return { top, left }
left -= STEP_PX
if (left <= 4) { left = 4; break }
}
return { top, left }
return { top, left: Math.max(left, minLeft) }
}
export function DockFallback({ store }: { store: SidebarStore }): ReactNode {
+61 -1
View File
@@ -222,6 +222,66 @@ describe('dock fallback(空白会话入口)', () => {
}
})
it('keeps an occupied desktop row outside the traffic-light reserve without losing the only entry', async () => {
phaseIs(true)
document.documentElement.dataset.platform = 'darwin'
const anchor = appendAnchor(100)
const hit = stubHitTest(() => [anchor])
const { unmount, store } = renderDockFallback()
try {
await settle()
const shell = document.querySelector<HTMLElement>('[data-dsh-dock-fallback]')
expect(shell, '空白会话没有其他 opener,不能隐藏唯一入口').not.toBeNull()
expect(Number.parseFloat(shell!.style.left), '无空位也不能落到 left<=4 或红绿灯区域').toBeGreaterThanOrEqual(88)
clickFallbackToggle()
expect(store.getSnapshot().state?.bottomOpen).toBe(true)
} finally {
unmount()
hit.restore()
anchor.remove()
delete document.documentElement.dataset.platform
}
})
it('avoids the desktop reserve even when native window controls are absent from the hit-test stack', async () => {
phaseIs(true)
document.documentElement.dataset.platform = 'darwin'
const anchor = appendAnchor(100)
const hit = stubHitTest(() => [])
const { unmount } = renderDockFallback()
try {
await settle()
const shell = document.querySelector<HTMLElement>('[data-dsh-dock-fallback]')
expect(shell).not.toBeNull()
expect(Number.parseFloat(shell!.style.left)).toBeGreaterThanOrEqual(88)
} finally {
unmount()
hit.restore()
anchor.remove()
delete document.documentElement.dataset.platform
}
})
it('keeps the bounded web walk (reaches the left edge, never hides)', async () => {
phaseIs(true)
const anchor = appendAnchor(100)
const hit = stubHitTest(() => [anchor])
const { unmount } = renderDockFallback()
try {
await settle()
const shell = document.querySelector<HTMLElement>('[data-dsh-dock-fallback]')
// Web keeps the original bounded walk: every sampled slot is occupied,
// so the entry stops at the viewport's left edge (4px). Hiding the only
// blank-session entry would be worse than a leftover overlap.
expect(shell).not.toBeNull()
expect(shell!.style.left).toBe('4px')
} finally {
unmount()
hit.restore()
anchor.remove()
}
})
// 占位判定走命中测试而不是角色筛选:该点下面整摞元素只要有不透明的小控件就算占着。
// 这里把命中测试桩成「前两个槽位被盖住」,断言入口继续左移。
it('steps past tab chips that are not buttons (hit-test occupancy)', async () => {
@@ -394,7 +454,7 @@ describe('dock fallback(空白会话入口)', () => {
expect(hit.hits(), '让位走查必须封顶在 100 步(400px)').toBe(100)
const shell = document.querySelector<HTMLElement>('[data-dsh-dock-fallback]')
// 锚点在 500、按钮 28px、间距 8px → 起点 464;100 步 × 4px = 400px → 64。
// 旧上限(400 步)会一路退到视口左缘并停成 4px。
// 耗尽上限后停在 464 - 400,而不是视口左缘;隐藏唯一入口不是可接受的兜底。
expect(shell!.style.left, '耗尽上限后停在 464 - 400,而不是视口左缘').toBe('64px')
} finally {
unmount()