Liquid Glass effect for GNU/Emacs
Liquid Glass effect for GNU/Emacs
GNU/Emacs 的 Liquid Glass(流体玻璃)效果
Emacs Liquid Glass This repo is a small recipe for building Emacs with a Ghostty-like macOS glass frame. It layers a local Cocoa patch on top of Homebrew emacs-plus@31 and the community frame-transparency patch, then configures Emacs with the same shape as Ghostty: background-opacity = 0.01 background-blur = macos-glass-regular This is not a dark overlay or a hard-coded theme. The patch adds native NSGlassEffectView support only. For the longer write-up, see the blog post.
Emacs Liquid Glass 是一个小型构建方案,旨在为 Emacs 打造类似 Ghostty 的 macOS 玻璃质感边框。它在 Homebrew 的 emacs-plus@31 和社区版 frame-transparency 补丁之上叠加了一个本地 Cocoa 补丁,并将 Emacs 配置为与 Ghostty 相同的形态:背景透明度 (background-opacity) 为 0.01,背景模糊 (background-blur) 为 macos-glass-regular。这不是深色遮罩或硬编码的主题,该补丁仅添加了原生的 NSGlassEffectView 支持。详细说明请参阅博客文章。
What This Builds
构建内容
The recipe uses the emacs-plus@31 formula, not the emacs-plus-app cask. The cask ships a prebuilt binary and ignores ~/.config/emacs-plus/build.yml, so it cannot apply local patches. The build applies two patches, in order: frame-transparency from d12frosted/emacs-plus patches/ns-glass-effect.patch from this repo.
该方案使用 emacs-plus@31 配方,而非 emacs-plus-app cask。Cask 提供的是预编译二进制文件,会忽略 ~/.config/emacs-plus/build.yml,因此无法应用本地补丁。构建过程按顺序应用两个补丁:来自 d12frosted/emacs-plus 的 frame-transparency 补丁,以及本仓库中的 ns-glass-effect.patch。
The local patch adds these frame parameters: 本地补丁添加了以下帧参数:
| Parameter | Purpose |
|---|---|
| ns-glass-material | Native material, currently regular, clear, or nil. |
| ns-glass-tint-opacity | Theme-owned tint opacity over the glass view. |
| ns-glass-saturation | Saturation multiplier for the glass tint. |
| ns-glass-inactive-opacity | Optional opacity when the frame is inactive. |
| ns-glass-corner-radius | Optional corner radius for the glass view. |
| ns-alpha-glyphs-alpha | Separate alpha for real glyph backgrounds. |
| 参数 | 用途 |
|---|---|
| ns-glass-material | 原生材质,目前支持 regular、clear 或 nil。 |
| ns-glass-tint-opacity | 玻璃视图上主题自带的色调透明度。 |
| ns-glass-saturation | 玻璃色调的饱和度乘数。 |
| ns-glass-inactive-opacity | 窗口非活动时的可选透明度。 |
| ns-glass-corner-radius | 玻璃视图的可选圆角半径。 |
| ns-alpha-glyphs-alpha | 实际字形背景的独立透明度。 |
The last parameter is what makes alpha-background values near 0 usable. Without it, hl-line, regions, and completion selections disappear with the frame background.
最后一个参数使得接近 0 的 alpha-background 值变得可用。如果没有它,hl-line、选区 (regions) 和补全选择项会随着帧背景一起消失。
Quick Start
快速开始
Install from your tap: 通过 tap 安装:
brew tap larrasket/emacs-liquid-glass https://github.com/larrasket/emacs-liquid-glass.git
brew emacs-liquid-glass install
Skip copying the rebuilt app bundle into /Applications: 跳过将重构的 app 包复制到 /Applications:
brew emacs-liquid-glass install --no-copy-app
Direct clone usage also works: 直接克隆使用也可以:
git clone https://github.com/larrasket/emacs-liquid-glass
cd emacs-liquid-glass
./install.sh
Use ./install.sh --no-copy-app if you do not want it to update /Applications/Emacs.app and /Applications/Emacs Client.app.
如果你不想更新 /Applications/Emacs.app 和 /Applications/Emacs Client.app,请使用 ./install.sh --no-copy-app。
Manual Build
手动构建
Copy the patch and build config: 复制补丁和构建配置:
mkdir -p ~/.config/emacs-plus
cp patches/ns-glass-effect.patch ~/.config/emacs-plus/ns-glass-effect.patch
cp config/build.yml ~/.config/emacs-plus/build.yml
Build Emacs from source: 从源码构建 Emacs:
brew tap d12frosted/emacs-plus
HOMEBREW_NO_AUTO_UPDATE=1 brew reinstall emacs-plus@31 --build-from-source
brew postinstall d12frosted/emacs-plus/emacs-plus@31
Copy the app bundles used by Spotlight and /opt/homebrew/bin/emacs: 复制 Spotlight 和 /opt/homebrew/bin/emacs 使用的 app 包:
rsync -a --delete /opt/homebrew/opt/emacs-plus@31/Emacs.app/ /Applications/Emacs.app/
rsync -a --delete "/opt/homebrew/opt/emacs-plus@31/Emacs Client.app/" "/Applications/Emacs Client.app/"
Emacs Config
Emacs 配置
Load lisp/lr-macos-glass.el from your Emacs config. If this repo is installed as a Homebrew tap, you can find its path with: brew emacs-liquid-glass path.
在你的 Emacs 配置中加载 lisp/lr-macos-glass.el。如果该仓库是通过 Homebrew tap 安装的,你可以通过 brew emacs-liquid-glass path 找到其路径。
Example: 示例:
(add-to-list 'load-path "/path/to/emacs-liquid-glass/lisp")
(require 'lr-macos-glass)
The regular preset currently uses: 常规预设目前使用:
(setq salih/glass-style 'macos-glass-regular
salih/alpha-background 0.01
salih/ns-background-blur 0
salih/ns-alpha-glyphs-min-alpha 0.24
salih/ns-glass-material 'regular
salih/ns-glass-tint-opacity 0.05
salih/ns-glass-saturation 1.9
salih/ns-glass-inactive-opacity 0.05
salih/ns-glass-corner-radius 2
salih/ns-transparent-titlebar t)
Interactive commands: 交互命令:
| Command | Effect |
|---|---|
| M-x salih/set-glass-style | Switch between macos-glass-regular and macos-glass-clear. |
| M-x salih/set-glass | Set frame alpha and CGS blur. |
| M-x salih/set-glass-glyph-alpha | Set highlight/selection glyph background alpha. |
| M-x salih/toggle-glass | Toggle between the glass frame and an opaque frame. |
| 命令 | 效果 |
|---|---|
| M-x salih/set-glass-style | 在 macos-glass-regular 和 macos-glass-clear 之间切换。 |
| M-x salih/set-glass | 设置帧透明度和 CGS 模糊。 |
| M-x salih/set-glass-glyph-alpha | 设置高亮/选区字形的背景透明度。 |
| M-x salih/toggle-glass | 在玻璃边框和不透明边框之间切换。 |
If you set salih/alpha-background to 0, keep salih/ns-alpha-glyphs-min-alpha above 0 if you still want hl-line, regions, and completion selections to be visible.
如果你将 salih/alpha-background 设置为 0,请保持 salih/ns-alpha-glyphs-min-alpha 大于 0,以便 hl-line、选区和补全选择项依然可见。
Verification
验证
If you find issue, please first check that the installed binary contains the new frame parameters: 如果遇到问题,请首先检查已安装的二进制文件是否包含新的帧参数:
strings /Applications/Emacs.app/Contents/MacOS/Emacs \
| rg 'ns-alpha-glyphs-alpha|ns-glass-material|ns-glass-saturation'
If emacs reports an invalid ns-glass-* value, you are probably running an older build than the app bundle you just compiled. Fully quit GUI Emacs, restart the daemon if you use one, and make sure /Applications/Emacs.app was copied from /opt/homebrew/opt/emacs-plus@31/Emacs.app.
如果 Emacs 报告无效的 ns-glass-* 值,你运行的可能还是旧版本的构建。请完全退出 GUI Emacs,重启 daemon(如果使用了的话),并确保 /Applications/Emacs.app 是从 /opt/homebrew/opt/emacs-plus@31/Emacs.app 复制过来的。
Notes
注意事项
This has been tested on macOS with Homebrew emacs-plus@31. It should not be expected to work on GNU/Linux, Windows, terminal Emacs, or the prebuilt emacs-plus-app cask.
此方案已在 macOS 上使用 Homebrew emacs-plus@31 进行测试。它不适用于 GNU/Linux、Windows、终端版 Emacs 或预编译的 emacs-plus-app cask。