diff --git a/keyboard_arm64.go b/keyboard_arm64.go new file mode 100644 index 0000000..f2f530e --- /dev/null +++ b/keyboard_arm64.go @@ -0,0 +1,51 @@ +//go:build darwin && arm64 +// +build darwin,arm64 + +package vz + +/* +#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc +#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization +# include "virtualization_14_arm64.h" +*/ +import "C" +import ( + "github.com/Code-Hex/vz/v3/internal/objc" +) + +// MacKeyboardConfiguration is a struct that defines the configuration +// for a Mac keyboard. +// +// This device is only recognized by virtual machines running macOS 14.0 and later. +// In order to support both macOS 13.0 and earlier guests, VirtualMachineConfiguration.keyboards +// can be set to an array containing both a MacKeyboardConfiguration and +// a USBKeyboardConfiguration object. macOS 14.0 and later guests will use the Mac keyboard device, +// while earlier versions of macOS will use the USB keyboard device. +// +// see: https://developer.apple.com/documentation/virtualization/vzmackeyboardconfiguration?language=objc +type MacKeyboardConfiguration struct { + *pointer + + *baseKeyboardConfiguration +} + +var _ KeyboardConfiguration = (*MacKeyboardConfiguration)(nil) + +// NewMacKeyboardConfiguration creates a new MacKeyboardConfiguration. +// +// This is only supported on macOS 14 and newer, error will +// be returned on older versions. +func NewMacKeyboardConfiguration() (*MacKeyboardConfiguration, error) { + if err := macOSAvailable(14); err != nil { + return nil, err + } + config := &MacKeyboardConfiguration{ + pointer: objc.NewPointer( + C.newVZMacKeyboardConfiguration(), + ), + } + objc.SetFinalizer(config, func(self *MacKeyboardConfiguration) { + objc.Release(self) + }) + return config, nil +} diff --git a/virtualization_14_arm64.h b/virtualization_14_arm64.h index dd4bb86..ddf8b71 100644 --- a/virtualization_14_arm64.h +++ b/virtualization_14_arm64.h @@ -21,4 +21,5 @@ void *newVZLinuxRosettaUnixSocketCachingOptionsWithPath(const char *path, void * uint32_t maximumPathLengthVZLinuxRosettaUnixSocketCachingOptions(); uint32_t maximumNameLengthVZLinuxRosettaAbstractSocketCachingOptions(); void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions); +void *newVZMacKeyboardConfiguration(); #endif \ No newline at end of file diff --git a/virtualization_14_arm64.m b/virtualization_14_arm64.m index a5e19e0..6ac992b 100644 --- a/virtualization_14_arm64.m +++ b/virtualization_14_arm64.m @@ -136,3 +136,23 @@ void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions) #endif RAISE_UNSUPPORTED_MACOS_EXCEPTION(); } + +/*! + @abstract Configuration for a Mac keyboard. + @discussion + This device can be used by VZVirtualMachineView to send keyboard events to the virtual machine. + This keyboard supports Apple-specific features such as the globe key. + Note: this device is only recognized by virtual machines running macOS 13.0 and later. In order to support both macOS 13.0 and earlier + guests, VZVirtualMachineConfiguration.keyboards can be set to an array containing both a VZMacKeyboardConfiguration and + a VZUSBKeyboardConfiguration object. macOS 13.0 and later guests will use the Mac keyboard device, + while earlier versions of macOS will use the USB keyboard device. + */ +void *newVZMacKeyboardConfiguration() +{ +#ifdef INCLUDE_TARGET_OSX_14 + if (@available(macOS 14, *)) { + return [[VZMacTrackpadConfiguration alloc] init]; + } +#endif + RAISE_UNSUPPORTED_MACOS_EXCEPTION(); +} \ No newline at end of file