You are an expert macOS systems and graphics engineer specializing in Rust, Swift/Cocoa, CoreGraphics, and tiling window managers.
Build a standalone, minimal, ultra-performant, and battery-friendly desktop status bar for macOS (Apple Silicon native) inspired by Linux's polybar. It must integrate deeply and reactively with the aerospace tiling window manager without polling bottlenecks or Electron/web-view bloat.
- Language / Stack: Rust (using
objc2/cocoa-rs/metal-rsorwinit) OR pure Swift/AppKit (rawNSPanel/NSWindow+CoreGraphics/Metal). Do NOT use SwiftUI or Web/Electron frameworks. - CPU & Memory Budget: Target idle CPU < 0.2%, memory usage < 30 MB RSS.
- Rendering: Direct 2D rendering via CoreGraphics or lightweight Metal pipeline. No heavy layout engines.
- Window Level & Layering:
- Create a borderless, non-activating floating panel using
NSPanel(styleMask: [.nonactivatingPanel, .borderless]). - Window level must be set above standard applications but below system alert overlays (
level = .floatingor.dock/.mainMenu). - Screen space reservation: Calculate display bounds excluding the menu bar and dock, or configure it to sit cleanly at the top or bottom of the screen.
- Exclude from macOS Mission Control and window lists (
collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle, .fullScreenAuxiliary]). - Multi-monitor support: Span across or spawn independent instances per active
NSScreen.
- Create a borderless, non-activating floating panel using
- Zero-Latency Event-Driven Updates:
- Do NOT poll
aerospace list-workspacesin a tight loop. - Implement a Unix domain socket server / listener or a dedicated CLI event subscriber (e.g., parsing
aerospace list-workspaces --focusedor listening toexec-on-workspace-changecallbacks registered inaerospace.toml). - Alternatively, monitor AeroSpace IPC via its CLI output stream or IPC socket if available.
- Do NOT poll
- Workspace Module:
- Distinct visual states:
active,visible-inactive,occupied,empty, andurgent. - Clickable workspace pills: Clicking a workspace pill should execute
aerospace workspace <name>. - Focused window title module: Display current focused window app name and title, updating on window focus change.
- Distinct visual states:
The application must parse a configuration file located at ~/.config/monobar/config.toml (or standard XDG paths).
- Bar Settings:
monitor,width,height,offset_x,offset_side,offset_y/offset_top,float,radius_top_left,radius_top_right,radius_bottom_right,radius_bottom_left,padding,module_margin- Colors: HEX/RGBA format for
background,foreground,border,accent - Fonts: Support primary text font + fallback glyph/symbol font (e.g., Nerd Fonts, SF Pro, FontAwesome) with baseline alignment.
- Layout Definition:
modules-left = ["workspaces", "title"]modules-center = ["music"]modules-right = ["cpu", "ram", "battery", "volume", "mic", "wifi", "bluetooth", "weather", "clock"]
Implement standard status bar modules with minimal syscall overhead:
- Workspaces (AeroSpace): Live workspace buttons with click handlers.
- Window Title: Active window/app name.
- Battery: Native reading via
IOPSCopyPowerSourcesInfo/IOPSGetPowerSourceDescription(register for I/O Kit sleep/wake/power state notifications instead of polling). - Clock / Date: High-efficiency timer scheduled on
RunLoopsynchronized to the top of each minute or second. - System Stats (CPU & RAM): Host statistics via
mach/host_info.h(HOST_VM_INFO64,host_cpu_load_info) polling at configurable intervals (e.g., 2–5s). - Weather: Current local conditions and temperature through a configurable provider.
- Audio: Output and microphone volume percentages, adjustable with vertical scrolling over each module.
- Custom Script Module (
custom/script):- Support
exec = "sh script.sh",interval = N,tail = bool(stream output line-by-line),click-left = "command".
- Support
Please structure the codebase cleanly:
src/main: App initialization,NSApplicationrunloop setup, panel spawning on screen bounds.src/bar/window: Native window/panel configuration, layer setup, mouse event handling (hit-testing modules).src/config: Parser and type definitions for bar layout, dimensions, colors, and typography.src/modules/:- Trait / Protocol
Module(render(&self, ctx),update(&mut self),handle_click(&self, button)). - Implementation of
workspaceswith AeroSpace IPC.
- Trait / Protocol
MakefileorCargo.toml/ Xcode project: Build script for instant compiling and binary output.- Sample Configuration: A complete
aerospace.tomlsnippet showing required hooks, plus an initialconfig.tomlthat looks clean and modern.
Please start by outputting the project structure and drafting the core window/panel initialization and AeroSpace IPC bridge.