Refine settings/about titlebar styling and controls alignment

This commit is contained in:
Lawrence Chen 2026-02-14 02:11:35 -08:00
parent 50f0dd334d
commit f8785f64b7
2 changed files with 926 additions and 137 deletions

View file

@ -3,6 +3,7 @@ import AppKit
final class WindowDecorationsController {
private var observers: [NSObjectProtocol] = []
private var didStart = false
private var trafficLightBaseFrames: [ObjectIdentifier: [NSWindow.ButtonType: NSRect]] = [:]
func start() {
guard !didStart else { return }
@ -14,6 +15,7 @@ final class WindowDecorationsController {
func apply(to window: NSWindow) {
let shouldHideButtons = shouldHideTrafficLights(for: window)
hideStandardButtons(on: window, hidden: shouldHideButtons)
applyTrafficLightOffset(on: window, hidden: shouldHideButtons)
}
private func installObservers() {
@ -38,6 +40,40 @@ final class WindowDecorationsController {
window.standardWindowButton(.zoomButton)?.isHidden = hidden
}
private func applyTrafficLightOffset(on window: NSWindow, hidden: Bool) {
DispatchQueue.main.async { [weak self, weak window] in
guard let self, let window else { return }
let offset = hidden ? NSPoint.zero : self.trafficLightOffset(for: window)
self.applyTrafficLightOffsetNow(on: window, offset: offset)
}
}
private func applyTrafficLightOffsetNow(on window: NSWindow, offset: NSPoint) {
let key = ObjectIdentifier(window)
let buttonTypes: [NSWindow.ButtonType] = [.closeButton, .miniaturizeButton, .zoomButton]
var baseFrames = trafficLightBaseFrames[key] ?? [:]
for type in buttonTypes {
guard let button = window.standardWindowButton(type) else { continue }
if baseFrames[type] == nil || (baseFrames[type]?.isEmpty ?? true) {
baseFrames[type] = button.frame
}
}
trafficLightBaseFrames[key] = baseFrames
for type in buttonTypes {
guard let button = window.standardWindowButton(type), let base = baseFrames[type] else { continue }
button.setFrameOrigin(NSPoint(x: base.origin.x + offset.x, y: base.origin.y + offset.y))
}
}
private func trafficLightOffset(for window: NSWindow) -> NSPoint {
guard window.identifier?.rawValue == "cmux.settings" else { return .zero }
// Nudge controls slightly right/down to align with the custom Settings title row.
return NSPoint(x: 7, y: -4)
}
private func shouldHideTrafficLights(for window: NSWindow) -> Bool {
if window.isSheet {
return true

File diff suppressed because it is too large Load diff