diff --git a/Sources/phbar/Models/Config/PHConfig.swift b/Sources/phbar/Models/Config/PHConfig.swift index a11b0ce..4a6d7ab 100644 --- a/Sources/phbar/Models/Config/PHConfig.swift +++ b/Sources/phbar/Models/Config/PHConfig.swift @@ -1,3 +1,4 @@ struct PHConfig: Decodable { + let window: String let env: [String: String]? } diff --git a/Sources/phbar/Models/Config/config.toml b/Sources/phbar/Models/Config/config.toml index 29de895..1cdc149 100644 --- a/Sources/phbar/Models/Config/config.toml +++ b/Sources/phbar/Models/Config/config.toml @@ -1,3 +1,2 @@ +window = "top" height = 30 - -[window] diff --git a/Sources/phbar/Models/Theme/PHTheme.swift b/Sources/phbar/Models/Theme/PHTheme.swift index 7efecdd..493d62a 100644 --- a/Sources/phbar/Models/Theme/PHTheme.swift +++ b/Sources/phbar/Models/Theme/PHTheme.swift @@ -1,10 +1,10 @@ struct PHTheme: Decodable { - let window: PHThemeWindow + let windows: [PHThemeWindow]? let texts: [PHThemeText]? let styles: [PHThemeStyle]? private enum CodingKeys: String, CodingKey { - case window + case windows = "window" case texts = "text" case styles = "style" } diff --git a/Sources/phbar/Models/Theme/PHThemeWindow.swift b/Sources/phbar/Models/Theme/PHThemeWindow.swift index 80362e5..6420e38 100644 --- a/Sources/phbar/Models/Theme/PHThemeWindow.swift +++ b/Sources/phbar/Models/Theme/PHThemeWindow.swift @@ -1,9 +1,19 @@ struct PHThemeWindow: Decodable { - let hasShadow: Bool - let blur: Double + let name: String + var hasShadow: Bool? = false + var blur: Double? = 0 private enum CodingKeys: String, CodingKey { + case name case hasShadow = "shadow" case blur } + + static let `default`: Self = { + PHThemeWindow( + name: "_default", + hasShadow: false, + blur: 0.0 + ) + }() } diff --git a/Sources/phbar/Models/Theme/theme.toml b/Sources/phbar/Models/Theme/theme.toml index 7430c03..4dd975b 100644 --- a/Sources/phbar/Models/Theme/theme.toml +++ b/Sources/phbar/Models/Theme/theme.toml @@ -2,7 +2,13 @@ # # Place at ~/.config/phbar/themes/voltage.toml -[window] +[[window]] +name = "default" +shadow = false +blur = 0.0 + +[[window]] +name = "bottom" shadow = false blur = 0.0 diff --git a/Sources/phbar/Views/BackgroundView.swift b/Sources/phbar/Views/BackgroundView.swift index 6fc5e82..3b328e0 100644 --- a/Sources/phbar/Views/BackgroundView.swift +++ b/Sources/phbar/Views/BackgroundView.swift @@ -1,17 +1,17 @@ import AppKit final class BackgroundView: NSView { - var hasShadow: Bool { + var hasShadow: Bool? = false { didSet { configureShadow() } } - var blur: CGFloat { + var blur: CGFloat? = 0 { didSet { configureBlur() } } init(controller: BarController) { - self.hasShadow = controller.theme.window.hasShadow - self.blur = controller.theme.window.blur + if let hasShadow = controller.window.hasShadow { self.hasShadow = hasShadow } + if let blur = controller.window.blur { self.blur = blur } super.init(frame: .zero) setup() } @@ -36,12 +36,12 @@ final class BackgroundView: NSView { } private func configureShadow() { - guard let window else { return } + guard let window, let hasShadow else { return } window.hasShadow = hasShadow } private func configureBlur() { - guard let window else { return } + guard let window, let blur else { return } // Window must be non-opaque for the desktop/other windows behind it // to be visible at all, let alone blurred. window.isOpaque = false diff --git a/Sources/phbar/Views/BarController.swift b/Sources/phbar/Views/BarController.swift index 5e1acc7..25b6ff5 100644 --- a/Sources/phbar/Views/BarController.swift +++ b/Sources/phbar/Views/BarController.swift @@ -5,6 +5,7 @@ final class BarController: ObservableObject { let config: PHConfig let screen: NSScreen let theme: PHTheme + let window: PHThemeWindow @Published var blocks: [PHBlock] var arrangedBlocks: [PHBlock] { @@ -19,6 +20,7 @@ final class BarController: ObservableObject { self.config = config self.screen = screen self.theme = theme + self.window = Self.window(for: config, from: theme) self.blocks = blocks for block in blocks { @@ -32,6 +34,16 @@ final class BarController: ObservableObject { // Theming extension BarController { + static func window(for config: PHConfig, from theme: PHTheme) -> PHThemeWindow { + guard let window = theme.windows?.first(where: { $0.name == config.window }) else { + guard let defaultWindow = theme.windows?.first(where: { $0.name == "default" }) else { + return PHThemeWindow.default + } + return defaultWindow + } + return window + } + func text(for block: PHBlock) -> PHThemeText { guard let text = theme.texts?.first(where: { $0.name == block.textName }) else { guard let defaultText = theme.texts?.first(where: { $0.name == "default" }) else {