From 57c91d04b4ae9898d37c61dacd3b98be2da93f68 Mon Sep 17 00:00:00 2001 From: Igor Kulman Date: Sun, 17 Jan 2021 13:01:56 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Adding=20a=20way=20to=20set=20w?= =?UTF-8?q?allpaper=20for=20all=20displays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Abstract/Command.swift | 28 ++++++++++++------- .../Commands/Gradient.swift | 7 +++++ .../Commands/SolidColor.swift | 7 +++++ 3 files changed, 32 insertions(+), 10 deletions(-) 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 From e9344ccdf9aead4a561aed6362afabb11d72fd4b Mon Sep 17 00:00:00 2001 From: Igor Kulman Date: Sun, 17 Jan 2021 13:05:32 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=96=20Documenting=20the=20way=20to?= =?UTF-8?q?=20use=20multiple=20displays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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.