diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index e877bf3b..6ca0d5e3 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -40,6 +40,11 @@ struct Run: AsyncParsableCommand { @Flag(help: "Disable audio pass-through to host.") var noAudio: Bool = false + @Flag(help: ArgumentHelp( + "Disable clipboard sharing between host and guest.", + discussion: "Only works with Linux-based guest operating systems.")) + var noClipboard: Bool = false + #if arch(arm64) @Flag(help: "Boot into recovery mode") #endif @@ -231,7 +236,8 @@ struct Run: AsyncParsableCommand { directorySharingDevices: directoryShares() + rosettaDirectoryShare(), serialPorts: serialPorts, suspendable: suspendable, - audio: !noAudio + audio: !noAudio, + clipboard: !noClipboard ) let vncImpl: VNC? = try { diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 6a6be9d7..d8467034 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -47,7 +47,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { directorySharingDevices: [VZDirectorySharingDeviceConfiguration] = [], serialPorts: [VZSerialPortConfiguration] = [], suspendable: Bool = false, - audio: Bool = true + audio: Bool = true, + clipboard: Bool = true ) throws { name = vmDir.name config = try VMConfig.init(fromURL: vmDir.configURL) @@ -64,7 +65,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { directorySharingDevices: directorySharingDevices, serialPorts: serialPorts, suspendable: suspendable, - audio: audio + audio: audio, + clipboard: clipboard ) virtualMachine = VZVirtualMachine(configuration: configuration) @@ -283,7 +285,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { directorySharingDevices: [VZDirectorySharingDeviceConfiguration], serialPorts: [VZSerialPortConfiguration], suspendable: Bool = false, - audio: Bool = true + audio: Bool = true, + clipboard: Bool = true ) throws -> VZVirtualMachineConfiguration { let configuration = VZVirtualMachineConfiguration() @@ -328,6 +331,16 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { return vio } + // Clipboard sharing via Spice agent + if clipboard && vmConfig.os == .linux { + let spiceAgentConsoleDevice = VZVirtioConsoleDeviceConfiguration() + let spiceAgentPort = VZVirtioConsolePortConfiguration() + spiceAgentPort.name = VZSpiceAgentPortAttachment.spiceAgentPortName + spiceAgentPort.attachment = VZSpiceAgentPortAttachment() + spiceAgentConsoleDevice.ports[0] = spiceAgentPort + configuration.consoleDevices.append(spiceAgentConsoleDevice) + } + // Storage let attachment: VZDiskImageStorageDeviceAttachment = vmConfig.os == .linux ? // Use "cached" caching mode for virtio drive to prevent fs corruption on linux