Skip to content

Commit

Permalink
Merge pull request #148 from Code-Hex/fix/mac-keyboard
Browse files Browse the repository at this point in the history
fixed mac keyboard
  • Loading branch information
Code-Hex authored Oct 22, 2023
2 parents b24d0b9 + 877edb3 commit b9079bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions example/macOS/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -85,7 +86,15 @@ func runVM(ctx context.Context) error {
log.Println("call stop")
if err := vm.Stop(); err != nil {
log.Println("stop with error", err)
return
}
// if err := vm.Pause(); err != nil {
// log.Println("pause with error", err)
// return
// }
// if err := vm.SaveMachineStateToPath("savestate"); err != nil {
// log.Println("save state with error", err)
// }
}
}
log.Println("finished cleanup")
Expand Down Expand Up @@ -173,8 +182,15 @@ func createNetworkDeviceConfiguration() (*vz.VirtioNetworkDeviceConfiguration, e
return vz.NewVirtioNetworkDeviceConfiguration(natAttachment)
}

func createKeyboardConfiguration() (*vz.USBKeyboardConfiguration, error) {
return vz.NewUSBKeyboardConfiguration()
func createKeyboardConfiguration() (vz.KeyboardConfiguration, error) {
config, err := vz.NewMacKeyboardConfiguration()
if err != nil {
if errors.Is(err, vz.ErrUnsupportedOSVersion) {
return vz.NewUSBKeyboardConfiguration()
}
return nil, err
}
return config, nil
}

func createAudioDeviceConfiguration() (*vz.VirtioSoundDeviceConfiguration, error) {
Expand Down Expand Up @@ -293,5 +309,11 @@ func setupVMConfiguration(platformConfig vz.PlatformConfiguration) (*vz.VirtualM
return nil, fmt.Errorf("invalid configuration")
}

// If you want to try this one, you need to comment out a few of configs.
//
// if _, err := config.ValidateSaveRestoreSupport(); err != nil {
// return nil, fmt.Errorf("failed to validate save restore configuration: %w", err)
// }

return config, nil
}
2 changes: 1 addition & 1 deletion virtualization_14_arm64.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions)
{
#ifdef INCLUDE_TARGET_OSX_14
if (@available(macOS 14, *)) {
return [[VZMacTrackpadConfiguration alloc] init];
return [[VZMacKeyboardConfiguration alloc] init];
}
#endif
RAISE_UNSUPPORTED_MACOS_EXCEPTION();
Expand Down

0 comments on commit b9079bb

Please sign in to comment.