Skip to content

Commit b9079bb

Browse files
authored
Merge pull request #148 from Code-Hex/fix/mac-keyboard
fixed mac keyboard
2 parents b24d0b9 + 877edb3 commit b9079bb

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

example/macOS/main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"flag"
67
"fmt"
78
"log"
@@ -85,7 +86,15 @@ func runVM(ctx context.Context) error {
8586
log.Println("call stop")
8687
if err := vm.Stop(); err != nil {
8788
log.Println("stop with error", err)
89+
return
8890
}
91+
// if err := vm.Pause(); err != nil {
92+
// log.Println("pause with error", err)
93+
// return
94+
// }
95+
// if err := vm.SaveMachineStateToPath("savestate"); err != nil {
96+
// log.Println("save state with error", err)
97+
// }
8998
}
9099
}
91100
log.Println("finished cleanup")
@@ -173,8 +182,15 @@ func createNetworkDeviceConfiguration() (*vz.VirtioNetworkDeviceConfiguration, e
173182
return vz.NewVirtioNetworkDeviceConfiguration(natAttachment)
174183
}
175184

176-
func createKeyboardConfiguration() (*vz.USBKeyboardConfiguration, error) {
177-
return vz.NewUSBKeyboardConfiguration()
185+
func createKeyboardConfiguration() (vz.KeyboardConfiguration, error) {
186+
config, err := vz.NewMacKeyboardConfiguration()
187+
if err != nil {
188+
if errors.Is(err, vz.ErrUnsupportedOSVersion) {
189+
return vz.NewUSBKeyboardConfiguration()
190+
}
191+
return nil, err
192+
}
193+
return config, nil
178194
}
179195

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

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

virtualization_14_arm64.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void setOptionsVZLinuxRosettaDirectoryShare(void *rosetta, void *cachingOptions)
151151
{
152152
#ifdef INCLUDE_TARGET_OSX_14
153153
if (@available(macOS 14, *)) {
154-
return [[VZMacTrackpadConfiguration alloc] init];
154+
return [[VZMacKeyboardConfiguration alloc] init];
155155
}
156156
#endif
157157
RAISE_UNSUPPORTED_MACOS_EXCEPTION();

0 commit comments

Comments
 (0)