Skip to content

Commit

Permalink
added VZMacKeyboardConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Hex committed Oct 15, 2023
1 parent 70933c2 commit a924e22
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
51 changes: 51 additions & 0 deletions keyboard_arm64.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions virtualization_14_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions virtualization_14_arm64.m
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit a924e22

Please sign in to comment.