Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple screens support #38

Merged
merged 2 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 18 additions & 10 deletions Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
7 changes: 7 additions & 0 deletions Sources/ChangeMenuBarColor/Commands/Gradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Sources/ChangeMenuBarColor/Commands/SolidColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down