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

Fixes #586, #678: Traymenu workspace statuses are not updating #687

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 1 addition & 13 deletions Sources/AppBundle/MenuBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ public func menuBar(viewModel: TrayMenuModel) -> some Scene {
Divider()
if viewModel.isEnabled {
Text("Workspaces:")
ForEach(Workspace.all) { (workspace: Workspace) in
Button {
refreshSession { _ = workspace.focusWorkspace() }
} label: {
Toggle(isOn: workspace == focus.workspace
? Binding(get: { true }, set: { _, _ in })
: Binding(get: { false }, set: { _, _ in }))
{
let monitor = workspace.isVisible || !workspace.isEffectivelyEmpty ? " - \(workspace.workspaceMonitor.name)" : ""
Text(workspace.name + monitor).font(.system(.body, design: .monospaced))
}
}
}
ForEach(viewModel.workspaceStatus) { $0.button }
Divider()
}
Button(viewModel.isEnabled ? "Disable" : "Enable") {
Expand Down
20 changes: 20 additions & 0 deletions Sources/AppBundle/TrayMenuModel.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import AppKit
import Common
import SwiftUI

struct WorkspaceButton: Identifiable {
let id = UUID()
let button: Button<Toggle<Text>>
}

public class TrayMenuModel: ObservableObject {
public static let shared = TrayMenuModel()
Expand All @@ -9,6 +15,7 @@ public class TrayMenuModel: ObservableObject {
@Published var trayText: String = ""
/// Is "layouting" enabled
@Published var isEnabled: Bool = true
@Published var workspaceStatus: [WorkspaceButton] = []
}

func updateTrayText() {
Expand All @@ -19,4 +26,17 @@ func updateTrayText() {
($0.activeWorkspace == focus.workspace && sortedMonitors.count > 1 ? "*" : "") + $0.activeWorkspace.name
}
.joined(separator: " │ ")
TrayMenuModel.shared.workspaceStatus = Workspace.all.map { (workspace: Workspace) in
WorkspaceButton(button: Button {
refreshSession { _ = workspace.focusWorkspace() }
} label: {
Toggle(isOn: workspace == focus.workspace
? Binding(get: { true }, set: { _, _ in })
: Binding(get: { false }, set: { _, _ in }))
{
let monitor = workspace.isVisible || !workspace.isEffectivelyEmpty ? " - \(workspace.workspaceMonitor.name)" : ""
Text(workspace.name + monitor).font(.system(.body, design: .monospaced))
}
})
}
}
1 change: 1 addition & 0 deletions Sources/AppBundle/config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct Config: Copyable {
var defaultRootContainerOrientation: DefaultContainerOrientation = .auto
var startAtLogin: Bool = false
var automaticallyUnhideMacosHiddenApps: Bool = false
var crossWorkspaceFloatingWindows: Bool = false
var accordionPadding: Int = 30
var enableNormalizationOppositeOrientationForNestedContainers: Bool = true
var execOnWorkspaceChange: [String] = [] // todo deprecate
Expand Down
1 change: 1 addition & 0 deletions Sources/AppBundle/config/parseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private let configParser: [String: any ParserProtocol<Config>] = [

"start-at-login": Parser(\.startAtLogin, parseBool),
"automatically-unhide-macos-hidden-apps": Parser(\.automaticallyUnhideMacosHiddenApps, parseBool),
"cross-workspace-floating-windows": Parser(\.crossWorkspaceFloatingWindows, parseBool),
"accordion-padding": Parser(\.accordionPadding, parseInt),
"exec-on-workspace-change": Parser(\.execOnWorkspaceChange, parseExecOnWorkspaceChange),
"exec": Parser(\.execConfig, parseExecConfig),
Expand Down
8 changes: 7 additions & 1 deletion Sources/AppBundle/normalizeLayoutReason.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ private func _normalizeLayoutReason(workspace: Workspace, windows: [Window]) {
window.bind(to: macosMinimizedWindowsContainer, adaptiveWeight: 1, index: INDEX_BIND_LAST)
} else if isMacosWindowOfHiddenApp {
window.layoutReason = .macos(prevParentKind: window.parent.kind)
window.bind(to: workspace.macOsNativeHiddenAppsWindowsContainer, adaptiveWeight: 1, index: INDEX_BIND_LAST)
if !config.crossWorkspaceFloatingWindows || window.parent.kind != .workspace {
window.bind(to: workspace.macOsNativeHiddenAppsWindowsContainer, adaptiveWeight: 1, index: INDEX_BIND_LAST)
} else {
window.bind(to: macosMinimizedWindowsContainer, adaptiveWeight: 1, index: INDEX_BIND_LAST)
}
} else if config.crossWorkspaceFloatingWindows && window.parent.kind == .workspace {
window.bindAsFloatingWindow(to: focus.workspace)
}
case .macos(let prevParentKind):
if !isMacosFullscreen && !isMacosMinimized && !isMacosWindowOfHiddenApp {
Expand Down
Loading