From 10fed47a34ace6f5fc4c9afe7144f68d1985d8fa Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Tue, 11 Aug 2026 12:15:57 +0200 Subject: move files to the correct folder --- Sources/bar/Models/AppDelegate.swift | 82 ------------------------------------ Sources/bar/Models/Screen.swift | 34 --------------- Sources/bar/Views/AppDelegate.swift | 82 ++++++++++++++++++++++++++++++++++++ Sources/bar/Views/Screen.swift | 34 +++++++++++++++ 4 files changed, 116 insertions(+), 116 deletions(-) delete mode 100644 Sources/bar/Models/AppDelegate.swift delete mode 100644 Sources/bar/Models/Screen.swift create mode 100644 Sources/bar/Views/AppDelegate.swift create mode 100644 Sources/bar/Views/Screen.swift (limited to 'Sources') diff --git a/Sources/bar/Models/AppDelegate.swift b/Sources/bar/Models/AppDelegate.swift deleted file mode 100644 index cefdfc0..0000000 --- a/Sources/bar/Models/AppDelegate.swift +++ /dev/null @@ -1,82 +0,0 @@ -import AppKit -import SwiftUI - -@MainActor -final class AppDelegate: NSObject, NSApplicationDelegate { - private var windows: [BarWindow] = [] - private var blocks: [Block] = Config.blocks.map(\.resolved) - private var tokens: [UnsafeMutableRawPointer] = [] - - func applicationDidFinishLaunching(_ notification: Notification) { - for screen in NSScreen.screens { - let frame = Screen.barFrame(screen, position: Config.position, height: Config.height) - let window = BarWindow(contentRect: frame) - window.contentView = NSHostingView(rootView: BarView(blocks: blocks)) - window.orderFrontRegardless() - windows.append(window) - } - - // Register a listener to hide the bar - tokens.append( - Notifier.register("bar.hide") { [weak self] in - self?.hide() - } - ) - - // Register a listener to show the bar - tokens.append( - Notifier.register("bar.show") { [weak self] in - self?.show() - } - ) - - // Register one listener per unique name; a single post fans out to every - // block with that name (see Notifier). - for name in Set(blocks.map(\.name)) { - let token = Notifier.register("bar.touch.\(name)") { [weak self] in - self?.handleRefresh(name) - } - tokens.append(token) - } - - // Start the block's auto refresh - for block in blocks { block.start() } - } - - func applicationWillTerminate(_ notification: Notification) { - for block in blocks { block.stop() } - for token in tokens { Notifier.cancel(token) } - } - - /// Order out all bar windows - nonisolated private func hide() { - Task { @MainActor [weak self] in - guard let self else { return } - for window in self.windows { - window.orderOut(nil) - } - } - } - - /// Order front all bar windows - nonisolated private func show() { - Task { @MainActor [weak self] in - guard let self else { return } - for window in self.windows { - window.orderFrontRegardless() - } - } - } - - /// Called from a Darwin notification handler. Marked `nonisolated` because - /// libnotify's delivery contract isn't statically visible to Swift, so we - /// hop back to the main actor explicitly. - nonisolated func handleRefresh(_ name: String) { - Task { @MainActor [weak self] in - guard let self else { return } - for block in self.blocks where block.name == name { - block.runScript() - } - } - } -} diff --git a/Sources/bar/Models/Screen.swift b/Sources/bar/Models/Screen.swift deleted file mode 100644 index 8029db4..0000000 --- a/Sources/bar/Models/Screen.swift +++ /dev/null @@ -1,34 +0,0 @@ -import AppKit -import Foundation - -enum Screen { - /// Frame of the bar within a screen, in global display coordinates. - /// - /// - Parameters: - /// - screen: The screen to calculate the bar frame for. - /// - position: Whether the bar sits at the top or bottom - /// of the screen. - /// - height: The bar height in points (see ``Config/height``). - /// - /// - Returns: An NSRect in screen coordinates. The bar spans - /// the full width of the screen and is anchored at the top - /// or bottom edge. - static func barFrame(_ screen: NSScreen, position: Config.Position, height: CGFloat) -> NSRect { - switch position { - case .top: - return NSRect( - x: screen.frame.minX, - y: screen.frame.maxY - height, - width: screen.frame.width, - height: height - ) - case .bottom: - return NSRect( - x: screen.frame.minX, - y: screen.frame.minY, - width: screen.frame.width, - height: height - ) - } - } -} diff --git a/Sources/bar/Views/AppDelegate.swift b/Sources/bar/Views/AppDelegate.swift new file mode 100644 index 0000000..cefdfc0 --- /dev/null +++ b/Sources/bar/Views/AppDelegate.swift @@ -0,0 +1,82 @@ +import AppKit +import SwiftUI + +@MainActor +final class AppDelegate: NSObject, NSApplicationDelegate { + private var windows: [BarWindow] = [] + private var blocks: [Block] = Config.blocks.map(\.resolved) + private var tokens: [UnsafeMutableRawPointer] = [] + + func applicationDidFinishLaunching(_ notification: Notification) { + for screen in NSScreen.screens { + let frame = Screen.barFrame(screen, position: Config.position, height: Config.height) + let window = BarWindow(contentRect: frame) + window.contentView = NSHostingView(rootView: BarView(blocks: blocks)) + window.orderFrontRegardless() + windows.append(window) + } + + // Register a listener to hide the bar + tokens.append( + Notifier.register("bar.hide") { [weak self] in + self?.hide() + } + ) + + // Register a listener to show the bar + tokens.append( + Notifier.register("bar.show") { [weak self] in + self?.show() + } + ) + + // Register one listener per unique name; a single post fans out to every + // block with that name (see Notifier). + for name in Set(blocks.map(\.name)) { + let token = Notifier.register("bar.touch.\(name)") { [weak self] in + self?.handleRefresh(name) + } + tokens.append(token) + } + + // Start the block's auto refresh + for block in blocks { block.start() } + } + + func applicationWillTerminate(_ notification: Notification) { + for block in blocks { block.stop() } + for token in tokens { Notifier.cancel(token) } + } + + /// Order out all bar windows + nonisolated private func hide() { + Task { @MainActor [weak self] in + guard let self else { return } + for window in self.windows { + window.orderOut(nil) + } + } + } + + /// Order front all bar windows + nonisolated private func show() { + Task { @MainActor [weak self] in + guard let self else { return } + for window in self.windows { + window.orderFrontRegardless() + } + } + } + + /// Called from a Darwin notification handler. Marked `nonisolated` because + /// libnotify's delivery contract isn't statically visible to Swift, so we + /// hop back to the main actor explicitly. + nonisolated func handleRefresh(_ name: String) { + Task { @MainActor [weak self] in + guard let self else { return } + for block in self.blocks where block.name == name { + block.runScript() + } + } + } +} diff --git a/Sources/bar/Views/Screen.swift b/Sources/bar/Views/Screen.swift new file mode 100644 index 0000000..8029db4 --- /dev/null +++ b/Sources/bar/Views/Screen.swift @@ -0,0 +1,34 @@ +import AppKit +import Foundation + +enum Screen { + /// Frame of the bar within a screen, in global display coordinates. + /// + /// - Parameters: + /// - screen: The screen to calculate the bar frame for. + /// - position: Whether the bar sits at the top or bottom + /// of the screen. + /// - height: The bar height in points (see ``Config/height``). + /// + /// - Returns: An NSRect in screen coordinates. The bar spans + /// the full width of the screen and is anchored at the top + /// or bottom edge. + static func barFrame(_ screen: NSScreen, position: Config.Position, height: CGFloat) -> NSRect { + switch position { + case .top: + return NSRect( + x: screen.frame.minX, + y: screen.frame.maxY - height, + width: screen.frame.width, + height: height + ) + case .bottom: + return NSRect( + x: screen.frame.minX, + y: screen.frame.minY, + width: screen.frame.width, + height: height + ) + } + } +} -- cgit v1.2.3