-
-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathSummonWorkspaceCommand.swift
More file actions
42 lines (37 loc) · 1.7 KB
/
SummonWorkspaceCommand.swift
File metadata and controls
42 lines (37 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import AppKit
import Common
struct SummonWorkspaceCommand: Command {
let args: SummonWorkspaceCmdArgs
/*conforms*/ var shouldResetClosedWindowsCache = true
func run(_ env: CmdEnv, _ io: CmdIo) -> Bool {
let workspace = Workspace.get(byName: args.target.val.raw)
let focusedMonitor = focus.workspace.workspaceMonitor
if focusedMonitor.activeWorkspace == workspace {
if !args.failIfNoop {
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
}
if !workspace.isVisible {
// then we just need to summon the workspace to the focused monitor
if focusedMonitor.setActiveWorkspace(workspace) {
return workspace.focusWorkspace()
} else {
return io.err("Can't move workspace '\(workspace.name)' to monitor '\(focusedMonitor.name)'. workspace-to-monitor-force-assignment doesn't allow it")
}
} else {
let otherMonitor = workspace.workspaceMonitor
let currentWorkspace = focusedMonitor.activeWorkspace
switch args.whenVisible {
case .swap:
if otherMonitor.setActiveWorkspace(currentWorkspace) && focusedMonitor.setActiveWorkspace(workspace) {
return workspace.focusWorkspace()
} else {
return io.err("Can't swap workspaces due to monitor force assignment restrictions")
}
case .focus:
return workspace.focusWorkspace()
}
}
}
}