-
-
Notifications
You must be signed in to change notification settings - Fork 473
Expand file tree
/
Copy pathMoveWorkspaceToMonitorCommand.swift
More file actions
34 lines (31 loc) · 1.45 KB
/
MoveWorkspaceToMonitorCommand.swift
File metadata and controls
34 lines (31 loc) · 1.45 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
import AppKit
import Common
struct MoveWorkspaceToMonitorCommand: Command {
let args: MoveWorkspaceToMonitorCmdArgs
/*conforms*/ var shouldResetClosedWindowsCache = true
func run(_ env: CmdEnv, _ io: CmdIo) -> Bool {
guard let target = args.resolveTargetOrReportError(env, io) else { return false }
let focusedWorkspace = target.workspace
let prevMonitor = focusedWorkspace.workspaceMonitor
switch args.target.val.resolve(target.workspace.workspaceMonitor, wrapAround: args.wrapAround) {
case .success(let targetMonitor):
if targetMonitor.monitorId == prevMonitor.monitorId {
return true
}
let stubWorkspace = getStubWorkspace(for: prevMonitor)
if targetMonitor.setActiveWorkspace(focusedWorkspace) {
check(
prevMonitor.setActiveWorkspace(stubWorkspace),
"getStubWorkspace generated incompatible stub workspace (\(stubWorkspace)) for the monitor (\(prevMonitor)",
)
return true
} else {
return io.err(
"Can't move workspace '\(focusedWorkspace.name)' to monitor '\(targetMonitor.name)'. workspace-to-monitor-force-assignment doesn't allow it",
)
}
case .failure(let msg):
return io.err(msg)
}
}
}