Skip to content

fix(ui): macOS 窗口贴顶时消除顶部阴影空隙 - #7331

Open
Silent-xiaomiao wants to merge 1 commit into
HMCL-dev:mainfrom
Silent-xiaomiao:fix/macos-top-flush
Open

Silent-xiaomiao wants to merge 1 commit into
HMCL-dev:mainfrom
Silent-xiaomiao:fix/macos-top-flush

Conversation

@Silent-xiaomiao

@Silent-xiaomiao Silent-xiaomiao commented Nov 20, 2026 •

Copy link
Copy Markdown

现象

macOS 上把窗口拖到屏幕顶部时,窗口内容与菜单栏之间仍有约 8px 的空隙,而且窗口无法再往上移动。
hmcl-top-gap-before-after

原因

自定义窗口阴影在四周预留了 8px(Decorator.SHADOW_INSETS)。macOS 不允许普通窗口覆盖菜单栏,窗口框贴住菜单栏后,这 8px 的透明阴影区就露在顶部,看起来像"顶不上去"。

修改

只在 macOS 上生效:

  • 监听窗口几何变化;
  • 窗口进入屏幕顶部 48px 范围后,顶部 inset 按距离连续收缩,正好贴顶时已经是 0;
  • 离开顶部时同样连续恢复;
  • 最大化、全屏、原生窗口装饰沿用原逻辑。

选择连续收缩而不是"到阈值再切换",是因为后者无论加不加动画,都会在跨过阈值的那一帧产生一个 8px 的位移,手感上像被吸住。

取舍

  • 贴顶时顶部 8px 不再作为拉伸热区;
  • 接近顶部的最后 48px 内,根节点 padding 会随拖动逐像素变化,多一次布局;
  • 其他平台行为不变。

验证

macOS 26.x 手工验证:拖拽贴顶、离开顶部、最大化切换均正常。多显示器和全屏场景建议再确认。

如果维护者认为这个视觉问题不值得引入额外的窗口几何监听,我可以直接关掉这个 PR。

@github-actions github-actions Bot added the 40+ label Nov 20, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant