Skip to content

Commit

Permalink
config(apple): make trackpad usage a configurable option
Browse files Browse the repository at this point in the history
Previously, we implemented both the USB pointer and trackpad device but it
introduced double-clicking and scrolling issues (#4636, #4645). After
setting the default to trackpad for macOS, it turns out that Monterey guests
do not have the right driver for it and does not work.

Now, we will attempt to detect Monterey on new installs and enable the
trackpad when it is not Monterey (no earlier macOS versions are supported).
Existing VMs will default to trackpad off for compatibility and will require
manual setting to enable it.

Fixes #5237
  • Loading branch information
osy committed Apr 24, 2023
1 parent af1929e commit 9a5a58b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Configuration/UTMAppleConfigurationVirtualization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct UTMAppleConfigurationVirtualization: Codable {

var hasPointer: Bool = false

var hasTrackpad: Bool = false

var hasRosetta: Bool?

var hasClipboardSharing: Bool = false
Expand All @@ -55,6 +57,7 @@ struct UTMAppleConfigurationVirtualization: Codable {
case hasEntropy = "Entropy"
case hasKeyboard = "Keyboard"
case hasPointer = "Pointer"
case hasTrackpad = "Trackpad"
case rosetta = "Rosetta"
case hasClipboardSharing = "ClipboardSharing"
}
Expand All @@ -70,8 +73,10 @@ struct UTMAppleConfigurationVirtualization: Codable {
hasKeyboard = try values.decode(Bool.self, forKey: .hasKeyboard)
if let legacyPointer = try? values.decode(PointerDevice.self, forKey: .hasPointer) {
hasPointer = legacyPointer != .disabled
hasTrackpad = legacyPointer == .trackpad
} else {
hasPointer = try values.decode(Bool.self, forKey: .hasPointer)
hasTrackpad = try values.decodeIfPresent(Bool.self, forKey: .hasTrackpad) ?? false
}
if #available(macOS 13, *) {
hasRosetta = try values.decodeIfPresent(Bool.self, forKey: .rosetta)
Expand Down Expand Up @@ -138,7 +143,7 @@ extension UTMAppleConfigurationVirtualization {
if hasPointer {
vzconfig.pointingDevices = [VZUSBScreenCoordinatePointingDeviceConfiguration()]
#if arch(arm64)
if #available(macOS 13, *), isMacOSGuest {
if #available(macOS 13, *), isMacOSGuest && hasTrackpad {
// replace with trackpad device
vzconfig.pointingDevices = [VZMacTrackpadConfiguration()]
}
Expand Down
1 change: 1 addition & 0 deletions Platform/Shared/VMWizardOSMacView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct VMWizardOSMacView: View {
await MainActor.run {
wizardState.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: model)
wizardState.macRecoveryIpswURL = url
wizardState.macIsMonterey = image.buildVersion.hasPrefix("21")
wizardState.isSkipBootImage = true
wizardState.bootImageURL = nil
wizardState.next()
Expand Down
3 changes: 3 additions & 0 deletions Platform/Shared/VMWizardState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum VMWizardOS: String, Identifiable {
#if os(macOS) && arch(arm64)
@Published var macPlatform: UTMAppleConfigurationMacPlatform?
@Published var macRecoveryIpswURL: URL?
@Published var macIsMonterey: Bool = false
#endif
@Published var isSkipBootImage: Bool = false
@Published var bootImageURL: URL?
Expand Down Expand Up @@ -264,6 +265,7 @@ enum VMWizardOS: String, Identifiable {
config.system.boot = try! UTMAppleConfigurationBoot(for: .macOS)
config.system.boot.macRecoveryIpswURL = macRecoveryIpswURL
config.system.macPlatform = macPlatform
config.virtualization.hasTrackpad = !macIsMonterey
}
#endif
case .Linux:
Expand Down Expand Up @@ -332,6 +334,7 @@ enum VMWizardOS: String, Identifiable {
if let hardwareModel = restoreImage.mostFeaturefulSupportedConfiguration?.hardwareModel {
self.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: hardwareModel)
self.macRecoveryIpswURL = restoreImage.url
self.macIsMonterey = restoreImage.buildVersion.hasPrefix("21")
} else {
self.alertMessage = AlertMessage(NSLocalizedString("Failed to get latest macOS version from Apple.", comment: "VMWizardState"))
}
Expand Down
4 changes: 4 additions & 0 deletions Platform/macOS/VMConfigAppleVirtualizationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct VMConfigAppleVirtualizationView: View {
Toggle("Enable Keyboard", isOn: $config.hasKeyboard)
Toggle("Enable Pointer", isOn: $config.hasPointer)
}
if #available(macOS 13, *), config.hasPointer {
Toggle("Use Trackpad", isOn: $config.hasTrackpad)
.help("Allows passing through additional input from trackpads. Only supported on macOS 13+ guests.")
}
if #available(macOS 13, *), operatingSystem == .linux {
#if arch(arm64)
Toggle("Enable Rosetta on Linux (x86_64 Emulation)", isOn: $config.hasRosetta.bound)
Expand Down

0 comments on commit 9a5a58b

Please sign in to comment.