Skip to content

Commit d172dfd

Browse files
committed
Fix that menuBar shows incorrect workspace
Apparently, this bug is only reproducible in macOS 15 Sequoia #586 #678
1 parent ba19c7c commit d172dfd

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

Sources/AppBundle/MenuBar.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ public func menuBar(viewModel: TrayMenuModel) -> some Scene {
1212
Divider()
1313
if viewModel.isEnabled {
1414
Text("Workspaces:")
15-
ForEach(Workspace.all) { (workspace: Workspace) in
15+
ForEach(viewModel.workspaces, id: \.name) { workspace in
1616
Button {
17-
refreshSession(screenIsDefinitelyUnlocked: true) { _ = workspace.focusWorkspace() }
17+
refreshSession(screenIsDefinitelyUnlocked: true) { _ = Workspace.get(byName: workspace.name).focusWorkspace() }
1818
} label: {
19-
Toggle(isOn: workspace == focus.workspace
20-
? Binding(get: { true }, set: { _, _ in })
21-
: Binding(get: { false }, set: { _, _ in }))
22-
{
23-
let monitor = workspace.isVisible || !workspace.isEffectivelyEmpty ? " - \(workspace.workspaceMonitor.name)" : ""
24-
Text(workspace.name + monitor).font(.system(.body, design: .monospaced))
19+
Toggle(isOn: .constant(workspace.isFocused)) {
20+
Text(workspace.name + workspace.suffix).font(.system(.body, design: .monospaced))
2521
}
2622
}
2723
}

Sources/AppBundle/TrayMenuModel.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class TrayMenuModel: ObservableObject {
99
@Published var trayText: String = ""
1010
/// Is "layouting" enabled
1111
@Published var isEnabled: Bool = true
12+
@Published var workspaces: [WorkspaceViewModel] = []
1213
}
1314

1415
func updateTrayText() {
@@ -20,4 +21,14 @@ func updateTrayText() {
2021
($0.activeWorkspace == focus.workspace && sortedMonitors.count > 1 ? "*" : "") + $0.activeWorkspace.name
2122
}
2223
.joined(separator: "")
24+
TrayMenuModel.shared.workspaces = Workspace.all.map {
25+
let monitor = $0.isVisible || !$0.isEffectivelyEmpty ? " - \($0.workspaceMonitor.name)" : ""
26+
return WorkspaceViewModel(name: $0.name, suffix: monitor, isFocused: focus.workspace == $0)
27+
}
28+
}
29+
30+
struct WorkspaceViewModel {
31+
let name: String
32+
let suffix: String
33+
let isFocused: Bool
2334
}

Sources/AppBundle/tree/Workspace.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ private func getStubWorkspace(forPoint point: CGPoint) -> Workspace {
3030
?? errorT("Can't create empty workspace")
3131
}
3232

33-
class Workspace: TreeNode, NonLeafTreeNodeObject, Hashable, Identifiable, CustomStringConvertible, Comparable {
33+
class Workspace: TreeNode, NonLeafTreeNodeObject, Hashable, CustomStringConvertible, Comparable {
3434
let name: String
3535
private let nameLogicalSegments: StringLogicalSegments
36-
var id: String { name } // satisfy Identifiable
3736
/// `assignedMonitorPoint` must be interpreted only when the workspace is invisible
3837
fileprivate var assignedMonitorPoint: CGPoint? = nil
3938

0 commit comments

Comments
 (0)