diff --git a/Spaceman/Helpers/IconCreator.swift b/Spaceman/Helpers/IconCreator.swift index aa2e4f4e..6e75240d 100644 --- a/Spaceman/Helpers/IconCreator.swift +++ b/Spaceman/Helpers/IconCreator.swift @@ -158,10 +158,15 @@ class IconCreator { var currentDisplayID = spaces[0].displayID displayCount = 1 + let shouldBypassInactiveSpaces = defaults.bool(forKey: "hideInactiveSpaces") for index in 0 ..< spaces.count { + if shouldBypassInactiveSpaces && !spaces[index].isCurrentSpace { + continue + } + var nextSpaceIsOnDifferentDisplay = false - if index + 1 < spaces.count { + if !shouldBypassInactiveSpaces && index + 1 < spaces.count { let thisDispID = spaces[index + 1].displayID if thisDispID != currentDisplayID { currentDisplayID = thisDispID diff --git a/Spaceman/View/PreferencesView.swift b/Spaceman/View/PreferencesView.swift index 68a95dc3..66a37075 100644 --- a/Spaceman/View/PreferencesView.swift +++ b/Spaceman/View/PreferencesView.swift @@ -16,6 +16,7 @@ struct PreferencesView: View { @AppStorage("displayStyle") private var selectedStyle = 0 @AppStorage("spaceNames") private var data = Data() @AppStorage("autoRefreshSpaces") private var autoRefreshSpaces = false + @AppStorage("hideInactiveSpaces") private var hideInactiveSpaces = false @StateObject private var prefsVM = PreferencesViewModel() // MARK: - Main Body @@ -134,9 +135,15 @@ struct PreferencesView: View { // Toggle("Use single icon indicator", isOn: .constant(false)) // TODO: Implement this spacesStylePicker spaceNameEditor.disabled(selectedStyle != SpacemanStyle.text.rawValue ? true : false) + + Toggle("Only show active spaces", isOn: $hideInactiveSpaces) + .disabled(selectedStyle == 0) // Rectangles style } .padding() - + .onChange(of: hideInactiveSpaces) { _ in + NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ButtonPressed"), object: nil) + } + } } @@ -151,6 +158,7 @@ struct PreferencesView: View { // MARK: - Style Picker private var spacesStylePicker: some View { + Picker(selection: $selectedStyle, label: Text("Style")) { Text("Rectangles").tag(SpacemanStyle.none.rawValue) Text("Numbers").tag(SpacemanStyle.numbers.rawValue) @@ -159,6 +167,10 @@ struct PreferencesView: View { Text("Named spaces").tag(SpacemanStyle.text.rawValue) } .onChange(of: selectedStyle) { val in + if val == 0 { // Rectangles style + hideInactiveSpaces = false + } + selectedStyle = val NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ButtonPressed"), object: nil) } diff --git a/Spaceman/View/PreferencesWindow.swift b/Spaceman/View/PreferencesWindow.swift index 3ef06328..e5e7455a 100644 --- a/Spaceman/View/PreferencesWindow.swift +++ b/Spaceman/View/PreferencesWindow.swift @@ -11,7 +11,7 @@ import AppKit class PreferencesWindow: NSWindow { init() { super.init( - contentRect: NSRect(x: 0, y: 0, width: 400, height: 314), + contentRect: NSRect(x: 0, y: 0, width: 400, height: 330), styleMask: [.titled, .fullSizeContentView], backing: .buffered, defer: false