diff --git a/README.md b/README.md index 44cc9c6..cd8a811 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,10 @@ If you do not provide the wallpaper path the currently set wallpaper will be used. +#### Multiple displays + +If you use multiple displays and want the wallpaper generated for all of them, add the `--all-displays` flag at the end of the command, so for example `./ChangeMenuBarColor Gradient "#FF0000" "#00FF00" --all-displays`. + ## Known issues Dynamic wallpapers are not supported at the moment. If you use a dynamic wallpaper the utility will not be able to use it and will fail. diff --git a/Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift b/Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift index d45a18e..cafbf80 100644 --- a/Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift +++ b/Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift @@ -13,25 +13,33 @@ import SwiftHEXColors class Command { func createWallpaper(screen: NSScreen) -> NSImage? { - return nil + fatalError("Override for each type") + } + + var useAllDisplays: Bool { + fatalError("Override for each type") } func run() { - Log.info("Starting up") + Log.info("Starting up\n") - guard let screen = NSScreen.main else { - Log.error("Could not find the main screen") - return - } + let screens: [NSScreen] = useAllDisplays ? NSScreen.screens : [NSScreen.main].compactMap({ $0 }) - guard let adjustedWallpaper = createWallpaper(screen: screen), let data = adjustedWallpaper.jpgData else { - Log.error("Could not generate new wallpaper fr the main screen") + guard !screens.isEmpty else { + Log.error("Could not detect any screens") return } - setWallpaper(screen: screen, wallpaper: data) + for (index, screen) in screens.enumerated() { + guard let adjustedWallpaper = createWallpaper(screen: screen), let data = adjustedWallpaper.jpgData else { + Log.error("Could not generate new wallpaper screen \(index)") + continue + } + + setWallpaper(screen: screen, wallpaper: data) + } - Log.info("All done!") + Log.info("\nAll done!") } func loadWallpaperImage(wallpaper: String?, screen: NSScreen) -> NSImage? { diff --git a/Sources/ChangeMenuBarColor/Commands/Gradient.swift b/Sources/ChangeMenuBarColor/Commands/Gradient.swift index b074432..2922eba 100644 --- a/Sources/ChangeMenuBarColor/Commands/Gradient.swift +++ b/Sources/ChangeMenuBarColor/Commands/Gradient.swift @@ -24,6 +24,13 @@ final class Gradient: Command, ParsableCommand { @Argument(help: "Wallpaper to use. If not provided the current macOS wallpaper will be used") private var wallpaper: String? + @Flag(help: "Flag to set wallpaper for all displays not just the main display") + private var allDisplays: Bool = false + + override var useAllDisplays: Bool { + return allDisplays + } + override func createWallpaper(screen: NSScreen) -> NSImage? { guard let wallpaper = loadWallpaperImage(wallpaper: wallpaper, screen: screen) else { return nil diff --git a/Sources/ChangeMenuBarColor/Commands/SolidColor.swift b/Sources/ChangeMenuBarColor/Commands/SolidColor.swift index a9f1530..141bbe7 100644 --- a/Sources/ChangeMenuBarColor/Commands/SolidColor.swift +++ b/Sources/ChangeMenuBarColor/Commands/SolidColor.swift @@ -22,6 +22,13 @@ final class SolidColor: Command, ParsableCommand { @Argument(help: "Wallpaper to use. If not provided the current macOS wallpaper will be used") private var wallpaper: String? + @Flag(help: "Flag to set wallpaper for all displays not just the main display") + private var allDisplays: Bool = false + + override var useAllDisplays: Bool { + return allDisplays + } + override func createWallpaper(screen: NSScreen) -> NSImage? { guard let wallpaper = loadWallpaperImage(wallpaper: wallpaper, screen: screen) else { return nil