为什么值得关注
这是一款开源的 Metal 屏幕保护程序,记录了构建现代 macOS 屏幕保护程序的关键修复,包括 Swift 主类、从 bundle 加载 Metal 库、自主驱动渲染以及处理宿主进程退出。
适合谁使用
- 追求美观屏幕保护程序的 macOS 用户
- 学习着色器开发的 Metal 图形程序员
- 构建屏幕保护程序的 macOS 开发者
- 对精美屏保感兴趣的开源爱好者
典型使用场景
- 个人桌面屏幕保护,可调节菲涅尔发光和深色模式
- 学习 Metal 着色器编程和屏保架构的参考
- 制作自定义 Metal 屏保的基础模板
- 测试和实验 macOS 屏幕保护程序开发
项目优势
- 华丽的液态玻璃视觉效果,带有逼真的水纹投影
- 支持浅色/深色模式和可调菲涅尔发光
- 采用 MIT 许可证开源,并提供已签名公证的预编译版本
- 详细的构建说明,涵盖常见屏保问题的解决方法
使用前须知
- 仅兼容 macOS
- 需要手动安装 .saver 文件
- 若未使用退出解决方法,宿主进程可能卡死,影响预览可靠性
README 快速开始
Liquid Glass Screensaver
A macOS screensaver that renders a liquid glass shader composition: three glass orbs floating over animated water caustics. Includes a light and dark mode, with options for controlling the fresnel glow. I thought it would be fun to open source this so others could build and learn from it!
Install (prebuilt)
Grab liquid-glass-screensaver.zip from the latest release, unzip, and double-click the .saver (or copy it to ~/Library/Screen Savers/), then select it in System Settings → Screen Saver. The build is Developer ID-signed and notarized.
Build & Install
xcodebuild -project liquid-glass-screensaver.xcodeproj -scheme liquid-glass-screensaver -configuration Release build
cp -R ~/Library/Developer/Xcode/DerivedData/liquid-glass-screensaver-*/Build/Products/Release/liquid-glass-screensaver.saver ~/Library/Screen\ Savers/
killall legacyScreenSaver 2>/dev/null
Then pick liquid-glass-screensaver in System Settings → Screen Saver. Options… has a fresnel glow slider and a dark background toggle.
(Or open the project in Xcode, ⌘B, and copy the built .saver to ~/Library/Screen Savers/.)
Building Your Own Metal Screensaver
Start from Xcode's macOS → Screen Saver template, then apply these. Each one is a hard-won fix for how modern macOS hosts screensavers:
- Swift principal class. The template is Obj-C. For Swift, name your view
@objc(your_principal_class_name)to matchNSPrincipalClassin the build settings, and addSWIFT_VERSIONto the project. - Load your Metal library from the saver's bundle.
device.makeDefaultLibrary()resolves against the host app (legacyScreenSaver), not your bundle, and silently fails. UsemakeDefaultLibrary(bundle: Bundle(for: YourClass.self)). - Drive rendering yourself. Run the
MTKViewwithisPaused = falseand its own display link. The host dropsanimateOneFrame/startAnimationcalls when it gets into a bad state; a saver that depends on them renders black. - Exit the host process when your saver stops. Observe the
com.apple.screensaver.willstopdistributed notification (andNSWorkspace.willSleepNotification) and callexit(0). Without this the host process wedges: Preview works exactly once and the process lingers until killed in Activity Monitor
