Panel (Floating Window / HUD) 面板(浮动窗口 / HUD) macos
An auxiliary macOS window that floats above related document windows
悬浮在相关文稿窗口上方的 macOS 辅助窗口
标本可交互 —— 点点看。Specimen is live — try it.
Anatomy — every part, named解剖 —— 每个部件的名字
-
1 Floating window level浮动窗口层级
NSWindow.Level.floating“The utility window that stays above the document” uses a floating window level.
“一直浮在文稿上面的工具窗口”用的就是浮动窗口层级。
Prompt fragmentPrompt 片段an NSPanel at NSWindow.Level.floating, remaining above its related document windows
一个层级为 NSWindow.Level.floating 的 NSPanel,始终位于相关文稿窗口上方
-
2 HUD chromeHUD 窗口外框
NSWindow.StyleMask.hudWindow“The dark translucent heads-up-display frame” is HUD chrome.
“深色半透明的 HUD 边框”就是 HUD 窗口外框。
Prompt fragmentPrompt 片段the dark translucent NSWindow.StyleMask.hudWindow chrome around an auxiliary NSPanel
辅助 NSPanel 周围深色半透明的 NSWindow.StyleMask.hudWindow 外框
Prompt — paste into your agentPrompt —— 直接粘贴给你的代理
Implement this auxiliary surface as a Panel (Floating Window / HUD) using NSPanel, with NSWindow.Level.floating so it stays above its related document windows. If it should behave like Spotlight, use the nonactivatingPanel style so showing it does not activate the app or steal focus unnecessarily.
用 NSPanel 把这个辅助界面实现为面板(浮动窗口 / HUD),设置 NSWindow.Level.floating 让它保持在相关文稿窗口上方。如果它应该像 Spotlight 那样工作,就使用 nonactivatingPanel 样式,让显示它时不会激活 App,也不会不必要地抢走焦点。
Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时
Debug my macOS panel (NSPanel). Rule out: the panel stealing focus from the main window because the nonactivatingPanel style mask is missing; text fields inside refusing input because the panel cannot become key; the panel vanishing on app deactivate via hidesOnDeactivate; a floating window level fighting other always-on-top windows. The symptom:
调试我的 macOS 面板(NSPanel)。逐一排除:缺少 nonactivatingPanel 样式导致面板从主窗口抢焦点;面板无法成为 key window,导致里面的文本框拒绝输入;hidesOnDeactivate 让面板在 App 失活时消失;浮动窗口层级与其他置顶窗口互相冲突。症状是:
In code代码里叫什么
| Framework框架 | Symbol符号 | Note说明 |
|---|---|---|
| AppKit | NSPanel | |
| AppKit | NSWindow.StyleMask.nonactivatingPanel | allows a panel that does not activate its app让面板显示时不激活所属 App |
| AppKit | NSWindow.StyleMask.hudWindow | heads-up-display panel appearanceHUD(平视显示)面板外观 |
| AppKit | NSWindow.Level.floating | |
| AppKit | NSPanel.becomesKeyOnlyIfNeeded |