Skip to content

Commit

Permalink
Use Mac-specific input devices when possible (#524)
Browse files Browse the repository at this point in the history
* Use VZMacKeyboardConfiguration when possible

* Use VZMacTrackpadConfiguration when possible
  • Loading branch information
edigaryev authored Jun 23, 2023
1 parent e89ef32 commit 1b53ce4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Sources/tart/Platform/Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,17 @@ struct Darwin: Platform {
return result
}

func keyboards() -> [VZKeyboardConfiguration] {
if #available(macOS 14, *) {
return [VZMacKeyboardConfiguration()]
} else {
return [VZUSBKeyboardConfiguration()]
}
}

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()]
return [VZMacTrackpadConfiguration()]
} else {
return [VZUSBScreenCoordinatePointingDeviceConfiguration()]
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/tart/Platform/Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct Linux: Platform {
return result
}

func keyboards() -> [VZKeyboardConfiguration] {
[VZUSBKeyboardConfiguration()]
}

func pointingDevices() -> [VZPointingDeviceConfiguration] {
[VZUSBScreenCoordinatePointingDeviceConfiguration()]
}
Expand Down
1 change: 1 addition & 0 deletions Sources/tart/Platform/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ protocol Platform: Codable {
func bootLoader(nvramURL: URL) throws -> VZBootLoader
func platform(nvramURL: URL) throws -> VZPlatformConfiguration
func graphicsDevice(vmConfig: VMConfig) -> VZGraphicsDeviceConfiguration
func keyboards() -> [VZKeyboardConfiguration]
func pointingDevices() -> [VZPointingDeviceConfiguration]
}
2 changes: 1 addition & 1 deletion Sources/tart/VM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
configuration.audioDevices = [soundDeviceConfiguration]

// Keyboard and mouse
configuration.keyboards = [VZUSBKeyboardConfiguration()]
configuration.keyboards = vmConfig.platform.keyboards()
configuration.pointingDevices = vmConfig.platform.pointingDevices()

// Networking
Expand Down

0 comments on commit 1b53ce4

Please sign in to comment.