From 12292303a28015e99735d3d38cd4617d0c1d2b4e Mon Sep 17 00:00:00 2001 From: Navonil Majumder Date: Sun, 10 Nov 2024 23:15:06 +0800 Subject: [PATCH 1/2] feature: added option `cross-workspace-floating-windows` to allow floating windows to exist across workspaces --- Sources/AppBundle/config/Config.swift | 1 + Sources/AppBundle/config/parseConfig.swift | 1 + Sources/AppBundle/normalizeLayoutReason.swift | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/AppBundle/config/Config.swift b/Sources/AppBundle/config/Config.swift index 2c0aad91..a79d2b07 100644 --- a/Sources/AppBundle/config/Config.swift +++ b/Sources/AppBundle/config/Config.swift @@ -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 diff --git a/Sources/AppBundle/config/parseConfig.swift b/Sources/AppBundle/config/parseConfig.swift index bca2b5d6..d253b171 100644 --- a/Sources/AppBundle/config/parseConfig.swift +++ b/Sources/AppBundle/config/parseConfig.swift @@ -102,6 +102,7 @@ private let configParser: [String: any ParserProtocol] = [ "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), diff --git a/Sources/AppBundle/normalizeLayoutReason.swift b/Sources/AppBundle/normalizeLayoutReason.swift index fef0520f..16fb6f78 100644 --- a/Sources/AppBundle/normalizeLayoutReason.swift +++ b/Sources/AppBundle/normalizeLayoutReason.swift @@ -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 { From 3370eea92dc16fb30534042577dcce292a6c88d6 Mon Sep 17 00:00:00 2001 From: Navonil Majumder Date: Mon, 11 Nov 2024 20:22:09 +0800 Subject: [PATCH 2/2] Fix traymenu update issue --- Sources/AppBundle/MenuBar.swift | 14 +------------- Sources/AppBundle/TrayMenuModel.swift | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Sources/AppBundle/MenuBar.swift b/Sources/AppBundle/MenuBar.swift index 3d2f9be8..27dc80c9 100644 --- a/Sources/AppBundle/MenuBar.swift +++ b/Sources/AppBundle/MenuBar.swift @@ -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") { diff --git a/Sources/AppBundle/TrayMenuModel.swift b/Sources/AppBundle/TrayMenuModel.swift index 0c4fc270..5fefec18 100644 --- a/Sources/AppBundle/TrayMenuModel.swift +++ b/Sources/AppBundle/TrayMenuModel.swift @@ -1,5 +1,11 @@ import AppKit import Common +import SwiftUI + +struct WorkspaceButton: Identifiable { + let id = UUID() + let button: Button> +} public class TrayMenuModel: ObservableObject { public static let shared = TrayMenuModel() @@ -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() { @@ -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)) + } + }) + } }