-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
_fixes #338 #186 The command is a replacement for planned `move-workspace-to-monitor --workspace <workspace> focused`. The problem with `move-workspace-to-monitor` is that, unlike `move-workspace-to-monitor next|prev`, it changes the focused workspace. That's why I think it should be a separate command with its own semantic
- Loading branch information
1 parent
620b246
commit 2fcf32d
Showing
10 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Sources/AppBundle/command/impl/SummonWorkspaceCommand.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import AppKit | ||
import Common | ||
|
||
struct SummonWorkspaceCommand: Command { | ||
let args: SummonWorkspaceCmdArgs | ||
|
||
func run(_ env: CmdEnv, _ io: CmdIo) -> Bool { | ||
check(Thread.current.isMainThread) | ||
let workspace = Workspace.get(byName: args.target.val.raw) | ||
let monitor = focus.workspace.workspaceMonitor | ||
if monitor.activeWorkspace == workspace { | ||
io.err("Workspace '\(workspace.name)' is already visible on the focused monitor. Tip: use --fail-if-noop to exit with non-zero code") | ||
return !args.failIfNoop | ||
} | ||
return monitor.setActiveWorkspace(workspace) && workspace.focusWorkspace() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Sources/AppBundleTests/command/SummonWorkspaceCommandTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@testable import AppBundle | ||
import Common | ||
import XCTest | ||
|
||
final class SummonWorkspaceCommandTest: XCTestCase { | ||
override func setUpWithError() throws { setUpWorkspacesForTests() } | ||
|
||
func testParse() { | ||
assertEquals(parseCommand("summon-workspace").errorOrNil, "ERROR: Argument '<workspace>' is mandatory") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public struct SummonWorkspaceCmdArgs: CmdArgs { | ||
public let rawArgs: EquatableNoop<[String]> | ||
public init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) } | ||
public static let parser: CmdParser<Self> = cmdParser( | ||
kind: .summonWorkspace, | ||
allowInConfig: true, | ||
help: workspace_help_generated, | ||
options: [ | ||
"--fail-if-noop": trueBoolFlag(\.failIfNoop), | ||
], | ||
arguments: [newArgParser(\.target, parseWorkspaceName, mandatoryArgPlaceholder: "<workspace>")] | ||
) | ||
|
||
public var windowId: UInt32? // unused | ||
public var workspaceName: WorkspaceName? // unused | ||
|
||
public var target: Lateinit<WorkspaceName> = .uninitialized | ||
public var failIfNoop: Bool = false | ||
} | ||
|
||
private func parseWorkspaceName(arg: String, nextArgs: inout [String]) -> Parsed<WorkspaceName> { | ||
WorkspaceName.parse(arg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
= aerospace-summon-workspace(1) | ||
include::util/man-attributes.adoc[] | ||
// tag::purpose[] | ||
:manpurpose: Move the requested workspace to the focused monitor. | ||
// end::purpose[] | ||
:manname: aerospace-summon-workspace | ||
|
||
// =========================================================== Synopsis | ||
== Synopsis | ||
[verse] | ||
// tag::synopsis[] | ||
aerospace summon-workspace [-h|--help] [--fail-if-noop] <workspace> | ||
|
||
// end::synopsis[] | ||
|
||
// =========================================================== Description | ||
== Description | ||
|
||
// tag::body[] | ||
{manpurpose} | ||
The moved workspace becomes focused. | ||
The behavior is identical to Xmonad. | ||
|
||
The command makes sense only in multi-monitor setup. | ||
In single monitor setup the command is identical to `workspace` command. | ||
|
||
// =========================================================== Options | ||
include::./util/conditional-options-header.adoc[] | ||
|
||
-h, --help:: Print help | ||
--fail-if-noop:: Exit with non-zero exit code if the workspace already visible on the focused monitor. | ||
|
||
// =========================================================== Arguments | ||
include::./util/conditional-arguments-header.adoc[] | ||
|
||
<workspace>:: The workspace to operate on. | ||
|
||
// end::body[] | ||
|
||
// =========================================================== Footer | ||
include::util/man-footer.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters