class ObservableWindowDelegate : NSObject, NSWindowDelegate, ObservableObject {
/// A Boolean value that indicates whether the window is the key window for the application.
var isKeyWindow: Bool { get }
init(_ isKeyWindow: Bool = false)
func windowDidBecomeKey(_ notification: Notification)
func windowDidResignKey(_ notification: Notification)
}
TitlebarDimensions
An object containing constant titlebar dimensions.
struct TitlebarDimensions {
/// An object containing constant titlebar heights.
struct height {
/// The height of a statusbar without toolbar.
static let withoutToolbar: CGFloat
/// The height of a statusbar with toolbar.
static let withToolbar: CGFloat
}
/// An object containing constant titlebar paddings.
struct padding {
/// An object containing constant titlebar left paddings.
struct left {
/// The left padding of a titlebar without toolbar.
static let withoutToolbar: CGFloat
/// The left padding of a titlebar with toolbar.
static let withToolbar: CGFloat
}
}
}
CustomTitlebar

Create custom titlebars for your SwiftUI applications.
Requirements
Installation
Add
https://github.com/JochenBe/CustomTitlebar
in the Swift Package Manager.Usage
CustomTitlebar uses an observable version of NSWindowDelegate called ObservableWindowDelegate to lower the opacity of the titlebar when the window resigns key. This ObservableWindowDelegate is passed down using environment objects. If you do not wish to use this feature, pass
ignoreIsKeyWindow: true
to your CustomTitlebar instance.Initiating and passing down the ObservableWindowDelegate:
Using the CustomTitlebar:
For more information about the parameters, check the CustomTitlebar reference.
Reference
CustomTitlebar
A SwiftUI View aligning your custom titlebar and window content.
Parameters
titlebar
: The contents of the titlebar.withToolbar
: Whether the titlebar contains a toolbar. This will result in a taller titlebar.hideDivider
: Whether the divider between the titlebar and the window content should be hidden.ignoreIsKeyWindow
: WhetherisKeyWindow
should be ignored. Setting this totrue
allows you to not pass an ObservableWindowDelegate.content
: The contents of the window.ObservableWindowDelegate
An observable version of NSWindowDelegate.
Parameters
isKeyWindow
: The initial value ofisKeyWindow
.TitlebarDimensions
An object containing constant titlebar dimensions.