From d546725792586a6aa2139654c4d5d554e967280d Mon Sep 17 00:00:00 2001 From: lxsavage <31578557+lxsavage@users.noreply.github.com> Date: Fri, 15 Mar 2024 20:24:15 -0400 Subject: [PATCH 1/3] Implemented "Only show active spaces" which will hide all non-active space numbers from showing on the menubar display --- Spaceman/Helpers/IconCreator.swift | 5 +++++ Spaceman/View/PreferencesView.swift | 10 ++++++++++ Spaceman/View/PreferencesWindow.swift | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Spaceman/Helpers/IconCreator.swift b/Spaceman/Helpers/IconCreator.swift index aa2e4f4e..b7fcd980 100644 --- a/Spaceman/Helpers/IconCreator.swift +++ b/Spaceman/Helpers/IconCreator.swift @@ -158,7 +158,12 @@ 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 { diff --git a/Spaceman/View/PreferencesView.swift b/Spaceman/View/PreferencesView.swift index 68a95dc3..b1d6e88a 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 @@ -110,6 +111,8 @@ struct PreferencesView: View { .fontWeight(.semibold) LaunchAtLogin.Toggle(){Text("Launch Spaceman at login")} Toggle("Refresh spaces in background", isOn: $autoRefreshSpaces) + Toggle("Only show active spaces", isOn: $hideInactiveSpaces) + .disabled(selectedStyle == 0) // Rectangles style shortcutRecorder.disabled(autoRefreshSpaces ? true : false) } .padding() @@ -123,6 +126,9 @@ struct PreferencesView: View { KeyboardShortcuts.enable(.refresh) } } + .onChange(of: hideInactiveSpaces) { _ in + NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ButtonPressed"), object: nil) + } Divider() @@ -159,6 +165,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 From 504f4b4d2cdbc39952fa254f01ca9e2ff9a51dca Mon Sep 17 00:00:00 2001 From: lxsavage <31578557+lxsavage@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:27:19 -0400 Subject: [PATCH 2/3] Fixed active icon spacing issue when in hiding inactive spaces --- Spaceman/Helpers/IconCreator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spaceman/Helpers/IconCreator.swift b/Spaceman/Helpers/IconCreator.swift index b7fcd980..6e75240d 100644 --- a/Spaceman/Helpers/IconCreator.swift +++ b/Spaceman/Helpers/IconCreator.swift @@ -166,7 +166,7 @@ class IconCreator { 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 From abe458046ce9f1ba5dd8a38fd798c5fc7ff5a86b Mon Sep 17 00:00:00 2001 From: lxsavage <31578557+lxsavage@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:54:04 -0400 Subject: [PATCH 3/3] Moved "Only show active spaces" checkbox to a more logical location --- Spaceman/View/PreferencesView.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Spaceman/View/PreferencesView.swift b/Spaceman/View/PreferencesView.swift index b1d6e88a..66a37075 100644 --- a/Spaceman/View/PreferencesView.swift +++ b/Spaceman/View/PreferencesView.swift @@ -111,8 +111,6 @@ struct PreferencesView: View { .fontWeight(.semibold) LaunchAtLogin.Toggle(){Text("Launch Spaceman at login")} Toggle("Refresh spaces in background", isOn: $autoRefreshSpaces) - Toggle("Only show active spaces", isOn: $hideInactiveSpaces) - .disabled(selectedStyle == 0) // Rectangles style shortcutRecorder.disabled(autoRefreshSpaces ? true : false) } .padding() @@ -126,9 +124,6 @@ struct PreferencesView: View { KeyboardShortcuts.enable(.refresh) } } - .onChange(of: hideInactiveSpaces) { _ in - NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ButtonPressed"), object: nil) - } Divider() @@ -140,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) + } + } } @@ -157,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)