為何合上 Apple Silicon MacBook 機蓋後 mini-LED 螢幕仍未關閉,以及如何修正
Why closing your MacBook lid does not turn off the mini-LED screen (and how to fix it)
Dopamine 是一款為 Apple Silicon MacBook 開發的原生 Swift 開源工具,可在合上機蓋並保持 CPU/GPU 醒着時,將 Liquid Retina/mini-LED 背光降至 0.0 nits。它透過 IOKit 監察機蓋狀態,打開機蓋後平順還原先前亮度。工具免費採用 MIT 授權,可透過 Homebrew Cask 或直接下載安裝。
If you own an Apple Silicon MacBook Pro or Air (M1, M2, M3, or M4), you might have noticed something strange when running long tasks with the lid closed: your laptop gets warm, and your battery drains faster than it should.
Here is the technical reality of what's happening under the hood, and how I built an open-source native Swift utility to fix it.
The Clamshell Problem on Modern Liquid Retina Screens
Like many developers, I often run long-running tasks on my MacBook:
- Compiling large codebases or Docker builds
- Running local LLM inference (Ollama / MLX)
- Exporting 4K video renders in Final Cut Pro / Premiere
- Large asset downloads
Naturally, you don't want to leave your laptop wide open taking up desk space, so you close the lid. And to keep the Mac awake without an external monitor, you use a keep-awake utility like Amphetamine, KeepingYouAwake, or caffeinate.
Here's the catch:
On Apple Silicon MacBooks, when you close the lid with a keep-awake assertion active (without an external monitor connected), macOS does NOT turn off the Liquid Retina / mini-LED display backlight.
Even though the clamshell lid is completely closed, thousands of mini-LEDs continue burning beneath the screen. They shine directly into the keyboard and display coatings, building up trapped heat and draining battery life.
Why Existing Tools Don't Solve This
Traditional tools like Amphetamine or caffeinate create a power assertion:
IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleSystemSleep, ...);
This tells macOS: "Don't put the CPU to sleep."
However, because macOS treats clamshell mode without an external monitor as an edge case, the display subsystem stays energized. Even setting display sleep timers often causes annoying backlight flickering because the kernel repeatedly attempts to wake the display.
The Native Fix: Enter Dopamine
I spent the past few weeks building Dopamine, a 100% native Swift menu bar utility built specifically for Apple Silicon.
Here is how it works:
-
Hardware Clamshell Detection: Dopamine registers an IOKit event listener directly with the
IOPMrootDomainservice to catchAppleClamshellStatestate changes instantly. - True 0.0-Nit Backlight Cutoff: The moment the lid closes, Dopamine drops the hardware backlight to absolute 0.0 nits (complete blackout / DPMS sleep) while maintaining the CPU/GPU keep-awake assertion.
- Instant Wake: The millisecond you lift the lid, Dopamine restores your previous brightness smoothly.
- Lightweight & Clean: Built with pure Swift and AppKit. Zero Electron bloat, ~15MB RAM footprint, and 0% idle CPU overhead.
- Security & Apple Notarization: Fully codesigned with an official Apple Developer ID and notarized by Apple's Notary Service (Gatekeeper trusted).
How to Install
Dopamine is 100% free and open-source under the MIT license.
Via Homebrew Cask:
brew install --cask universalsdk/dopamine/dopamine
Direct Download:
You can grab the notarized Dopamine.dmg directly from:
- 🌐 Website: dopamine.33rd.pro
- 🐙 GitHub: github.com/UniversalSDK/Dopamine
Open Source & Community
The entire codebase is open on GitHub. If you're a Mac developer, feel free to inspect the Swift power assertion and display controllers, leave feedback, or submit a PR!
Hope this helps anyone who noticed their closed MacBook heating up during overnight renders or compiles!
來源:DEV Community · dev.to