From 68f63858702015f8994b9c3413708e08ed4693e7 Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Tue, 11 Aug 2026 14:18:06 +0200 Subject: fix typo --- README.md | 4 +- Sources/bar/bar.docc/patches.md | 6 +- patches/bar-screen_hotplug-20260810-f6805c9.patch | 73 ---------------------- .../patch-screen_hotplug-20260810-f6805c9.patch | 73 ++++++++++++++++++++++ 4 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 patches/bar-screen_hotplug-20260810-f6805c9.patch create mode 100644 patches/patch-screen_hotplug-20260810-f6805c9.patch diff --git a/README.md b/README.md index ad23845..55fba16 100644 --- a/README.md +++ b/README.md @@ -174,12 +174,12 @@ Browse the available patches in the [patches directory](patches/). | Patch | Description | |---|---| | [font-offset](patches/bar-font_offset-20260810-11d813c.patch) | Adjust vertical text centering | -| [screen-hotplug](patches/bar-screen_hotplug-20260810-f6805c9.patch) | Auto-rebuild windows when displays are added/removed | +| [screen-hotplug](patches/patch-screen_hotplug-20260810-f6805c9.patch) | Auto-rebuild windows when displays are added/removed | To apply a patch: ```shell -curl -sL https://raw.githubusercontent.com/paninihouse/bar/refs/heads/master/patches/bar-screen_hotplug-20260810-f6805c9.patch | patch -p1 +curl -sL https://raw.githubusercontent.com/paninihouse/bar/refs/heads/master/patches/patch-screen_hotplug-20260810-f6805c9.patch | patch -p1 make install ``` diff --git a/Sources/bar/bar.docc/patches.md b/Sources/bar/bar.docc/patches.md index e2646f3..de0514a 100644 --- a/Sources/bar/bar.docc/patches.md +++ b/Sources/bar/bar.docc/patches.md @@ -18,7 +18,7 @@ The file contains a diff of the changes needed to add a specific feature. For example, to apply a patch from the *bar* collection: ```shell -curl -sL https://raw.githubusercontent.com/paninihouse/bar/refs/heads/master/patches/bar-font_offset-20260810-11d813c.patch | patch -p1 +curl -sL https://raw.githubusercontent.com/paninihouse/bar/refs/heads/master/patches/patch-font_offset-20260810-11d813c.patch | patch -p1 ``` After applying the patch, rebuild the program: @@ -63,13 +63,13 @@ This modular approach lets the community mix and match features without duplicat When publishing a patch, use a descriptive file name that follows the convention: ``` -bar---.patch +patch---.patch ``` For example: ``` -bar-font_offset-20260810-11d813c.patch +patch-font_offset-20260810-11d813c.patch ``` The date pinpoints which version of the code the patch was made against, and the commit hash makes it easy to look up the exact state of the repository at that point. diff --git a/patches/bar-screen_hotplug-20260810-f6805c9.patch b/patches/bar-screen_hotplug-20260810-f6805c9.patch deleted file mode 100644 index 1533b15..0000000 --- a/patches/bar-screen_hotplug-20260810-f6805c9.patch +++ /dev/null @@ -1,73 +0,0 @@ -diff --git a/Sources/bar/Models/AppDelegate.swift b/Sources/bar/Models/AppDelegate.swift -index cefdfc0..5db4946 100644 ---- a/Sources/bar/Models/AppDelegate.swift -+++ b/Sources/bar/Models/AppDelegate.swift -@@ -6,15 +6,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate { - private var windows: [BarWindow] = [] - private var blocks: [Block] = Config.blocks.map(\.resolved) - private var tokens: [UnsafeMutableRawPointer] = [] -+ private var screenObserver: NSObjectProtocol? - - 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) -- } -+ buildWindows() - - // Register a listener to hide the bar - tokens.append( -@@ -41,11 +36,24 @@ final class AppDelegate: NSObject, NSApplicationDelegate { - - // Start the block's auto refresh - for block in blocks { block.start() } -+ -+ // Observe screen changes — recreate windows when displays -+ // are added or removed. -+ screenObserver = NotificationCenter.default.addObserver( -+ forName: NSApplication.didChangeScreenParametersNotification, -+ object: nil, -+ queue: .main -+ ) { [weak self] _ in -+ self?.rebuildWindows() -+ } - } - - func applicationWillTerminate(_ notification: Notification) { - for block in blocks { block.stop() } - for token in tokens { Notifier.cancel(token) } -+ if let observer = screenObserver { -+ NotificationCenter.default.removeObserver(observer) -+ } - } - - /// Order out all bar windows -@@ -68,6 +76,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate { - } - } - -+ /// Create a bar window for each connected screen. -+ @MainActor private func buildWindows() { -+ 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) -+ } -+ } -+ -+ /// Remove all existing windows and create new ones for the current -+ /// set of screens — called when a display is connected or disconnected. -+ @MainActor private func rebuildWindows() { -+ for window in windows { window.orderOut(nil) } -+ windows.removeAll() -+ buildWindows() -+ } -+ - /// 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. diff --git a/patches/patch-screen_hotplug-20260810-f6805c9.patch b/patches/patch-screen_hotplug-20260810-f6805c9.patch new file mode 100644 index 0000000..1533b15 --- /dev/null +++ b/patches/patch-screen_hotplug-20260810-f6805c9.patch @@ -0,0 +1,73 @@ +diff --git a/Sources/bar/Models/AppDelegate.swift b/Sources/bar/Models/AppDelegate.swift +index cefdfc0..5db4946 100644 +--- a/Sources/bar/Models/AppDelegate.swift ++++ b/Sources/bar/Models/AppDelegate.swift +@@ -6,15 +6,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate { + private var windows: [BarWindow] = [] + private var blocks: [Block] = Config.blocks.map(\.resolved) + private var tokens: [UnsafeMutableRawPointer] = [] ++ private var screenObserver: NSObjectProtocol? + + 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) +- } ++ buildWindows() + + // Register a listener to hide the bar + tokens.append( +@@ -41,11 +36,24 @@ final class AppDelegate: NSObject, NSApplicationDelegate { + + // Start the block's auto refresh + for block in blocks { block.start() } ++ ++ // Observe screen changes — recreate windows when displays ++ // are added or removed. ++ screenObserver = NotificationCenter.default.addObserver( ++ forName: NSApplication.didChangeScreenParametersNotification, ++ object: nil, ++ queue: .main ++ ) { [weak self] _ in ++ self?.rebuildWindows() ++ } + } + + func applicationWillTerminate(_ notification: Notification) { + for block in blocks { block.stop() } + for token in tokens { Notifier.cancel(token) } ++ if let observer = screenObserver { ++ NotificationCenter.default.removeObserver(observer) ++ } + } + + /// Order out all bar windows +@@ -68,6 +76,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate { + } + } + ++ /// Create a bar window for each connected screen. ++ @MainActor private func buildWindows() { ++ 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) ++ } ++ } ++ ++ /// Remove all existing windows and create new ones for the current ++ /// set of screens — called when a display is connected or disconnected. ++ @MainActor private func rebuildWindows() { ++ for window in windows { window.orderOut(nil) } ++ windows.removeAll() ++ buildWindows() ++ } ++ + /// 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. -- cgit v1.2.3