From 048a5506df871aaddc412ddfabe2e52bec850e57 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Sat, 27 Aug 2022 12:05:45 -0400 Subject: [PATCH] Support trackpad on macOS and clipboard sharing on Linux (#202) Fixes #66 Relates to #14 since fixes on Linux --- Sources/tart/Platform/Darwin.swift | 10 ++++++++++ Sources/tart/Platform/Linux.swift | 4 ++++ Sources/tart/Platform/Platform.swift | 1 + Sources/tart/VM.swift | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/tart/Platform/Darwin.swift b/Sources/tart/Platform/Darwin.swift index 009cf01..eb08d94 100644 --- a/Sources/tart/Platform/Darwin.swift +++ b/Sources/tart/Platform/Darwin.swift @@ -84,4 +84,14 @@ struct Darwin: Platform { return result } + + func pointingDevices() -> [VZPointingDeviceConfiguration] { + if #available(macOS 13, *) { + // Trackpad is only supported starting with macOS Ventura + // macOS Monterey will continue using a USB device == .darwin + return [VZMacTrackpadConfiguration(), VZUSBScreenCoordinatePointingDeviceConfiguration()] + } else { + return [VZUSBScreenCoordinatePointingDeviceConfiguration()] + } + } } diff --git a/Sources/tart/Platform/Linux.swift b/Sources/tart/Platform/Linux.swift index 6938d5c..10ed0c8 100644 --- a/Sources/tart/Platform/Linux.swift +++ b/Sources/tart/Platform/Linux.swift @@ -30,4 +30,8 @@ struct Linux: Platform { return result } + + func pointingDevices() -> [VZPointingDeviceConfiguration] { + [VZUSBScreenCoordinatePointingDeviceConfiguration()] + } } diff --git a/Sources/tart/Platform/Platform.swift b/Sources/tart/Platform/Platform.swift index b7255fc..84abd37 100644 --- a/Sources/tart/Platform/Platform.swift +++ b/Sources/tart/Platform/Platform.swift @@ -5,4 +5,5 @@ protocol Platform: Codable { func bootLoader(nvramURL: URL) throws -> VZBootLoader func platform(nvramURL: URL) -> VZPlatformConfiguration func graphicsDevice(vmConfig: VMConfig) -> VZGraphicsDeviceConfiguration + func pointingDevices() -> [VZPointingDeviceConfiguration] } diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 419f24c..5a5919f 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -256,7 +256,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { // Keyboard and mouse configuration.keyboards = [VZUSBKeyboardConfiguration()] - configuration.pointingDevices = [VZUSBScreenCoordinatePointingDeviceConfiguration()] + configuration.pointingDevices = vmConfig.platform.pointingDevices() // Networking let vio = VZVirtioNetworkDeviceConfiguration()