### Complete Integration Example: Custom Window Background in Swift Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Demonstrates a full integration of custom window background components. This example shows manual window creation, view hierarchy assembly, and programmatic adjustment of background styles and colors using `WindowBackgroundSettings` and SwiftUI `Color`. ```swift import Cocoa import SwiftUI // 1. Define or reuse WindowBackgroundSettings let settings = WindowBackgroundSettings.shared // 2. Configure window with custom background let window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 640, height: 640), styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false ) window.backgroundColor = .clear window.hasShadow = true window.center() // 3. Create background view let backgroundVC = BackgroundViewController() let backgroundView = backgroundVC.view backgroundView.frame = window.contentView!.bounds backgroundView.autoresizingMask = [.width, .height] // 4. Create main content view let mainVC = MainViewController() let mainView = mainVC.view mainView.frame = window.contentView!.bounds mainView.autoresizingMask = [.width, .height] // 5. Assemble layered hierarchy window.contentView?.addSubview(backgroundView, positioned: .below, relativeTo: nil) window.contentView?.addSubview(mainView) // 6. Show window window.makeKeyAndOrderFront(nil) // 7. Change background programmatically settings.windowBackgroundStyle = .regularGlass settings.usingTintColor = true settings.glassTintColor = Color.purple.opacity(0.3) ``` -------------------------------- ### MainWindowController: Setup and Configure Window in Swift Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Manages the window's visual hierarchy, including setting window dimensions, background, shadow, and positioning. It also handles the setup and layering of background and main content view controllers. ```swift import Cocoa class MainWindowController: NSWindowController { var backgroundViewController: BackgroundViewController? var mainViewController: MainViewController? override func windowDidLoad() { super.windowDidLoad() configureWindow() setupBackgroundViewController() } private func configureWindow() { guard let window = window else { return } window.setContentSize(NSSize(width: 640, height: 640)) window.minSize = NSSize(width: 240, height: 240) window.center() window.backgroundColor = .clear window.hasShadow = true window.makeKeyAndOrderFront(nil) } private func setupBackgroundViewController() { backgroundViewController = BackgroundViewController() mainViewController = MainViewController() guard let contentView = window?.contentView else { return } guard let backgroundView = backgroundViewController?.view else { return } guard let mainView = mainViewController?.view else { return } backgroundView.frame = contentView.bounds mainView.frame = contentView.bounds backgroundView.autoresizingMask = [.width, .height] mainView.autoresizingMask = [.width, .height] contentView.addSubview(backgroundView, positioned: .below, relativeTo: nil) contentView.addSubview(mainView) } } // Usage example let windowController = MainWindowController() windowController.showWindow(nil) ``` -------------------------------- ### AppDelegate: Application Entry Point and Lifecycle in Swift Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Serves as the main entry point for the macOS application. It initializes the `MainWindowController` upon successful launch and manages application lifecycle events, including termination and secure state restoration. ```swift import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate { var mainWindowController: MainWindowController? func applicationDidFinishLaunching(_ notification: Notification) { mainWindowController = MainWindowController() mainWindowController?.showWindow(self) } func applicationShouldTerminateAfterLastWindowClosed(_ app: NSApplication) -> Bool { return true } func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { return false } } // Application is launched via @main attribute // No manual instantiation required ``` -------------------------------- ### Create SwiftUI control interface Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Implements a SwiftUI view with interactive controls for selecting background styles and configuring tint colors. Requires SwiftUI framework. Uses @ObservedObject for shared settings and includes Picker, Toggle, and ColorPicker controls. Depends on WindowBackgroundSettings and WindowBackgroundStyle implementations. ```swift import SwiftUI struct MainView: View { @ObservedObject private var settings = WindowBackgroundSettings.shared var body: some View { VStack { Text("Custom Window Background Demo") .font(.largeTitle) Form { Picker("Select Style", selection: $settings.windowBackgroundStyle) { ForEach(WindowBackgroundStyle.allCases, id: \.self) { option in Text(option.rawValue).tag(option) } } .pickerStyle(.menu) Toggle("Use Tint Color for Liquid Glass", isOn: $settings.usingTintColor) .toggleStyle(.switch) if settings.usingTintColor { ColorPicker("Tint Color", selection: $settings.glassTintColor) } } } } } // Usage example import Cocoa let hostingView = NSHostingView(rootView: MainView()) hostingView.frame = NSRect(x: 0, y: 0, width: 400, height: 300) ``` -------------------------------- ### Manage Window Background Settings (Swift) Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt This code defines a singleton class `WindowBackgroundSettings` that manages global window background configuration using Combine publishers. It allows reactive updates to the window background style, tint color, and whether to use a tint color. ```swift import Foundation import Combine import SwiftUI class WindowBackgroundSettings: ObservableObject { @Published var windowBackgroundStyle: WindowBackgroundStyle = .regularGlass @Published var usingTintColor: Bool = false @Published var glassTintColor: Color = .clear static let shared = WindowBackgroundSettings() private init() {} } // Usage example let settings = WindowBackgroundSettings.shared settings.windowBackgroundStyle = .clearGlass settings.usingTintColor = true settings.glassTintColor = Color.blue.opacity(0.5) ``` -------------------------------- ### Host SwiftUI interface in NSViewController Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Implements an AppKit view controller that hosts a SwiftUI interface within an NSWindow. Requires Cocoa and SwiftUI frameworks. Uses NSHostingView to embed the SwiftUI view. Provides integration between AppKit and SwiftUI components. ```swift import Cocoa import SwiftUI class MainViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() self.view = NSHostingView(rootView: MainView()) } } // Usage example let mainVC = MainViewController() window.contentViewController = mainVC ``` -------------------------------- ### Apply custom tint to glass effect Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Creates a glass effect with custom tint color for branded window backgrounds. Requires Cocoa and SwiftUI frameworks. Supports both Color and RGB initialization for tint colors. Depends on NSGlassEffectView implementation. ```swift import Cocoa import SwiftUI let view = NSGlassEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.cornerRadius = 16 view.style = .regular view.tintColor = NSColor(Color.blue.opacity(0.3)) view.autoresizingMask = [.width, .height] // Alternative with RGB values view.tintColor = NSColor(red: 0.2, green: 0.5, blue: 0.8, alpha: 0.4) // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Dynamic Background View Controller (Swift) Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Manages window background views with reactive updates. Observes settings changes and creates appropriate NSView subclasses for different visual styles. Requires Cocoa, SwiftUI, and Combine frameworks. ```swift import Cocoa import SwiftUI import Combine class BackgroundViewController: NSViewController { private var containerView: NSView! private var currentBackgroundView: NSView? private var cancellables = Set() private let settings = WindowBackgroundSettings.shared override func viewDidLoad() { super.viewDidLoad() containerView = NSView() containerView.autoresizingMask = [.width, .height] self.view = containerView updateCurrentView() setupObservers() } private func setupObservers() { Publishers.CombineLatest3( settings.$windowBackgroundStyle, settings.$usingTintColor, settings.$glassTintColor ) .sink { [weak self] style, usingTintColor, tintColor in self?.updateCurrentView(style: style, usingTintColor: usingTintColor, tintColor: tintColor) } .store(in: &cancellables) } func createView( for style: WindowBackgroundStyle, usingTintColor: Bool = false, tintColor: Color = .clear ) -> NSView { switch style { case .regularGlass: let view = NSGlassEffectView() view.cornerRadius = 16 view.style = .regular if usingTintColor { view.tintColor = NSColor(tintColor) } return view case .clearGlass: let view = NSGlassEffectView() view.cornerRadius = 16 view.style = .clear if usingTintColor { view.tintColor = NSColor(tintColor) } return view case .hudWindow: let view = NSVisualEffectView() view.material = .hudWindow view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view case .popover: let view = NSVisualEffectView() view.material = .popover view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view case .menu: let view = NSVisualEffectView() view.material = .menu view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view case .windowBackground: let view = NSVisualEffectView() view.material = .windowBackground view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view case .underWindowBackground: let view = NSVisualEffectView() view.material = .underWindowBackground view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view case .sidebar: let view = NSVisualEffectView() view.material = .sidebar view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view case .titlebar: let view = NSVisualEffectView() view.material = .titlebar view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true return view } } func replaceView(with newView: NSView) { currentBackgroundView?.removeFromSuperview() newView.frame = containerView.bounds newView.autoresizingMask = [.width, .height] containerView.addSubview(newView) currentBackgroundView = newView } func updateCurrentView(style: WindowBackgroundStyle, usingTintColor: Bool, tintColor: Color) { let newView = createView(for: style, usingTintColor: usingTintColor, tintColor: tintColor) replaceView(with: newView) } } ``` -------------------------------- ### Create menu material background Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Implements a menu-style background with appropriate blur and vibrancy for context menus. Requires Cocoa framework. Uses NSVisualEffectView with menu material and behindWindow blending mode. Designed for menu and contextual UI elements. ```swift import Cocoa let view = NSVisualEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.material = .menu view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Create popover material background Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Creates a popover-style background suitable for floating panels and tooltips. Requires Cocoa framework. Uses NSVisualEffectView with popover material and behindWindow blending mode. Provides appropriate blur and vibrancy for floating UI elements. ```swift import Cocoa let view = NSVisualEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.material = .popover view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Create clear glass effect with NSGlassEffectView Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Implements a transparent glass effect view without blur using NSGlassEffectView. Requires Cocoa framework. The view supports corner radius customization and autoresizing. No external dependencies required. ```swift import Cocoa let view = NSGlassEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.cornerRadius = 16 view.style = .clear view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Create Menu Background in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates a menu background effect using NSVisualEffectView with specific material and blending mode. ```swift let view = NSVisualEffectView() view.material = .menu view.blendingMode = .behindWindow view.state = .active ``` -------------------------------- ### Create Under Window Background in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates an under-window background effect using NSVisualEffectView with specific material and blending mode. ```swift let view = NSVisualEffectView() view.material = .underWindowBackground view.blendingMode = .behindWindow view.state = .active ``` -------------------------------- ### Create sidebar material background Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Creates a sidebar-style background for navigation panels and sidebars. Requires Cocoa framework. Uses NSVisualEffectView with sidebar material and behindWindow blending mode. Provides appropriate visual styling for sidebar UI components. ```swift import Cocoa let view = NSVisualEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.material = .sidebar view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Create HUD window material background Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Implements a high-contrast heads-up display style background with blur effect. Requires Cocoa framework. Uses NSVisualEffectView with hudWindow material and behindWindow blending mode. Suitable for overlay interfaces. ```swift import Cocoa let view = NSVisualEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.material = .hudWindow view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Create titlebar material background Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Implements a titlebar-style background matching the system window titlebar appearance. Requires Cocoa framework. Uses NSVisualEffectView with titlebar material and behindWindow blending mode. Provides native macOS titlebar visual consistency. ```swift import Cocoa let view = NSVisualEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.material = .titlebar view.blendingMode = .behindWindow view.state = .active view.wantsLayer = true view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Glass Effect View Configuration (Swift) Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt Creates a liquid glass effect view with configurable corner radius and style. Requires macOS 26+ for NSGlassEffectView. Can be added to any window content view. ```swift import Cocoa let view = NSGlassEffectView() view.frame = NSRect(x: 0, y: 0, width: 400, height: 300) view.cornerRadius = 16 view.style = .regular view.autoresizingMask = [.width, .height] // Add to window window.contentView?.addSubview(view) ``` -------------------------------- ### Create HUD Window Background in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates a HUD window background effect using NSVisualEffectView with specific material and blending mode. ```swift let view = NSVisualEffectView() view.material = .hudWindow view.blendingMode = .behindWindow view.state = .active ``` -------------------------------- ### Create Popover Background in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates a popover background effect using NSVisualEffectView with specific material and blending mode. ```swift let view = NSVisualEffectView() view.material = .popover view.blendingMode = .behindWindow view.state = .active ``` -------------------------------- ### Define Window Background Style Enumeration (Swift) Source: https://context7.com/aaron-212/customwindowbackgrounddemo/llms.txt This code defines an enumeration `WindowBackgroundStyle` that lists the available background styles supported by the demo application. It implements `CaseIterable` to allow iteration over all styles and uses a `switch` statement to control behavior. It uses a String conversion for each case. ```swift import Combine import Foundation enum WindowBackgroundStyle: String, CaseIterable { case regularGlass case clearGlass case hudWindow case popover case menu case windowBackground case underWindowBackground case sidebar case titlebar } // Usage example - iterate through all styles for style in WindowBackgroundStyle.allCases { print("Available style: (style.rawValue)") } // Usage example - create picker options let selectedStyle: WindowBackgroundStyle = .regularGlass switch selectedStyle { case .regularGlass, .clearGlass: print("Liquid glass style selected") default: print("Visual effect style selected") } ``` -------------------------------- ### Apply Tint Color to Glass Effect in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Applies a custom tint color to a glass effect view using NSGlassEffectView. Requires macOS 26.0. ```swift let view = NSGlassEffectView() view.cornerRadius = 16 view.style = .regular view.tintColor = NSColor(tintColor) ``` -------------------------------- ### Create Clear Glass Effect in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates a transparent glass effect without blur using NSGlassEffectView. Requires macOS 26.0. ```swift let view = NSGlassEffectView() view.cornerRadius = 16 view.style = .clear ``` -------------------------------- ### Create Titlebar Background in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates a titlebar background effect using NSVisualEffectView with specific material and blending mode. ```swift let view = NSVisualEffectView() view.material = .titlebar view.blendingMode = .behindWindow view.state = .active ``` -------------------------------- ### Create Regular Glass Effect in Swift Source: https://github.com/aaron-212/customwindowbackgrounddemo/blob/main/README.md Creates a frosted glass effect with slight background blur and edge distortion using NSGlassEffectView. Requires macOS 26.0. ```swift let view = NSGlassEffectView() view.cornerRadius = 16 view.style = .regular ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.