Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support pasting clipboard from host for Linux VMs #806

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/tart/Commands/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -231,7 +236,8 @@ struct Run: AsyncParsableCommand {
directorySharingDevices: directoryShares() + rosettaDirectoryShare(),
serialPorts: serialPorts,
suspendable: suspendable,
audio: !noAudio
audio: !noAudio,
clipboard: !noClipboard
)

let vncImpl: VNC? = try {
Expand Down
19 changes: 16 additions & 3 deletions Sources/tart/VM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down