Skip to content

fix(desktop): 对齐 tab bar 左上角 Home 按钮与 macOS 红绿灯 - #793

Open
Gyarados4157 wants to merge 1 commit into
codedogQBY:mainfrom
Gyarados4157:fix/macos-traffic-light-alignment
Open

Gyarados4157 wants to merge 1 commit into
codedogQBY:mainfrom
Gyarados4157:fix/macos-traffic-light-alignment

Conversation

@Gyarados4157

Copy link
Copy Markdown

Fixes #792

问题

macOS 桌面端左侧栏上方的 tab bar 左上角,Home 按钮和系统红绿灯既垂直错位 8pt,又水平贴在一起(Home 按钮的 hover 背景伸进红绿灯 4pt)。本机 macOS 27.0 (26A428) + ReadAny 1.3.6 实测:

元素 窗口坐标
红绿灯 14×14pt,中心距 23pt,x=12…72,顶部 y=1,垂直中心 y=8
Home 按钮 图标盒 18px 居中于 32pt 行 → 垂直中心 y=16,图标盒左边缘 x=72,hover 左边缘 x=68

issue 里有标注截图和完整的推导过程。

改动

  1. packages/app/src-tauri/tauri.conf.json:trafficLightPosition.y 由 10 改为 18
  2. packages/app/src/components/layout/TabBar.tsx:paddingLeft 的 68 抽成常量 MAC_TRAFFIC_LIGHTS_INSET = 80,推导写进注释

为什么是这两个值

y = 18:trafficLightPosition.y 并不是"按钮顶部 = y"。tao 的 inset_traffic_lights 把 titlebar 容器高度改成 按钮高 + y 并只改按钮的 origin.x,AppKit 让按钮与容器底边保持固定内边距,所以实际顶部 = y − 默认内边距。用相同 styleMask(fullSizeContentView + titlebarAppearsTransparent + 隐藏 title)的最小 AppKit 探针套用该算法,在本机实测:

trafficLightPosition.y 按钮顶部 垂直中心
不设置(系统默认) 9pt 16pt
10(改动前) 1pt 8pt
18(改动后) 9pt 16pt

18 让红绿灯回到系统默认位置,也正好是 32pt tab bar(h-8)的中心。按旧版 macOS 的标准几何(28pt 标题栏、12pt 按钮、默认内边距 8pt)推算同样得到中心 16pt,所以旧系统不会回归。

80:红绿灯组现在是 12 + 3×14 + 2×9 = 72pt 宽,旧的 68 是按 12 + 3×12 + 2×8 = 64pt 加 4pt 留白算的。取 72 + 8 留白;旧系统上多出的 12pt 空白无害。

验证

  • 最小 AppKit 探针:套用 tao 的算法后读 standardWindowButton(...).frame,得上面的表格(y=10 → 顶部 1pt / 中心 8pt;y=18 → 顶部 9pt / 中心 16pt)
  • 用本机 1.3.6 的截图按窗口坐标反推实际几何,与探针结果在 1pt 内一致(卡片边框 x=192 / y=32 作为基准)
  • 未改 x: 12(与红绿灯宽度无关),未做其他 macOS 标题栏相关的假设改动
  • npx @biomejs/biome@1.9.4 check:改动没有新增告警(该文件在 main 上已有 format / organizeImports / useKeyWithClickEvents 三条既存告警,为保持 diff 最小未一并处理)

说明

  • 这次没有做完整 app 构建验证,改动只有两个数值/常量;上面用「探针 + 截图反推」互相印证。如果需要,我可以补一张改后构建的实机截图。
  • 更彻底的做法是在 Rust 侧读 standardWindowButton(...).frame 把真实几何传给前端,避免以后系统改版再次错位;这个 PR 先做最小修复。

…ghts

`trafficLightPosition.y` does not set the buttons' top offset: tao's
`inset_traffic_lights` only rewrites the titlebar container's height (button
height + y) and each button's origin.x, and AppKit keeps the buttons at a fixed
inset from the container's bottom edge. The effective top is therefore
`y - defaultInset`: with y = 10 the lights land at y = 1 (centre 8) on macOS
27.0 while the 32pt tab bar centres the home button at y = 16, so the button
sits 8pt below the window controls and looks misplaced. y = 18 restores the
intended centre of 16pt (= where macOS puts them when no position is set).

The 68pt leading inset was derived from the old window-control geometry
(12 + 3*12 + 2*8 = 64, +4pt gap). The controls are now 14pt wide on 23pt
centres, so the group reaches 72pt and the home button's hover area overlapped
the green button. Reserve the wider geometry plus an 8pt gap.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] macOS 桌面端:左上角 Home 按钮与系统红绿灯按钮错位(高 8pt,hover 区伸进红绿灯)

1 participant