Skip to content

Commit 90d9500

Browse files
authored
chore: adding no-keyboard, no-pointer options for run (#1091)
1 parent b05c731 commit 90d9500

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

Sources/tart/Commands/Run.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ struct Run: AsyncParsableCommand {
266266
#endif
267267
var noTrackpad: Bool = false
268268

269+
@Flag(help: ArgumentHelp("Disable the pointer"))
270+
var noPointer: Bool = false
271+
272+
@Flag(help: ArgumentHelp("Disable the keyboard"))
273+
var noKeyboard: Bool = false
274+
269275
mutating func validate() throws {
270276
if vnc && vncExperimental {
271277
throw ValidationError("--vnc and --vnc-experimental are mutually exclusive")
@@ -317,8 +323,15 @@ struct Run: AsyncParsableCommand {
317323
if noTrackpad {
318324
throw ValidationError("--no-trackpad cannot be used with --suspendable")
319325
}
326+
if noKeyboard {
327+
throw ValidationError("--no-keyboard cannot be used with --suspendable")
328+
}
329+
if noPointer {
330+
throw ValidationError("--no-pointer cannot be used with --suspendable")
331+
}
320332
}
321333

334+
322335
if noTrackpad {
323336
let config = try VMConfig.init(fromURL: vmDir.configURL)
324337
if config.os != .darwin {
@@ -394,7 +407,9 @@ struct Run: AsyncParsableCommand {
394407
clipboard: !noClipboard,
395408
sync: VZDiskImageSynchronizationMode(diskOptions.syncModeRaw),
396409
caching: VZDiskImageCachingMode(diskOptions.cachingModeRaw),
397-
noTrackpad: noTrackpad
410+
noTrackpad: noTrackpad,
411+
noPointer: noPointer,
412+
noKeyboard: noKeyboard
398413
)
399414

400415
let vncImpl: VNC? = try {

Sources/tart/VM.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
5151
clipboard: Bool = true,
5252
sync: VZDiskImageSynchronizationMode = .full,
5353
caching: VZDiskImageCachingMode? = nil,
54-
noTrackpad: Bool = false
54+
noTrackpad: Bool = false,
55+
noPointer: Bool = false,
56+
noKeyboard: Bool = false
5557
) throws {
5658
name = vmDir.name
5759
config = try VMConfig.init(fromURL: vmDir.configURL)
@@ -73,7 +75,9 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
7375
clipboard: clipboard,
7476
sync: sync,
7577
caching: caching,
76-
noTrackpad: noTrackpad
78+
noTrackpad: noTrackpad,
79+
noPointer: noPointer,
80+
noKeyboard: noKeyboard
7781
)
7882
virtualMachine = VZVirtualMachine(configuration: configuration)
7983

@@ -316,7 +320,9 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
316320
clipboard: Bool = true,
317321
sync: VZDiskImageSynchronizationMode = .full,
318322
caching: VZDiskImageCachingMode? = nil,
319-
noTrackpad: Bool = false
323+
noTrackpad: Bool = false,
324+
noPointer: Bool = false,
325+
noKeyboard: Bool = false
320326
) throws -> VZVirtualMachineConfiguration {
321327
let configuration = VZVirtualMachineConfiguration()
322328

@@ -356,8 +362,16 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
356362
configuration.keyboards = platformSuspendable.keyboardsSuspendable()
357363
configuration.pointingDevices = platformSuspendable.pointingDevicesSuspendable()
358364
} else {
359-
configuration.keyboards = vmConfig.platform.keyboards()
360-
if noTrackpad {
365+
366+
if noKeyboard {
367+
configuration.keyboards = []
368+
} else {
369+
configuration.keyboards = vmConfig.platform.keyboards()
370+
}
371+
372+
if noPointer {
373+
configuration.pointingDevices = []
374+
} else if noTrackpad {
361375
configuration.pointingDevices = vmConfig.platform.pointingDevicesSimplified()
362376
} else {
363377
configuration.pointingDevices = vmConfig.platform.pointingDevices()

0 commit comments

Comments
 (0)